diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-29 14:00:25 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-29 16:47:34 +0300 |
commit | 3f938834227d544f8b5fe05dcf3f57eecc5e9197 (patch) | |
tree | 8297b3295e1a08cde7e5e6f86372d7c64b36476e | |
parent | 1de4bd512440c175f4b9dfed947d58f3d420bcb3 (diff) | |
download | smap-3f938834227d544f8b5fe05dcf3f57eecc5e9197.tar.gz smap-3f938834227d544f8b5fe05dcf3f57eecc5e9197.tar.bz2 |
Configuration parser debugging.
* src/smapd.c (debug_init): New category "conf".
* src/smapd.h (DBG_CONF): New constant.
* src/cfg.c (parse_config_loop): Add debugging
output.
(smapd_ws_debug): New function.
* lib/wordsplit.c (wordsplit_len): Fix character case in
debug output.
(wordsplit_init): Consistency checking for WRDSF_SHOWDBG.
(wordsplit_dump_nodes, wordsplit_len): Debugging output
is triggered by WRDSF_SHOWDBG flag.
* include/smap/wordsplit.h (wordsplit): New member ws_debug.
(WRDSF_SHOWDBG): New flag.
-rw-r--r-- | include/smap/wordsplit.h | 6 | ||||
-rw-r--r-- | lib/wordsplit.c | 33 | ||||
-rw-r--r-- | src/cfg.c | 32 | ||||
-rw-r--r-- | src/smapd.c | 1 | ||||
-rw-r--r-- | src/smapd.h | 1 |
5 files changed, 59 insertions, 14 deletions
diff --git a/include/smap/wordsplit.h b/include/smap/wordsplit.h index ced28f3..07afc0a 100644 --- a/include/smap/wordsplit.h +++ b/include/smap/wordsplit.h @@ -30,6 +30,8 @@ struct wordsplit const char *ws_comment; void (*ws_alloc_die)(struct wordsplit *wsp); void (*ws_error)(const char *, ...); + void (*ws_debug)(const char *, ...); + const char **ws_env; char *(*ws_getvar)(const char *, size_t); @@ -86,7 +88,7 @@ struct wordsplit /* ws_getvar field is initialized */ #define WRDSF_GETVAR 0x040000 /* enable debugging */ -#define WRDSF_DEBUG 0x080000 +#define WRDSF_SHOWDBG 0x080000 /* Don't split input into words. Useful for side effects. */ #define WRDSF_NOSPLIT 0x100000 /* Keep undefined variables in place, instead of expanding them to @@ -94,6 +96,8 @@ struct wordsplit #define WRDSF_KEEPUNDEF 0x200000 /* Handle C escapes */ #define WRDSF_CESCAPES 0x400000 +/* ws_debug field is initialized */ +#define WRDSF_DEBUG 0x800000 #define WRDSF_DEFFLAGS \ (WRDSF_NOVAR | WRDSF_NOCMD | \ diff --git a/lib/wordsplit.c b/lib/wordsplit.c index d235fde..9f1b9d5 100644 --- a/lib/wordsplit.c +++ b/lib/wordsplit.c @@ -113,6 +113,15 @@ wordsplit_init(struct wordsplit *wsp, const char *input, size_t len, return wsp->ws_errno; } + if (wsp->ws_flags & WRDSF_SHOWDBG) { + if (!(wsp->ws_flags & WRDSF_DEBUG)) { + if (wsp->ws_flags & WRDSF_ERROR) + wsp->ws_debug = wsp->ws_error; + else + wsp->ws_flags &= ~WRDSF_SHOWDBG; + } + } + wsp->ws_input = input; wsp->ws_len = len; @@ -354,11 +363,11 @@ wordsplit_dump_nodes(struct wordsplit *wsp) for (p = wsp->ws_head, n = 0; p; p = p->next, n++) { if (p->flags & _WSNF_WORD) - wsp->ws_error("%4d: %p: %#04x (%s):%s;", + wsp->ws_debug("%4d: %p: %#04x (%s):%s;", n, p, p->flags, wsnode_flagstr(p->flags), p->v.word); else - wsp->ws_error("%4d: %p: %#04x (%s):%.*s;", + wsp->ws_debug("%4d: %p: %#04x (%s):%.*s;", n, p, p->flags, wsnode_flagstr(p->flags), p->v.segm.end - p->v.segm.beg, wsp->ws_input + p->v.segm.beg); @@ -1126,8 +1135,8 @@ wordsplit_len(const char *command, size_t len, struct wordsplit *wsp, if (rc) return rc; - if (wsp->ws_flags & WRDSF_DEBUG) - wsp->ws_error("INPUT:%.*s;", len, command); + if (wsp->ws_flags & WRDSF_SHOWDBG) + wsp->ws_debug("Input:%.*s;", len, command); if (wsp->ws_flags & WRDSF_NOSPLIT) { /* Treat entire input as a quoted argument */ @@ -1138,8 +1147,8 @@ wordsplit_len(const char *command, size_t len, struct wordsplit *wsp, start = skip_delim(wsp); } - if (wsp->ws_flags & WRDSF_DEBUG) { - wsp->ws_error("Initial list:"); + if (wsp->ws_flags & WRDSF_SHOWDBG) { + wsp->ws_debug("Initial list:"); wordsplit_dump_nodes(wsp); } if (rc) { @@ -1153,8 +1162,8 @@ wordsplit_len(const char *command, size_t len, struct wordsplit *wsp, wordsplit_free_nodes(wsp); return wsp->ws_errno; } - if (wsp->ws_flags & WRDSF_DEBUG) { - wsp->ws_error("Expanded list:"); + if (wsp->ws_flags & WRDSF_SHOWDBG) { + wsp->ws_debug("Expanded list:"); wordsplit_dump_nodes(wsp); } } @@ -1162,16 +1171,16 @@ wordsplit_len(const char *command, size_t len, struct wordsplit *wsp, do { if (wsnode_quoteremoval(wsp)) break; - if (wsp->ws_flags & WRDSF_DEBUG) { - wsp->ws_error("After quote removal:"); + if (wsp->ws_flags & WRDSF_SHOWDBG) { + wsp->ws_debug("After quote removal:"); wordsplit_dump_nodes(wsp); } if (wsnode_coalesce(wsp)) break; - if (wsp->ws_flags & WRDSF_DEBUG) { - wsp->ws_error("Coalesced list:"); + if (wsp->ws_flags & WRDSF_SHOWDBG) { + wsp->ws_debug("Coalesced list:"); wordsplit_dump_nodes(wsp); } @@ -251,6 +251,18 @@ asgn(struct wordsplit *ws, size_t *psize) } +static void +smapd_ws_debug(const char *fmt, ...) +{ + va_list ap; + + smap_stream_printf(smap_debug_str, "WS: "); + va_start(ap, fmt); + smap_stream_vprintf(smap_debug_str, fmt, ap); + va_end(ap); + smap_stream_write(smap_debug_str, "\n", 1, NULL); +} + void parse_config_loop(struct cfg_kw *kwtab, void *data) { @@ -266,7 +278,12 @@ parse_config_loop(struct cfg_kw *kwtab, void *data) ws.ws_error = smap_error; ws.ws_comment = "#"; - + + if (smap_debug_np(DBG_CONF, 100)) { + ws.ws_debug = smapd_ws_debug; + wsflags |= WRDSF_DEBUG | WRDSF_SHOWDBG; + } + while (!eof && read_line(&buf, &size)) { struct cfg_kw *kwp; @@ -281,6 +298,19 @@ parse_config_loop(struct cfg_kw *kwtab, void *data) if (ws.ws_wordc == 0) continue; + if (smap_debug_np(DBG_CONF, 1)) { + size_t i; + + smap_stream_printf(smap_debug_str, + "%s:%lu: [%u args]:", + cfg_file_name, cfg_line, + ws.ws_wordc); + for (i = 0; i < ws.ws_wordc; i++) + smap_stream_printf(smap_debug_str, " '%s'", + ws.ws_wordv[i]); + smap_stream_printf(smap_debug_str, "\n"); + } + if (asgn_p(ws.ws_wordv[0])) { if (ws.ws_wordc > 1) { smap_error("%s:%u: too many arguments " diff --git a/src/smapd.c b/src/smapd.c index 3365387..9ce30e7 100644 --- a/src/smapd.c +++ b/src/smapd.c @@ -830,6 +830,7 @@ debug_init() "module", "database", "query", + "conf", NULL }; int i; for (i = 0; dbgname[i]; i++) diff --git a/src/smapd.h b/src/smapd.h index 5a7b780..59a4dd9 100644 --- a/src/smapd.h +++ b/src/smapd.h @@ -133,6 +133,7 @@ void add_trace_pattern(const char *arg); #define DBG_MODULE 2 #define DBG_DATABASE 3 #define DBG_QUERY 4 +#define DBG_CONF 5 #define debug smap_debug |