add debug messages and fix parsing (last)
authorMazet Laurent <laurent.mazet@thalesgroup.com>
Thu, 24 Apr 2025 16:55:18 +0000 (18:55 +0200)
committerMazet Laurent <laurent.mazet@thalesgroup.com>
Thu, 24 Apr 2025 16:55:18 +0000 (18:55 +0200)
parse.c
parse.h

diff --git a/parse.c b/parse.c
index 5129d9197594bf46e21610413a8e9c67e183483e..405b6fe51bf4546b9e40d97c4cf15fe4aa35eeea 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -73,7 +73,9 @@ int parse_array (char *str, uint8_t *buffer, int maxlen)
                 fseek (fid, 0L, SEEK_SET);
                 fseek (fid, 0L, SEEK_END);
                 int flen = ftell (fid);
-                VERBOSE (morep, WARNING, PRINTF ("file too large (%d > %d) for '%s'\n", flen, maxlen, str));
+                if (flen > maxlen) {
+                    VERBOSE (morep, WARNING, PRINTF ("file too large (%d > %d) for '%s'\n", flen, maxlen, str));
+                }
             }
             fclose (fid);
         } else {
diff --git a/parse.h b/parse.h
index c678aba8c0019a89907547ac959e1d9a8927060f..4f783a519a6655d777a4c65b5685459ffa3798e0 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -76,7 +76,7 @@ __BEGIN_DECLS
         char *val = pt;                                    \
         while (*pt != '\0') {                              \
             if ((*pt == ' ') && (*(pt - 1) != '\\')) {     \
-                *pt = '\0'; \
+                *pt++ = '\0';                              \
                 break;                                     \
             }                                              \
             pt++;                                          \
@@ -95,10 +95,11 @@ __BEGIN_DECLS
    @param name field name
    @param buf preallocated storage
 */
-#define PARSE_INT(name, buf)                     \
-        else if (p++, strcmp (var, name) == 0) { \
-            buf = parse_int (val);               \
-            rc |= 1 << p;                        \
+#define PARSE_INT(name, buf)                                      \
+        else if (p++, strcmp (var, name) == 0) {                  \
+            buf = parse_int (val);                                \
+            VERBOSE (morep, DEBUG, PRINTF ("%s=%d\n", var, buf)); \
+            rc |= 1 << p;                                         \
         }
 /**
    @ingroup MESSAGES
@@ -108,10 +109,11 @@ __BEGIN_DECLS
    @param name field name
    @param buf preallocated storage
 */
-#define PARSE_DOUBLE(name, buf)                  \
-        else if (p++, strcmp (var, name) == 0) { \
-            buf = parse_double (val);            \
-            rc |= 1 << p;                        \
+#define PARSE_DOUBLE(name, buf)                                   \
+        else if (p++, strcmp (var, name) == 0) {                  \
+            buf = parse_double (val);                             \
+            VERBOSE (morep, DEBUG, PRINTF ("%s=%g\n", var, buf)); \
+            rc |= 1 << p;                                         \
         }
 
 /**
@@ -126,6 +128,7 @@ __BEGIN_DECLS
 #define PARSE_ARRAY(name, buf, ...)                                                                \
         else if (p++, strcmp (var, name) == 0) {                                                   \
             buf##_len = parse_array (val, buf, (__VA_ARGS__ + 0) ? buf##_len : (int)sizeof (buf)); \
+            VERBOSE (morep, DEBUG, PRINTF ("%s=[%d]\n", var, buf##_len));                          \
             rc |= 1 << p;                                                                          \
         }
 
@@ -137,10 +140,12 @@ __BEGIN_DECLS
    @param name field name
    @param buf preallocated storage
 */
-#define PARSE_TAB(name, buf)                      \
-        else if (p++, strcmp (var, name) == 0) {  \
-            parse_array (val, buf, sizeof (buf)); \
-            rc |= 1 << p; \
+#define PARSE_TAB(name, buf)                                        \
+        else if (p++, strcmp (var, name) == 0) {                    \
+            int len = sizeof (buf);                                 \
+            parse_array (val, buf, len);                            \
+            VERBOSE (morep, DEBUG, PRINTF ("%s=[%d]\n", var, len)); \
+            rc |= 1 << p;                                           \
         }
 
 /**