修改通用的版本 现阶段可用[:MEASure][:DC]
| | |
| | | size_t arbitrary_remaining; |
| | | |
| | | int SCPIerror; |
| | | //增加了一个命令列表的长度 防止非法越界 |
| | | int cmdlistSize; |
| | | }; |
| | | |
| | | |
| | |
| | | */ |
| | | static scpi_bool_t findCommandHeader(scpi_t * context, const char * header, int len) { |
| | | int32_t i; |
| | | const scpi_command_t * cmd; |
| | | |
| | | for (i = 0; context->cmdlist[i].pattern != NULL; i++) { |
| | | const scpi_command_t * cmd = NULL; |
| | | for (i = 0; i<context->cmdlistSize; i++) { |
| | | cmd = &context->cmdlist[i]; |
| | | if (matchCommand(cmd->pattern, header, len, NULL, 0, 0)) { |
| | | context->param_list.cmd = cmd; |
| | | bool result =test_match(cmd->pattern, header); |
| | | if(result) |
| | | { |
| | | 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; |
| | |
| | | context->buffer.data = input_buffer; |
| | | context->buffer.length = input_buffer_length; |
| | | context->buffer.position = 0; |
| | | |
| | | |
| | | SCPI_ErrorInit(context, error_queue_data, error_queue_size); |
| | | } |
| | | |
| | |
| | | #include <string.h> |
| | | #include <ctype.h> |
| | | #include <math.h> |
| | | |
| | | #include "utils_private.h" |
| | | #include "scpi/utils.h" |
| | | |
| | |
| | | ((val & 0x00FF000000000000ull) >> 40) | |
| | | ((val & 0xFF00000000000000ull) >> 56); |
| | | } |
| | | |
| | | 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; |
| | | // 跳过'[' |
| | | 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 |
| | | { |
| | | // 处理固定段 |
| | | segments[seg_count].is_variable = FALSE; |
| | | |
| | | 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'; |
| | | } |
| | | |
| | | 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++; |
| | | // 模式中也应该有对应的分隔符 |
| | | if (segments[current_seg].text[0] != ':') |
| | | { |
| | | return FALSE; |
| | | } |
| | | 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 (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[16]; |
| | | int seg_count = parse_pattern(pattern, segments, 16); |
| | | return (match_command(command, segments, seg_count)); |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | #include<scpi/config.h> |
| | | #include<scpi/types.h> |
| | | |
| | | |
| | | #ifdef _WIN32 |
| | | #include <string.h> |
| | | #define strncasecmp _strnicmp |
| | | #else |
| | | #include <strings.h> |
| | | #endif |
| | | |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | | #endif |
| | |
| | | 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; |
| | | |
| | | |
| | | |
| | | typedef struct { |
| | | bool is_variable; // 是否为可变部分(用[]括起来的) |
| | | 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); |
| | | |
| | | #define SCPI_DTOSTRE_UPPERCASE 1 |
| | | #define SCPI_DTOSTRE_ALWAYS_SIGN 2 |
| | | #define SCPI_DTOSTRE_PLUS_SIGN 4 |