aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-06-29 21:34:34 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-06-29 21:34:34 +0300
commit2f831a4b8b76074284c9f8321ad1f8249664834e (patch)
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).
-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
@@ -40,3 +40,16 @@ 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
@@ -46,8 +46,8 @@ struct wordsplit
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
@@ -55,47 +55,49 @@ struct wordsplit
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
@@ -111,2 +113,3 @@ struct wordsplit
#define WRDSE_CBRACE 5
+#define WRDSE_UNDEF 6
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,
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 */
@@ -1223,4 +1233,3 @@ wordsplit_perror(struct wordsplit *wsp)
case WRDSE_NOSUPP:
- wsp->ws_error(_("command substitution "
- "is not yet supported"));
+ wsp->ws_error(_("command substitution is not yet supported"));
@@ -1233,2 +1242,6 @@ wordsplit_perror(struct wordsplit *wsp)
break;
+
+ case WRDSE_UNDEF:
+ wsp->ws_error(_("undefined variable"));
+ break;
@@ -1246,3 +1259,4 @@ const char *_wordsplit_errstr[] = {
N_("invalid wordsplit usage"),
- N_("unbalanced curly brace")
+ N_("unbalanced curly brace"),
+ N_("undefined variable")
};
diff --git a/src/cfg.c b/src/cfg.c
index b0efe1c..ca61ab4 100644
--- a/src/cfg.c
+++ b/src/cfg.c
@@ -280,3 +280,5 @@ parse_config_loop(struct cfg_kw *kwtab, void *data)
ws.ws_comment = "#";
-
+
+ if (smap_debug_np(DBG_CONF, 1))
+ wsflags |= WRDSF_WARNUNDEF;
if (smap_debug_np(DBG_CONF, 100)) {
@@ -300,3 +302,3 @@ parse_config_loop(struct cfg_kw *kwtab, void *data)
- if (smap_debug_np(DBG_CONF, 1)) {
+ if (smap_debug_np(DBG_CONF, 2)) {
size_t i;

Return to:

Send suggestions and report system problems to the System administrator.