From 26f6db056b48a58ac725ea0026a215bfc70bfa73 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周日, 04 10月 2015 17:31:20 +0800 Subject: [PATCH] Enable all errors on full blown systems by default --- libscpi/src/expression.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 55 insertions(+), 4 deletions(-) diff --git a/libscpi/src/expression.c b/libscpi/src/expression.c index e0cae6c..1141f0a 100644 --- a/libscpi/src/expression.c +++ b/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, ¶mFrom, ¶mTo); if (res == SCPI_EXPR_OK) { + *isRange = range; SCPI_ParamToInt(context, ¶mFrom, valueFrom); if (range) { - SCPI_ParamToInt(context, ¶mTo, valueFrom); + SCPI_ParamToInt(context, ¶mTo, 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, ¶mFrom, ¶mTo); if (res == SCPI_EXPR_OK) { + *isRange = range; SCPI_ParamToDouble(context, ¶mFrom, valueFrom); if (range) { - SCPI_ParamToDouble(context, ¶mTo, valueFrom); + SCPI_ParamToDouble(context, ¶mTo, valueTo); } } -- Gitblit v1.9.1