/** * Convert parameter to signed/unsigned 32 bit integer * @param context * @param parameter * @param value result * @param sign * @return TRUE if succesful */ static scpi_bool_t ParamSignToUInt32(scpi_t * context, scpi_parameter_t * parameter, uint32_t * value, scpi_bool_t sign) { if (!value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } switch (parameter->type) { case SCPI_TOKEN_HEXNUM: return strBaseToUInt32(parameter->ptr, value, 16) > 0 ? TRUE : FALSE; case SCPI_TOKEN_OCTNUM: return strBaseToUInt32(parameter->ptr, value, 8) > 0 ? TRUE : FALSE; case SCPI_TOKEN_BINNUM: return strBaseToUInt32(parameter->ptr, value, 2) > 0 ? TRUE : FALSE; case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: if (sign) { return strBaseToInt32(parameter->ptr, (int32_t *)value, 10) > 0 ? TRUE : FALSE; } else { return strBaseToUInt32(parameter->ptr, value, 10) > 0 ? TRUE : FALSE; } default: return FALSE; } }
/** * Compare two strings, one be longer but may contains only numbers in that section * @param str1 * @param len1 * @param str2 * @param len2 * @return TRUE if strings match */ scpi_bool_t compareStrAndNum(const char * str1, size_t len1, const char * str2, size_t len2, int32_t * num) { scpi_bool_t result = FALSE; size_t i; if (len2 < len1) { return FALSE; } if (SCPIDEFINE_strncasecmp(str1, str2, len1) == 0) { result = TRUE; if (num) { if (len1 == len2) { //*num = 1; } else { int32_t tmpNum; i = len1 + strBaseToInt32(str2 + len1, &tmpNum, 10); if (i != len2) { result = FALSE; } else { *num = tmpNum; } } } else { for (i = len1; i < len2; i++) { if (!isdigit((int) str2[i])) { result = FALSE; break; } } } } return result; }