From 11f2f2e329ef404d0e9c022cb2f9fbbb45bae285 Mon Sep 17 00:00:00 2001
From: nancy.liao <huihui.liao@greentest.com.cn>
Date: 周日, 27 4月 2025 17:33:31 +0800
Subject: [PATCH] 完成了SCPI命令语法分析器的完整规则

---
 libscpi/inc/scpi/externinterface.h |  257 +------------------
 /dev/null                          |    2 
 libscpi/inc/scpi/types.h           |    4 
 libscpi/src/parser.c               |   19 -
 libscpi/src/utils_private.h        |    8 
 libscpi/src/utils.c                |   97 -------
 libscpi/src/externinterface.cpp    |  350 ++++++++++++++++++++++++++
 7 files changed, 377 insertions(+), 360 deletions(-)

diff --git a/libscpi/inc/scpi/externinterface.cpp b/libscpi/inc/scpi/externinterface.cpp
deleted file mode 100644
index 1868dce..0000000
--- a/libscpi/inc/scpi/externinterface.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-#include "externinterface.h"
-
diff --git a/libscpi/inc/scpi/externinterface.h b/libscpi/inc/scpi/externinterface.h
index 6e7c4db..03d1107 100644
--- a/libscpi/inc/scpi/externinterface.h
+++ b/libscpi/inc/scpi/externinterface.h
@@ -1,253 +1,34 @@
 #ifndef EXTERNINTERFACE_H
 #define EXTERNINTERFACE_H
