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";
|
static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95";
|
||||||
#endif
|
#endif
|
||||||
static const char rcsid[] =
|
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 */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -142,8 +142,7 @@ expandhere(arg, fd)
|
|||||||
{
|
{
|
||||||
herefd = fd;
|
herefd = fd;
|
||||||
expandarg(arg, (struct arglist *)NULL, 0);
|
expandarg(arg, (struct arglist *)NULL, 0);
|
||||||
xwrite(fd, stackblock(),
|
xwrite(fd, stackblock(), expdest - stackblock());
|
||||||
rmquotes(stackblock(), expdest - stackblock()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -185,8 +184,6 @@ expandarg(arg, arglist, flag)
|
|||||||
} else {
|
} else {
|
||||||
if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
|
if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
|
||||||
rmescapes(p);
|
rmescapes(p);
|
||||||
else
|
|
||||||
rmquotes0(p);
|
|
||||||
sp = (struct strlist *)stalloc(sizeof (struct strlist));
|
sp = (struct strlist *)stalloc(sizeof (struct strlist));
|
||||||
sp->text = p;
|
sp->text = p;
|
||||||
*exparg.lastp = sp;
|
*exparg.lastp = sp;
|
||||||
@ -235,7 +232,8 @@ argstr(p, flag)
|
|||||||
/* "$@" syntax adherence hack */
|
/* "$@" syntax adherence hack */
|
||||||
if (p[0] == CTLVAR && p[2] == '@' && p[3] == '=')
|
if (p[0] == CTLVAR && p[2] == '@' && p[3] == '=')
|
||||||
break;
|
break;
|
||||||
STPUTC(c, expdest);
|
if ((flag & EXP_FULL) != 0)
|
||||||
|
STPUTC(c, expdest);
|
||||||
break;
|
break;
|
||||||
case CTLESC:
|
case CTLESC:
|
||||||
if (quotes)
|
if (quotes)
|
||||||
@ -292,6 +290,8 @@ exptilde(p, flag)
|
|||||||
switch(c) {
|
switch(c) {
|
||||||
case CTLESC:
|
case CTLESC:
|
||||||
return (startp);
|
return (startp);
|
||||||
|
case CTLQUOTEMARK:
|
||||||
|
return (startp);
|
||||||
case ':':
|
case ':':
|
||||||
if (flag & EXP_VARTILDE)
|
if (flag & EXP_VARTILDE)
|
||||||
goto done;
|
goto done;
|
||||||
@ -1464,58 +1464,6 @@ rmescapes(str)
|
|||||||
*q = '\0';
|
*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.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#)expand.h 8.2 (Berkeley) 5/4/95
|
* @(#)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 {
|
struct strlist {
|
||||||
@ -64,6 +64,4 @@ void expandarg __P((union node *, struct arglist *, int));
|
|||||||
void expari __P((int));
|
void expari __P((int));
|
||||||
int patmatch __P((char *, char *));
|
int patmatch __P((char *, char *));
|
||||||
void rmescapes __P((char *));
|
void rmescapes __P((char *));
|
||||||
void rmquotes0 __P((char *));
|
|
||||||
int rmquotes __P((char *, int));
|
|
||||||
int casematch __P((union node *, char *));
|
int casematch __P((union node *, char *));
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95";
|
static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95";
|
||||||
#endif
|
#endif
|
||||||
static const char rcsid[] =
|
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 */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
@ -269,7 +269,7 @@ char *
|
|||||||
growstackstr() {
|
growstackstr() {
|
||||||
int len = stackblocksize();
|
int len = stackblocksize();
|
||||||
if (herefd >= 0 && len >= 1024) {
|
if (herefd >= 0 && len >= 1024) {
|
||||||
xwrite(herefd, stackblock(), rmquotes(stackblock(), len));
|
xwrite(herefd, stackblock(), len);
|
||||||
sstrnleft = len - 1;
|
sstrnleft = len - 1;
|
||||||
return stackblock();
|
return stackblock();
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
|
static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
|
||||||
#endif
|
#endif
|
||||||
static const char rcsid[] =
|
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 */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -619,7 +619,6 @@ parsefname() {
|
|||||||
if (quoteflag == 0)
|
if (quoteflag == 0)
|
||||||
n->type = NXHERE;
|
n->type = NXHERE;
|
||||||
TRACE(("Here document %d\n", n->type));
|
TRACE(("Here document %d\n", n->type));
|
||||||
rmquotes0(wordtext);
|
|
||||||
if (here->striptabs) {
|
if (here->striptabs) {
|
||||||
while (*wordtext == '\t')
|
while (*wordtext == '\t')
|
||||||
wordtext++;
|
wordtext++;
|
||||||
@ -943,31 +942,36 @@ readtoken1(firstc, syntax, eofmark, striptabs)
|
|||||||
USTPUTC('\\', out);
|
USTPUTC('\\', out);
|
||||||
if (SQSYNTAX[c] == CCTL)
|
if (SQSYNTAX[c] == CCTL)
|
||||||
USTPUTC(CTLESC, out);
|
USTPUTC(CTLESC, out);
|
||||||
else
|
else if (eofmark == NULL)
|
||||||
USTPUTC(CTLQUOTEMARK, out);
|
USTPUTC(CTLQUOTEMARK, out);
|
||||||
USTPUTC(c, out);
|
USTPUTC(c, out);
|
||||||
quotef++;
|
quotef++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CSQUOTE:
|
case CSQUOTE:
|
||||||
USTPUTC(CTLQUOTEMARK, out);
|
if (eofmark == NULL)
|
||||||
|
USTPUTC(CTLQUOTEMARK, out);
|
||||||
syntax = SQSYNTAX;
|
syntax = SQSYNTAX;
|
||||||
break;
|
break;
|
||||||
case CDQUOTE:
|
case CDQUOTE:
|
||||||
USTPUTC(CTLQUOTEMARK, out);
|
if (eofmark == NULL)
|
||||||
|
USTPUTC(CTLQUOTEMARK, out);
|
||||||
syntax = DQSYNTAX;
|
syntax = DQSYNTAX;
|
||||||
dblquote = 1;
|
dblquote = 1;
|
||||||
break;
|
break;
|
||||||
case CENDQUOTE:
|
case CENDQUOTE:
|
||||||
if (eofmark) {
|
if (eofmark != NULL && arinest == 0 &&
|
||||||
|
varnest == 0) {
|
||||||
USTPUTC(c, out);
|
USTPUTC(c, out);
|
||||||
} else {
|
} else {
|
||||||
if (arinest)
|
if (arinest) {
|
||||||
syntax = ARISYNTAX;
|
syntax = ARISYNTAX;
|
||||||
else
|
dblquote = 0;
|
||||||
|
} else if (eofmark == NULL) {
|
||||||
syntax = BASESYNTAX;
|
syntax = BASESYNTAX;
|
||||||
|
dblquote = 0;
|
||||||
|
}
|
||||||
quotef++;
|
quotef++;
|
||||||
dblquote = 0;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CVAR: /* '$' */
|
case CVAR: /* '$' */
|
||||||
@ -994,6 +998,10 @@ readtoken1(firstc, syntax, eofmark, striptabs)
|
|||||||
if (--arinest == 0) {
|
if (--arinest == 0) {
|
||||||
USTPUTC(CTLENDARI, out);
|
USTPUTC(CTLENDARI, out);
|
||||||
syntax = prevsyntax;
|
syntax = prevsyntax;
|
||||||
|
if (syntax == DQSYNTAX)
|
||||||
|
dblquote = 1;
|
||||||
|
else
|
||||||
|
dblquote = 0;
|
||||||
} else
|
} else
|
||||||
USTPUTC(')', out);
|
USTPUTC(')', out);
|
||||||
} else {
|
} else {
|
||||||
@ -1445,6 +1453,8 @@ noexpand(text)
|
|||||||
|
|
||||||
p = text;
|
p = text;
|
||||||
while ((c = *p++) != '\0') {
|
while ((c = *p++) != '\0') {
|
||||||
|
if ( c == CTLQUOTEMARK)
|
||||||
|
continue;
|
||||||
if (c == CTLESC)
|
if (c == CTLESC)
|
||||||
p++;
|
p++;
|
||||||
else if (BASESYNTAX[c] == CCTL)
|
else if (BASESYNTAX[c] == CCTL)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user