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/src/utils.c |  138 ----------------------------------------------
 1 files changed, 0 insertions(+), 138 deletions(-)

diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c
index afb6664..17d057c 100644
--- a/libscpi/src/utils.c
+++ b/libscpi/src/utils.c
@@ -1144,141 +1144,3 @@
            ((val & 0x00FF000000000000ull) >> 40) |
            ((val & 0xFF00000000000000ull) >> 56);
 }
-
-
-// 瑙f瀽妯″紡锛屽皢姣忎釜閮ㄥ垎淇濆瓨鍒� segments 涓�
-int parse_pattern(const char* pattern, Segment segments[], int max_segments) {
-    int seg_count = 0;
-    const char* p = pattern;
-
-    while (*p && seg_count < max_segments) {
-        if (*p == '[') {
-            // 澶勭悊鍙彉娈碉紙[]锛�
-            segments[seg_count].is_variable = TRUE;
-            segments[seg_count].is_required = FALSE;  // []鏄彲閫夌殑
-            segments[seg_count].is_option = FALSE;
-            p++;  // 璺宠繃'['
-
-            int i = 0;
-            while (*p && *p != ']' && i < sizeof(segments[seg_count].text) - 1) {
-                segments[seg_count].text[i++] = toupper(*p++);
-            }
-            segments[seg_count].text[i] = '\0';  // 缁撴潫绗�
-
-            if (*p == ']') {
-                p++;  // 璺宠繃']'
-            }
-        }
-        else if (*p == '<') {
-            // 澶勭悊蹇呴�夋锛�<>锛�
-            segments[seg_count].is_variable = TRUE;
-            segments[seg_count].is_required = TRUE;  // <>鏄繀閫夌殑
-            segments[seg_count].is_option = FALSE;
-            p++;  // 璺宠繃'<'
-
-            int i = 0;
-            while (*p && *p != '>' && i < sizeof(segments[seg_count].text) - 1) {
-                segments[seg_count].text[i++] = toupper(*p++);
-            }
-            segments[seg_count].text[i] = '\0';  // 缁撴潫绗�
-
-            if (*p == '>') {
-                p++;  // 璺宠繃'>'
-            }
-        }
-        else if (*p == '|') {
-            // 澶勭悊绔栫嚎鍒嗛殧鐨勫閫夐儴鍒嗭紙|锛�
-            segments[seg_count].is_variable = TRUE;
-            segments[seg_count].is_required = TRUE;  // 閫夐」鏄繀閫夌殑
-            segments[seg_count].is_option = TRUE;   // 杩欒〃绀洪�夐」缁�
-            p++;  // 璺宠繃'|'
-
-            int i = 0;
-            while (*p && *p != '|' && *p != '>' && *p != '[' && *p != ']' && i < sizeof(segments[seg_count].text) - 1) {
-                segments[seg_count].text[i++] = toupper(*p++);
-            }
-            segments[seg_count].text[i] = '\0';  // 缁撴潫绗�
-
-            // 璺宠繃'|'缁х画澶勭悊涓嬩竴涓�夐」
-            if (*p == '|') {
-                p++;  // 璺宠繃'|'
-            }
-        }
-        else {
-            // 澶勭悊鍥哄畾娈�
-            segments[seg_count].is_variable = FALSE;
-            segments[seg_count].is_required = TRUE;  // 鍥哄畾娈靛繀閫�
-            segments[seg_count].is_option = FALSE;
-            int i = 0;
-            while (*p && *p != '[' && *p != '<' && *p != '|' && *p != ':' && i < sizeof(segments[seg_count].text) - 1) {
-                segments[seg_count].text[i++] = toupper(*p++);
-            }
-            segments[seg_count].text[i] = '\0';  // 缁撴潫绗�
-        }
-
-        seg_count++;
-    }
-
-    return seg_count;
-}
-
-// 鍖归厤鍛戒护瀛楃涓叉槸鍚︾鍚堟ā寮�
-bool match_command(const char* command, Segment segments[], int seg_count) {
-    const char* cmd = command;
-    int current_seg = 0;
-
-    while (*cmd && current_seg < seg_count) {
-        // 鎸夊啋鍙峰垎闅斿懡浠�
-        if (*cmd == ':') {
-            cmd++;  // 璺宠繃鍒嗛殧绗�
-            continue;
-        }
-
-        size_t seg_len = strlen(segments[current_seg].text);
-
-        if (segments[current_seg].is_variable) {
-            // 鍙彉娈� - 璺宠繃瀵瑰簲闀垮害鐨勫瓧绗�
-            int i = 0;
-            while (*cmd && *cmd != ':' && i < seg_len) {
-                cmd++;
-                i++;
-            }
-        }
-        else if (segments[current_seg].is_option) {
-            // 閫夐」缁� - 蹇呴』鍖归厤鍏朵腑涓�涓�夐」
-            bool matched = FALSE;
-            const char* options[] = { segments[current_seg].text, NULL };
-            for (int i = 0; options[i]; i++) {
-                if (strncasecmp(cmd, options[i], strlen(options[i])) == 0) {
-                    matched = TRUE;
-                    break;
-                }
-            }
-            if (!matched) {
-                return FALSE;
-            }
-            cmd += strlen(options[0]);
-        }
-        else {
-            // 鍥哄畾娈� - 蹇呴』绮剧‘鍖归厤
-            if (strncasecmp(cmd, segments[current_seg].text, seg_len) != 0) {
-                return FALSE;
-            }
-            cmd += seg_len;  // 璺宠繃鍖归厤鐨勯儴鍒�
-        }
-
-        current_seg++;
-    }
-
-    // 妫�鏌ユ槸鍚﹀鐞嗗畬鎵�鏈夊懡浠ゅ拰鎵�鏈夋
-    return (*cmd == '\0') && (current_seg == seg_count);
-}
-
-// 娴嬭瘯鍖归厤鍑芥暟
-bool test_match(const char* pattern, const char* command)
-{
-
-    Segment segments[MAX_SEGMENTS];
-    int seg_count = parse_pattern(pattern, segments, MAX_SEGMENTS);
-    return match_command(command, segments, seg_count);
-}

--
Gitblit v1.9.1