Exemplo n.º 1
0
void
teststrToULong(){
    
    printf( "Testing strToULong()\n");
    
    TEST( strToULong("999", 10)== 999);
    TEST( strToULong("123",10)== 123);
    TEST( strToULong("123ab",10)== 1);
    TEST( strToULong("999999999999999999",10)== 1);

    
    printf( "Finished running tests on strToULong()\n" );
}
Exemplo n.º 2
0
extern boolean strToUInt(const char *const str, int base, unsigned int *value)
{
	unsigned long ulong_value;

	if(!strToULong(str, base, &ulong_value) || ulong_value > UINT_MAX)
		return false;

	*value = (unsigned int) ulong_value;
	return true;
}
Exemplo n.º 3
0
/**
 * Convert parameter to integer
 * @param context
 * @param parameter
 * @param value result
 * @return TRUE if succesful
 */
static scpi_bool_t ParamToInt(scpi_t * context, scpi_parameter_t * parameter, int32_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 strToULong(parameter->ptr, (uint32_t *)value, 16) > 0 ? TRUE : FALSE;
        case SCPI_TOKEN_OCTNUM:
            return strToULong(parameter->ptr, (uint32_t *)value, 8) > 0 ? TRUE : FALSE;
        case SCPI_TOKEN_BINNUM:
            return strToULong(parameter->ptr, (uint32_t *)value, 2) > 0 ? TRUE : FALSE;
        case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA:
        case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX:
            if (sign) {
                return strToLong(parameter->ptr, value, 10) > 0 ? TRUE : FALSE;
            } else {
                return strToULong(parameter->ptr, (uint32_t *)value, 10) > 0 ? TRUE : FALSE;
            }
    }
    return FALSE;
}
Exemplo n.º 4
0
int cr8LcolFromStr(cli *c, char  *start, uint32 len, uchar *sflag, ulong *col) {
    if (!len) { *sflag = 0; *col = 0;       return 0; }
    if (!strToULong(c, start, len, col, 0)) return -1;
    return cr8Lcol(*col, sflag, col);
}