NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/39709: improvements for '/bin/sh -x'
The following reply was made to PR bin/39709; it has been noted by GNATS.
From: Aleksey Cheusov <cheusov%tut.by@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: bin/39709: improvements for '/bin/sh -x'
Date: Fri, 31 Oct 2008 22:31:43 +0200
The patch below improves '/bin/sh -x' output.
Demo:
0 ~>cat /home/cheusov/tmp/1.sh
#!/bin/sh
echo a
echo b c 'd e'
echo 'a b' c '' '"'
echo "'"
echo "aaa'bbb"
0 ~>/bin/sh -x /home/cheusov/tmp/1.sh # original shell
+ echo a
a
+ echo b c d e
b c d e
+ echo a b c "
a b c "
+ echo '
'
+ echo aaa'bbb
aaa'bbb
0 ~>/srv/src_netbsd/bin/sh/sh -x /home/cheusov/tmp/1.sh # patched shell
+ echo a
a
+ echo b c 'd e'
b c d e
+ echo 'a b' c '' '"'
a b c "
+ echo ''\'''
'
+ echo 'aaa'\''bbb'
aaa'bbb
0 ~>
Index: eval.c
===================================================================
RCS file: /pub/NetBSD-CVS/src/bin/sh/eval.c,v
retrieving revision 1.88.2.1
diff -u -r1.88.2.1 eval.c
--- eval.c 8 Jun 2008 20:08:01 -0000 1.88.2.1
+++ eval.c 30 Oct 2008 22:52:46 -0000
@@ -759,13 +759,13 @@
for (sp = varlist.list ; sp ; sp = sp->next) {
if (sep != 0)
outc(sep, &errout);
- out2str(sp->text);
+ out2shstr(sp->text);
sep = ' ';
}
for (sp = arglist.list ; sp ; sp = sp->next) {
if (sep != 0)
outc(sep, &errout);
- out2str(sp->text);
+ out2shstr(sp->text);
sep = ' ';
}
outc('\n', &errout);
Index: output.c
===================================================================
RCS file: /pub/NetBSD-CVS/src/bin/sh/output.c,v
retrieving revision 1.29
diff -u -r1.29 output.c
--- output.c 17 Mar 2006 14:47:10 -0000 1.29
+++ output.c 30 Oct 2008 22:52:46 -0000
@@ -140,6 +140,43 @@
}
+void
+out2shstr(const char *p)
+{
+ outshstr(p, out2);
+}
+
+
+void
+outshstr(const char *p, struct output *file)
+{
+ static const char norm_chars [] \
+ =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ int need_q = p[0] == 0 || p[strspn(p, norm_chars)] != 0;
+ char c;
+
+ if (need_q)
+ outc('\'', file);
+
+ while (c = *p++, c != 0){
+ if (c != '\''){
+ outc(c, file);
+ }else{
+ outc('\'', file);
+ outc('\\', file);
+ outc(c, file);
+ outc('\'', file);
+ }
+ }
+
+ if (need_q)
+ outc('\'', file);
+
+ if (file == out2)
+ flushout(file);
+}
+
+
char out_junk[16];
Index: output.h
===================================================================
RCS file: /pub/NetBSD-CVS/src/bin/sh/output.h,v
retrieving revision 1.17
diff -u -r1.17 output.h
--- output.h 7 Aug 2003 09:05:36 -0000 1.17
+++ output.h 30 Oct 2008 22:52:46 -0000
@@ -57,6 +57,8 @@
void out1str(const char *);
void out2str(const char *);
void outstr(const char *, struct output *);
+void out2shstr(const char *);
+void outshstr(const char *, struct output *);
void emptyoutbuf(struct output *);
void flushall(void);
void flushout(struct output *);
--
Best regards, Aleksey Cheusov.
Home |
Main Index |
Thread Index |
Old Index