From fea06605af79832c6abe7a8e6a24c142987994d6 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周二, 22 10月 2013 17:59:45 +0800 Subject: [PATCH] Add more robust detection of case insensitive string compare --- libscpi/src/parser.c | 30 ++++++++++++++++++++++-------- 1 files changed, 22 insertions(+), 8 deletions(-) diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index fb6396f..e333fc7 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -41,6 +41,7 @@ #include "scpi/parser.h" #include "utils.h" #include "scpi/error.h" +#include "scpi/constants.h" static size_t cmdTerminatorPos(const char * cmd, size_t len); @@ -285,6 +286,19 @@ * @param interface */ void SCPI_Init(scpi_t * context) { + if (context->idn[0] == NULL) { + context->idn[0] = SCPI_DEFAULT_1_MANUFACTURE; + } + if (context->idn[1] == NULL) { + context->idn[1] = SCPI_DEFAULT_2_MODEL; + } + if (context->idn[2] == NULL) { + context->idn[2] = SCPI_DEFAULT_3; + } + if (context->idn[3] == NULL) { + context->idn[3] = SCPI_DEFAULT_4_REVISION; + } + context->buffer.position = 0; SCPI_ErrorInit(context); } @@ -579,7 +593,7 @@ } /** - * Parse boolean parameter + * Parse boolean parameter as described in the spec SCPI-99 7.3 Boolean Program Data * @param context * @param value * @param mandatory @@ -625,7 +639,7 @@ * @param mandatory * @return */ -bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], size_t * value, bool_t mandatory) { +bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, bool_t mandatory) { const char * param; size_t param_len; size_t res; @@ -638,14 +652,14 @@ return FALSE; } - for (res = 0; options[res]; ++res) { - if (matchPattern(options[res], strlen(options[res]), param, param_len)) { - *value = res; - return TRUE; - } + for (res = 0; options[res]; ++res) { + if (matchPattern(options[res], strlen(options[res]), param, param_len)) { + *value = res; + return TRUE; + } } - SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); + SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); return FALSE; } -- Gitblit v1.9.1