From: Mazet Laurent Date: Thu, 24 Apr 2025 16:55:18 +0000 (+0200) Subject: add debug messages and fix parsing (last) X-Git-Tag: v1.0~34 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=aa30b5aa84e298d7eb0a4312503ff48c2d67ef47;p=morep.git add debug messages and fix parsing (last) --- diff --git a/parse.c b/parse.c index 5129d91..405b6fe 100644 --- 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 c678aba..4f783a5 100644 --- 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; \ } /**