Jan Breuer
2015-10-04 26f6db056b48a58ac725ea0026a215bfc70bfa73
libscpi/src/expression.c
@@ -39,6 +39,16 @@
#include "lexer_private.h"
/**
 * Parse one range or single value
 * @param state lexical state
 * @param isRange return true if parsed expression is range
 * @param valueFrom return parsed value from
 * @param valueTo return parsed value to
 * @return SCPI_EXPR_OK - parsing was succesful
 *         SCPI_EXPR_ERROR - parser error
 *         SCPI_EXPR_NO_MORE - no more data
 */
static scpi_expr_result_t numericRange(lex_state_t * state, scpi_bool_t * isRange, scpi_token_t * valueFrom, scpi_token_t * valueTo)
{
    if (scpiLex_DecimalNumericProgramData(state, valueFrom)) {
@@ -58,11 +68,24 @@
    return SCPI_EXPR_NO_MORE;
}
/**
 * Parse entry on specified position
 * @param context scpi context
 * @param param input parameter
 * @param index index of position (start from 0)
 * @param isRange return true if expression at index was range
 * @param valueFrom return value from
 * @param valueTo return value to
 * @return SCPI_EXPR_OK - parsing was succesful
 *         SCPI_EXPR_ERROR - parser error
 *         SCPI_EXPR_NO_MORE - no more data
 * @see SCPI_ExprNumericListEntryInt, SCPI_ExprNumericListEntryDouble
 */
scpi_expr_result_t SCPI_ExprNumericListEntry(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, scpi_parameter_t * valueFrom, scpi_parameter_t * valueTo)
{
    lex_state_t lex;
    int i;
    scpi_expr_result_t res;
    scpi_expr_result_t res = SCPI_EXPR_OK;
    if (!isRange || !valueFrom || !valueTo || !param) {
        SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR);
@@ -85,7 +108,7 @@
        }
        if (i != index) {
            if (!scpiLex_Comma(&lex, valueFrom)) {
                res = SCPI_EXPR_ERROR;
                res = scpiLex_IsEos(&lex) ? SCPI_EXPR_NO_MORE : SCPI_EXPR_ERROR;
                break;
            }
        }
@@ -97,6 +120,19 @@
    return res;
}
/**
 * Parse entry on specified position and convert result to int32_t
 * @param context scpi context
 * @param param input parameter
 * @param index index of position (start from 0)
 * @param isRange return true if expression at index was range
 * @param valueFrom return value from
 * @param valueTo return value to
 * @return SCPI_EXPR_OK - parsing was succesful
 *         SCPI_EXPR_ERROR - parser error
 *         SCPI_EXPR_NO_MORE - no more data
 * @see SCPI_ExprNumericListEntry, SCPI_ExprNumericListEntryDouble
 */
scpi_expr_result_t SCPI_ExprNumericListEntryInt(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, int32_t * valueFrom, int32_t * valueTo)
{
    scpi_expr_result_t res;
@@ -106,15 +142,29 @@
    res = SCPI_ExprNumericListEntry(context, param, index, &range, &paramFrom, &paramTo);
    if (res == SCPI_EXPR_OK) {
        *isRange = range;
        SCPI_ParamToInt(context, &paramFrom, valueFrom);
        if (range) {
            SCPI_ParamToInt(context, &paramTo, valueFrom);
            SCPI_ParamToInt(context, &paramTo, valueTo);
        }
    }
    return res;
}
/**
 * Parse entry on specified position and convert result to double
 * @param context scpi context
 * @param param input parameter
 * @param index index of position (start from 0)
 * @param isRange return true if expression at index was range
 * @param valueFrom return value from
 * @param valueTo return value to
 * @return SCPI_EXPR_OK - parsing was succesful
 *         SCPI_EXPR_ERROR - parser error
 *         SCPI_EXPR_NO_MORE - no more data
 * @see SCPI_ExprNumericListEntry, SCPI_ExprNumericListEntryInt
 */
scpi_expr_result_t SCPI_ExprNumericListEntryDouble(scpi_t * context, scpi_parameter_t * param, int index, scpi_bool_t * isRange, double * valueFrom, double * valueTo)
{
    scpi_expr_result_t res;
@@ -124,9 +174,10 @@
    res = SCPI_ExprNumericListEntry(context, param, index, &range, &paramFrom, &paramTo);
    if (res == SCPI_EXPR_OK) {
        *isRange = range;
        SCPI_ParamToDouble(context, &paramFrom, valueFrom);
        if (range) {
            SCPI_ParamToDouble(context, &paramTo, valueFrom);
            SCPI_ParamToDouble(context, &paramTo, valueTo);
        }
    }