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/inc/scpi/externinterface.h |    1 
 libscpi/src/lexer.c                |    9 +-
 libscpi/src/ieee488.c              |    3 
 libscpi/src/parser.c               |   13 ++-
 libscpi/src/units.c                |    2 
 libscpi/inc/scpi/config.h          |    6 +
 libscpi/inc/scpi/parser.h          |    2 
 libscpi/src/test-interactive.cpp   |    1 
 libscpi/src/utils.c                |   26 ++++----
 libscpi/src/scpi-def.cpp           |    6 +-
 libscpi/src/externinterface.cpp    |   70 +++++++++-------------
 11 files changed, 64 insertions(+), 75 deletions(-)

diff --git a/libscpi/inc/scpi/config.h b/libscpi/inc/scpi/config.h
index 2d3652e..c611fa8 100644
--- a/libscpi/inc/scpi/config.h
+++ b/libscpi/inc/scpi/config.h
@@ -264,8 +264,10 @@
 #else
   #define SCPIDEFINE_strtoll(n, p, b)                   strtoll((n), (p), (b))
   #define SCPIDEFINE_strtoull(n, p, b)                  strtoull((n), (p), (b))
-  extern long long int strtoll(const char *nptr, char **endptr, int base);
-  extern unsigned long long int strtoull(const char *nptr, char **endptr, int base);
+    //杩欓噷娉ㄩ噴鏄负浜嗘秷闄よ鍛�
+  //extern long long int strtoll(const char *nptr, char **endptr, int base);
+  //extern unsigned long long int strtoull(const char *nptr, char **endptr, int base);
+
   /* TODO: implement OUR_strtoll and OUR_strtoull */
   /* #warning "64bit string to int conversion not implemented" */
 #endif
diff --git a/libscpi/inc/scpi/externinterface.h b/libscpi/inc/scpi/externinterface.h
index 1d3b41f..9fc8280 100644
--- a/libscpi/inc/scpi/externinterface.h
+++ b/libscpi/inc/scpi/externinterface.h
@@ -22,7 +22,6 @@
     int segments_count;
 } CPatternResult;
 
-static CPatternResult *GetInstance();
 
 int match_segments_global(const char* input, int pattern_index);
 void parse_pattern_global(const char* pattern);
diff --git a/libscpi/inc/scpi/parser.h b/libscpi/inc/scpi/parser.h
index d0ddfb1..5cade1e 100644
--- a/libscpi/inc/scpi/parser.h
+++ b/libscpi/inc/scpi/parser.h
@@ -64,7 +64,7 @@
 #if USE_DEVICE_DEPENDENT_ERROR_INFORMATION && !USE_MEMORY_ALLOCATION_FREE
     void SCPI_InitHeap(scpi_t * context, char * error_info_heap, size_t error_info_heap_length);
 #endif
-    scpi_bool_t findCommandHeader(scpi_t * context, const char * header, int len);
+    scpi_bool_t findCommandHeader(scpi_t * context, const char * header,int len);
     scpi_bool_t SCPI_Input(scpi_t * context, const char * data, int len);
     scpi_bool_t SCPI_Parse(scpi_t * context, char * data, int len);
 
diff --git a/libscpi/src/externinterface.cpp b/libscpi/src/externinterface.cpp
index 222a863..15153ed 100644
--- a/libscpi/src/externinterface.cpp
+++ b/libscpi/src/externinterface.cpp
@@ -82,52 +82,45 @@
     }
 
     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++)
+                                   const std::vector<Segment>& vecSegment) {
+        size_t currentIndex = 0;
+        for (const auto& segment : vecSegment)
         {
-            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 (currentIndex >= stringList.size())
             {
-                if (stringList.size() == vecSegment.size())
+                return false;
+            }
+            if (segment.is_required)
+            {
+                bool matched = false;
+                for (const auto& option : segment.options)
                 {
-                    auto vecTempSegments = currentSegment.options;
-                    for (const auto& option : vecTempSegments)
+                    if (stringList[currentIndex] == option)
                     {
-                        if (stringList[currentIndex] != option)
-                        {
-                            return false;
-                        } else {
-                            currentIndex += 1;
-                        }
+                        matched = true;
                         break;
                     }
                 }
+                if (!matched)
+                {
+                    return false;
+                }
+                currentIndex++;
             }
-            else {
-                currentIndex += 1;
+            else if (segment.is_variable)
+            {
+                // 鍙彉鍙傛暟锛氱洿鎺ヨ烦杩�
+                currentIndex++;
+            } else
+            {
+
+                if (segment.options.empty() || stringList[currentIndex] != segment.options[0]) {
+                    return false;
+                }
+                currentIndex++;
             }
         }
-        return true;
+        return currentIndex == stringList.size();
     }
 
     static std::vector<Segment> extract_all_segments(const std::string& pattern)
@@ -339,9 +332,4 @@
     }
 
     return PatternParser::match_all_segments(inputList, segments) ? 1 : 0;
-}
-
-CPatternResult *GetInstance()
-{
-    return g_pattern_results;
 }
diff --git a/libscpi/src/ieee488.c b/libscpi/src/ieee488.c
index 09279ba..05fb73c 100644
--- a/libscpi/src/ieee488.c
+++ b/libscpi/src/ieee488.c
@@ -193,7 +193,7 @@
                     enable = 0xFFFF;
                 }
 
