From a2e83e5ff635f040cffe4c12cfdaa60fa320c3de Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周三, 22 4月 2015 01:59:50 +0800
Subject: [PATCH] Make public SCPI_LongToStr, SCPI_DoubleToStr

---
 libscpi/src/parser.c |   34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index 1f4e9d7..49080ff 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -39,7 +39,8 @@
 
 #include "scpi/config.h"
 #include "scpi/parser.h"
-#include "utils.h"
+#include "scpi/utils_private.h"
+#include "scpi/utils.h"
 #include "scpi/error.h"
 #include "scpi/constants.h"
 
@@ -236,6 +237,9 @@
             context->paramlist.cmd = cmd;
             context->paramlist.parameters = cmdline_ptr + cmd_len;
             context->paramlist.length = cmdline_len - cmd_len;
+            context->paramlist.cmd_raw.data = cmdline_ptr;
+            context->paramlist.cmd_raw.length = cmd_len;
+            context->paramlist.cmd_raw.position = 0;
             return TRUE;
         }
     }
@@ -379,7 +383,7 @@
 size_t SCPI_ResultInt(scpi_t * context, int32_t val) {
     char buffer[12];
     size_t result = 0;
-    size_t len = longToStr(val, buffer, sizeof (buffer));
+    size_t len = SCPI_LongToStr(val, buffer, sizeof (buffer), 10);
     result += writeDelimiter(context);
     result += writeData(context, buffer, len);
     context->output_count++;
@@ -405,7 +409,7 @@
 size_t SCPI_ResultDouble(scpi_t * context, double val) {
     char buffer[32];
     size_t result = 0;
-    size_t len = doubleToStr(val, buffer, sizeof (buffer));
+    size_t len = SCPI_DoubleToStr(val, buffer, sizeof (buffer));
     result += writeDelimiter(context);
     result += writeData(context, buffer, len);
     context->output_count++;
@@ -543,8 +547,8 @@
 /**
  * Parse string parameter
  * @param context
- * @param value
- * @param len
+ * @param value Pointer to string buffer where pointer to non-null terminated string will be returned
+ * @param len Length of returned non-null terminated string
  * @param mandatory
  * @return 
  */
@@ -574,8 +578,8 @@
 /**
  * Parse text parameter (can be inside "")
  * @param context
- * @param value
- * @param len
+ * @param value Pointer to string buffer where pointer to non-null terminated string will be returned
+ * @param len Length of returned non-null terminated string
  * @param mandatory
  * @return 
  */
@@ -590,8 +594,10 @@
         return FALSE;
     }
 
+    paramSkipWhitespace(context);
     if (locateText(context->paramlist.parameters, context->paramlist.length, value, &length)) {
-        paramSkipBytes(context, length);
+        paramSkipBytes(context, length + 2);
+        paramSkipWhitespace(context);
         if (len) {
             *len = length;
         }
@@ -672,3 +678,15 @@
     return FALSE;
 }
 
+scpi_bool_t SCPI_IsCmd(scpi_t * context, const char * cmd) {
+    if (! context->paramlist.cmd) {
+        return FALSE;
+    }
+
+    const char * pattern = context->paramlist.cmd->pattern;
+    return matchCommand (pattern, cmd, strlen (cmd));
+}
+
+scpi_bool_t SCPI_Match(const char * pattern, const char * value, size_t len) {
+    return matchCommand (pattern, value, len);
+}

--
Gitblit v1.9.1