diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-29 21:34:34 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-29 21:34:34 +0300 |
commit | 2f831a4b8b76074284c9f8321ad1f8249664834e (patch) | |
tree | ea804cc077f9831b8e76cb3edc87e47df17283ca | |
parent | 3f938834227d544f8b5fe05dcf3f57eecc5e9197 (diff) | |
download | smap-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).
-rw-r--r-- | doc/debugcat.texi | 15 | ||||
-rw-r--r-- | include/smap/wordsplit.h | 53 | ||||
-rw-r--r-- | lib/wordsplit.c | 28 | ||||
-rw-r--r-- | src/cfg.c | 6 |
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 | |||
@@ -40,3 +40,16 @@ Databases and their functionality. | |||
40 | @item query (4) | 40 | @item query (4) |
41 | Query routing. | 41 | Query dispatcher. |
42 | |||
43 | @item conf (5) | ||
44 | Configuration file parser. | ||
45 | |||
46 | Level @samp{1} enables warnings about undefined variables. | ||
47 | |||
48 | Level @samp{2} displays each logical line and the result of | ||
49 | expanding and splitting it. | ||
50 | |||
51 | Level @samp{100} enables wordsplitter debugging. This means a | ||
52 | @emph{lot} of cryptic output useful only to those who have a | ||
53 | good knowledge of how the wordsplitter works. | ||
54 | |||
42 | @end table | 55 | @end table |
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 | |||
@@ -46,8 +46,8 @@ struct wordsplit | |||
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 |
@@ -55,47 +55,49 @@ struct wordsplit | |||
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 | ||
@@ -111,2 +113,3 @@ struct wordsplit | |||
111 | #define WRDSE_CBRACE 5 | 113 | #define WRDSE_CBRACE 5 |
114 | #define WRDSE_UNDEF 6 | ||
112 | 115 | ||
diff --git a/lib/wordsplit.c b/lib/wordsplit.c index 9f1b9d5..d1851bf 100644 --- a/lib/wordsplit.c +++ b/lib/wordsplit.c | |||
@@ -671,6 +671,16 @@ expvar(struct wordsplit *wsp, const char *str, size_t len, | |||
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 */ |
@@ -1223,4 +1233,3 @@ wordsplit_perror(struct wordsplit *wsp) | |||
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 | ||
@@ -1233,2 +1242,6 @@ wordsplit_perror(struct wordsplit *wsp) | |||
1233 | break; | 1242 | break; |
1243 | |||
1244 | case WRDSE_UNDEF: | ||
1245 | wsp->ws_error(_("undefined variable")); | ||
1246 | break; | ||
1234 | 1247 | ||
@@ -1246,3 +1259,4 @@ const char *_wordsplit_errstr[] = { | |||
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 | }; |
@@ -280,3 +280,5 @@ parse_config_loop(struct cfg_kw *kwtab, void *data) | |||
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)) { |
@@ -300,3 +302,3 @@ parse_config_loop(struct cfg_kw *kwtab, void *data) | |||
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; |