diff options
author | Tim J. Robbins <tjr@FreeBSD.org> | 2002-06-04 12:59:12 +0000 |
---|---|---|
committer | Tim J. Robbins <tjr@FreeBSD.org> | 2002-06-04 12:59:12 +0000 |
commit | e5341cbb170f5fda00f5458fd5fd99e19ef7a4c0 (patch) | |
tree | 20257442bc2cc5cae672c11d72306aa5eae7e200 /bin/sh/output.c | |
parent | 4ffc41abddcbfb5fa5cab519b38e50fa0b9d9d02 (diff) | |
download | src-e5341cbb170f5fda00f5458fd5fd99e19ef7a4c0.tar.gz src-e5341cbb170f5fda00f5458fd5fd99e19ef7a4c0.zip |
Quote alias values in the output of the alias(1) builtin so they are
suitable for re-input to the shell (SUSv3)
Notes
Notes:
svn path=/head/; revision=97815
Diffstat (limited to 'bin/sh/output.c')
-rw-r--r-- | bin/sh/output.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/bin/sh/output.c b/bin/sh/output.c index 56a437cd0baa..9b8fa5cf1b61 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) { |