wip
authorLaurent Mazet <mazet@softndesign.org>
Fri, 11 Apr 2025 04:51:01 +0000 (06:51 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 11 Apr 2025 04:51:01 +0000 (06:51 +0200)
parse.h

diff --git a/parse.h b/parse.h
index f141972136a8fd2dbdcb18a5f153fa9a26b84026..67747b50f4c8834c95dead340e265ffe8342c504 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -56,6 +56,7 @@ __BEGIN_DECLS
 */
 #define BEGIN_PARSE(line)                                  \
 {                                                          \
+    int p = 0;                                             \
     int rc = 0;                                            \
     char *pt = line;                                       \
     while (1) {                                            \
@@ -92,8 +93,9 @@ __BEGIN_DECLS
    @param buf preallocated storage
 */
 #define PARSE_INT(name, buf)                \
-        else if (strcmp (var, name) == 0) { \
+        else if (p++, strcmp (var, name) == 0) { \
             buf = parse_int (val);          \
+            rc |= 1 << p; \
         }
 /**
    @ingroup MESSAGES
@@ -104,8 +106,9 @@ __BEGIN_DECLS
    @param buf preallocated storage
 */
 #define PARSE_DOUBLE(name, buf)             \
-        else if (strcmp (var, name) == 0) { \
+        else if (p++, strcmp (var, name) == 0) { \
             buf = parse_double (val);       \
+            rc |= 1 << p; \
         }
 
 /**
@@ -118,8 +121,9 @@ __BEGIN_DECLS
    @param optinal parameter to use defined length
 */
 #define PARSE_ARRAY(name, buf, ...)                                                                \
-        else if (strcmp (var, name) == 0) {                                                        \
+        else if (p++, strcmp (var, name) == 0) {                                                        \
             buf##_len = parse_array (val, buf, (__VA_ARGS__ + 0) ? buf##_len : (int)sizeof (buf)); \
+            rc |= 1 << p; \
         }
 
 /**
@@ -131,8 +135,9 @@ __BEGIN_DECLS
    @param buf preallocated storage
 */
 #define PARSE_TAB(name, buf)                      \
-        else if (strcmp (var, name) == 0) {       \
+        else if (p++, strcmp (var, name) == 0) {       \
             parse_array (val, buf, sizeof (buf)); \
+            rc |= 1 << p; \
         }
 
 /**
@@ -143,7 +148,7 @@ __BEGIN_DECLS
 #define END_PARSE()                                                            \
         else {                                                                 \
             VERBOSE (morep, WARNING, PRINTF ("can't understand '%s'\n", var)); \
-            rc = 1;                                                            \
+            rc = -1;                                                            \
             break;                                                             \
         }                                                                      \
     }                                                                          \