diff options
author | jilles <jilles@FreeBSD.org> | 2011-06-12 23:06:04 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2011-06-12 23:06:04 +0000 |
commit | 91789615b49a87147298eee12c9b111d8c1b64c9 (patch) | |
tree | b1cbd950b159dbb3fa6211ba5a7f7fb7709a612e /bin/sh/expand.c | |
parent | 5f2600c6a978923a3904716ce73814baca63fd0f (diff) | |
download | FreeBSD-src-91789615b49a87147298eee12c9b111d8c1b64c9.zip FreeBSD-src-91789615b49a87147298eee12c9b111d8c1b64c9.tar.gz |
sh: Save/restore changed variables in optimized command substitution.
In optimized command substitution, save and restore any variables changed by
expansions (${var=value} and $((var=assigned))), instead of trying to
determine if an expansion may cause such changes.
If $! is referenced in optimized command substitution, do not cause jobs to
be remembered longer.
This fixes $(jobs $!) again, simplifies the man page and shortens the code.
Diffstat (limited to 'bin/sh/expand.c')
-rw-r--r-- | bin/sh/expand.c | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c index beb655d..c6c54ab 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -1621,78 +1621,6 @@ cvtnum(int num, char *buf) } /* - * Check statically if expanding a string may have side effects. - */ -int -expandhassideeffects(const char *p) -{ - int c; - int arinest; - - arinest = 0; - while ((c = *p++) != '\0') { - switch (c) { - case CTLESC: - p++; - break; - case CTLVAR: - c = *p++; - /* Expanding $! sets the job to remembered. */ - if (*p == '!') - return 1; - if ((c & VSTYPE) == VSASSIGN) - return 1; - /* - * If we are in arithmetic, the parameter may contain - * '=' which may cause side effects. Exceptions are - * the length of a parameter and $$, $# and $? which - * are always numeric. - */ - if ((c & VSTYPE) == VSLENGTH) { - while (*p != '=') - p++; - p++; - break; - } - if ((*p == '$' || *p == '#' || *p == '?') && - p[1] == '=') { - p += 2; - break; - } - if (arinest > 0) - return 1; - break; - case CTLBACKQ: - case CTLBACKQ | CTLQUOTE: - if (arinest > 0) - return 1; - break; - case CTLARI: - arinest++; - break; - case CTLENDARI: - arinest--; - break; - case '=': - if (*p == '=') { - /* Allow '==' operator. */ - p++; - continue; - } - if (arinest > 0) - return 1; - break; - case '!': case '<': case '>': - /* Allow '!=', '<=', '>=' operators. */ - if (*p == '=') - p++; - break; - } - } - return 0; -} - -/* * Do most of the work for wordexp(3). */ |