support escape and quote of whitespace in filenames

quote automatically with " in readline completion


git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1737 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Arnim Läuger 15 years ago
parent 7b54f73634
commit a07667ffb7

@ -1,3 +1,11 @@
2010-01-26 Arnim Laeuger <arniml>
* 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 <jie.zhang@analog.com>
Mike Frysinger <vapier@gentoo.org>

@ -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

@ -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';

Loading…
Cancel
Save