From 3c575a24e24577b888bc68b4dbc20c43e80eef21 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周一, 16 1月 2023 16:29:40 +0800
Subject: [PATCH] Merge pull request #115 from PolyPik/response_separator_fix

---
 libscpi/src/parser.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index 058cde7..2e83ced 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -93,7 +93,7 @@
  * @return number of characters written
  */
 static size_t writeNewLine(scpi_t * context) {
-    if (context->output_count > 0) {
+    if (!context->first_output) {
         size_t len;
 #ifndef SCPI_LINE_ENDING
 #error no termination character defined
@@ -127,9 +127,12 @@
     const scpi_command_t * cmd = context->param_list.cmd;
     lex_state_t * state = &context->param_list.lex_state;
     scpi_bool_t result = TRUE;
+    scpi_bool_t is_query = context->param_list.cmd_raw.data[context->param_list.cmd_raw.length - 1] == '?';
 
-    /* conditionaly write ; */
-    writeSemicolon(context);
+    /* conditionally write ; */
+    if(!context->first_output && is_query) {
+        writeData(context, ";", 1);
+    }
 
     context->cmd_error = FALSE;
     context->output_count = 0;
@@ -146,6 +149,10 @@
         } else {
             if (context->cmd_error) {
                 result = FALSE;
+            } else {
+                if(context->first_output && is_query) {
+                    context->first_output = FALSE;
+                }
             }
         }
     }
@@ -197,6 +204,7 @@
 
     state = &context->parser_state;
     context->output_count = 0;
+    context->first_output = TRUE;
 
     while (1) {
         r = scpiParser_detectProgramMessageUnit(state, data, len);

--
Gitblit v1.9.1