From 9b9bc8a81ad303ffb1e5eef12f34702b2aceef60 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周三, 22 4月 2015 03:52:29 +0800
Subject: [PATCH] Support RESPONSE MESSAGE UNIT SEPARATOR, issue #21

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

diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index 5940432..f437018 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -40,6 +40,7 @@
 #include "scpi/config.h"
 #include "scpi/parser.h"
 #include "scpi/utils_private.h"
+#include "scpi/utils.h"
 #include "scpi/error.h"
 #include "scpi/constants.h"
 
@@ -191,6 +192,19 @@
 }
 
 /**
+ * Conditionaly write ";"
+ * @param context
+ * @return number of characters written
+ */
+static size_t writeSemicolon(scpi_t * context) {
+    if (context->output_count > 0) {
+        return writeData(context, ";", 1);
+    } else {
+        return 0;
+    }
+}
+
+/**
  * Process command
  * @param context
  */
@@ -198,6 +212,10 @@
     const scpi_command_t * cmd = context->paramlist.cmd;
 
     context->cmd_error = FALSE;
+
+    /* conditionaly write ; */
+    writeSemicolon(context);
+
     context->output_count = 0;
     context->input_count = 0;
 
@@ -208,9 +226,6 @@
             SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
         }
     }
-
-    /* conditionaly write new line */
-    writeNewLine(context);
 
     /* skip all whitespaces */
     paramSkipWhitespace(context);
@@ -265,6 +280,8 @@
         return -1;
     }
 
+    context->output_count = 0;
+
     while (cmdline_ptr < cmdline_end) {
         result = 0;
         cmd_len = cmdTerminatorPos(cmdline_ptr, cmdline_end - cmdline_ptr);
@@ -284,6 +301,10 @@
         cmdline_ptr += skipCmdLine(cmdline_ptr, cmdline_end - cmdline_ptr);
         cmdline_ptr += skipWhitespace(cmdline_ptr, cmdline_end - cmdline_ptr);
     }
+
+    /* conditionaly write new line */
+    writeNewLine(context);
+
     return result;
 }
 
@@ -382,7 +403,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++;
@@ -408,7 +429,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++;

--
Gitblit v1.9.1