From bf8143c649292042de87c0cef63e6cb3c523388f Mon Sep 17 00:00:00 2001 From: nancy.liao <huihui.liao@greentest.com.cn> Date: 周四, 08 5月 2025 16:40:10 +0800 Subject: [PATCH] 修改了一些警告信息 --- libscpi/src/utils.c | 131 ++++--------------------------------------- 1 files changed, 13 insertions(+), 118 deletions(-) diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c index bdde1ea..9358b51 100644 --- a/libscpi/src/utils.c +++ b/libscpi/src/utils.c @@ -319,7 +319,7 @@ */ size_t strToFloat(const char * str, float * val) { char * endptr; - *val = SCPIDEFINE_strtof(str, &endptr); + *val = (float)SCPIDEFINE_strtof(str, &endptr); return endptr - str; } @@ -480,13 +480,13 @@ if ((pattern_len > 0) && pattern[pattern_len - 1] == '#') { size_t new_pattern_len = pattern_len - 1; - pattern_sep_pos_short = patternSeparatorShortPos(pattern, new_pattern_len); + pattern_sep_pos_short = (int)patternSeparatorShortPos(pattern, new_pattern_len); return compareStrAndNum(pattern, new_pattern_len, str, str_len, num) || compareStrAndNum(pattern, pattern_sep_pos_short, str, str_len, num); } else { - pattern_sep_pos_short = patternSeparatorShortPos(pattern, pattern_len); + pattern_sep_pos_short = (int)patternSeparatorShortPos(pattern, pattern_len); return compareStr(pattern, pattern_len, str, str_len) || compareStr(pattern, pattern_sep_pos_short, str, str_len); @@ -512,7 +512,7 @@ int32_t *number_ptr = NULL; const char * pattern_ptr = pattern; - int pattern_len = strlen(pattern); + int pattern_len = (int)strlen(pattern); const char * cmd_ptr = cmd; size_t cmd_len = SCPIDEFINE_strnlen(cmd, len); @@ -548,9 +548,9 @@ } while (1) { - int pattern_sep_pos = patternSeparatorPos(pattern_ptr, pattern_len); + int pattern_sep_pos = (int)patternSeparatorPos(pattern_ptr, pattern_len); - cmd_sep_pos = cmdSeparatorPos(cmd_ptr, cmd_len); + cmd_sep_pos = (int)cmdSeparatorPos(cmd_ptr, cmd_len); if ((pattern_sep_pos > 0) && pattern_ptr[pattern_sep_pos - 1] == '#') { if (numbers && (numbers_idx < numbers_len)) { @@ -584,7 +584,7 @@ if (cmd_len == 0) { /* verify all subsequent pattern parts are also optional */ while (pattern_len) { - pattern_sep_pos = patternSeparatorPos(pattern_ptr, pattern_len); + pattern_sep_pos = (int)patternSeparatorPos(pattern_ptr, pattern_len); switch (pattern_ptr[pattern_sep_pos]) { case '[': brackets++; @@ -677,7 +677,7 @@ //缁勫悎澶嶅悎SCPI鍛戒护 scpi_bool_t composeCompoundCommand(const scpi_token_t * prev, scpi_token_t * current) { - size_t i; + int i; /* Invalid input */ if (current == NULL || current->ptr == NULL || current->len == 0) @@ -741,8 +741,8 @@ unsigned char c1, c2; for (; n != 0; n--) { - c1 = tolower((unsigned char) *s1++); - c2 = tolower((unsigned char) *s2++); + c1 = (unsigned char)tolower((unsigned char) *s1++); + c2 = (unsigned char)tolower((unsigned char) *s2++); if (c1 != c2) { return c1 - c2; } @@ -958,7 +958,7 @@ if (fi != 0) { r1 = r1 * 308 / 1024 - ndigits; - w2 = bufsize; + w2 = (int)bufsize; while (r1 > 0) { fj = modf(fi / 10, &fi); r2++; @@ -966,7 +966,7 @@ } while (fi != 0) { fj = modf(fi / 10, &fi); - buf[--w2] = (int) ((fj + .03) * 10) + '0'; + buf[--w2] = (char) ((fj + .03) * 10) + '0'; r2++; } while (w2 < (int) bufsize) buf[w1++] = buf[w2++]; @@ -985,7 +985,7 @@ while (w1 <= w2 && w1 < (int) bufsize) { arg *= 10; arg = modf(arg, &fj); - buf[w1++] = (int) fj + '0'; + buf[w1++] = (char) fj + '0'; } if (w2 >= (int) bufsize) { buf[bufsize - 1] = '\0'; @@ -1144,108 +1144,3 @@ ((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)); - -} - - -- Gitblit v1.9.1