From 8a0ad09e70d555974cd319e6157b09f857960867 Mon Sep 17 00:00:00 2001
From: nancy.liao <huihui.liao@greentest.com.cn>
Date: 周三, 23 4月 2025 11:31:35 +0800
Subject: [PATCH] 通用的命令解析完成 如<[:MEASure]|[SOURCE]><[:ARM]|[TRigger]>[:DC] 以及[:MEASure][:DC],当前还没有区分必填项和可选性,输入参数将严格按照:的参数个数进行解析

---
 libscpi/src/utils_private.h |   77 ++++++++++++++++++++------------------
 1 files changed, 41 insertions(+), 36 deletions(-)

diff --git a/libscpi/src/utils_private.h b/libscpi/src/utils_private.h
index 485ba16..fbc81e0 100644
--- a/libscpi/src/utils_private.h
+++ b/libscpi/src/utils_private.h
@@ -60,62 +60,67 @@
 #define LOCAL
 #endif
 
-    char * strnpbrk(const char *str, size_t size, const char *set) LOCAL;
-    scpi_bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL;
-    scpi_bool_t compareStrAndNum(const char * str1, size_t len1, const char * str2, size_t len2, int32_t * num) LOCAL;
-    size_t UInt32ToStrBaseSign(uint32_t val, char * str, size_t len, int8_t base, scpi_bool_t sign) LOCAL;
-    size_t UInt64ToStrBaseSign(uint64_t val, char * str, size_t len, int8_t base, scpi_bool_t sign) LOCAL;
-    size_t strBaseToInt32(const char * str, int32_t * val, int8_t base) LOCAL;
-    size_t strBaseToUInt32(const char * str, uint32_t * val, int8_t base) LOCAL;
-    size_t strBaseToInt64(const char * str, int64_t * val, int8_t base) LOCAL;
-    size_t strBaseToUInt64(const char * str, uint64_t * val, int8_t base) LOCAL;
-    size_t strToFloat(const char * str, float * val) LOCAL;
-    size_t strToDouble(const char * str, double * val) LOCAL;
-    scpi_bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL;
-    scpi_bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL;
-    size_t skipWhitespace(const char * cmd, size_t len) LOCAL;
-    scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len, int32_t * num) LOCAL;
-    scpi_bool_t matchCommand(const char * pattern, const char * cmd, size_t len, int32_t *numbers, size_t numbers_len, int32_t default_value) LOCAL;
-    scpi_bool_t composeCompoundCommand(const scpi_token_t * prev, scpi_token_t * current) LOCAL;
+char * strnpbrk(const char *str, size_t size, const char *set) LOCAL;
+scpi_bool_t compareStr(const char * str1, size_t len1, const char * str2, size_t len2) LOCAL;
+scpi_bool_t compareStrAndNum(const char * str1, size_t len1, const char * str2, size_t len2, int32_t * num) LOCAL;
+size_t UInt32ToStrBaseSign(uint32_t val, char * str, size_t len, int8_t base, scpi_bool_t sign) LOCAL;
+size_t UInt64ToStrBaseSign(uint64_t val, char * str, size_t len, int8_t base, scpi_bool_t sign) LOCAL;
+size_t strBaseToInt32(const char * str, int32_t * val, int8_t base) LOCAL;
+size_t strBaseToUInt32(const char * str, uint32_t * val, int8_t base) LOCAL;
+size_t strBaseToInt64(const char * str, int64_t * val, int8_t base) LOCAL;
+size_t strBaseToUInt64(const char * str, uint64_t * val, int8_t base) LOCAL;
+size_t strToFloat(const char * str, float * val) LOCAL;
+size_t strToDouble(const char * str, double * val) LOCAL;
+scpi_bool_t locateText(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL;
+scpi_bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) LOCAL;
+size_t skipWhitespace(const char * cmd, size_t len) LOCAL;
+scpi_bool_t matchPattern(const char * pattern, size_t pattern_len, const char * str, size_t str_len, int32_t * num) LOCAL;
+scpi_bool_t matchCommand(const char * pattern, const char * cmd, size_t len, int32_t *numbers, size_t numbers_len, int32_t default_value) LOCAL;
+scpi_bool_t composeCompoundCommand(const scpi_token_t * prev, scpi_token_t * current) LOCAL;
 
 
+#define MAX_SEGMENTS 16
 
