From 2e78fdc66afab833fdbba16dd12f0e69df54700c Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@mobatime.cz>
Date: 周三, 05 9月 2018 23:35:28 +0800
Subject: [PATCH] Fix #103 semicolon with empty command causes problems

---
 libscpi/src/parser.c       |    3 ++-
 libscpi/test/test_parser.c |    8 ++++++++
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index 0e85599..67b9bd5 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -340,7 +340,8 @@
                 context->buffer.position -= totcmdlen;
                 totcmdlen = 0;
             } else {
-                if (context->parser_state.programHeader.type == SCPI_TOKEN_UNKNOWN) break;
+                if (context->parser_state.programHeader.type == SCPI_TOKEN_UNKNOWN
+                        && context->parser_state.termination == SCPI_MESSAGE_TERMINATION_NONE) break;
                 if (totcmdlen >= context->buffer.position) break;
             }
         }
diff --git a/libscpi/test/test_parser.c b/libscpi/test/test_parser.c
index 76e8008..fc33a74 100644
--- a/libscpi/test/test_parser.c
+++ b/libscpi/test/test_parser.c
@@ -265,6 +265,14 @@
     TEST_INPUT("\r\n", "MA,IN,0,VER\r\n");
     output_buffer_clear();
 
+    /* Test empty command at the beggining */
+    TEST_INPUT(";*IDN?\r\n", "MA,IN,0,VER\r\n");
+    output_buffer_clear();
+
+    TEST_INPUT(";", "");
+    TEST_INPUT("*IDN?\r\n", "MA,IN,0,VER\r\n");
+    output_buffer_clear();
+
     /* Test input "timeout" - input with length == 0 */
     TEST_INPUT("*IDN?", "");
     TEST_INPUT("", "MA,IN,0,VER\r\n");

--
Gitblit v1.9.1