summaryrefslogtreecommitdiffstats
path: root/bin/sh/output.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-06-04 12:59:12 +0000
committertjr <tjr@FreeBSD.org>2002-06-04 12:59:12 +0000
commit33d27dd210c9b2a95f1ab802306f257894298a4f (patch)
tree20257442bc2cc5cae672c11d72306aa5eae7e200 /bin/sh/output.c
parentf5f8d2529997c1813e19eef4f358b49317c1698b (diff)
downloadFreeBSD-src-33d27dd210c9b2a95f1ab802306f257894298a4f.zip
FreeBSD-src-33d27dd210c9b2a95f1ab802306f257894298a4f.tar.gz
Quote alias values in the output of the alias(1) builtin so they are
suitable for re-input to the shell (SUSv3)
Diffstat (limited to 'bin/sh/output.c')
-rw-r--r--bin/sh/output.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/bin/sh/output.c b/bin/sh/output.c
index 56a437c..9b8fa5c 100644
--- a/bin/sh/output.c
+++ b/bin/sh/output.c
@@ -107,6 +107,11 @@ out1str(const char *p)
outstr(p, out1);
}
+void
+out1qstr(const char *p)
+{
+ outqstr(p, out1);
+}
void
out2str(const char *p)
@@ -114,6 +119,11 @@ out2str(const char *p)
outstr(p, out2);
}
+void
+out2qstr(const char *p)
+{
+ outqstr(p, out2);
+}
void
outstr(const char *p, struct output *file)
@@ -124,10 +134,31 @@ outstr(const char *p, struct output *file)
flushout(file);
}
+/* Like outstr(), but quote for re-input into the shell. */
+void
+outqstr(const char *p, struct output *file)
+{
+ char ch;
+
+ out1c('\'');
+ while ((ch = *p++) != '\0') {
+ switch (ch) {
+ case '\'':
+ /*
+ * Can't quote single quotes inside single quotes;
+ * close them, write escaped single quote, open again.
+ */
+ outstr("'\\''", file);
+ break;
+ default:
+ outc(ch, file);
+ }
+ }
+ out1c('\'');
+}
char out_junk[16];
-
void
emptyoutbuf(struct output *dest)
{
OpenPOWER on IntegriCloud