From 8cdce50e8cb227096d312a1636c2cab79ac641f5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Jun 2015 14:23:59 -0600 Subject: [PATCH] Extend the mkconfig tool so that it can dequote a quoated list of quoated strings. THTTPD uses such a configration setting to provide the list of index files. --- tools/cfgdefine.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/cfgdefine.c b/tools/cfgdefine.c index 80975b7aae..de91882a56 100644 --- a/tools/cfgdefine.c +++ b/tools/cfgdefine.c @@ -90,7 +90,7 @@ static const char *dequote_list[] = "CONFIG_EXAMPLES_HELLO_PROGNAME", /* Name of installed hello example program */ "CONFIG_EXAMPLES_NSH_PROGNAME", /* Name of installed NSH example program */ - + "CONFIG_THTTPD_INDEX_NAMES", /* List of index file names */ NULL /* Marks the end of the list */ }; @@ -225,7 +225,9 @@ static char *dequote_value(const char *varname, char *varval) { const char **dqnam; char *dqval = varval; + char *ptr; int len; + int i; if (dqval) { @@ -240,12 +242,12 @@ static char *dequote_value(const char *varname, char *varval) } /* Did we find the variable name in the list of configuration variables - * to be dequoated? + * to be dequoted? */ if (*dqnam) { - /* Yes... Check if there is a traiing quote */ + /* Yes... Check if there is a trailing quote */ len = strlen(dqval); if (dqval[len-1] == '"') @@ -266,6 +268,28 @@ static char *dequote_value(const char *varname, char *varval) len--; } + /* A special case is a quoted list of quoted strings. In that case + * we will need to remove the backspaces from the internally quoted + * strings. NOTE: this will not handle nested quoted quotes. + */ + + for (ptr = dqval; *ptr; ptr++) + { + /* Check for a quoted quote */ + + if (ptr[0] == '\\' && ptr[1] == '"') + { + /* Delete the backslash by moving the rest of the string */ + + for (i = 0; ptr[i]; i++) + { + ptr[i] = ptr[i+1]; + } + + len--; + } + } + /* Handle the case where nothing is left after dequoting */ if (len <= 0)