From a10c464ba98e980b21185bf084789f6c8df22473 Mon Sep 17 00:00:00 2001 From: Iztok Jeras <iztok.jeras@gmail.com> Date: 周三, 19 7月 2017 21:03:37 +0800 Subject: [PATCH] moving bool choice definition (ON, OFF) to units.c, so it could be used by various applications --- libscpi/inc/scpi/units.h | 1 + libscpi/src/parser.c | 9 ++------- libscpi/src/units.c | 9 +++++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libscpi/inc/scpi/units.h b/libscpi/inc/scpi/units.h index 975a644..11449db 100644 --- a/libscpi/inc/scpi/units.h +++ b/libscpi/inc/scpi/units.h @@ -45,6 +45,7 @@ extern const scpi_unit_def_t scpi_units_def[]; extern const scpi_choice_def_t scpi_special_numbers_def[]; + extern const scpi_choice_def_t scpi_bool_def[]; scpi_bool_t SCPI_ParamNumber(scpi_t * context, const scpi_choice_def_t * special, scpi_number_t * value, scpi_bool_t mandatory); diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index 1f16ecf..e3b9606 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -44,6 +44,7 @@ #include "scpi/error.h" #include "scpi/constants.h" #include "scpi/utils.h" +#include "scpi/units.h" /** * Write data to SCPI output @@ -1282,12 +1283,6 @@ scpi_parameter_t param; int32_t intval; - scpi_choice_def_t bool_options[] = { - {"OFF", 0}, - {"ON", 1}, - SCPI_CHOICE_LIST_END /* termination of option list */ - }; - if (!value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; @@ -1300,7 +1295,7 @@ SCPI_ParamToInt32(context, ¶m, &intval); *value = intval ? TRUE : FALSE; } else { - result = SCPI_ParamToChoice(context, ¶m, bool_options, &intval); + result = SCPI_ParamToChoice(context, ¶m, scpi_bool_def, &intval); if (result) { *value = intval ? TRUE : FALSE; } diff --git a/libscpi/src/units.c b/libscpi/src/units.c index 3274205..a8bb7f1 100644 --- a/libscpi/src/units.c +++ b/libscpi/src/units.c @@ -285,6 +285,15 @@ SCPI_CHOICE_LIST_END, }; +/* + * Special number values definition + */ +const scpi_choice_def_t scpi_bool_def[] = { + {"OFF", 0}, + {"ON", 1}, + SCPI_CHOICE_LIST_END /* termination of option list */ +}; + /** * Convert string describing unit to its representation * @param units units patterns -- Gitblit v1.9.1