-#include <iostream>
-#include<vector>
+
+//杩欎釜绫荤敤鍦ㄥ仛SCPI鍛戒护鐨勮娉曞垎鏋�,浼氬皢璇嶆硶鍖归厤鐨勭粨鏋滆繑鍥炵粰SCPI搴�
 #ifdef __cplusplus
 extern "C"
 {
 #endif
-namespace SCPIPASER
+typedef struct
 {
-class Segment {
-public:
-    //蹇呭~
-    bool is_required = false;
-    //鍙橀噺 [:Measure] 杩欑鐨勪负鍙橀噺 浼氱疆涓篢RUE
-    bool is_variable = false;
-    //鏄惁鏈夊祵濂楀舰寮�
-    bool is_nested = false;
-    // 鍙�夌粍鐨勬暟閲�
-    int variableSize = 0;
-    std::vector<std::string> options;
-    // std::vector<Segment> sub_segments; // 鐢ㄤ簬瀛樺偍宓屽鐨勫彲閫夌粍
-};
+    int is_required;
+    int is_variable;
+    int is_nested;
+    int variableSize;
+    char** options;
+    int options_count;
+} CSegment;
 
-class PatternParser
+typedef struct
 {
-private:
-    static void trim_whitespace(std::string& str)
-    {
-        auto not_space = [](int ch) { return !std::isspace(ch); };
-        str.erase(str.begin(), std::find_if(str.begin(), str.end(), not_space));
-        str.erase(std::find_if(str.rbegin(), str.rend(), not_space).base(), str.end());
-    }
-
-    static std::vector<std::string> split_options(const std::string& input) {
-        std::vector<std::string> result;
-        size_t start = 0;
-        size_t end = input.find('|');
-
-        while (end != std::string::npos) {
-            std::string token = input.substr(start, end - start);
-            trim_whitespace(token);
-            //token = remove_colon(token); // 绉婚櫎鍐掑彿
-            if (!token.empty()) result.push_back(token);
-            start = end + 1;
-            end = input.find('|', start);
-        }
-
-        std::string last_token = input.substr(start);
-        trim_whitespace(last_token);
-        last_token = remove_colon(last_token); // 绉婚櫎鍐掑彿
-        if (!last_token.empty()) result.push_back(last_token);
-        return result;
-    }
-
-    static std::string remove_colon(const std::string& input) {
-        std::string result;
-        for (char ch : input) {
-            if (ch != ':') {
-                result += ch;
-            }
-        }
-        return result;
-    }
-public:
-    static std::vector<std::string> parse_input_data(const std::string& input)
-    {
-        std::vector<std::string> result;
-        size_t start = 0;
-        size_t end = input.find(':');
-
-        while (end != std::string::npos)
-        {
-            result.push_back(input.substr(start, end - start));
-            start = end + 1;
-            end = input.find(':', start);
-        }
-
-        result.push_back(input.substr(start));
-        return result;
-    }
-    static bool match_all_segments(std::vector<std::string> stringList, std::vector<Segment> vecSegment)
-    {
-        int currentIndex = 0;
-        for (int i =0;i<vecSegment.size();i++)
-        {
-            auto currentSegment = vecSegment[i];
-            //涓ユ牸鍖归厤
-            if (currentSegment.is_required)
-            {
-                for (auto option : currentSegment.options)
-                {
-                    if (stringList[currentIndex] != option)
-                    {
-                        //std::cout << "鍙傛暟鍖归厤澶辫触  " << stringList[currentIndex] << "   option :  " << option;
-                        return false;
-                    }
-                    else
-                    {
-                        //std::cout << "鍙傛暟鍖归厤鎴愬姛 " << stringList[currentIndex] << "   option :  " << option<<std::endl;
-                        currentIndex += 1;
-                    }
-                    break;
-                }
-            }
-            //鍙�夌粍
-            else if (currentSegment.is_variable)
-            {
-                //濡傛灉鏈夊彲閫夌粍鐨勬儏鍐典笅 涓斿弬鏁伴暱搴︿竴鐩� 鍒欏尮閰嶅彲閫夐」鍐呭 鍚﹀垯鐨勮瘽璺宠繃
-                if (stringList.size() == vecSegment.size())
-                {
-                    auto vecTempSegments = currentSegment.options;
-                    for (auto option : vecTempSegments)
-                    {
-                        if (stringList[currentIndex] != option)
-                        {
-                            //std::cout << "鍙傛暟鍖归厤澶辫触  " << stringList[currentIndex] << "   option :  " << option;
-                            return false;
-                        }
-                        else
-                        {
-                            //std::cout << "鍙傛暟鍖归厤鎴愬姛 " << stringList[currentIndex] << "   option :  " << option << std::endl;
-                            currentIndex += 1;
-                        }
-                        break;
-                    }
-                }
-            }
-            //鍙彉鍙�
-            else
-            {
-                //std::cout << "鍙彉鍙傛暟锛� "<< stringList[currentIndex] << " " << currentSegment.options[0] << std::endl;
-                currentIndex += 1;
-            }
-        }
-        return true;
-    }
+    CSegment* segments;
+    int segments_count;
+} CPatternResult;
 
 
-    static std::vector<Segment> extract_all_segments(const std::string& pattern)
-    {
-        std::vector<Segment> segments;
-        size_t pos = 0;
-        const size_t len = pattern.length();
-
-        while (pos < len)
-        {
-            while (pos < len && std::isspace(pattern[pos])) ++pos;
-            if (pos >= len) break;
-
-            if (pattern[pos] == '<') {
-                size_t end_pos = pattern.find('>', pos);
-                if (end_pos == std::string::npos) break;
-
-                std::string content = pattern.substr(pos + 1, end_pos - pos - 1);
-                trim_whitespace(content);
-
-                Segment segment;
-                segment.is_variable = false; // `<...>` 涓嶈瑙嗕负鍙橀噺
-                segment.options = split_options(content);
-
-                // 妫�鏌ユ槸鍚﹀寘鍚� `:`
-                if (content.find(':') != std::string::npos) {
-                    segment.is_required = true; // 濡傛灉鍖呭惈 `:`
-                }
-                else {
-                    segment.is_required = false; // 濡傛灉涓嶅寘鍚� `:`
-                }
-
-                segments.push_back(segment);
-                pos = end_pos + 1;
-            }
-            else if (pattern[pos] == '[')
-            {
-                size_t end_pos = pattern.find(']', pos);
-                if (end_pos == std::string::npos) break;
-
-                std::string content = pattern.substr(pos + 1, end_pos - pos - 1);
-                trim_whitespace(content);
-
-                Segment segment;
-                segment.variableSize += 1;
-                segment.is_required = false;
-                segment.is_variable = true;
-
-                segment.options = split_options(content);
-
-                segments.push_back(segment);
-                pos = end_pos + 1;
-            }
-            else
-            {
-                size_t next_lt = pattern.find('<', pos);
-                size_t next_lb = pattern.find('[', pos);
-                size_t next_special = std::min(next_lt, next_lb);
-
-                std::string content;
-                if (next_special != std::string::npos)
-                {
-                    content = pattern.substr(pos, next_special - pos);
-                }
-                else
-                {
-                    content = pattern.substr(pos);
-                }
-                trim_whitespace(content);
-
-                if (!content.empty())
-                {
-                    // 鐢� ':' 鎷嗗垎鍙傛暟
-                    size_t start = 0;
-                    size_t end = content.find(':');
-                    while (end != std::string::npos)
-                    {
-                        std::string token = content.substr(start, end - start);
-                        trim_whitespace(token);
-
-                        if (!token.empty())
-                        {
-                            Segment segment;
-                            segment.is_required = true; // 鏄庣‘鏍囪涓哄繀濉」
-                            segment.is_variable = false; // 鏅�氭枃鏈笉瑙嗕负鍙橀噺
-                            segment.options.push_back(token);
-                            segments.push_back(segment);
-                        }
-                        start = end + 1;
-                        end = content.find(':', start);
-                    }
-                    // 澶勭悊鏈�鍚庝竴涓儴鍒�
-                    std::string last_token = content.substr(start);
-                    trim_whitespace(last_token);
-                    if (!last_token.empty())
-                    {
-                        Segment segment;
-                        segment.is_required = true;
-                        segment.is_variable = false;
-                        segment.options.push_back(last_token);
-                        segments.push_back(segment);
-                    }
-                }
-                pos = (next_special != std::string::npos) ? next_special : len;
-            }
-        }
-
-        return segments;
-    }
-
-};
-}
+int match_segments_global(const char* input, int pattern_index);
+void parse_pattern_global(const char* pattern);
+int get_pattern_count();
+void clear_global_patterns();
 #ifdef __cplusplus
 }
 #endif
