Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/bin/sh Pull up following revision(s) (requested by kre in...
details: https://anonhg.NetBSD.org/src/rev/8940e2d33079
branches: netbsd-8
changeset: 434430:8940e2d33079
user: martin <martin%NetBSD.org@localhost>
date: Thu Nov 23 13:26:01 2017 +0000
description:
Pull up following revision(s) (requested by kre in ticket #384):
bin/sh/output.c: revision 1.37
Improve quoting in xtrace (-x) output ... if a string ("word") to be
output includes a single quote (') then see if using double-quotes
to quote it is reasonable (if no chars that are magic in " also appear).
If so, and if the string is not entirely the ' character, then
use " quoting. This avoids some ugly looking results (occasionally).
Also, fix a bug introduced about 20 months ago where null strings
in xtrace output are dropped, instead of made explicit ('').
To observe this, before you get the fix: set -x; echo '' (or similar.)
Move a comment from the wrong place to the right place.
diffstat:
bin/sh/output.c | 46 ++++++++++++++++++++++++++++++++++------------
1 files changed, 34 insertions(+), 12 deletions(-)
diffs (83 lines):
diff -r e7da8ef6936c -r 8940e2d33079 bin/sh/output.c
--- a/bin/sh/output.c Thu Nov 23 13:16:21 2017 +0000
+++ b/bin/sh/output.c Thu Nov 23 13:26:01 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: output.c,v 1.36 2017/05/18 13:31:10 kre Exp $ */
+/* $NetBSD: output.c,v 1.36.2.1 2017/11/23 13:26:01 martin Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)output.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: output.c,v 1.36 2017/05/18 13:31:10 kre Exp $");
+__RCSID("$NetBSD: output.c,v 1.36.2.1 2017/11/23 13:26:01 martin Exp $");
#endif
#endif /* not lint */
@@ -146,6 +146,11 @@
}
+/*
+ * ' is in this list, not because it does not require quoting
+ * (which applies to all the others) but because '' quoting cannot
+ * be used to quote it.
+ */
static const char norm_chars [] = \
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/+-=_,.'";
@@ -158,25 +163,42 @@
return s == NULL ? p[l] != '\0' : s - p > (off_t)l;
}
-
void
outshstr(const char *p, struct output *file)
{
- /*
- * ' is in this list, not because it does not require quoting
- * (which applies to all the others) but because '' quoting cannot
- * be used to quote it.
- */
- int need_q = p[0] == 0 || p[strspn(p, norm_chars)] != 0;
+ int need_q;
int inq;
char c;
+ if (strchr(p, '\'') != NULL && p[1] != '\0') {
+ /*
+ * string contains ' in it, and is not only the '
+ * see if " quoting will work
+ */
+ size_t i = strcspn(p, "\\\"$`");
+
+ if (p[i] == '\0') {
+ /*
+ * string contains no $ ` \ or " chars, perfect...
+ *
+ * We know it contains ' so needs quoting, so
+ * this is easy...
+ */
+ outc('"', file);
+ outstr(p, file);
+ outc('"', file);
+ return;
+ }
+ }
+
+ need_q = p[0] == 0 || p[strspn(p, norm_chars)] != 0;
+
/*
* Don't emit ' unless something needs quoting before closing '
*/
- if (need_q) {
- if ((inq = inquote(p)) != 0)
- outc('\'', file);
+ if (need_q && (p[0] == 0 || inquote(p) != 0)) {
+ outc('\'', file);
+ inq = 1;
} else
inq = 0;
Home |
Main Index |
Thread Index |
Old Index