diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 0c1c734c..7d980490 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -1,3 +1,11 @@ +2010-01-26 Arnim Laeuger + + * src/apps/jtag/jtag.c: quote whitespace in filenames with " in + readline completion + + * src/global/parse.c: escape whitespace with '\' (Gaston Rodriguez) + quote whitespace with ' and " + 2010-01-26 Jie Zhang Mike Frysinger diff --git a/urjtag/src/apps/jtag/jtag.c b/urjtag/src/apps/jtag/jtag.c index fe530655..fdca5b25 100644 --- a/urjtag/src/apps/jtag/jtag.c +++ b/urjtag/src/apps/jtag/jtag.c @@ -563,6 +563,9 @@ main (int argc, char *const argv[]) #ifdef HAVE_LIBREADLINE #ifdef HAVE_READLINE_COMPLETION + rl_completer_quote_characters = "\""; + rl_filename_completion_desired = 1; + rl_filename_quote_characters = " "; rl_attempted_completion_function = urj_cmd_completion; #endif #endif diff --git a/urjtag/src/global/parse.c b/urjtag/src/global/parse.c index d6a01a1c..82132c9b 100644 --- a/urjtag/src/global/parse.c +++ b/urjtag/src/global/parse.c @@ -48,6 +48,7 @@ int urj_parse_line (urj_chain_t *chain, char *line) { int l, i, r, tcnt; + int escape = 0, quote_single = 0, quote_double = 0; char **a; char *c, *d; char *sline; @@ -84,10 +85,32 @@ urj_parse_line (urj_chain_t *chain, char *line) if (*c == '\0' || *c == '#') break; - /* copy the meat (non-space, non-NUL) */ - while (!isspace (*c) && *c != '\0') + /* copy the meat (non-space, non-NUL), consider escape and quotes */ + while ((!isspace (*c) + || escape + || quote_single + || quote_double) && *c != '\0') { - *d++ = *c++; + if (*c == '\'' && !escape && !quote_double) + { + quote_single ^= 1; + c++; + } + else if (*c == '"' && !escape && !quote_single) + { + quote_double ^= 1; + c++; + } + else if (*c == '\\' && !escape) + { + escape = 1; + c++; + } + else + { + escape = 0; + *d++ = *c++; + } } /* mark the end to the destination string */ *d++ = '\0';