sh: Get rid of global variable argbackq.
This commit is contained in:
parent
429528f376
commit
439948cdf6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=315428
@ -89,15 +89,18 @@ struct worddest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static char *expdest; /* output of current string */
|
static char *expdest; /* output of current string */
|
||||||
static struct nodelist *argbackq; /* list of back quote expressions */
|
|
||||||
|
|
||||||
static const char *argstr(const char *, int, struct worddest *);
|
static const char *argstr(const char *, struct nodelist **restrict, int,
|
||||||
|
struct worddest *);
|
||||||
static const char *exptilde(const char *, int);
|
static const char *exptilde(const char *, int);
|
||||||
static const char *expari(const char *, int, struct worddest *);
|
static const char *expari(const char *, struct nodelist **restrict, int,
|
||||||
|
struct worddest *);
|
||||||
static void expbackq(union node *, int, int, struct worddest *);
|
static void expbackq(union node *, int, int, struct worddest *);
|
||||||
static void subevalvar_trim(const char *, int, int, int);
|
static void subevalvar_trim(const char *, struct nodelist *, int, int, int);
|
||||||
static int subevalvar_misc(const char *, const char *, int, int, int);
|
static int subevalvar_misc(const char *, struct nodelist *, const char *, int,
|
||||||
static const char *evalvar(const char *, int, struct worddest *);
|
int, int);
|
||||||
|
static const char *evalvar(const char *, struct nodelist **restrict, int,
|
||||||
|
struct worddest *);
|
||||||
static int varisset(const char *, int);
|
static int varisset(const char *, int);
|
||||||
static void strtodest(const char *, int, int, int, struct worddest *);
|
static void strtodest(const char *, int, int, int, struct worddest *);
|
||||||
static void reprocess(int, int, int, int, struct worddest *);
|
static void reprocess(int, int, int, int, struct worddest *);
|
||||||
@ -224,6 +227,7 @@ void
|
|||||||
expandarg(union node *arg, struct arglist *arglist, int flag)
|
expandarg(union node *arg, struct arglist *arglist, int flag)
|
||||||
{
|
{
|
||||||
struct worddest exparg;
|
struct worddest exparg;
|
||||||
|
struct nodelist *argbackq;
|
||||||
|
|
||||||
if (fflag)
|
if (fflag)
|
||||||
flag &= ~EXP_GLOB;
|
flag &= ~EXP_GLOB;
|
||||||
@ -231,7 +235,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
|
|||||||
exparg.list = arglist;
|
exparg.list = arglist;
|
||||||
exparg.state = WORD_IDLE;
|
exparg.state = WORD_IDLE;
|
||||||
STARTSTACKSTR(expdest);
|
STARTSTACKSTR(expdest);
|
||||||
argstr(arg->narg.text, flag, &exparg);
|
argstr(arg->narg.text, &argbackq, flag, &exparg);
|
||||||
if (arglist == NULL) {
|
if (arglist == NULL) {
|
||||||
STACKSTRNUL(expdest);
|
STACKSTRNUL(expdest);
|
||||||
return; /* here document expanded */
|
return; /* here document expanded */
|
||||||
@ -263,7 +267,8 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
|
|||||||
* If EXP_SPLIT is set, dst receives any complete words produced.
|
* If EXP_SPLIT is set, dst receives any complete words produced.
|
||||||
*/
|
*/
|
||||||
static const char *
|
static const char *
|
||||||
argstr(const char *p, int flag, struct worddest *dst)
|
argstr(const char *p, struct nodelist **restrict argbackq, int flag,
|
||||||
|
struct worddest *dst)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
int quotes = flag & (EXP_GLOB | EXP_CASE); /* do CTLESC */
|
int quotes = flag & (EXP_GLOB | EXP_CASE); /* do CTLESC */
|
||||||
@ -308,15 +313,15 @@ argstr(const char *p, int flag, struct worddest *dst)
|
|||||||
USTPUTC(c, expdest);
|
USTPUTC(c, expdest);
|
||||||
break;
|
break;
|
||||||
case CTLVAR:
|
case CTLVAR:
|
||||||
p = evalvar(p, flag, dst);
|
p = evalvar(p, argbackq, flag, dst);
|
||||||
break;
|
break;
|
||||||
case CTLBACKQ:
|
case CTLBACKQ:
|
||||||
case CTLBACKQ|CTLQUOTE:
|
case CTLBACKQ|CTLQUOTE:
|
||||||
expbackq(argbackq->n, c & CTLQUOTE, flag, dst);
|
expbackq((*argbackq)->n, c & CTLQUOTE, flag, dst);
|
||||||
argbackq = argbackq->next;
|
*argbackq = (*argbackq)->next;
|
||||||
break;
|
break;
|
||||||
case CTLARI:
|
case CTLARI:
|
||||||
p = expari(p, flag, dst);
|
p = expari(p, argbackq, flag, dst);
|
||||||
break;
|
break;
|
||||||
case ':':
|
case ':':
|
||||||
case '=':
|
case '=':
|
||||||
@ -405,7 +410,8 @@ exptilde(const char *p, int flag)
|
|||||||
* Expand arithmetic expression.
|
* Expand arithmetic expression.
|
||||||
*/
|
*/
|
||||||
static const char *
|
static const char *
|
||||||
expari(const char *p, int flag, struct worddest *dst)
|
expari(const char *p, struct nodelist **restrict argbackq, int flag,
|
||||||
|
struct worddest *dst)
|
||||||
{
|
{
|
||||||
char *q, *start;
|
char *q, *start;
|
||||||
arith_t result;
|
arith_t result;
|
||||||
@ -415,7 +421,7 @@ expari(const char *p, int flag, struct worddest *dst)
|
|||||||
|
|
||||||
quoted = *p++ == '"';
|
quoted = *p++ == '"';
|
||||||
begoff = expdest - stackblock();
|
begoff = expdest - stackblock();
|
||||||
p = argstr(p, 0, NULL);
|
p = argstr(p, argbackq, 0, NULL);
|
||||||
STPUTC('\0', expdest);
|
STPUTC('\0', expdest);
|
||||||
start = stackblock() + begoff;
|
start = stackblock() + begoff;
|
||||||
|
|
||||||
@ -448,7 +454,6 @@ expbackq(union node *cmd, int quoted, int flag, struct worddest *dst)
|
|||||||
char buf[128];
|
char buf[128];
|
||||||
char *p;
|
char *p;
|
||||||
char *dest = expdest;
|
char *dest = expdest;
|
||||||
struct nodelist *saveargbackq;
|
|
||||||
char lastc;
|
char lastc;
|
||||||
char const *syntax = quoted? DQSYNTAX : BASESYNTAX;
|
char const *syntax = quoted? DQSYNTAX : BASESYNTAX;
|
||||||
int quotes = flag & (EXP_GLOB | EXP_CASE);
|
int quotes = flag & (EXP_GLOB | EXP_CASE);
|
||||||
@ -456,7 +461,6 @@ expbackq(union node *cmd, int quoted, int flag, struct worddest *dst)
|
|||||||
const char *ifs;
|
const char *ifs;
|
||||||
|
|
||||||
INTOFF;
|
INTOFF;
|
||||||
saveargbackq = argbackq;
|
|
||||||
p = grabstackstr(dest);
|
p = grabstackstr(dest);
|
||||||
evalbackcmd(cmd, &in);
|
evalbackcmd(cmd, &in);
|
||||||
ungrabstackstr(p, dest);
|
ungrabstackstr(p, dest);
|
||||||
@ -522,7 +526,6 @@ expbackq(union node *cmd, int quoted, int flag, struct worddest *dst)
|
|||||||
((dest - stackblock()) - startloc),
|
((dest - stackblock()) - startloc),
|
||||||
(int)((dest - stackblock()) - startloc),
|
(int)((dest - stackblock()) - startloc),
|
||||||
stackblock() + startloc));
|
stackblock() + startloc));
|
||||||
argbackq = saveargbackq;
|
|
||||||
expdest = dest;
|
expdest = dest;
|
||||||
INTON;
|
INTON;
|
||||||
}
|
}
|
||||||
@ -541,18 +544,18 @@ recordleft(const char *str, const char *loc, char *startp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
subevalvar_trim(const char *p, int strloc, int subtype, int startloc)
|
subevalvar_trim(const char *p, struct nodelist *argbackq, int strloc,
|
||||||
|
int subtype, int startloc)
|
||||||
{
|
{
|
||||||
char *startp;
|
char *startp;
|
||||||
char *loc = NULL;
|
char *loc = NULL;
|
||||||
char *str;
|
char *str;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
struct nodelist *saveargbackq = argbackq;
|
struct nodelist *argbackqcopy = argbackq;
|
||||||
int amount;
|
int amount;
|
||||||
|
|
||||||
argstr(p, EXP_CASE | EXP_TILDE, NULL);
|
argstr(p, &argbackqcopy, EXP_CASE | EXP_TILDE, NULL);
|
||||||
STACKSTRNUL(expdest);
|
STACKSTRNUL(expdest);
|
||||||
argbackq = saveargbackq;
|
|
||||||
startp = stackblock() + startloc;
|
startp = stackblock() + startloc;
|
||||||
str = stackblock() + strloc;
|
str = stackblock() + strloc;
|
||||||
|
|
||||||
@ -615,16 +618,15 @@ subevalvar_trim(const char *p, int strloc, int subtype, int startloc)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
subevalvar_misc(const char *p, const char *var, int subtype, int startloc,
|
subevalvar_misc(const char *p, struct nodelist *argbackq, const char *var, int subtype, int startloc,
|
||||||
int varflags)
|
int varflags)
|
||||||
{
|
{
|
||||||
char *startp;
|
char *startp;
|
||||||
struct nodelist *saveargbackq = argbackq;
|
struct nodelist *argbackqcopy = argbackq;
|
||||||
int amount;
|
int amount;
|
||||||
|
|
||||||
argstr(p, EXP_TILDE, NULL);
|
argstr(p, &argbackqcopy, EXP_TILDE, NULL);
|
||||||
STACKSTRNUL(expdest);
|
STACKSTRNUL(expdest);
|
||||||
argbackq = saveargbackq;
|
|
||||||
startp = stackblock() + startloc;
|
startp = stackblock() + startloc;
|
||||||
|
|
||||||
switch (subtype) {
|
switch (subtype) {
|
||||||
@ -655,7 +657,8 @@ subevalvar_misc(const char *p, const char *var, int subtype, int startloc,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
evalvar(const char *p, int flag, struct worddest *dst)
|
evalvar(const char *p, struct nodelist **restrict argbackq, int flag,
|
||||||
|
struct worddest *dst)
|
||||||
{
|
{
|
||||||
int subtype;
|
int subtype;
|
||||||
int varflags;
|
int varflags;
|
||||||
@ -759,7 +762,8 @@ evalvar(const char *p, int flag, struct worddest *dst)
|
|||||||
case VSPLUS:
|
case VSPLUS:
|
||||||
case VSMINUS:
|
case VSMINUS:
|
||||||
if (!set) {
|
if (!set) {
|
||||||
argstr(p, flag | (flag & EXP_SPLIT ? EXP_SPLIT_LIT : 0) |
|
argstr(p, argbackq,
|
||||||
|
flag | (flag & EXP_SPLIT ? EXP_SPLIT_LIT : 0) |
|
||||||
(varflags & VSQUOTE ? EXP_LIT_QUOTED : 0), dst);
|
(varflags & VSQUOTE ? EXP_LIT_QUOTED : 0), dst);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -779,7 +783,7 @@ evalvar(const char *p, int flag, struct worddest *dst)
|
|||||||
*/
|
*/
|
||||||
STPUTC('\0', expdest);
|
STPUTC('\0', expdest);
|
||||||
patloc = expdest - stackblock();
|
patloc = expdest - stackblock();
|
||||||
subevalvar_trim(p, patloc, subtype, startloc);
|
subevalvar_trim(p, *argbackq, patloc, subtype, startloc);
|
||||||
reprocess(startloc, flag, VSNORMAL, varflags & VSQUOTE, dst);
|
reprocess(startloc, flag, VSNORMAL, varflags & VSQUOTE, dst);
|
||||||
if (flag & EXP_SPLIT && *var == '@' && varflags & VSQUOTE)
|
if (flag & EXP_SPLIT && *var == '@' && varflags & VSQUOTE)
|
||||||
dst->state = WORD_QUOTEMARK;
|
dst->state = WORD_QUOTEMARK;
|
||||||
@ -788,8 +792,8 @@ evalvar(const char *p, int flag, struct worddest *dst)
|
|||||||
case VSASSIGN:
|
case VSASSIGN:
|
||||||
case VSQUESTION:
|
case VSQUESTION:
|
||||||
if (!set) {
|
if (!set) {
|
||||||
if (subevalvar_misc(p, var, subtype, startloc,
|
if (subevalvar_misc(p, *argbackq, var, subtype,
|
||||||
varflags)) {
|
startloc, varflags)) {
|
||||||
varflags &= ~VSNUL;
|
varflags &= ~VSNUL;
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
@ -813,7 +817,7 @@ evalvar(const char *p, int flag, struct worddest *dst)
|
|||||||
p++;
|
p++;
|
||||||
else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE)) {
|
else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE)) {
|
||||||
if (set)
|
if (set)
|
||||||
argbackq = argbackq->next;
|
*argbackq = (*argbackq)->next;
|
||||||
} else if (c == CTLVAR) {
|
} else if (c == CTLVAR) {
|
||||||
if ((*p++ & VSTYPE) != VSNORMAL)
|
if ((*p++ & VSTYPE) != VSNORMAL)
|
||||||
nesting++;
|
nesting++;
|
||||||
@ -1440,13 +1444,14 @@ int
|
|||||||
casematch(union node *pattern, const char *val)
|
casematch(union node *pattern, const char *val)
|
||||||
{
|
{
|
||||||
struct stackmark smark;
|
struct stackmark smark;
|
||||||
|
struct nodelist *argbackq;
|
||||||
int result;
|
int result;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
setstackmark(&smark);
|
setstackmark(&smark);
|
||||||
argbackq = pattern->narg.backquote;
|
argbackq = pattern->narg.backquote;
|
||||||
STARTSTACKSTR(expdest);
|
STARTSTACKSTR(expdest);
|
||||||
argstr(pattern->narg.text, EXP_TILDE | EXP_CASE, NULL);
|
argstr(pattern->narg.text, &argbackq, EXP_TILDE | EXP_CASE, NULL);
|
||||||
STPUTC('\0', expdest);
|
STPUTC('\0', expdest);
|
||||||
p = grabstackstr(expdest);
|
p = grabstackstr(expdest);
|
||||||
result = patmatch(p, val);
|
result = patmatch(p, val);
|
||||||
|
Loading…
Reference in New Issue
Block a user