From 932061c92277c46278b2b4027e1fdb873e1bc19b Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周二, 04 12月 2012 18:28:17 +0800 Subject: [PATCH] Update README - file structure --- scpi/scpi_units.c | 37 +++++++++++++++++++++++++------------ 1 files changed, 25 insertions(+), 12 deletions(-) diff --git a/scpi/scpi_units.c b/scpi/scpi_units.c index 723e0d9..5754109 100644 --- a/scpi/scpi_units.c +++ b/scpi/scpi_units.c @@ -35,7 +35,7 @@ */ #include <string.h> -#include "scpi.h" +#include "scpi_parser.h" #include "scpi_units.h" #include "scpi_utils.h" #include "scpi_error.h" @@ -114,6 +114,10 @@ static scpi_special_number_t translateSpecialNumber(const scpi_special_number_def_t * specs, const char * str, size_t len) { int i; + if (specs == NULL) { + return SCPI_NUM_NUMBER; + } + for (i = 0; specs[i].name != NULL; i++) { if (matchPattern(specs[i].name, strlen(specs[i].name), str, len)) { return specs[i].type; @@ -126,6 +130,10 @@ static const char * translateSpecialNumberInverse(const scpi_special_number_def_t * specs, scpi_special_number_t type) { int i; + if (specs == NULL) { + return NULL; + } + for (i = 0; specs[i].name != NULL; i++) { if (specs[i].type == type) { return specs[i].name; @@ -137,6 +145,11 @@ static const scpi_unit_def_t * translateUnit(const scpi_unit_def_t * units, const char * unit, size_t len) { int i; + + if (units == NULL) { + return NULL; + } + for (i = 0; units[i].name != NULL; i++) { if (compareStr(unit, len, units[i].name, strlen(units[i].name))) { return &units[i]; @@ -148,6 +161,11 @@ static const char * translateUnitInverse(const scpi_unit_def_t * units, const scpi_unit_t unit) { int i; + + if (units == NULL) { + return NULL; + } + for (i = 0; units[i].name != NULL; i++) { if ((units[i].unit == unit) && (units[i].mult == 1)) { return units[i].name; @@ -186,13 +204,11 @@ * @param mandatory if the parameter is mandatory * @return */ -bool_t SCPI_ParamNumber(scpi_context_t * context, scpi_number_t * value, bool_t mandatory) { +bool_t SCPI_ParamNumber(scpi_t * context, scpi_number_t * value, bool_t mandatory) { bool_t result; char * param; size_t len; size_t numlen; - - // TODO: get scpi_special_numbers_def and scpi_units_def from context result = SCPI_ParamString(context, ¶m, &len, mandatory); @@ -211,7 +227,7 @@ value->unit = SCPI_UNIT_NONE; value->value = 0.0; - value->type = translateSpecialNumber(scpi_special_numbers_def, param, len); + value->type = translateSpecialNumber(context->special_numbers, param, len); if (value->type != SCPI_NUM_NUMBER) { // found special type @@ -221,7 +237,7 @@ numlen = strToDouble(param, &value->value); if (numlen <= len) { - if (transformNumber(scpi_units_def, param + numlen, len - numlen, value)) { + if (transformNumber(context->units, param + numlen, len - numlen, value)) { return TRUE; } else { SCPI_ErrorPush(context, SCPI_ERROR_INVALID_SUFFIX); @@ -231,19 +247,16 @@ } -size_t SCPI_NumberToStr(scpi_context_t * context, scpi_number_t * value, char * str, size_t len) { +size_t SCPI_NumberToStr(scpi_t * context, scpi_number_t * value, char * str, size_t len) { const char * type; const char * unit; size_t result; - - (void) context; // TODO: get scpi_special_numbers_def and scpi_units_def from context - if (!value || !str) { return 0; } - type = translateSpecialNumberInverse(scpi_special_numbers_def, value->type); + type = translateSpecialNumberInverse(context->special_numbers, value->type); if (type) { strncpy(str, type, len); @@ -252,7 +265,7 @@ result = doubleToStr(value->value, str, len); - unit = translateUnitInverse(scpi_units_def, value->unit); + unit = translateUnitInverse(context->units, value->unit); if (unit) { strncat(str, " ", len); -- Gitblit v1.9.1