+
 #endif // EXTERNINTERFACE_H
diff --git a/libscpi/inc/scpi/types.h b/libscpi/inc/scpi/types.h
index 45e4d53..d2fe6d2 100644
--- a/libscpi/inc/scpi/types.h
+++ b/libscpi/inc/scpi/types.h
@@ -435,6 +435,7 @@
     };
 
 
+
     struct _scpi_t {
         //鍛戒护琛ㄧ殑鎸囬拡
         const scpi_command_t * cmdlist;
@@ -474,9 +475,8 @@
         int SCPIerror;
         //澧炲姞浜嗕竴涓懡浠ゅ垪琛ㄧ殑闀垮害 闃叉闈炴硶瓒婄晫
         int cmdlistSize;
+
     };
-
-
 
     enum _scpi_array_format_t {
         SCPI_FORMAT_ASCII = 0,
diff --git a/libscpi/src/externinterface.cpp b/libscpi/src/externinterface.cpp
new file mode 100644
index 0000000..17e3621
--- /dev/null
+++ b/libscpi/src/externinterface.cpp
@@ -0,0 +1,350 @@
+#include "scpi/externinterface.h"
+#include <vector>
+#include <string>
+#include <algorithm>
+#include <cstring>
+
+// 鍏ㄥ眬鍙橀噺瀹氫箟
+CPatternResult* g_pattern_results = nullptr;
+int g_pattern_count = 0;
+
+class Segment {
+public:
+    bool is_required = false;
+    bool is_variable = false;
+    bool is_nested = false;
+    int variableSize = 0;
+    std::vector<std::string> options;
+};
+
+class PatternParser
+{
+private:
+    //娓呴櫎绌烘牸
+    static void trim_whitespace(std::string& str)
+    {
+        auto not_space = [](int ch) { return !std::isspace(ch); };
+        str.erase(str.begin(), std::find_if(str.begin(), str.end(), not_space));
+        str.erase(std::find_if(str.rbegin(), str.rend(), not_space).base(), str.end());
+    }
+    //鎷嗗垎鍙�夊弬鏁�
+    static std::vector<std::string> split_options(const std::string& input)
+    {
+        std::vector<std::string> result;
+        size_t start = 0;
+        size_t end = input.find('|');
+
+        while (end != std::string::npos)
+        {
+            std::string token = input.substr(start, end - start);
+            trim_whitespace(token);
+            if (!token.empty()) result.push_back(token);
+            start = end + 1;
+            end = input.find('|', start);
+        }
+
+        std::string last_token = input.substr(start);
+        trim_whitespace(last_token);
+        last_token = remove_colon(last_token);
+        if (!last_token.empty()) result.push_back(last_token);
+        return result;
+    }
+
+    //鍒犳帀鍙兘鎼哄甫鐨�:鍒嗗壊绗�
+    static std::string remove_colon(const std::string& input)
+    {
+        std::string result;
+        for (char ch : input)
+        {
+            if (ch != ':') {
+                result += ch;
+            }
+        }
+        return result;
+    }
+
+public:
+    static std::vector<std::string> parse_input_data(const std::string& input)
+    {
+        std::vector<std::string> result;
+        size_t start = 0;
+        size_t end = input.find(':');
+
+        while (end != std::string::npos)
+        {
+            result.push_back(input.substr(start, end - start));
+            start = end + 1;
+            end = input.find(':', start);
+        }
+
+        result.push_back(input.substr(start));
+        return result;
+    }
+
+    static bool match_all_segments(const std::vector<std::string>& stringList,
+                                   const std::vector<Segment>& vecSegment)
+    {
+        int currentIndex = 0;
+        for (size_t i = 0; i < vecSegment.size(); i++)
+        {
+            auto currentSegment = vecSegment[i];
+
+            if (currentSegment.is_required) {
+                for (const auto& option : currentSegment.options)
+                {
+                    //褰撶储寮昳ndex瓒呰繃杈撳叆鍙傛暟鐨勮瘝缁勫ぇ灏� 鍒欒〃绀哄懡浠や笉鍖归厤
+                    if(currentIndex >= stringList.size())
+                    {
+                        return false;
+                    }
+                    if (stringList[currentIndex] != option)
+                    {
+                        return false;
+                    } else {
+                        currentIndex += 1;
+                    }
+                    break;
+                }
+            }
+            else if (currentSegment.is_variable)
+            {
+                if (stringList.size() == vecSegment.size())
+                {
+                    auto vecTempSegments = currentSegment.options;
+                    for (const auto& option : vecTempSegments)
+                    {
+                        if (stringList[currentIndex] != option)
+                        {
+                            return false;
+                        } else {
+                            currentIndex += 1;
+                        }
+                        break;
+                    }
+                }
+            }
+            else {
+                currentIndex += 1;
+            }
+        }
+        return true;
+    }
+
+    static std::vector<Segment> extract_all_segments(const std::string& pattern)
+    {
+        std::vector<Segment> segments;
+        size_t pos = 0;
+        const size_t len = pattern.length();
+
+        while (pos < len)
+        {
+            while (pos < len && std::isspace(pattern[pos])) ++pos;
+            if (pos >= len) break;
+
+            if (pattern[pos] == '<')
+            {
+                size_t end_pos = pattern.find('>', pos);
+                if (end_pos == std::string::npos) break;
+
+                std::string content = pattern.substr(pos + 1, end_pos - pos - 1);
+                trim_whitespace(content);
+
+                Segment segment;
+                segment.is_variable = false;
+                segment.options = split_options(content);
+
+                if (content.find(':') != std::string::npos)
+                {
+                    segment.is_required = true;
+                } else
+                {
+                    segment.is_required = false;
+                }
+
+                segments.push_back(segment);
+                pos = end_pos + 1;
+            }
+            else if (pattern[pos] == '[')
+            {
+                size_t end_pos = pattern.find(']', pos);
+                if (end_pos == std::string::npos) break;
+
+                std::string content = pattern.substr(pos + 1, end_pos - pos - 1);
+                trim_whitespace(content);
+
+                Segment segment;
+                segment.variableSize += 1;
+                segment.is_required = false;
+                segment.is_variable = true;
+                segment.options = split_options(content);
+
+                segments.push_back(segment);
+                pos = end_pos + 1;
+            }
+            else
+            {
+                size_t next_lt = pattern.find('<', pos);
+                size_t next_lb = pattern.find('[', pos);
+                size_t next_special = std::min(next_lt, next_lb);
+
+                std::string content;
+                if (next_special != std::string::npos)
+                {
+                    content = pattern.substr(pos, next_special - pos);
+                } else
+                {
+                    content = pattern.substr(pos);
+                }
+                trim_whitespace(content);
+
+                if (!content.empty())
+                {
+                    size_t start = 0;
+                    size_t end = content.find(':');
+                    while (end != std::string::npos)
+                    {
+                        std::string token = content.substr(start, end - start);
+                        trim_whitespace(token);
+
+                        if (!token.empty())
+                        {
+                            Segment segment;
+                            segment.is_required = true;
+                            segment.is_variable = false;
+                            segment.options.push_back(token);
+                            segments.push_back(segment);
+                        }
+                        start = end + 1;
+                        end = content.find(':', start);
+                    }
+                    std::string last_token = content.substr(start);
+                    trim_whitespace(last_token);
+                    if (!last_token.empty())
+                    {
+                        Segment segment;
+                        segment.is_required = true;
+                        segment.is_variable = false;
+                        segment.options.push_back(last_token);
+                        segments.push_back(segment);
+                    }
+                }
+                pos = (next_special != std::string::npos) ? next_special : len;
+            }
+        }
+        return segments;
+    }
+};
+
+// 鍏ㄥ眬绠$悊鍑芥暟瀹炵幇
+void add_pattern_to_global(const std::vector<Segment>& segments)
+{
+    // 閲嶆柊鍒嗛厤鍐呭瓨
+    CPatternResult* new_results = new CPatternResult[g_pattern_count + 1];
+
+    // 澶嶅埗鏃ф暟鎹�
+    for (int i = 0; i < g_pattern_count; ++i)
+    {
+        new_results[i] = g_pattern_results[i];
+    }
+
+    // 娣诲姞鏂版暟鎹�
+    CPatternResult& new_item = new_results[g_pattern_count];
+    new_item.segments_count = static_cast<int>(segments.size());
+    new_item.segments = new CSegment[segments.size()];
+
+    for (size_t i = 0; i < segments.size(); ++i)
+    {
+        const auto& seg = segments[i];
+        new_item.segments[i].is_required = seg.is_required;
+        new_item.segments[i].is_variable = seg.is_variable;
+        new_item.segments[i].is_nested = seg.is_nested;
+        new_item.segments[i].variableSize = seg.variableSize;
+
+        new_item.segments[i].options_count = static_cast<int>(seg.options.size());
+        new_item.segments[i].options = new char*[seg.options.size()];
+
+        for (size_t j = 0; j < seg.options.size(); ++j)
+        {
+            new_item.segments[i].options[j] = strdup(seg.options[j].c_str());
+        }
+    }
+
+    // 閲婃斁鏃у唴瀛樺苟鏇存柊鎸囬拡
+    delete[] g_pattern_results;
+    g_pattern_results = new_results;
+    g_pattern_count++;
+}
+
+void clear_global_patterns() {
+    for (int i = 0; i < g_pattern_count; ++i)
+    {
+        for (int j = 0; j < g_pattern_results[i].segments_count; ++j)
+        {
+            for (int k = 0; k < g_pattern_results[i].segments[j].options_count; ++k)
+            {
+                free(g_pattern_results[i].segments[j].options[k]);
+            }
+            delete[] g_pattern_results[i].segments[j].options;
+        }
+        delete[] g_pattern_results[i].segments;
+    }
+    delete[] g_pattern_results;
+    g_pattern_results = nullptr;
+    g_pattern_count = 0;
+}
+
+int get_pattern_count() { return g_pattern_count; }
+
+
+void parse_pattern_global(const char* pattern)
+{
+    auto segments = PatternParser::extract_all_segments(pattern);
+    add_pattern_to_global(segments);
+}
+
+
+int match_segments_global(const char* input, int pattern_index)
+{
+    if (pattern_index < 0 || pattern_index >= g_pattern_count)
+    {
+        return 0;
+    }
+
+
+    std::string inputStr(input);
+    inputStr.erase(std::remove(inputStr.begin(), inputStr.end(), '\n'), inputStr.end());
+
+    std::vector<std::string> inputList;
+    size_t start = 0;
+    size_t end = inputStr.find(':');
+
+    while (end != std::string::npos)
+    {
+        inputList.push_back(inputStr.substr(start, end - start));
+        start = end + 1;
+        end = inputStr.find(':', start);
+    }
+    inputList.push_back(inputStr.substr(start));
+
+    std::vector<Segment> segments;
+    CPatternResult& pattern = g_pattern_results[pattern_index];
+
+    for (int i = 0; i < pattern.segments_count; ++i)
+    {
+        Segment seg;
+        seg.is_required = pattern.segments[i].is_required;
+        seg.is_variable = pattern.segments[i].is_variable;
+        seg.is_nested = pattern.segments[i].is_nested;
+        seg.variableSize = pattern.segments[i].variableSize;
+
+        for (int j = 0; j < pattern.segments[i].options_count; ++j)
+        {
+            seg.options.push_back(pattern.segments[i].options[j]);
+        }
+
+        segments.push_back(seg);
+    }
+
+    return PatternParser::match_all_segments(inputList, segments) ? 1 : 0;
+}
+
diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index e51eb7a..a6376cf 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
@@ -183,21 +184,13 @@
 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)
