////////// // // Function: INT() // Takes a value and returns the INT(n) of that value. // ////// // Version 0.58 // Last update: // Apr.02.2015 ////// // Change log: // Apr.02.2015 - Refactoring // Jul.13.2014 - Initial creation ////// // Parameters: // p1 -- Numeric or floating point // ////// // Returns: // INT(n) of the value in p1 ////// void function_int(SReturnsParams* rpar) { SVariable* varNumber = rpar->ip[0]; f64 fValue; u32 errorNum; bool error; SVariable* result; ////////// // Parameter 1 must be numeric ////// rpar->rp[0] = NULL; if (!iVariable_isValid(varNumber) || !iVariable_isTypeNumeric(varNumber)) { iError_report_byNumber(_ERROR_PARAMETER_IS_INCORRECT, iVariable_get_relatedComp(varNumber), false); return; } ////////// // Based on its type, process it accordingly ////// if (iVariable_isTypeFloatingPoint(varNumber)) { fValue = iiVariable_getAs_f64(varNumber, false, &error, &errorNum); if (error) { iError_report_byNumber(errorNum, iVariable_get_relatedComp(varNumber), false); return; } // Convert to S64 result = iVariable_create(_VAR_TYPE_S64, NULL, true); if (result) *(s64*)result->value.data_s8 = (s64)fValue; } else { // Copy whatever it already is result = iVariable_copy(varNumber, false); } ////////// // Are we good? ////// if (!result) { iError_report(cgcInternalError, false); return; } ////////// // Return our converted result ////// rpar->rp[0] = result; }
////////// // // Function: LOWER() // Converts every character in the string to lowercase. // ////// // Version 0.57 // Last update: // Jul.12.2014 ////// // Change log: // Jul.12.2014 - Initial creation ////// // Parameters: // pString -- Character, the string to lower // ////// // Returns: // Character -- The string with all lowercase characters converted to lowercase ////// void function_lower(SThisCode* thisCode, SFunctionParms* rpar) { SVariable* varString = rpar->params[0]; s32 lnI; SVariable* result; ////////// // Parameter 1 must be character ////// rpar->returns[0] = NULL; if (!iVariable_isValid(varString) || iVariable_getType(varString) != _VAR_TYPE_CHARACTER) { iError_reportByNumber(thisCode, _ERROR_P1_IS_INCORRECT, iVariable_getRelatedComp(thisCode, varString), false); return; } ////////// // Create our return result ////// result = iVariable_create(thisCode, _VAR_TYPE_CHARACTER, NULL, true); if (!result) { iError_report(thisCode, cgcInternalError, false); return; } ////////// // Copy the source string ////// iDatum_duplicate(&result->value, &varString->value); ////////// // Lower every character ////// for (lnI = 0; lnI < result->value.length; lnI++) { if (result->value.data[lnI] >= 'A' && result->value.data[lnI] <= 'Z') result->value.data[lnI] += 0x20; } ////////// // Return our converted result ////// rpar->returns[0] = result; }
////////// // // Function: LEN() // Returns the length of the string. // ////// // Version 0.57 // Last update: // Jul.12.2014 ////// // Change log: // Jul.12.2014 - Initial creation ////// // Parameters: // pString -- Character, the string to return the length from // ////// // Returns: // Numeric -- The length of the string ////// void function_len(SThisCode* thisCode, SFunctionParms* rpar) { SVariable* varString = rpar->params[0]; SVariable* result; ////////// // Parameter 1 must be character ////// rpar->returns[0] = NULL; if (!iVariable_isValid(varString) || iVariable_getType(varString) != _VAR_TYPE_CHARACTER) { iError_reportByNumber(thisCode, _ERROR_P1_IS_INCORRECT, iVariable_getRelatedComp(thisCode, varString), false); return; } ////////// // Create our return result ////// result = iVariable_create(thisCode, _VAR_TYPE_S32, NULL, true); if (!result) { iError_report(thisCode, cgcInternalError, false); return; } ////////// // Populate based on the length ////// *(s32*)result->value.data = varString->value.length; ////////// // Return our converted result ////// rpar->returns[0] = result; }
////////// // // Function: VERSION() // Based on input, retrieves various version information. // ////// // Version 0.58 // Last update: // Jul.13.2014 ////// // Change log: // Jul.13.2014 - Initial creation ////// // Parameters: // pIndex -- (Optional) If present, Numeric, in the range 1..5 // ////// // Returns: // Numeric or Character -- Depending on index, various values are returned ////// void function_version(SReturnsParams* rpar) { SVariable* varIndex = rpar->ip[0]; s32 index; u32 errorNum; bool error; u8* lptr; SVariable* result; ////////// // Parameter 1 must be numeric ////// rpar->rp[0] = NULL; lptr = NULL; if (!iVariable_isValid(varIndex)) { // They are requesting the default information lptr = (u8*)cgcVersionText; } else if (!iVariable_isTypeNumeric(varIndex)) { // The parameter is not numeric iError_report_byNumber(_ERROR_P1_IS_INCORRECT, iVariable_get_relatedComp(varIndex), false); return; } else { // It must be in the range 1..5 index = iiVariable_getAs_s32(varIndex, false, &error, &errorNum); if (error) { iError_report_byNumber(errorNum, iVariable_get_relatedComp(varIndex), false); return; } else if (index < 1 || index > 5) { // We report our own error iError_report((cu8*)"Parameter must be in the range 1..5", false); return; } } ////////// // Create our return result ////// if (lptr || index == 1 || index == 4) { // Character return result = iVariable_create(_VAR_TYPE_CHARACTER, NULL, true); if (lptr) { // Copy the version info iDatum_duplicate(&result->value, lptr, -1); } else if (index == 1) { // Copy the version1 info iDatum_duplicate(&result->value, cgcVersion1Text, -1); } else { // Copy the version4 info iDatum_duplicate(&result->value, cgcVersion4Text, -1); } } else { result = iVariable_create(_VAR_TYPE_S32, NULL, true); if (index == 2) { // 0=runtime, 1=standard, 2=professional *(s32*)result->value.data = gnVersion2; // Oh yeah! } else if (index == 3) { // Localized version *(s32*)result->value.data = gnVersion3; // English } else { // Version in a form like Major.Minor as M.mm, or 123 for version 1.23 *(s32*)result->value.data = gnVersion5; } } if (!result) { iError_report(cgcInternalError, false); return; } ////////// // Return our converted result ////// rpar->rp[0] = result; }
////////// // // Function: LEFT() // Returns the left N characters of a string. // ////// // Version 0.57 // Last update: // Jul.12.2014 ////// // Change log: // Jul.12.2014 - Initial creation ////// // Parameters: // pString -- Character, the string to trim // pCount -- Numeric, the number of characters to copy // ////// // Returns: // Character -- The string of the left N characters ////// void function_left(SThisCode* thisCode, SFunctionParms* rpar) { SVariable* varString = rpar->params[0]; SVariable* varCount = rpar->params[1]; s32 lnLength; u32 errorNum; bool error; SVariable* result; ////////// // Parameter 1 must be character ////// rpar->returns[0] = NULL; if (!iVariable_isValid(varString) || iVariable_getType(varString) != _VAR_TYPE_CHARACTER) { iError_reportByNumber(thisCode, _ERROR_P1_IS_INCORRECT, iVariable_getRelatedComp(thisCode, varString), false); return; } ////////// // Parameter 2 must be numeric ////// if (!iVariable_isValid(varCount) || !iVariable_isTypeNumeric(varCount)) { iError_reportByNumber(thisCode, _ERROR_P2_IS_INCORRECT, iVariable_getRelatedComp(thisCode, varCount), false); return; } ////////// // Find out how long they want our string to be ////// lnLength = iiVariable_getAs_s32(thisCode, varCount, false, &error, &errorNum); if (error) { iError_reportByNumber(thisCode, errorNum, iVariable_getRelatedComp(thisCode, varCount), false); return; } ////////// // Create our return result ////// result = iVariable_create(thisCode, _VAR_TYPE_CHARACTER, NULL, true); if (!result) { iError_report(thisCode, cgcInternalError, false); return; } ////////// // Copy as much of the source string as will fit ////// if (lnLength > 0) iDatum_duplicate(&result->value, varString->value.data_u8, min(varString->value.length, lnLength)); ////////// // Return our converted result ////// rpar->returns[0] = result; }