From 77a92c3204b95eaf2870605718b9099ab6ece56a Mon Sep 17 00:00:00 2001
From: nancy.liao <huihui.liao@greentest.com.cn>
Date: 周一, 26 5月 2025 08:41:11 +0800
Subject: [PATCH] 匹配时添加了一个当前索引项

---
 libscpi/src/parser.c |   41 +++++++++++++++++++++--------------------
 1 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index 2240d5c..5e34d1c 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -37,6 +37,7 @@
 
 #include <ctype.h>
 #include <string.h>
+#include "scpi/externinterface.h"
 
 #include "scpi/config.h"
 #include "scpi/parser.h"
@@ -45,7 +46,7 @@
 #include "scpi/error.h"
 #include "scpi/constants.h"
 #include "scpi/utils.h"
-
+#include "scpi/externinterface.h"
 /**
  * Write data to SCPI output
  * @param context
@@ -56,7 +57,7 @@
 static size_t writeData(scpi_t * context, const char * data, size_t len) {
     if ((len > 0) && (data != NULL)) {
         return 0;
-       // return context->interface->write(context, data, len);
+        return context->interface->write(context, data, len);
     } else {
         return 0;
     }
@@ -126,10 +127,9 @@
  */
 
  //璐熷懡浠ゅ洖璋冪殑鎵ц銆佸弬鏁板鐞嗗拰閿欒绠$悊
-static scpi_bool_t processCommand(scpi_t * context) {
-    //杩欎釜鍦版柟淇敼涓� 璇籧omdlist->pattern
+static scpi_bool_t processCommand(scpi_t * context)
+{
     const scpi_command_t * cmd = context->param_list.cmd;
-    //const scpi_command_t * cmd = context->cmdlist->pattern;
     lex_state_t * state = &context->param_list.lex_state;
     scpi_bool_t result = TRUE;
     // 鍏堟娴嬫槸鍚︿负鏌ヨ鍛戒护(浠�?缁撳熬)
@@ -180,23 +180,23 @@
  * @param context
  * @result TRUE if context->paramlist is filled with correct values
  */
-static scpi_bool_t findCommandHeader(scpi_t * context, const char * header, int len) {
-    int32_t i;
-    const scpi_command_t * cmd = NULL;
-    for (i = 0; i<context->cmdlistSize; i++) {
-        cmd = &context->cmdlist[i];
-        bool result =test_match(cmd->pattern, header);
-        if(result)
+scpi_bool_t findCommandHeader(scpi_t * context, const char * header)
+{
+    //鍙傛暟宸茬粡鍦ㄥ墠闈㈤儴鍒嗚В鏋愬畬鎴�,鍖归厤鍛戒护鏃跺氨涓嶅啀闇�瑕佸弬鏁伴儴鍒� 灏嗗懡浠ゆ媶闄ゅ嵆鍙�
+    char *header_copy = strdup(header);
+    char *first_part = strtok(header_copy, " ");
+
+    for(int i=0;i<get_pattern_count();i++)
+    {
+        if( match_segments_global(first_part,i) )
         {
-             context->param_list.cmd = &context->cmdlist[i];
+            setCurrentIndex(i);
+            context->param_list.cmd = &context->cmdlist[i];
+            free(header_copy);
             return TRUE;
         }
-        // if (matchCommand(cmd->pattern, header, len, NULL, 0, 0)) {
-        //     context->param_list.cmd = cmd;
-        //     return TRUE;
-        // }
     }
-    context->SCPIerror = RETURN_NotFind;
+     context->SCPIerror = RETURN_NotFind;
     return FALSE;
 }
 
@@ -246,7 +246,7 @@
             //鍛戒护鏈夋晥寮�濮嬪鐞�
             composeCompoundCommand(&cmd_prev, &state->programHeader);
             //鏌ユ壘鍛戒护鍚庡苟涓旇缃В鏋愮姸鎬佸苟涓旀墽琛屽懡浠�
-            if (findCommandHeader(context, state->programHeader.ptr, state->programHeader.len)) {
+            if (findCommandHeader(context, state->programHeader.ptr)) {
 
                 context->param_list.lex_state.buffer = state->programData.ptr;
                 context->param_list.lex_state.pos = context->param_list.lex_state.buffer;
@@ -362,7 +362,8 @@
  */
 scpi_bool_t SCPI_Input(scpi_t * context, const char * data, int len)
 {
-     scpi_bool_t result = FALSE;
+    clearCurrentGroup();
+    scpi_bool_t result = FALSE;
     size_t totcmdlen = 0;
     int cmdlen = 0;
     //褰撻暱搴︿负0鏃�  瑙f瀽褰撳墠鐨勬暟鎹� 骞朵笖娓呯┖context鐨刡uff鏍囪浣�

--
Gitblit v1.9.1