From 3cd538634f71538370f5af239f342aec48b7470b Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Wed, 30 May 2018 02:06:03 +0800 Subject: expand: Do not reprocess data when expanding words Currently various paths will reprocess data when performing word expansion. For example, expari will skip backwards looking for the start of the arithmetic expansion, while evalvar will skip unexpanded words manually. This is cumbersome and error-prone. This patch fixes this by making word expansions proceed in a linear fashion. This means changing argstr and the various expansion functions such as expari and subevalvar to return the next character to be expanded. This is inspired by similar code from FreeBSD. However, we take things one step further and completely remove the manual word skipping in evalvar. This is accomplished by introducing a new EXP_DISCARD flag that tells argstr to only parse and not produce any actual expansions. Incidentally, argstr will now always NUL-terminate the expansion unless the EXP_WORD flag is set. This is because all but one caller of argstr wants the result to be NUL-termianted. Signed-off-by: Herbert Xu --- src/expand.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/expand.h') diff --git a/src/expand.h b/src/expand.h index 617b851..c44b848 100644 --- a/src/expand.h +++ b/src/expand.h @@ -59,11 +59,11 @@ struct arglist { #define EXP_WORD 0x80 /* expand word in parameter expansion */ #define EXP_QUOTED 0x100 /* expand word in double quotes */ #define EXP_KEEPNUL 0x200 /* do not skip NUL characters */ +#define EXP_DISCARD 0x400 /* discard result of expansion */ union node; void expandarg(union node *, struct arglist *, int); -void expari(int); #define rmescapes(p) _rmescapes((p), 0) char *_rmescapes(char *, int); int casematch(union node *, char *); -- cgit 1.4.1