summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2010-06-29 18:34:34 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2010-06-29 18:34:34 (GMT)
commit2f831a4b8b76074284c9f8321ad1f8249664834e (patch) (unidiff)
treeea804cc077f9831b8e76cb3edc87e47df17283ca
parent3f938834227d544f8b5fe05dcf3f57eecc5e9197 (diff)
downloadsmap-2f831a4b8b76074284c9f8321ad1f8249664834e.tar.gz
smap-2f831a4b8b76074284c9f8321ad1f8249664834e.tar.bz2
Improve debugging features.
* include/smap/wordsplit.h: Rearrange WRDSF_ flags. (WRDSF_WARNUNDEF): New flag. (WRDSE_UNDEF): New error code. * lib/wordsplit.c (expvar): Handle WRDSF_UNDEF and WRDSF_WARNUNDEF. (wordsplit_perror, _wordsplit_errstr): Handle WRDSE_UNDEF. * src/cfg.c (parse_config_loop): Level 1 enables WRDSF_WARNUNDEF. * doc/debugcat.texi: Document level conf(5).
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--doc/debugcat.texi15
-rw-r--r--include/smap/wordsplit.h53
-rw-r--r--lib/wordsplit.c28
-rw-r--r--src/cfg.c6
4 files changed, 67 insertions, 35 deletions
diff --git a/doc/debugcat.texi b/doc/debugcat.texi
index 5bafb84..7bb9023 100644
--- a/doc/debugcat.texi
+++ b/doc/debugcat.texi
@@ -38,6 +38,19 @@ loaded, etc.
38Databases and their functionality. 38Databases and their functionality.
39 39
40@item query (4) 40@item query (4)
41Query routing. 41Query dispatcher.
42
43@item conf (5)
44Configuration file parser.
45
46Level @samp{1} enables warnings about undefined variables.
47
48Level @samp{2} displays each logical line and the result of
49expanding and splitting it.
50
51Level @samp{100} enables wordsplitter debugging. This means a
52@emph{lot} of cryptic output useful only to those who have a
53good knowledge of how the wordsplitter works.
54
42@end table 55@end table
43 56
diff --git a/include/smap/wordsplit.h b/include/smap/wordsplit.h
index 07afc0a..de3a697 100644
--- a/include/smap/wordsplit.h
+++ b/include/smap/wordsplit.h
@@ -44,60 +44,62 @@ struct wordsplit
44 44
45/* Append the words found to the array resulting from a previous 45/* Append the words found to the array resulting from a previous
46 call. */ 46 call. */
47#define WRDSF_APPEND 0x000001 47#define WRDSF_APPEND 0x0000001
48/* Insert we_offs initial NULLs in the array ws_wordv. 48/* Insert we_offs initial NULLs in the array ws_wordv.
49 (These are not counted in the returned ws_wordc.) */ 49 (These are not counted in the returned ws_wordc.) */
50#define WRDSF_DOOFFS 0x000002 50#define WRDSF_DOOFFS 0x0000002
51/* Don't do command substitution. Reserved for future use. */ 51/* Don't do command substitution. Reserved for future use. */
52#define WRDSF_NOCMD 0x000004 52#define WRDSF_NOCMD 0x0000004
53/* The parameter p resulted from a previous call to 53/* The parameter p resulted from a previous call to
54 wordsplit(), and wordsplit_free() was not called. Reuse the 54 wordsplit(), and wordsplit_free() was not called. Reuse the
55 allocated storage. */ 55 allocated storage. */
56#define WRDSF_REUSE 0x000008 56#define WRDSF_REUSE 0x0000008
57/* Print errors */ 57/* Print errors */
58#define WRDSF_SHOWERR 0x000010 58#define WRDSF_SHOWERR 0x0000010
59/* Consider it an error if an undefined shell variable 59/* Consider it an error if an undefined shell variable
60 is expanded. */ 60 is expanded. */
61#define WRDSF_UNDEF 0x000020 61#define WRDSF_UNDEF 0x0000020
62 62
63/* Don't do variable expansion. Reserved for future use. */ 63/* Don't do variable expansion. Reserved for future use. */
64#define WRDSF_NOVAR 0x000040 64#define WRDSF_NOVAR 0x0000040
65/* Abort on ENOMEM error */ 65/* Abort on ENOMEM error */
66#define WRDSF_ENOMEMABRT 0x000080 66#define WRDSF_ENOMEMABRT 0x0000080
67/* Treat whitespace as delimiters */ 67/* Treat whitespace as delimiters */
68#define WRDSF_WS 0x000100 68#define WRDSF_WS 0x0000100
69/* Handle quotes and escape directives */ 69/* Handle quotes and escape directives */
70#define WRDSF_QUOTE 0x000200 70#define WRDSF_QUOTE 0x0000200
71/* Replace each input sequence of repeated delimiters with a single 71/* Replace each input sequence of repeated delimiters with a single
72 delimiter */ 72 delimiter */
73#define WRDSF_SQUEEZE_DELIMS 0x000400 73#define WRDSF_SQUEEZE_DELIMS 0x0000400
74/* Return delimiters */ 74/* Return delimiters */
75#define WRDSF_RETURN_DELIMS 0x000800 75#define WRDSF_RETURN_DELIMS 0x0000800
76/* Treat sed expressions as words */ 76/* Treat sed expressions as words */
77#define WRDSF_SED_EXPR 0x001000 77#define WRDSF_SED_EXPR 0x0001000
78/* ws_delim field is initialized */ 78/* ws_delim field is initialized */
79#define WRDSF_DELIM 0x002000 79#define WRDSF_DELIM 0x0002000
80/* ws_comment field is initialized */ 80/* ws_comment field is initialized */
81#define WRDSF_COMMENT 0x004000 81#define WRDSF_COMMENT 0x0004000
82/* ws_alloc_die field is initialized */ 82/* ws_alloc_die field is initialized */
83#define WRDSF_ALLOC_DIE 0x008000 83#define WRDSF_ALLOC_DIE 0x0008000
84/* ws_error field is initialized */ 84/* ws_error field is initialized */
85#define WRDSF_ERROR 0x010000 85#define WRDSF_ERROR 0x0010000
86/* ws_debug field is initialized */
87#define WRDSF_DEBUG 0x0020000
86/* ws_env field is initialized */ 88/* ws_env field is initialized */
87#define WRDSF_ENV 0x020000 89#define WRDSF_ENV 0x0040000
88/* ws_getvar field is initialized */ 90/* ws_getvar field is initialized */
89#define WRDSF_GETVAR 0x040000 91#define WRDSF_GETVAR 0x0080000
90/* enable debugging */ 92/* enable debugging */
91#define WRDSF_SHOWDBG 0x080000 93#define WRDSF_SHOWDBG 0x0100000
92/* Don't split input into words. Useful for side effects. */ 94/* Don't split input into words. Useful for side effects. */
93#define WRDSF_NOSPLIT 0x100000 95#define WRDSF_NOSPLIT 0x0200000
94/* Keep undefined variables in place, instead of expanding them to 96/* Keep undefined variables in place, instead of expanding them to
95 empty string */ 97 empty string */
96#define WRDSF_KEEPUNDEF 0x200000 98#define WRDSF_KEEPUNDEF 0x0400000
99/* Warn about undefined variables */
100#define WRDSF_WARNUNDEF 0x0800000
97/* Handle C escapes */ 101/* Handle C escapes */
98#define WRDSF_CESCAPES 0x400000 102#define WRDSF_CESCAPES 0x1000000
99/* ws_debug field is initialized */
100#define WRDSF_DEBUG 0x800000
101 103
102 #define WRDSF_DEFFLAGS \ 104 #define WRDSF_DEFFLAGS \
103 (WRDSF_NOVAR | WRDSF_NOCMD | \ 105 (WRDSF_NOVAR | WRDSF_NOCMD | \
@@ -109,6 +111,7 @@ struct wordsplit
109#define WRDSE_NOSUPP 3 111#define WRDSE_NOSUPP 3
110#define WRDSE_USAGE 4 112#define WRDSE_USAGE 4
111#define WRDSE_CBRACE 5 113#define WRDSE_CBRACE 5
114#define WRDSE_UNDEF 6
112 115
113int wordsplit(const char *s, struct wordsplit *p, int flags); 116int wordsplit(const char *s, struct wordsplit *p, int flags);
114void wordsplit_free(struct wordsplit *p); 117void wordsplit_free(struct wordsplit *p);
diff --git a/lib/wordsplit.c b/lib/wordsplit.c
index 9f1b9d5..d1851bf 100644
--- a/lib/wordsplit.c
+++ b/lib/wordsplit.c
@@ -669,10 +669,20 @@ expvar(struct wordsplit *wsp, const char *str, size_t len,
669 return _wsplt_nomem(wsp); 669 return _wsplt_nomem(wsp);
670 } else if (wsp->ws_flags & WRDSF_GETVAR) 670 } else if (wsp->ws_flags & WRDSF_GETVAR)
671 value = wsp->ws_getvar(str, i); 671 value = wsp->ws_getvar(str, i);
672 else if (wsp->ws_flags & WRDSF_KEEPUNDEF) 672 else if (wsp->ws_flags & WRDSF_UNDEF) {
673 value = NULL; 673 wsp->ws_errno = WRDSE_UNDEF;
674 else 674 if (wsp->ws_flags & WRDSF_SHOWERR)
675 value = ""; 675 wordsplit_perror(wsp);
676 return 1;
677 } else {
678 if (wsp->ws_flags & WRDSF_WARNUNDEF)
679 wsp->ws_error(_("warning: undefined variable `%.*s'"),
680 i, str);
681 if (wsp->ws_flags & WRDSF_KEEPUNDEF)
682 value = NULL;
683 else
684 value = "";
685 }
676 /* FIXME: handle defstr */ 686 /* FIXME: handle defstr */
677 if (value) { 687 if (value) {
678 if (flg & _WSNF_QUOTE) { 688 if (flg & _WSNF_QUOTE) {
@@ -1221,8 +1231,7 @@ wordsplit_perror(struct wordsplit *wsp)
1221 break; 1231 break;
1222 1232
1223 case WRDSE_NOSUPP: 1233 case WRDSE_NOSUPP:
1224 wsp->ws_error(_("command substitution " 1234 wsp->ws_error(_("command substitution is not yet supported"));
1225 "is not yet supported"));
1226 1235
1227 case WRDSE_USAGE: 1236 case WRDSE_USAGE:
1228 wsp->ws_error(_("invalid wordsplit usage")); 1237 wsp->ws_error(_("invalid wordsplit usage"));
@@ -1231,6 +1240,10 @@ wordsplit_perror(struct wordsplit *wsp)
1231 case WRDSE_CBRACE: 1240 case WRDSE_CBRACE:
1232 wsp->ws_error(_("unbalanced curly brace")); 1241 wsp->ws_error(_("unbalanced curly brace"));
1233 break; 1242 break;
1243
1244 case WRDSE_UNDEF:
1245 wsp->ws_error(_("undefined variable"));
1246 break;
1234 1247
1235 default: 1248 default:
1236 wsp->ws_error(_("unknown error")); 1249 wsp->ws_error(_("unknown error"));
@@ -1244,7 +1257,8 @@ const char *_wordsplit_errstr[] = {
1244 N_("variable expansion and command substitution " 1257 N_("variable expansion and command substitution "
1245 "are not yet supported"), 1258 "are not yet supported"),
1246 N_("invalid wordsplit usage"), 1259 N_("invalid wordsplit usage"),
1247 N_("unbalanced curly brace") 1260 N_("unbalanced curly brace"),
1261 N_("undefined variable")
1248}; 1262};
1249int _wordsplit_nerrs = sizeof(_wordsplit_errstr)/sizeof(_wordsplit_errstr[0]); 1263int _wordsplit_nerrs = sizeof(_wordsplit_errstr)/sizeof(_wordsplit_errstr[0]);
1250 1264
diff --git a/src/cfg.c b/src/cfg.c
index b0efe1c..ca61ab4 100644
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -278,7 +278,9 @@ parse_config_loop(struct cfg_kw *kwtab, void *data)
278 278
279 ws.ws_error = smap_error; 279 ws.ws_error = smap_error;
280 ws.ws_comment = "#"; 280 ws.ws_comment = "#";
281 281
282 if (smap_debug_np(DBG_CONF, 1))
283 wsflags |= WRDSF_WARNUNDEF;
282 if (smap_debug_np(DBG_CONF, 100)) { 284 if (smap_debug_np(DBG_CONF, 100)) {
283 ws.ws_debug = smapd_ws_debug; 285 ws.ws_debug = smapd_ws_debug;
284 wsflags |= WRDSF_DEBUG | WRDSF_SHOWDBG; 286 wsflags |= WRDSF_DEBUG | WRDSF_SHOWDBG;
@@ -298,7 +300,7 @@ parse_config_loop(struct cfg_kw *kwtab, void *data)
298 if (ws.ws_wordc == 0) 300 if (ws.ws_wordc == 0)
299 continue; 301 continue;
300 302
301 if (smap_debug_np(DBG_CONF, 1)) { 303 if (smap_debug_np(DBG_CONF, 2)) {
302 size_t i; 304 size_t i;
303 305
304 smap_stream_printf(smap_debug_str, 306 smap_stream_printf(smap_debug_str,

Return to:

Send suggestions and report system problems to the System administrator.