diff options
-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 @@ -38,6 +38,19 @@ loaded, etc. Databases and their functionality. @item query (4) -Query routing. +Query dispatcher. + +@item conf (5) +Configuration file parser. + +Level @samp{1} enables warnings about undefined variables. + +Level @samp{2} displays each logical line and the result of +expanding and splitting it. + +Level @samp{100} enables wordsplitter debugging. This means a +@emph{lot} of cryptic output useful only to those who have a +good knowledge of how the wordsplitter works. + @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 @@ -44,60 +44,62 @@ struct wordsplit /* Append the words found to the array resulting from a previous call. */ -#define WRDSF_APPEND 0x000001 +#define WRDSF_APPEND 0x0000001 /* Insert we_offs initial NULLs in the array ws_wordv. (These are not counted in the returned ws_wordc.) */ -#define WRDSF_DOOFFS 0x000002 +#define WRDSF_DOOFFS 0x0000002 /* Don't do command substitution. Reserved for future use. */ -#define WRDSF_NOCMD 0x000004 +#define WRDSF_NOCMD 0x0000004 /* The parameter p resulted from a previous call to wordsplit(), and wordsplit_free() was not called. Reuse the allocated storage. */ -#define WRDSF_REUSE 0x000008 +#define WRDSF_REUSE 0x0000008 /* Print errors */ -#define WRDSF_SHOWERR 0x000010 +#define WRDSF_SHOWERR 0x0000010 /* Consider it an error if an undefined shell variable is expanded. */ -#define WRDSF_UNDEF 0x000020 +#define WRDSF_UNDEF 0x0000020 /* Don't do variable expansion. Reserved for future use. */ -#define WRDSF_NOVAR 0x000040 +#define WRDSF_NOVAR 0x0000040 /* Abort on ENOMEM error */ -#define WRDSF_ENOMEMABRT 0x000080 +#define WRDSF_ENOMEMABRT 0x0000080 /* Treat whitespace as delimiters */ -#define WRDSF_WS 0x000100 +#define WRDSF_WS 0x0000100 /* Handle quotes and escape directives */ -#define WRDSF_QUOTE 0x000200 +#define WRDSF_QUOTE 0x0000200 /* Replace each input sequence of repeated delimiters with a single delimiter */ -#define WRDSF_SQUEEZE_DELIMS 0x000400 +#define WRDSF_SQUEEZE_DELIMS 0x0000400 /* Return delimiters */ -#define WRDSF_RETURN_DELIMS 0x000800 +#define WRDSF_RETURN_DELIMS 0x0000800 /* Treat sed expressions as words */ -#define WRDSF_SED_EXPR 0x001000 +#define WRDSF_SED_EXPR 0x0001000 /* ws_delim field is initialized */ -#define WRDSF_DELIM 0x002000 +#define WRDSF_DELIM 0x0002000 /* ws_comment field is initialized */ -#define WRDSF_COMMENT 0x004000 +#define WRDSF_COMMENT 0x0004000 /* ws_alloc_die field is initialized */ -#define WRDSF_ALLOC_DIE 0x008000 +#define WRDSF_ALLOC_DIE 0x0008000 /* ws_error field is initialized */ -#define WRDSF_ERROR 0x010000 +#define WRDSF_ERROR 0x0010000 +/* ws_debug field is initialized */ +#define WRDSF_DEBUG 0x0020000 /* ws_env field is initialized */ -#define WRDSF_ENV 0x020000 +#define WRDSF_ENV 0x0040000 /* ws_getvar field is initialized */ -#define WRDSF_GETVAR 0x040000 +#define WRDSF_GETVAR 0x0080000 /* enable debugging */ -#define WRDSF_SHOWDBG 0x080000 +#define WRDSF_SHOWDBG 0x0100000 /* Don't split input into words. Useful for side effects. */ -#define WRDSF_NOSPLIT 0x100000 +#define WRDSF_NOSPLIT 0x0200000 /* Keep undefined variables in place, instead of expanding them to empty string */ -#define WRDSF_KEEPUNDEF 0x200000 +#define WRDSF_KEEPUNDEF 0x0400000 +/* Warn about undefined variables */ +#define WRDSF_WARNUNDEF 0x0800000 /* Handle C escapes */ -#define WRDSF_CESCAPES 0x400000 -/* ws_debug field is initialized */ -#define WRDSF_DEBUG 0x800000 +#define WRDSF_CESCAPES 0x1000000 #define WRDSF_DEFFLAGS \ (WRDSF_NOVAR | WRDSF_NOCMD | \ @@ -109,6 +111,7 @@ struct wordsplit #define WRDSE_NOSUPP 3 #define WRDSE_USAGE 4 #define WRDSE_CBRACE 5 +#define WRDSE_UNDEF 6 int wordsplit(const char *s, struct wordsplit *p, int flags); void 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, return _wsplt_nomem(wsp); } else if (wsp->ws_flags & WRDSF_GETVAR) value = wsp->ws_getvar(str, i); - else if (wsp->ws_flags & WRDSF_KEEPUNDEF) - value = NULL; - else - value = ""; + else if (wsp->ws_flags & WRDSF_UNDEF) { + wsp->ws_errno = WRDSE_UNDEF; + if (wsp->ws_flags & WRDSF_SHOWERR) + wordsplit_perror(wsp); + return 1; + } else { + if (wsp->ws_flags & WRDSF_WARNUNDEF) + wsp->ws_error(_("warning: undefined variable `%.*s'"), + i, str); + if (wsp->ws_flags & WRDSF_KEEPUNDEF) + value = NULL; + else + value = ""; + } /* FIXME: handle defstr */ if (value) { if (flg & _WSNF_QUOTE) { @@ -1221,8 +1231,7 @@ wordsplit_perror(struct wordsplit *wsp) break; case WRDSE_NOSUPP: - wsp->ws_error(_("command substitution " - "is not yet supported")); + wsp->ws_error(_("command substitution is not yet supported")); case WRDSE_USAGE: wsp->ws_error(_("invalid wordsplit usage")); @@ -1231,6 +1240,10 @@ wordsplit_perror(struct wordsplit *wsp) case WRDSE_CBRACE: wsp->ws_error(_("unbalanced curly brace")); break; + + case WRDSE_UNDEF: + wsp->ws_error(_("undefined variable")); + break; default: wsp->ws_error(_("unknown error")); @@ -1244,7 +1257,8 @@ const char *_wordsplit_errstr[] = { N_("variable expansion and command substitution " "are not yet supported"), N_("invalid wordsplit usage"), - N_("unbalanced curly brace") + N_("unbalanced curly brace"), + N_("undefined variable") }; int _wordsplit_nerrs = sizeof(_wordsplit_errstr)/sizeof(_wordsplit_errstr[0]); @@ -278,7 +278,9 @@ parse_config_loop(struct cfg_kw *kwtab, void *data) ws.ws_error = smap_error; ws.ws_comment = "#"; - + + if (smap_debug_np(DBG_CONF, 1)) + wsflags |= WRDSF_WARNUNDEF; if (smap_debug_np(DBG_CONF, 100)) { ws.ws_debug = smapd_ws_debug; wsflags |= WRDSF_DEBUG | WRDSF_SHOWDBG; @@ -298,7 +300,7 @@ parse_config_loop(struct cfg_kw *kwtab, void *data) if (ws.ws_wordc == 0) continue; - if (smap_debug_np(DBG_CONF, 1)) { + if (smap_debug_np(DBG_CONF, 2)) { size_t i; smap_stream_printf(smap_debug_str, |