+    for(int i=0;i<get_pattern_count();i++)
+    {
+        if( match_segments_global(header,i) )
         {
-             context->param_list.cmd = &context->cmdlist[i];
+            context->param_list.cmd = &context->cmdlist[i];
             return TRUE;
         }
-        // if (matchCommand(cmd->pattern, header, len, NULL, 0, 0)) {
-        //     context->param_list.cmd = cmd;
-        //     return TRUE;
-        // }
     }
     context->SCPIerror = RETURN_NotFind;
     return FALSE;
diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c
index 8758917..17d057c 100644
--- a/libscpi/src/utils.c
+++ b/libscpi/src/utils.c
@@ -1144,100 +1144,3 @@
            ((val & 0x00FF000000000000ull) >> 40) |
            ((val & 0xFF00000000000000ull) >> 56);
 }
-
-
-// 鐢ㄤ簬鎻愬彇骞跺鐞嗛�夐」鐨勫嚱鏁�
-int extract_required_options(const char* pattern, char options[MAX_TAGS][MAX_OPTION_LEN][MAX_OPTION_LEN], int max_tags) {
-    const char* start = strchr(pattern, '<');  // 鏌ユ壘绗竴涓� '<'
-    const char* end = NULL;
-    int tag_count = 0;
-
-    // 澶勭悊 <...> 鍐呯殑閫夐」
-    while (start != NULL && tag_count < max_tags)
-    {
-        end = strchr(start, '>');  // 鏌ユ壘瀵瑰簲鐨� '>'
-
-        if (end == NULL) {
-            break;  // 濡傛灉娌℃湁鎵惧埌 '>'锛屽垯閫�鍑�
-        }
-
-        // 鎻愬彇 <...> 涓殑鍐呭
-        int len = end - start - 1;
-        if (len > 0 && len < MAX_OPTION_LEN) {
-            char buffer[MAX_OPTION_LEN];
-            strncpy(buffer, start + 1, len);  // 澶嶅埗 '<' 鍜� '>' 涔嬮棿鐨勫唴瀹�
-            buffer[len] = '\0';  // 缁撴潫绗�
-
-            // 澶勭悊 | 鍒嗛殧绗︼紝鎻愬彇澶氫釜閫夐」
-            char* token = strtok(buffer, "|");
-            int option_count = 0;
-            while (token && option_count < MAX_OPTION_LEN) {
-                // 鍘婚櫎 token 涓殑 "[:", "]" 鍜岀┖鏍�
-                char* p = token;
-                while (*p == ' ' || *p == '[' || *p == ':') p++;  // 鍘婚櫎鍓嶅绌烘牸鍜� [:
-                char* q = p + strlen(p) - 1;
-                while (q > p && (*q == ' ' || *q == ']')) q--;  // 鍘婚櫎灏鹃殢绌烘牸鍜� ]
-                *(q + 1) = '\0';  // 纭繚缁撳熬鏄�'\0'
-
-                // 鎷疯礉閫夐」鍒� options 鏁扮粍
-                if (option_count < MAX_OPTION_LEN) {  // 纭繚涓嶄細瓒婄晫
-                    strncpy(options[tag_count][option_count], p, MAX_OPTION_LEN - 1);
-                    options[tag_count][option_count][MAX_OPTION_LEN - 1] = '\0';  // 纭繚缁撴潫绗�
-                    option_count++;
-                }
-                token = strtok(NULL, "|");
-            }
-        }
-
-        // 绉诲姩鍒颁笅涓�涓� '<' 浣嶇疆锛岀户缁煡鎵�
-        start = strchr(end + 1, '<');
-        tag_count++;
-    }
-
-    return tag_count;
-}
-
-// 鐢ㄤ簬妫�鏌ヨ緭鍏ユ槸鍚﹁兘鍖归厤姣忎竴缁勯�夐」
-int match_input_to_options(const char* input, char options[MAX_TAGS][MAX_OPTION_LEN][MAX_OPTION_LEN], int num_tags) {
-    char input_copy[MAX_INPUT_LEN];
-    strncpy(input_copy, input, MAX_INPUT_LEN - 1);
-    input_copy[MAX_INPUT_LEN - 1] = '\0';  // 纭繚缁撳熬鏄�'\0'
-
-    // 鎷嗗垎杈撳叆瀛楃涓诧紝鎸� ":" 鍒嗗壊
-    char* token = strtok(input_copy, ":");
-    int group_idx = 0;
-
-    // 瀵规瘡涓�缁勮繘琛屽尮閰�
-    while (token != NULL && group_idx < num_tags) {
-        int match_found = 0;
-        // 妫�鏌ュ綋鍓嶇粍鐨勬瘡涓�夐」鏄惁涓庤緭鍏ョ殑 token 鍖归厤
-        printf("Checking input token: '%s' against group %d options\n", token, group_idx + 1); // Debug info
-        for (int i = 0; i < MAX_OPTION_LEN && options[group_idx][i][0] != '\0'; i++) {
-            printf("  Comparing with option: '%s'\n", options[group_idx][i]); // Debug info
-            if (strcmp(options[group_idx][i], token) == 0) {
-                match_found = 1;
-                break;
-            }
-        }
-
-        // 濡傛灉褰撳墠缁勭殑鏌愪釜閫夐」娌℃湁鍖归厤涓婏紝杩斿洖 false
-        if (!match_found) {
-            return 0;  // 涓嶅尮閰�
-        }
-
-        // 澶勭悊涓嬩竴涓緭鍏ラ儴鍒�
-        token = strtok(NULL, ":");
-        group_idx++;
-    }
-
-    return (group_idx == num_tags);
-}
-
-
-// 娴嬭瘯鍖归厤鍑芥暟
-bool test_match(const char* pattern, const char* command)
-{
-    char options[MAX_TAGS][MAX_OPTION_LEN][MAX_OPTION_LEN] = { {{0}} };
-    int num_tags = extract_required_options(pattern, options, MAX_TAGS);
-    return match_input_to_options(command, options, num_tags);
-}
diff --git a/libscpi/src/utils_private.h b/libscpi/src/utils_private.h
index 101bd71..b0dece2 100644
--- a/libscpi/src/utils_private.h
+++ b/libscpi/src/utils_private.h
@@ -79,14 +79,6 @@
 scpi_bool_t composeCompoundCommand(const scpi_token_t * prev, scpi_token_t * current) LOCAL;
 
 
-#define MAX_OPTION_LEN 256
-#define MAX_TAGS 10
-#define MAX_INPUT_LEN 256
-int extract_required_options(const char* pattern, char options[MAX_TAGS][MAX_OPTION_LEN][MAX_OPTION_LEN], int max_tags);
-int match_input_to_options(const char* input, char options[MAX_TAGS][MAX_OPTION_LEN][MAX_OPTION_LEN], int num_tags);
-bool test_match(const char* pattern, const char* command);
-
-
 #define SCPI_DTOSTRE_UPPERCASE   1
 #define SCPI_DTOSTRE_ALWAYS_SIGN 2
 #define SCPI_DTOSTRE_PLUS_SIGN   4

--
Gitblit v1.9.1