summaryrefslogtreecommitdiff
path: root/src/expand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expand.c')
-rw-r--r--src/expand.c51
1 files changed, 24 insertions, 27 deletions
diff --git a/src/expand.c b/src/expand.c
index 11fd7b7..b2d710d 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -116,7 +116,7 @@ STATIC const char *subevalvar(char *, char *, int, int, int, int, int);
STATIC char *evalvar(char *, int);
STATIC size_t strtodest(const char *, const char *, int);
STATIC void memtodest(const char *, size_t, const char *, int);
-STATIC ssize_t varvalue(char *, int, int);
+STATIC ssize_t varvalue(char *, int, int, int *);
STATIC void expandmeta(struct strlist *, int);
#ifdef HAVE_GLOB
STATIC void addglob(const glob_t *);
@@ -736,7 +736,7 @@ evalvar(char *p, int flag)
p = strchr(p, '=') + 1;
again:
- varlen = varvalue(var, varflags, flag);
+ varlen = varvalue(var, varflags, flag, &quoted);
if (varflags & VSNUL)
varlen--;
@@ -751,28 +751,22 @@ vsplus:
argstr(p, flag | EXP_TILDE | EXP_WORD);
goto end;
}
- if (easy)
- goto record;
- goto end;
+ goto record;
}
if (subtype == VSASSIGN || subtype == VSQUESTION) {
- if (varlen < 0) {
- if (subevalvar(p, var, 0, subtype, startloc,
- varflags, flag & ~QUOTES_ESC)) {
- varflags &= ~VSNUL;
- /*
- * Remove any recorded regions beyond
- * start of variable
- */
- removerecordregions(startloc);
- goto again;
- }
- goto end;
- }
- if (easy)
+ if (varlen >= 0)
goto record;
- goto end;
+
+ subevalvar(p, var, 0, subtype, startloc, varflags,
+ flag & ~QUOTES_ESC);
+ varflags &= ~VSNUL;
+ /*
+ * Remove any recorded regions beyond
+ * start of variable
+ */
+ removerecordregions(startloc);
+ goto again;
}
if (varlen < 0 && uflag)
@@ -784,9 +778,9 @@ vsplus:
}
if (subtype == VSNORMAL) {
+record:
if (!easy)
goto end;
-record:
recordregion(startloc, expdest - (char *)stackblock(), quoted);
goto end;
}
@@ -892,7 +886,7 @@ strtodest(p, syntax, quotes)
*/
STATIC ssize_t
-varvalue(char *name, int varflags, int flags)
+varvalue(char *name, int varflags, int flags, int *quotedp)
{
int num;
char *p;
@@ -901,13 +895,13 @@ varvalue(char *name, int varflags, int flags)
char sepc;
char **ap;
char const *syntax;
- int quoted = flags & EXP_QUOTED;
+ int quoted = *quotedp;
int subtype = varflags & VSTYPE;
int discard = subtype == VSPLUS || subtype == VSLENGTH;
int quotes = (discard ? 0 : (flags & QUOTES_ESC)) | QUOTES_KEEPNUL;
ssize_t len = 0;
- sep = quoted ? ((flags & EXP_FULL) << CHAR_BIT) : 0;
+ sep = (flags & EXP_FULL) << CHAR_BIT;
syntax = quoted ? DQSYNTAX : BASESYNTAX;
switch (*name) {
@@ -938,15 +932,18 @@ numvar:
expdest = p;
break;
case '@':
- if (sep)
+ if (quoted && sep)
goto param;
/* fall through */
case '*':
- sep = ifsset() ? ifsval()[0] : ' ';
+ if (quoted)
+ sep = 0;
+ sep |= ifsset() ? ifsval()[0] : ' ';
param:
+ sepc = sep;
+ *quotedp = !sepc;
if (!(ap = shellparam.p))
return -1;
- sepc = sep;
while ((p = *ap++)) {
len += strtodest(p, syntax, quotes);