From 59d4618036c85dafc9026d0f84ab00fcb900acc9 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周三, 23 10月 2013 21:46:41 +0800
Subject: [PATCH] merge functionality from 'master' branch

---
 libscpi/src/parser.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index 2a0eabf..c65e6bc 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -42,6 +42,7 @@
 #include "scpi/lexer.h"
 #include "utils.h"
 #include "scpi/error.h"
+#include "scpi/constants.h"
 
 /**
  * Write data to SCPI output
@@ -74,7 +75,7 @@
  */
 static size_t writeDelimiter(scpi_t * context) {
     if (context->output_count > 0) {
-        return writeData(context, ", ", 2);
+        return writeData(context, ",", 2);
     } else {
         return 0;
     }
@@ -168,7 +169,7 @@
         r = SCPI_DetectProgramMessageUnit(state, data, len);
 
         if (state->programHeader.type == TokInvalid) {
-            SCPI_ErrorPush(context, SCPI_ERROR_UNEXPECTED_CHARACTER);
+            SCPI_ErrorPush(context, SCPI_ERROR_INVALID_CHARACTER);
         } else if (state->programHeader.len > 0) {
             if (findCommandHeader(context, state->programHeader.ptr, state->programHeader.len)) {
 
@@ -203,6 +204,19 @@
  * @param interface
  */
 void SCPI_Init(scpi_t * context) {
+    if (context->idn[0] == NULL) {
+        context->idn[0] = SCPI_DEFAULT_1_MANUFACTURE;
+    }
+    if (context->idn[1] == NULL) {
+        context->idn[1] = SCPI_DEFAULT_2_MODEL;
+    }
+    if (context->idn[2] == NULL) {
+        context->idn[2] = SCPI_DEFAULT_3;
+    }
+    if (context->idn[3] == NULL) {
+        context->idn[3] = SCPI_DEFAULT_4_REVISION;
+    }
+
     context->buffer.position = 0;
     SCPI_ErrorInit(context);
 }
@@ -433,7 +447,7 @@
             parameter->type = TokUnknown;
             parameter->data.ptr = NULL;
             parameter->data.len = 0;
-            SCPI_ErrorPush(context, SCPI_ERROR_UNKNOWN_PARAMETER);
+            SCPI_ErrorPush(context, SCPI_ERROR_INVALID_STRING_DATA);
             return FALSE;
     }
 }
@@ -447,7 +461,7 @@
         case TokDecimalNumericProgramDataWithSuffix:
             return parameter->number.value;
         default:
-            SCPI_ErrorPush(context, SCPI_ERROR_INVALID_PARAMETER);
+            SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR);
             return 0;
     }
 }
@@ -472,15 +486,41 @@
             } else if (compareStr("OFF", 3, parameter->data.ptr, parameter->data.len)) {
                 return FALSE;
             } else {
-                SCPI_ErrorPush(context, SCPI_ERROR_INVALID_PARAMETER);
+                SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
                 return FALSE;
             }
         default:
-            SCPI_ErrorPush(context, SCPI_ERROR_INVALID_PARAMETER);
+            SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR);
             return FALSE;
     }
 }
 
+/**
+ * Get choice parameter
+ */
+int32_t SCPI_ParamGetChoiceVal(scpi_t * context, scpi_parameter_t * parameter, const char * options[]) {
+    size_t res;
+
+    if (!options) {
+        SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR);
+        return -1;
+    }
+
+    switch(parameter->type) {
+        case TokProgramMnemonic:
+            for (res = 0; options[res]; ++res) {
+                if (matchPattern(options[res], strlen(options[res]), parameter->data.ptr, parameter->data.len)) {
+                    return res;
+                }
+            }
+            SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE);
+            return -1;
+        default:
+            SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR);
+            return -1;
+    }
+}
+
 int SCPI_ParseProgramData(lex_state_t * state, token_t * token) {
     token_t tmp;
     int result = 0;

--
Gitblit v1.9.1