#define EXP_VARTILDE2 0x20 /* expand tildes after colons only */
#define EXP_WORD 0x40 /* expand word in parameter expansion */
#define EXP_QUOTED 0x100 /* expand word in double quotes */
+#define EXP_KEEPNUL 0x200 /* do not skip NUL characters */
+
/*
* rmescape() flags
*/
/* Add CTLESC when necessary. */
#define QUOTES_ESC (EXP_FULL | EXP_CASE)
-/* Do not skip NUL characters. */
-#define QUOTES_KEEPNUL EXP_TILDE
/*
* Structure specifying which parts of the string should be searched
* Put a string on the stack.
*/
static void
-memtodest(const char *p, size_t len, int syntax, int quotes)
+memtodest(const char *p, size_t len, int flags)
{
+ int syntax = flags & EXP_QUOTED ? DQSYNTAX : BASESYNTAX;
char *q;
if (!len)
return;
- q = makestrspace((quotes & QUOTES_ESC) ? len * 2 : len, expdest);
+ q = makestrspace(len * 2, expdest);
do {
unsigned char c = *p++;
if (c) {
- if (quotes & QUOTES_ESC) {
+ if (flags & QUOTES_ESC) {
int n = SIT(c, syntax);
if (n == CCTL
- || (syntax != BASESYNTAX && n == CBACK)
+ || ((flags & EXP_QUOTED) && n == CBACK)
) {
USTPUTC(CTLESC, q);
}
}
- } else if (!(quotes & QUOTES_KEEPNUL))
+ } else if (!(flags & EXP_KEEPNUL))
continue;
USTPUTC(c, q);
} while (--len);
}
static size_t
-strtodest(const char *p, int syntax, int quotes)
+strtodest(const char *p, int flags)
{
size_t len = strlen(p);
- memtodest(p, len, syntax, quotes);
+ memtodest(p, len, flags);
return len;
}
}
static char *
-exptilde(char *startp, char *p, int flags)
+exptilde(char *startp, char *p, int flag)
{
unsigned char c;
char *name;
struct passwd *pw;
const char *home;
- int quotes = flags & QUOTES_ESC;
name = p + 1;
case CTLQUOTEMARK:
return startp;
case ':':
- if (flags & EXP_VARTILDE)
+ if (flag & EXP_VARTILDE)
goto done;
break;
case '/':
if (!home)
goto lose;
*p = c;
- strtodest(home, SQSYNTAX, quotes);
+ strtodest(home, flag | EXP_QUOTED);
return p;
lose:
*p = c;
char *p;
char *dest;
int startloc;
- int syntax = flag & EXP_QUOTED ? DQSYNTAX : BASESYNTAX;
struct stackmark smark;
INT_OFF;
if (i == 0)
goto read;
for (;;) {
- memtodest(p, i, syntax, flag & QUOTES_ESC);
+ memtodest(p, i, flag);
read:
if (in.fd < 0)
break;
int sep;
int subtype = varflags & VSTYPE;
int discard = subtype == VSPLUS || subtype == VSLENGTH;
- int quotes = (discard ? 0 : (flags & QUOTES_ESC)) | QUOTES_KEEPNUL;
- int syntax;
+ flags |= EXP_KEEPNUL;
+ flags &= discard ? ~QUOTES_ESC : ~0;
sep = (flags & EXP_FULL) << CHAR_BIT;
- syntax = quoted ? DQSYNTAX : BASESYNTAX;
switch (*name) {
case '$':
if (!ap)
return -1;
while ((p = *ap++) != NULL) {
- len += strtodest(p, syntax, quotes);
+ len += strtodest(p, flags);
if (*ap && sep) {
len++;
- memtodest(&sepc, 1, syntax, quotes);
+ memtodest(&sepc, 1, flags);
}
}
break;
if (!p)
return -1;
- len = strtodest(p, syntax, quotes);
+ len = strtodest(p, flags);
#if ENABLE_UNICODE_SUPPORT
if (subtype == VSLENGTH && len > 0) {
reinit_unicode_for_ash();