From a2006d9935f97a233f75942e1a3eab69f27cf4b3 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周日, 19 4月 2015 17:59:23 +0800 Subject: [PATCH] Update c++ example, make special numbers more correct --- libscpi/src/units.c | 22 ++++++++++++++-------- 1 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libscpi/src/units.c b/libscpi/src/units.c index 792df76..93f1d82 100644 --- a/libscpi/src/units.c +++ b/libscpi/src/units.c @@ -112,6 +112,7 @@ {/* name */ "NAN", /* type */ SCPI_NUM_NAN}, {/* name */ "INFinity", /* type */ SCPI_NUM_INF}, {/* name */ "NINF", /* type */ SCPI_NUM_NINF}, + {/* name */ "AUTO", /* type */ SCPI_NUM_AUTO}, SCPI_CHOICE_LIST_END, }; @@ -204,7 +205,7 @@ lex_state_t state; scpi_parameter_t param; scpi_bool_t result; - int32_t intval; + int32_t tag; if (!value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); @@ -229,7 +230,7 @@ case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: case SCPI_TOKEN_PROGRAM_MNEMONIC: value->unit = SCPI_UNIT_NONE; - value->type = SCPI_NUM_NUMBER; + value->special = FALSE; result = TRUE; break; } @@ -278,10 +279,10 @@ scpiLex_CharacterProgramData(&state, &token); /* convert string to special number type */ - SCPI_ParamToChoice(context, &token, special, &intval); + SCPI_ParamToChoice(context, &token, special, &tag); - value->type = intval; - value->value = 0; + value->special = TRUE; + value->tag = tag; break; default: @@ -308,9 +309,14 @@ return 0; } - if (SCPI_ChoiceToName(special, value->type, &type)) { - strncpy(str, type, len); - return min(strlen(type), len); + if (value->special) { + if (SCPI_ChoiceToName(special, value->tag, &type)) { + strncpy(str, type, len); + return min(strlen(type), len); + } else { + str[0] = 0; + return 0; + } } result = doubleToStr(value->value, str, len); -- Gitblit v1.9.1