Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Avoid truncating the command string saved with backgr...
details: https://anonhg.NetBSD.org/src/rev/a71c3514002a
branches: trunk
changeset: 823847:a71c3514002a
user: kre <kre%NetBSD.org@localhost>
date: Thu May 11 14:57:14 2017 +0000
description:
Avoid truncating the command string saved with background jobs if
one of the words happens to contain ${#var}. (This is the command
string shown by the "jobs" command, and when a background job completes)
While here, undo the LINENO hack when building that string.
And one ot two other foibles...
diffstat:
bin/sh/jobs.c | 35 ++++++++++++++++++++++++-----------
1 files changed, 24 insertions(+), 11 deletions(-)
diffs (93 lines):
diff -r eba8d5b67c44 -r a71c3514002a bin/sh/jobs.c
--- a/bin/sh/jobs.c Thu May 11 13:20:02 2017 +0000
+++ b/bin/sh/jobs.c Thu May 11 14:57:14 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: jobs.c,v 1.83 2017/05/09 05:14:03 kre Exp $ */
+/* $NetBSD: jobs.c,v 1.84 2017/05/11 14:57:14 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: jobs.c,v 1.83 2017/05/09 05:14:03 kre Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.84 2017/05/11 14:57:14 kre Exp $");
#endif
#endif /* not lint */
@@ -1423,7 +1423,7 @@
int subtype = 0;
int quoted = 0;
static char vstype[16][4] = { "", "}", "-", "+", "?", "=",
- "#", "##", "%", "%%" };
+ "#", "##", "%", "%%", "}" };
p = s;
nextc = cmdnextc;
@@ -1435,22 +1435,28 @@
break;
case CTLVAR:
subtype = *p++;
- if ((subtype & VSTYPE) == VSLENGTH)
+ if (subtype & VSLINENO) {
+ if ((subtype & VSTYPE) == VSLENGTH)
+ str = "${#LINENO";
+ else
+ str = "${LINENO";
+ while (is_digit(*p))
+ p++;
+ } else if ((subtype & VSTYPE) == VSLENGTH)
str = "${#";
else
str = "${";
if (!(subtype & VSQUOTE) != !(quoted & 1)) {
quoted ^= 1;
c = '"';
- } else
+ } else {
c = *str++;
+ }
break;
case CTLENDVAR:
- if (quoted & 1) {
- c = '"';
- str = "}";
- } else
- c = '}';
+ c = '}';
+ if (quoted & 1)
+ str = "\"";
quoted >>= 1;
subtype = 0;
break;
@@ -1474,6 +1480,10 @@
quoted ^= 1;
c = '"';
break;
+ case CTLQUOTEEND:
+ quoted >>= 1;
+ c = '"';
+ break;
case '=':
if (subtype == 0)
break;
@@ -1484,6 +1494,9 @@
c = *str++;
if (c != '}')
quoted <<= 1;
+ else if (*p == CTLENDVAR)
+ c = *str++;
+ subtype = 0;
break;
case '\'':
case '\\':
@@ -1497,7 +1510,7 @@
default:
break;
}
- do {
+ if (c != '\0') do { /* c == 0 implies nothing in str */
*nextc++ = c;
} while (--nleft > 0 && str && (c = *str++));
str = 0;
Home |
Main Index |
Thread Index |
Old Index