diff options
author | tegge <tegge@FreeBSD.org> | 1998-09-13 19:24:57 +0000 |
---|---|---|
committer | tegge <tegge@FreeBSD.org> | 1998-09-13 19:24:57 +0000 |
commit | c82e121ce74c6eb8a8320558d50687405f5c3b06 (patch) | |
tree | 8dc9a8aa332a6ba94153af431e81d754f41f4a2e /bin | |
parent | da907f2515cfc4bb9e3baebdeead74eded772425 (diff) | |
download | FreeBSD-src-c82e121ce74c6eb8a8320558d50687405f5c3b06.zip FreeBSD-src-c82e121ce74c6eb8a8320558d50687405f5c3b06.tar.gz |
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.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sh/expand.c | 64 | ||||
-rw-r--r-- | bin/sh/expand.h | 4 | ||||
-rw-r--r-- | bin/sh/memalloc.c | 4 | ||||
-rw-r--r-- | bin/sh/parser.c | 28 |
4 files changed, 28 insertions, 72 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c index 25cdc1e..757ff3a 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -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; -} - /* diff --git a/bin/sh/expand.h b/bin/sh/expand.h index 5212518..18c1663 100644 --- a/bin/sh/expand.h +++ b/bin/sh/expand.h @@ -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 *)); diff --git a/bin/sh/memalloc.c b/bin/sh/memalloc.c index b2fa2b4..c40eadd 100644 --- a/bin/sh/memalloc.c +++ b/bin/sh/memalloc.c @@ -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(); } diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 8df30ca..ba60254 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -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) |