-    typedef struct {
-        bool is_variable;  // 鏄惁涓哄彲鍙橀儴鍒嗭紙鐢╗]鎷捣鏉ョ殑锛�
-        char text[32];     // 娈靛唴瀹癸紙涓嶅寘鍚玔]锛�
-    } Segment;
+typedef struct {
+    bool is_variable;  // 鏄惁涓哄彲鍙橀儴鍒嗭紙鐢╗]鎷捣鏉ョ殑锛�
+    bool is_required;  // 鏄惁涓哄繀閫夐儴鍒嗭紙鐢�<>鎷捣鏉ョ殑锛�
+    bool is_option;    // 鏄惁涓洪�夐」缁勯儴鍒嗭紙鐢▅鍒嗛殧锛�
+    char text[32];     // 娈靛唴瀹癸紙涓嶅寘鍚玔]鎴�<>锛�
+} Segment;
 
-    int parse_pattern(const char* pattern, Segment segments[], int max_segments);
-    bool match_command(const char* command, Segment segments[], int seg_count);
-    bool test_match(const char* pattern, const char* command);
+//鍖归厤[:MEASure][:VOLTage]
+int parse_pattern(const char* pattern, Segment segments[], int max_segments);
+bool match_command(const char* command, Segment segments[], int seg_count);
+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
-    char * SCPI_dtostre(double __val, char * __s, size_t __ssize, unsigned char __prec, unsigned char __flags);
+char * SCPI_dtostre(double __val, char * __s, size_t __ssize, unsigned char __prec, unsigned char __flags);
 
-    scpi_array_format_t SCPI_GetNativeFormat(void);
-    uint16_t SCPI_Swap16(uint16_t val);
-    uint32_t SCPI_Swap32(uint32_t val);
-    uint64_t SCPI_Swap64(uint64_t val);
+scpi_array_format_t SCPI_GetNativeFormat(void);
+uint16_t SCPI_Swap16(uint16_t val);
+uint32_t SCPI_Swap32(uint32_t val);
+uint64_t SCPI_Swap64(uint64_t val);
 
 #if !HAVE_STRNLEN
-    size_t BSD_strnlen(const char *s, size_t maxlen) LOCAL;
+size_t BSD_strnlen(const char *s, size_t maxlen) LOCAL;
 #endif
 
 #if !HAVE_STRNCASECMP && !HAVE_STRNICMP
-    int OUR_strncasecmp(const char *s1, const char *s2, size_t n) LOCAL;
+int OUR_strncasecmp(const char *s1, const char *s2, size_t n) LOCAL;
 #endif
 
 #if USE_DEVICE_DEPENDENT_ERROR_INFORMATION && !USE_MEMORY_ALLOCATION_FREE
-    void scpiheap_init(scpi_error_info_heap_t * heap, char * error_info_heap, size_t error_info_heap_length);
-    char * scpiheap_strndup(scpi_error_info_heap_t * heap, const char *s, size_t n) LOCAL;
-    void scpiheap_free(scpi_error_info_heap_t * heap, char *s, scpi_bool_t rollback) LOCAL;
-    scpi_bool_t scpiheap_get_parts(scpi_error_info_heap_t * heap, const char *s1, size_t * len1, const char ** s2, size_t * len2) LOCAL;
+void scpiheap_init(scpi_error_info_heap_t * heap, char * error_info_heap, size_t error_info_heap_length);
+char * scpiheap_strndup(scpi_error_info_heap_t * heap, const char *s, size_t n) LOCAL;
+void scpiheap_free(scpi_error_info_heap_t * heap, char *s, scpi_bool_t rollback) LOCAL;
+scpi_bool_t scpiheap_get_parts(scpi_error_info_heap_t * heap, const char *s1, size_t * len1, const char ** s2, size_t * len2) LOCAL;
 #endif
 
 #if !HAVE_STRNDUP
-    char *OUR_strndup(const char *s, size_t n);
+char *OUR_strndup(const char *s, size_t n);
 #endif
 
 #ifndef min

--
Gitblit v1.9.1