From b0f3f01bd236b56223d4fbc85aaad61e15062440 Mon Sep 17 00:00:00 2001 From: Andrey Nakin <andrey.nakin@gmail.com> Date: 周五, 20 9月 2013 23:24:04 +0800 Subject: [PATCH] modified: libscpi/inc/scpi/parser.h modified: libscpi/src/parser.c --- libscpi/src/parser.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ libscpi/inc/scpi/parser.h | 2 ++ 2 files changed, 52 insertions(+), 0 deletions(-) diff --git a/libscpi/inc/scpi/parser.h b/libscpi/inc/scpi/parser.h index dfa5608..509879d 100644 --- a/libscpi/inc/scpi/parser.h +++ b/libscpi/inc/scpi/parser.h @@ -54,11 +54,13 @@ size_t SCPI_ResultInt(scpi_t * context, int32_t val); size_t SCPI_ResultDouble(scpi_t * context, double val); size_t SCPI_ResultText(scpi_t * context, const char * data); + size_t SCPI_ResultBool(scpi_t * context, bool_t val); bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, bool_t mandatory); bool_t SCPI_ParamDouble(scpi_t * context, double * value, bool_t mandatory); bool_t SCPI_ParamString(scpi_t * context, const char ** value, size_t * len, bool_t mandatory); bool_t SCPI_ParamText(scpi_t * context, const char ** value, size_t * len, bool_t mandatory); + bool_t SCPI_ParamBool(scpi_t * context, bool_t * value, bool_t mandatory); #ifdef __cplusplus diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index a6acd6e..59713c6 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -364,6 +364,16 @@ } /** + * Write boolean value to the result + * @param context + * @param val + * @return + */ +size_t SCPI_ResultBool(scpi_t * context, bool_t val) { + return SCPI_ResultInt(context, val); +} + +/** * Write double walue to the result * @param context * @param val @@ -567,3 +577,43 @@ return FALSE; } + +/** + * Parse boolean parameter + * @param context + * @param value + * @param mandatory + * @return + */ +bool_t SCPI_ParamBool(scpi_t * context, bool_t * value, bool_t mandatory) { + const char * param; + size_t param_len; + size_t num_len; + int32_t i; + + if (!value) { + return FALSE; + } + + if (!SCPI_ParamString(context, ¶m, ¶m_len, mandatory)) { + return FALSE; + } + + if (matchPattern("ON", 2, param, param_len)) { + *value = TRUE; + } else if (matchPattern("OFF", 3, param, param_len)) { + *value = FALSE; + } else { + num_len = strToLong(param, &i); + + if (num_len != param_len) { + SCPI_ErrorPush(context, SCPI_ERROR_SUFFIX_NOT_ALLOWED); + return FALSE; + } + + *value = i ? TRUE : FALSE; + } + + return TRUE; +} + -- Gitblit v1.9.1