Andrey Nakin
2013-09-20 b0f3f01bd236b56223d4fbc85aaad61e15062440
libscpi/src/parser.c
@@ -272,6 +272,7 @@
            }
        }
        cmdline_ptr = cmdlineNext(cmdline_ptr, cmdline_end - cmdline_ptr);
        cmdline_ptr += skipWhitespace(cmdline_ptr, cmdline_end - cmdline_ptr);
    }
    return result;
}
@@ -360,6 +361,16 @@
    result += writeData(context, buffer, len);
    context->output_count++;
    return result;
}
/**
 * Write boolean value to the result
 * @param context
 * @param val
 * @return
 */
size_t SCPI_ResultBool(scpi_t * context, bool_t val) {
   return SCPI_ResultInt(context, val);
}
/**
@@ -566,3 +577,43 @@
    return FALSE;
}
/**
 * Parse boolean parameter
 * @param context
 * @param value
 * @param mandatory
 * @return
 */
bool_t SCPI_ParamBool(scpi_t * context, bool_t * value, bool_t mandatory) {
    const char * param;
    size_t param_len;
    size_t num_len;
    int32_t i;
    if (!value) {
        return FALSE;
    }
    if (!SCPI_ParamString(context, &param, &param_len, mandatory)) {
        return FALSE;
    }
    if (matchPattern("ON", 2, param, param_len)) {
        *value = TRUE;
    } else if (matchPattern("OFF", 3, param, param_len)) {
        *value = FALSE;
    } else {
        num_len = strToLong(param, &i);
        if (num_len != param_len) {
            SCPI_ErrorPush(context, SCPI_ERROR_SUFFIX_NOT_ALLOWED);
            return FALSE;
        }
        *value = i ? TRUE : FALSE;
    }
    return TRUE;
}