From 17056c5b7fb299d8c5ad980507d7e5f440c88e3f Mon Sep 17 00:00:00 2001
From: Iztok Jeras <iztok.jeras@redpitaya.com>
Date: 摹曛, 08 10月 2015 03:00:34 +0800
Subject: [PATCH] integer parser: fixed return values

---
 libscpi/src/units.c |   28 +++++++++++++++++++---------
 1 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/libscpi/src/units.c b/libscpi/src/units.c
index d4f3784..acf44fa 100644
--- a/libscpi/src/units.c
+++ b/libscpi/src/units.c
@@ -38,6 +38,7 @@
 #include "scpi/parser.h"
 #include "scpi/units.h"
 #include "utils_private.h"
+#include "scpi/utils.h"
 #include "scpi/error.h"
 #include "lexer_private.h"
 
@@ -205,7 +206,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);
@@ -230,8 +231,10 @@
         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;
+        default:
             break;
     }
 
@@ -249,6 +252,8 @@
             break;
         case SCPI_TOKEN_OCTNUM:
             value->base = 8;
+            break;
+        default:
             break;
     }
 
@@ -279,10 +284,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:
@@ -309,12 +314,17 @@
         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);
+    result = SCPI_DoubleToStr(value->value, str, len);
 
     unit = translateUnitInverse(context->units, value->unit);
 

--
Gitblit v1.9.1