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 | |||
30 | const char *ws_comment; | 30 | const char *ws_comment; |
31 | void (*ws_alloc_die)(struct wordsplit *wsp); | 31 | void (*ws_alloc_die)(struct wordsplit *wsp); |
32 | void (*ws_error)(const char *, ...); | 32 | void (*ws_error)(const char *, ...); |
33 | void (*ws_debug)(const char *, ...); | ||
34 | |||
33 | const char **ws_env; | 35 | const char **ws_env; |
34 | char *(*ws_getvar)(const char *, size_t); | 36 | char *(*ws_getvar)(const char *, size_t); |
35 | 37 | ||
@@ -86,7 +88,7 @@ struct wordsplit | |||
86 | /* ws_getvar field is initialized */ | 88 | /* ws_getvar field is initialized */ |
87 | #define WRDSF_GETVAR 0x040000 | 89 | #define WRDSF_GETVAR 0x040000 |
88 | /* enable debugging */ | 90 | /* enable debugging */ |
89 | #define WRDSF_DEBUG 0x080000 | 91 | #define WRDSF_SHOWDBG 0x080000 |
90 | /* Don't split input into words. Useful for side effects. */ | 92 | /* Don't split input into words. Useful for side effects. */ |
91 | #define WRDSF_NOSPLIT 0x100000 | 93 | #define WRDSF_NOSPLIT 0x100000 |
92 | /* Keep undefined variables in place, instead of expanding them to | 94 | /* Keep undefined variables in place, instead of expanding them to |
@@ -94,6 +96,8 @@ struct wordsplit | |||
94 | #define WRDSF_KEEPUNDEF 0x200000 | 96 | #define WRDSF_KEEPUNDEF 0x200000 |
95 | /* Handle C escapes */ | 97 | /* Handle C escapes */ |
96 | #define WRDSF_CESCAPES 0x400000 | 98 | #define WRDSF_CESCAPES 0x400000 |
99 | /* ws_debug field is initialized */ | ||
100 | #define WRDSF_DEBUG 0x800000 | ||
97 | 101 | ||
98 | #define WRDSF_DEFFLAGS \ | 102 | #define WRDSF_DEFFLAGS \ |
99 | (WRDSF_NOVAR | WRDSF_NOCMD | \ | 103 | (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, | |||
113 | return wsp->ws_errno; | 113 | return wsp->ws_errno; |
114 | } | 114 | } |
115 | 115 | ||
116 | if (wsp->ws_flags & WRDSF_SHOWDBG) { | ||
117 | if (!(wsp->ws_flags & WRDSF_DEBUG)) { | ||
118 | if (wsp->ws_flags & WRDSF_ERROR) | ||
119 | wsp->ws_debug = wsp->ws_error; | ||
120 | else | ||
121 | wsp->ws_flags &= ~WRDSF_SHOWDBG; | ||
122 | } | ||
123 | } | ||
124 | |||
116 | wsp->ws_input = input; | 125 | wsp->ws_input = input; |
117 | wsp->ws_len = len; | 126 | wsp->ws_len = len; |
118 | 127 | ||
@@ -354,11 +363,11 @@ wordsplit_dump_nodes(struct wordsplit *wsp) | |||
354 | 363 | ||
355 | for (p = wsp->ws_head, n = 0; p; p = p->next, n++) { | 364 | for (p = wsp->ws_head, n = 0; p; p = p->next, n++) { |
356 | if (p->flags & _WSNF_WORD) | 365 | if (p->flags & _WSNF_WORD) |
357 | wsp->ws_error("%4d: %p: %#04x (%s):%s;", | 366 | wsp->ws_debug("%4d: %p: %#04x (%s):%s;", |
358 | n, p, p->flags, wsnode_flagstr(p->flags), | 367 | n, p, p->flags, wsnode_flagstr(p->flags), |
359 | p->v.word); | 368 | p->v.word); |
360 | else | 369 | else |
361 | wsp->ws_error("%4d: %p: %#04x (%s):%.*s;", | 370 | wsp->ws_debug("%4d: %p: %#04x (%s):%.*s;", |
362 | n, p, p->flags, wsnode_flagstr(p->flags), | 371 | n, p, p->flags, wsnode_flagstr(p->flags), |
363 | p->v.segm.end - p->v.segm.beg, | 372 | p->v.segm.end - p->v.segm.beg, |
364 | wsp->ws_input + p->v.segm.beg); | 373 | wsp->ws_input + p->v.segm.beg); |
@@ -1126,8 +1135,8 @@ wordsplit_len(const char *command, size_t len, struct wordsplit *wsp, | |||
1126 | if (rc) | 1135 | if (rc) |
1127 | return rc; | 1136 | return rc; |
1128 | 1137 | ||
1129 | if (wsp->ws_flags & WRDSF_DEBUG) | 1138 | if (wsp->ws_flags & WRDSF_SHOWDBG) |
1130 | wsp->ws_error("INPUT:%.*s;", len, command); | 1139 | wsp->ws_debug("Input:%.*s;", len, command); |
1131 | 1140 | ||
1132 | if (wsp->ws_flags & WRDSF_NOSPLIT) { | 1141 | if (wsp->ws_flags & WRDSF_NOSPLIT) { |
1133 | /* Treat entire input as a quoted argument */ | 1142 | /* Treat entire input as a quoted argument */ |
@@ -1138,8 +1147,8 @@ wordsplit_len(const char *command, size_t len, struct wordsplit *wsp, | |||
1138 | start = skip_delim(wsp); | 1147 | start = skip_delim(wsp); |
1139 | } | 1148 | } |
1140 | 1149 | ||
1141 | if (wsp->ws_flags & WRDSF_DEBUG) { | 1150 | if (wsp->ws_flags & WRDSF_SHOWDBG) { |
1142 | wsp->ws_error("Initial list:"); | 1151 | wsp->ws_debug("Initial list:"); |
1143 | wordsplit_dump_nodes(wsp); | 1152 | wordsplit_dump_nodes(wsp); |
1144 | } | 1153 | } |
1145 | if (rc) { | 1154 | if (rc) { |
@@ -1153,8 +1162,8 @@ wordsplit_len(const char *command, size_t len, struct wordsplit *wsp, | |||
1153 | wordsplit_free_nodes(wsp); | 1162 | wordsplit_free_nodes(wsp); |
1154 | return wsp->ws_errno; | 1163 | return wsp->ws_errno; |
1155 | } | 1164 | } |
1156 | if (wsp->ws_flags & WRDSF_DEBUG) { | 1165 | if (wsp->ws_flags & WRDSF_SHOWDBG) { |
1157 | wsp->ws_error("Expanded list:"); | 1166 | wsp->ws_debug("Expanded list:"); |
1158 | wordsplit_dump_nodes(wsp); | 1167 | wordsplit_dump_nodes(wsp); |
1159 | } | 1168 | } |
1160 | } | 1169 | } |
@@ -1162,16 +1171,16 @@ wordsplit_len(const char *command, size_t len, struct wordsplit *wsp, | |||
1162 | do { | 1171 | do { |
1163 | if (wsnode_quoteremoval(wsp)) | 1172 | if (wsnode_quoteremoval(wsp)) |
1164 | break; | 1173 | break; |
1165 | if (wsp->ws_flags & WRDSF_DEBUG) { | 1174 | if (wsp->ws_flags & WRDSF_SHOWDBG) { |
1166 | wsp->ws_error("After quote removal:"); | 1175 | wsp->ws_debug("After quote removal:"); |
1167 | wordsplit_dump_nodes(wsp); | 1176 | wordsplit_dump_nodes(wsp); |
1168 | } | 1177 | } |
1169 | 1178 | ||
1170 | if (wsnode_coalesce(wsp)) | 1179 | if (wsnode_coalesce(wsp)) |
1171 | break; | 1180 | break; |
1172 | 1181 | ||
1173 | if (wsp->ws_flags & WRDSF_DEBUG) { | 1182 | if (wsp->ws_flags & WRDSF_SHOWDBG) { |
1174 | wsp->ws_error("Coalesced list:"); | 1183 | wsp->ws_debug("Coalesced list:"); |
1175 | wordsplit_dump_nodes(wsp); | 1184 | wordsplit_dump_nodes(wsp); |
1176 | } | 1185 | } |
1177 | 1186 | ||
@@ -251,6 +251,18 @@ asgn(struct wordsplit *ws, size_t *psize) | |||
251 | } | 251 | } |
252 | 252 | ||
253 | 253 | ||
254 | static void | ||
255 | smapd_ws_debug(const char *fmt, ...) | ||
256 | { | ||
257 | va_list ap; | ||
258 | |||
259 | smap_stream_printf(smap_debug_str, "WS: "); | ||
260 | va_start(ap, fmt); | ||
261 | smap_stream_vprintf(smap_debug_str, fmt, ap); | ||
262 | va_end(ap); | ||
263 | smap_stream_write(smap_debug_str, "\n", 1, NULL); | ||
264 | } | ||
265 | |||
254 | void | 266 | void |
255 | parse_config_loop(struct cfg_kw *kwtab, void *data) | 267 | parse_config_loop(struct cfg_kw *kwtab, void *data) |
256 | { | 268 | { |
@@ -266,7 +278,12 @@ parse_config_loop(struct cfg_kw *kwtab, void *data) | |||
266 | 278 | ||
267 | ws.ws_error = smap_error; | 279 | ws.ws_error = smap_error; |
268 | ws.ws_comment = "#"; | 280 | ws.ws_comment = "#"; |
269 | 281 | ||
282 | if (smap_debug_np(DBG_CONF, 100)) { | ||
283 | ws.ws_debug = smapd_ws_debug; | ||
284 | wsflags |= WRDSF_DEBUG | WRDSF_SHOWDBG; | ||
285 | } | ||
286 | |||
270 | while (!eof && read_line(&buf, &size)) { | 287 | while (!eof && read_line(&buf, &size)) { |
271 | struct cfg_kw *kwp; | 288 | struct cfg_kw *kwp; |
272 | 289 | ||
@@ -281,6 +298,19 @@ parse_config_loop(struct cfg_kw *kwtab, void *data) | |||
281 | if (ws.ws_wordc == 0) | 298 | if (ws.ws_wordc == 0) |
282 | continue; | 299 | continue; |
283 | 300 | ||
301 | if (smap_debug_np(DBG_CONF, 1)) { | ||
302 | size_t i; | ||
303 | |||
304 | smap_stream_printf(smap_debug_str, | ||
305 | "%s:%lu: [%u args]:", | ||
306 | cfg_file_name, cfg_line, | ||
307 | ws.ws_wordc); | ||
308 | for (i = 0; i < ws.ws_wordc; i++) | ||
309 | smap_stream_printf(smap_debug_str, " '%s'", | ||
310 | ws.ws_wordv[i]); | ||
311 | smap_stream_printf(smap_debug_str, "\n"); | ||
312 | } | ||
313 | |||
284 | if (asgn_p(ws.ws_wordv[0])) { | 314 | if (asgn_p(ws.ws_wordv[0])) { |
285 | if (ws.ws_wordc > 1) { | 315 | if (ws.ws_wordc > 1) { |
286 | smap_error("%s:%u: too many arguments " | 316 | 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() | |||
830 | "module", | 830 | "module", |
831 | "database", | 831 | "database", |
832 | "query", | 832 | "query", |
833 | "conf", | ||
833 | NULL }; | 834 | NULL }; |
834 | int i; | 835 | int i; |
835 | for (i = 0; dbgname[i]; i++) | 836 | 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); | |||
133 | #define DBG_MODULE 2 | 133 | #define DBG_MODULE 2 |
134 | #define DBG_DATABASE 3 | 134 | #define DBG_DATABASE 3 |
135 | #define DBG_QUERY 4 | 135 | #define DBG_QUERY 4 |
136 | #define DBG_CONF 5 | ||
136 | 137 | ||
137 | #define debug smap_debug | 138 | #define debug smap_debug |
138 | 139 | ||