SCCS-vsn: bin/sh/expand.c 5.8
SCCS-vsn: bin/sh/expand.h 5.3
-static char sccsid[] = "@(#)expand.c 5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)expand.c 5.8 (Berkeley) %G%";
STATIC void ifsbreakup(char *, struct arglist *);
STATIC void expandmeta(struct strlist *, int);
STATIC void expmeta(char *, char *);
STATIC void ifsbreakup(char *, struct arglist *);
STATIC void expandmeta(struct strlist *, int);
STATIC void expmeta(char *, char *);
+STATIC void expari(int);
STATIC void addfname(char *);
STATIC struct strlist *expsort(struct strlist *);
STATIC struct strlist *msort(struct strlist *, int);
STATIC void addfname(char *);
STATIC struct strlist *expsort(struct strlist *);
STATIC struct strlist *msort(struct strlist *, int);
STATIC void ifsbreakup();
STATIC void expandmeta();
STATIC void expmeta();
STATIC void ifsbreakup();
STATIC void expandmeta();
STATIC void expmeta();
STATIC void addfname();
STATIC struct strlist *expsort();
STATIC struct strlist *msort();
STATIC void addfname();
STATIC struct strlist *expsort();
STATIC struct strlist *msort();
/*
* Perform variable substitution and command substitution on an argument,
/*
* Perform variable substitution and command substitution on an argument,
- * placing the resulting list of arguments in arglist. If full is true,
+ * placing the resulting list of arguments in arglist. If EXP_FULL is true,
* perform splitting and file name expansion. When arglist is NULL, perform
* here document expansion.
*/
* perform splitting and file name expansion. When arglist is NULL, perform
* here document expansion.
*/
- * Perform variable and command substitution. If full is set, output CTLESC
- * characters to allow for further processing. If full is not set, treat
+ * Perform variable and command substitution. If EXP_FULL is set, output CTLESC
+ * characters to allow for further processing. Otherwise treat
* $@ like $* since no splitting will be performed.
*/
* $@ like $* since no splitting will be performed.
*/
argstr(p, flag)
register char *p;
{
argstr(p, flag)
register char *p;
{
- char c;
- int sawari = 0;
- int full = flag & EXP_FULL; /* is there a later stage? */
- int vartilde = flag & EXP_VARTILDE;
+ register char c;
+ int quotes = flag & (EXP_FULL | EXP_CASE); /* do CTLESC */
if (*p == '~' && (flag & (EXP_TILDE | EXP_VARTILDE)))
if (*p == '~' && (flag & (EXP_TILDE | EXP_VARTILDE)))
- p = exptilde(p, vartilde);
for (;;) {
switch (c = *p++) {
case '\0':
case CTLENDVAR: /* ??? */
goto breakloop;
case CTLESC:
for (;;) {
switch (c = *p++) {
case '\0':
case CTLENDVAR: /* ??? */
goto breakloop;
case CTLESC:
STPUTC(c, expdest);
c = *p++;
STPUTC(c, expdest);
STPUTC(c, expdest);
c = *p++;
STPUTC(c, expdest);
break;
case CTLBACKQ:
case CTLBACKQ|CTLQUOTE:
break;
case CTLBACKQ:
case CTLBACKQ|CTLQUOTE:
- expbackq(argbackq->n, c & CTLQUOTE, full);
+ expbackq(argbackq->n, c & CTLQUOTE, flag);
argbackq = argbackq->next;
break;
case CTLENDARI:
argbackq = argbackq->next;
break;
case CTLENDARI:
break;
case ':':
STPUTC(c, expdest);
break;
case ':':
STPUTC(c, expdest);
- if (vartilde && *p == '~')
- p = exptilde(p, vartilde);
+ if (flag & EXP_VARTILDE && *p == '~')
+ p = exptilde(p, flag);
break;
default:
STPUTC(c, expdest);
break;
default:
STPUTC(c, expdest);
char *p;
{
char c, *startp = p;
struct passwd *pw;
char *home;
char *p;
{
char c, *startp = p;
struct passwd *pw;
char *home;
+ int quotes = flag & (EXP_FULL | EXP_CASE);
while (c = *p) {
switch(c) {
case CTLESC:
return (startp);
case ':':
while (c = *p) {
switch(c) {
case CTLESC:
return (startp);
case ':':
+ if (flag & EXP_VARTILDE)
goto done;
break;
case '/':
goto done;
break;
case '/':
goto lose;
*p = c;
while (c = *home++) {
goto lose;
*p = c;
while (c = *home++) {
- if (SQSYNTAX[c] == CCTL)
+ if (quotes && SQSYNTAX[c] == CCTL)
STPUTC(CTLESC, expdest);
STPUTC(c, expdest);
}
STPUTC(CTLESC, expdest);
STPUTC(c, expdest);
}
* Expand arithmetic expression. Backup to start of expression,
* evaluate, place result in (backed up) result, adjust string position.
*/
* Expand arithmetic expression. Backup to start of expression,
* evaluate, place result in (backed up) result, adjust string position.
*/
{
char *p, *start;
int result;
{
char *p, *start;
int result;
+ int quotes = flag & (EXP_FULL | EXP_CASE);
/*
* This routine is slightly over-compilcated for
/*
* This routine is slightly over-compilcated for
for (p = start; *p != CTLARI; p++)
if (*p == CTLESC)
p++;
for (p = start; *p != CTLARI; p++)
if (*p == CTLESC)
p++;
+ if (quotes)
+ rmescapes(p+1);
result = arith(p+1);
fmtstr(p, 10, "%d", result);
while (*p++)
result = arith(p+1);
fmtstr(p, 10, "%d", result);
while (*p++)
-expbackq(cmd, quoted, full)
+expbackq(cmd, quoted, flag)
union node *cmd;
{
struct backcmd in;
union node *cmd;
{
struct backcmd in;
int startloc = dest - stackblock();
char const *syntax = quoted? DQSYNTAX : BASESYNTAX;
int saveherefd;
int startloc = dest - stackblock();
char const *syntax = quoted? DQSYNTAX : BASESYNTAX;
int saveherefd;
+ int quotes = flag & (EXP_FULL | EXP_CASE);
INTOFF;
saveifs = ifsfirst;
INTOFF;
saveifs = ifsfirst;
}
lastc = *p++;
if (lastc != '\0') {
}
lastc = *p++;
if (lastc != '\0') {
- if (full && syntax[lastc] == CCTL)
+ if (quotes && syntax[lastc] == CCTL)
STPUTC(CTLESC, dest);
STPUTC(lastc, dest);
}
STPUTC(CTLESC, dest);
STPUTC(lastc, dest);
}
int set;
int special;
int startloc;
int set;
int special;
int startloc;
+ int quotes = flag & (EXP_FULL | EXP_CASE);
varflags = *p++;
subtype = varflags & VSTYPE;
varflags = *p++;
subtype = varflags & VSTYPE;
char const *syntax = (varflags & VSQUOTE)? DQSYNTAX : BASESYNTAX;
while (*val) {
char const *syntax = (varflags & VSQUOTE)? DQSYNTAX : BASESYNTAX;
while (*val) {
- if ((flag & EXP_FULL) && syntax[*val] == CCTL)
+ if (quotes && syntax[*val] == CCTL)
STPUTC(CTLESC, expdest);
STPUTC(*val++, expdest);
}
STPUTC(CTLESC, expdest);
STPUTC(*val++, expdest);
}
char *pattern;
char *string;
{
char *pattern;
char *string;
{
if (pattern[0] == '!' && pattern[1] == '!')
return 1 - pmatch(pattern + 2, string);
else
if (pattern[0] == '!' && pattern[1] == '!')
return 1 - pmatch(pattern + 2, string);
else
return pmatch(pattern, string);
}
return pmatch(pattern, string);
}
if (*q++ != c)
return 0;
break;
if (*q++ != c)
return 0;
break;
argbackq = pattern->narg.backquote;
STARTSTACKSTR(expdest);
ifslastp = NULL;
argbackq = pattern->narg.backquote;
STARTSTACKSTR(expdest);
ifslastp = NULL;
- argstr(pattern->narg.text, 0);
+ argstr(pattern->narg.text, EXP_TILDE | EXP_CASE);
STPUTC('\0', expdest);
p = grabstackstr(expdest);
result = patmatch(p, val);
STPUTC('\0', expdest);
p = grabstackstr(expdest);
result = patmatch(p, val);
*
* %sccs.include.redist.c%
*
*
* %sccs.include.redist.c%
*
- * @(#)expand.h 5.2 (Berkeley) %G%
+ * @(#)expand.h 5.3 (Berkeley) %G%
#define EXP_TILDE 0x2 /* do normal tilde expansion */
#define EXP_VARTILDE 0x4 /* expand tildes in an assignment */
#define EXP_REDIR 0x8 /* file glob for a redirection (1 match only) */
#define EXP_TILDE 0x2 /* do normal tilde expansion */
#define EXP_VARTILDE 0x4 /* expand tildes in an assignment */
#define EXP_REDIR 0x8 /* file glob for a redirection (1 match only) */
+#define EXP_CASE 0x10 /* keeps quotes around for CASE pattern */