From 781ef98e5441bf6aa12c50657bf2161953a79858 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周二, 14 4月 2015 05:38:38 +0800
Subject: [PATCH] Add command handling tests, resolve bugs

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

diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index d7f5eee..1f13b1b 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -75,7 +75,7 @@
  */
 static size_t writeDelimiter(scpi_t * context) {
     if (context->output_count > 0) {
-        return writeData(context, ",", 2);
+        return writeData(context, ",", 1);
     } else {
         return 0;
     }
@@ -258,15 +258,16 @@
         while (1) {
             cmdlen = scpiParser_detectProgramMessageUnit(&context->parser_state, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen);
             totcmdlen += cmdlen;
-            if (context->parser_state.termination == SCPI_MESSAGE_TERMINATION_NL) break;
-            if (context->parser_state.programHeader.type == SCPI_TOKEN_UNKNOWN) break;
-            if (totcmdlen >= context->buffer.position) break;
-        }
 
-        if (context->parser_state.termination == SCPI_MESSAGE_TERMINATION_NL) {
-            result = SCPI_Parse(context, context->buffer.data, totcmdlen);
-            memmove(context->buffer.data, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen);
-            context->buffer.position -= totcmdlen;
+            if (context->parser_state.termination == SCPI_MESSAGE_TERMINATION_NL) {
+                result = SCPI_Parse(context, context->buffer.data, totcmdlen);
+                memmove(context->buffer.data, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen);
+                context->buffer.position -= totcmdlen;
+                totcmdlen = 0;
+            } else {
+                if (context->parser_state.programHeader.type == SCPI_TOKEN_UNKNOWN) break;
+                if (totcmdlen >= context->buffer.position) break;
+            }
         }
     }
 

--
Gitblit v1.9.1