-                scpi_bool_t summary = val & enable;
+                scpi_bool_t summary = (scpi_bool_t)val & enable;
 
                 name = register_group.parent_reg;
                 val = SCPI_RegGet(context, register_group.parent_reg);
@@ -328,7 +328,6 @@
     {
         if (context->idn[i])
         {
-            char* outPut = "IDNS鍝嶅簲";
            // context->interface->write(context,context->idn[i],0);
             SCPI_ResultMnemonic(context, context->idn[i]);
         } else {
diff --git a/libscpi/src/lexer.c b/libscpi/src/lexer.c
index 07284c1..830d4a2 100644
--- a/libscpi/src/lexer.c
+++ b/libscpi/src/lexer.c
@@ -313,11 +313,10 @@
         }
     }
 
-    if (iseos(state)) {
-        return (state->pos - startPos) * SKIP_INCOMPLETE;
-    } else {
-        return (state->pos - startPos) * SKIP_OK;
-    }
+    ptrdiff_t diff = state->pos - startPos;
+    long long result = diff * (iseos(state) ? SKIP_INCOMPLETE : SKIP_OK);
+
+    return (int)result;
 }
 
 /* tokens */
diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index a6376cf..8530871 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -127,10 +127,9 @@
  */
 
  //璐熷懡浠ゅ洖璋冪殑鎵ц銆佸弬鏁板鐞嗗拰閿欒绠$悊
-static scpi_bool_t processCommand(scpi_t * context) {
-    //杩欎釜鍦版柟淇敼涓� 璇籧omdlist->pattern
+static scpi_bool_t processCommand(scpi_t * context)
+{
     const scpi_command_t * cmd = context->param_list.cmd;
-    //const scpi_command_t * cmd = context->cmdlist->pattern;
     lex_state_t * state = &context->param_list.lex_state;
     scpi_bool_t result = TRUE;
     // 鍏堟娴嬫槸鍚︿负鏌ヨ鍛戒护(浠�?缁撳熬)
@@ -181,14 +180,18 @@
  * @param context
  * @result TRUE if context->paramlist is filled with correct values
  */
-scpi_bool_t findCommandHeader(scpi_t * context, const char * header, int len)
+scpi_bool_t findCommandHeader(scpi_t * context, const char * header,int len)
 {
+    //鍙傛暟宸茬粡鍦ㄥ墠闈㈤儴鍒嗚В鏋愬畬鎴�,鍖归厤鍛戒护鏃跺氨涓嶅啀闇�瑕佸弬鏁伴儴鍒� 灏嗗懡浠ゆ媶闄ゅ嵆鍙�
+    char *header_copy = strdup(header);
+    char *first_part = strtok(header_copy, " ");
 
     for(int i=0;i<get_pattern_count();i++)
     {
-        if( match_segments_global(header,i) )
+        if( match_segments_global(first_part,i) )
         {
             context->param_list.cmd = &context->cmdlist[i];
+            free(header_copy);
             return TRUE;
         }
     }
diff --git a/libscpi/src/scpi-def.cpp b/libscpi/src/scpi-def.cpp
index 83ec9cc..38c665a 100644
--- a/libscpi/src/scpi-def.cpp
+++ b/libscpi/src/scpi-def.cpp
@@ -234,7 +234,7 @@
             chanlst_idx = 0; /* call first index */
             arr_idx = 0; /* set arr_idx to 0 */
             do { /* if valid, iterate over channel_list_param index while res == valid (do-while cause we have to do it once) */
-                res = SCPI_ExprChannelListEntry(context, &channel_list_param, chanlst_idx, &is_range, values_from, values_to, 4, &dimensions);
+                res = (scpi_expr_result_t)SCPI_ExprChannelListEntry(context, &channel_list_param, chanlst_idx, &is_range, values_from, values_to, 4, &dimensions);
                 if (is_range == FALSE) { /* still can have multiple dimensions */
                     if (dimensions == 1) {
                         /* here we have our values
@@ -283,8 +283,8 @@
                                  * row == n
                                  * col == m
                                  * call a function or something */
-                                array[arr_idx].row = n;
-                                array[arr_idx].col = m;
+                                array[arr_idx].row =(int32_t) n;
+                                array[arr_idx].col = (int32_t)m;
                                 arr_idx++;
                                 if (arr_idx >= MAXROW * MAXCOL) {
                                     return SCPI_RES_ERR;
diff --git a/libscpi/src/test-interactive.cpp b/libscpi/src/test-interactive.cpp
index edec5f5..880e2d1 100644
--- a/libscpi/src/test-interactive.cpp
+++ b/libscpi/src/test-interactive.cpp
@@ -54,7 +54,6 @@
 
 int SCPI_Error(scpi_t * context, int_fast16_t err) {
     (void) context;
-    std::cerr << "**ERROR: " << err << ", \"" << SCPI_ErrorTranslate(err) << "\"" << std::endl;
     return 0;
 }
 
diff --git a/libscpi/src/units.c b/libscpi/src/units.c
index 1e64701..25ce33f 100644
--- a/libscpi/src/units.c
+++ b/libscpi/src/units.c
@@ -495,7 +495,7 @@
 
     if (value->special) {
         if (SCPI_ChoiceToName(special, value->content.tag, &type)) {
-            strncpy(str, type, len);
+            memcpy(str, type, len);
             result = SCPIDEFINE_strnlen(str, len - 1);
             str[result] = '\0';
             return result;
diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c
index 17d057c..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';

--
Gitblit v1.9.1