Be more consistent with handling of quote mark control character.
Don't output double-quotes inside variable expansion/arithmetic expansion region in here-documents. When leaving the arithmetic expansion syntax mode, adjust the dblquote flag according to previous syntax, in order to avoid splitting of quoted variables.
This commit is contained in:
parent
7dcba2c8a1
commit
5557a02a60
@ -39,7 +39,7 @@
|
||||
static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id: expand.c,v 1.22 1998/05/18 06:43:40 charnier Exp $";
|
||||
"$Id: expand.c,v 1.23 1998/09/06 21:13:09 tegge Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -142,8 +142,7 @@ expandhere(arg, fd)
|
||||
{
|
||||
herefd = fd;
|
||||
expandarg(arg, (struct arglist *)NULL, 0);
|
||||
xwrite(fd, stackblock(),
|
||||
rmquotes(stackblock(), expdest - stackblock()));
|
||||
xwrite(fd, stackblock(), expdest - stackblock());
|
||||
}
|
||||
|
||||
|
||||
@ -185,8 +184,6 @@ expandarg(arg, arglist, flag)
|
||||
} else {
|
||||
if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
|
||||
rmescapes(p);
|
||||
else
|
||||
rmquotes0(p);
|
||||
sp = (struct strlist *)stalloc(sizeof (struct strlist));
|
||||
sp->text = p;
|
||||
*exparg.lastp = sp;
|
||||
@ -235,7 +232,8 @@ argstr(p, flag)
|
||||
/* "$@" syntax adherence hack */
|
||||
if (p[0] == CTLVAR && p[2] == '@' && p[3] == '=')
|
||||
break;
|
||||
STPUTC(c, expdest);
|
||||
if ((flag & EXP_FULL) != 0)
|
||||
STPUTC(c, expdest);
|
||||
break;
|
||||
case CTLESC:
|
||||
if (quotes)
|
||||
@ -292,6 +290,8 @@ exptilde(p, flag)
|
||||
switch(c) {
|
||||
case CTLESC:
|
||||
return (startp);
|
||||
case CTLQUOTEMARK:
|
||||
return (startp);
|
||||
case ':':
|
||||
if (flag & EXP_VARTILDE)
|
||||
goto done;
|
||||
@ -1464,58 +1464,6 @@ rmescapes(str)
|
||||
*q = '\0';
|
||||
}
|
||||
|
||||
void rmquotes0(str)
|
||||
char *str;
|
||||
{
|
||||
char *p, *q;
|
||||
|
||||
p = str;
|
||||
while (*p != CTLQUOTEMARK) {
|
||||
if (*p == CTLESC) {
|
||||
p++;
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
if (*p++ == '\0')
|
||||
return;
|
||||
}
|
||||
q = p;
|
||||
while (*p) {
|
||||
if (*p == CTLQUOTEMARK) {
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
if (*p == CTLESC)
|
||||
*q++ = *p++;
|
||||
*q++ = *p++;
|
||||
}
|
||||
*q = '\0';
|
||||
}
|
||||
|
||||
int
|
||||
rmquotes(str, len)
|
||||
char *str;
|
||||
int len;
|
||||
{
|
||||
char *p, *q, *pe;
|
||||
|
||||
p = str;
|
||||
pe = str + len;
|
||||
while (*p != CTLQUOTEMARK) {
|
||||
if (++p == pe)
|
||||
return len;
|
||||
}
|
||||
q = p;
|
||||
while (p < pe) {
|
||||
if (*p == CTLQUOTEMARK) {
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
*q++ = *p++;
|
||||
}
|
||||
return q - str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
@ -34,7 +34,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)expand.h 8.2 (Berkeley) 5/4/95
|
||||
* $Id: expand.h,v 1.5 1997/02/22 13:58:26 peter Exp $
|
||||
* $Id: expand.h,v 1.6 1998/09/06 21:13:09 tegge Exp $
|
||||
*/
|
||||
|
||||
struct strlist {
|
||||
@ -64,6 +64,4 @@ void expandarg __P((union node *, struct arglist *, int));
|
||||
void expari __P((int));
|
||||
int patmatch __P((char *, char *));
|
||||
void rmescapes __P((char *));
|
||||
void rmquotes0 __P((char *));
|
||||
int rmquotes __P((char *, int));
|
||||
int casematch __P((union node *, char *));
|
||||
|
@ -39,7 +39,7 @@
|
||||
static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id: memalloc.c,v 1.10 1998/09/06 21:13:09 tegge Exp $";
|
||||
"$Id: memalloc.c,v 1.11 1998/09/10 14:51:06 cracauer Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "shell.h"
|
||||
@ -269,7 +269,7 @@ char *
|
||||
growstackstr() {
|
||||
int len = stackblocksize();
|
||||
if (herefd >= 0 && len >= 1024) {
|
||||
xwrite(herefd, stackblock(), rmquotes(stackblock(), len));
|
||||
xwrite(herefd, stackblock(), len);
|
||||
sstrnleft = len - 1;
|
||||
return stackblock();
|
||||
}
|
||||
|
@ -39,7 +39,7 @@
|
||||
static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id: parser.c,v 1.22 1998/05/18 06:44:12 charnier Exp $";
|
||||
"$Id: parser.c,v 1.23 1998/09/06 21:13:09 tegge Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -619,7 +619,6 @@ parsefname() {
|
||||
if (quoteflag == 0)
|
||||
n->type = NXHERE;
|
||||
TRACE(("Here document %d\n", n->type));
|
||||
rmquotes0(wordtext);
|
||||
if (here->striptabs) {
|
||||
while (*wordtext == '\t')
|
||||
wordtext++;
|
||||
@ -943,31 +942,36 @@ readtoken1(firstc, syntax, eofmark, striptabs)
|
||||
USTPUTC('\\', out);
|
||||
if (SQSYNTAX[c] == CCTL)
|
||||
USTPUTC(CTLESC, out);
|
||||
else
|
||||
else if (eofmark == NULL)
|
||||
USTPUTC(CTLQUOTEMARK, out);
|
||||
USTPUTC(c, out);
|
||||
quotef++;
|
||||
}
|
||||
break;
|
||||
case CSQUOTE:
|
||||
USTPUTC(CTLQUOTEMARK, out);
|
||||
if (eofmark == NULL)
|
||||
USTPUTC(CTLQUOTEMARK, out);
|
||||
syntax = SQSYNTAX;
|
||||
break;
|
||||
case CDQUOTE:
|
||||
USTPUTC(CTLQUOTEMARK, out);
|
||||
if (eofmark == NULL)
|
||||
USTPUTC(CTLQUOTEMARK, out);
|
||||
syntax = DQSYNTAX;
|
||||
dblquote = 1;
|
||||
break;
|
||||
case CENDQUOTE:
|
||||
if (eofmark) {
|
||||
if (eofmark != NULL && arinest == 0 &&
|
||||
varnest == 0) {
|
||||
USTPUTC(c, out);
|
||||
} else {
|
||||
if (arinest)
|
||||
if (arinest) {
|
||||
syntax = ARISYNTAX;
|
||||
else
|
||||
dblquote = 0;
|
||||
} else if (eofmark == NULL) {
|
||||
syntax = BASESYNTAX;
|
||||
dblquote = 0;
|
||||
}
|
||||
quotef++;
|
||||
dblquote = 0;
|
||||
}
|
||||
break;
|
||||
case CVAR: /* '$' */
|
||||
@ -994,6 +998,10 @@ readtoken1(firstc, syntax, eofmark, striptabs)
|
||||
if (--arinest == 0) {
|
||||
USTPUTC(CTLENDARI, out);
|
||||
syntax = prevsyntax;
|
||||
if (syntax == DQSYNTAX)
|
||||
dblquote = 1;
|
||||
else
|
||||
dblquote = 0;
|
||||
} else
|
||||
USTPUTC(')', out);
|
||||
} else {
|
||||
@ -1445,6 +1453,8 @@ noexpand(text)
|
||||
|
||||
p = text;
|
||||
while ((c = *p++) != '\0') {
|
||||
if ( c == CTLQUOTEMARK)
|
||||
continue;
|
||||
if (c == CTLESC)
|
||||
p++;
|
||||
else if (BASESYNTAX[c] == CCTL)
|
||||
|
Loading…
x
Reference in New Issue
Block a user