diff options
| author | Jilles Tjoelker <jilles@FreeBSD.org> | 2009-06-19 22:09:55 +0000 |
|---|---|---|
| committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2009-06-19 22:09:55 +0000 |
| commit | e68165a6bb73c754455474a9b3a316836b703f56 (patch) | |
| tree | 71969d5c4fcd6d3c7f130909631c731d8065fd94 | |
| parent | 5b204a113c89e1e881a115db9ecbe0ac9f9b460c (diff) | |
Notes
| -rw-r--r-- | bin/sh/output.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/bin/sh/output.c b/bin/sh/output.c index b59e11e0e870..0d55fdfcb28e 100644 --- a/bin/sh/output.c +++ b/bin/sh/output.c @@ -133,32 +133,38 @@ void outqstr(const char *p, struct output *file) { char ch; + int inquotes; if (p[0] == '\0') { outstr("''", file); return; } - if (p[strcspn(p, "|&;<>()$`\\\"'")] == '\0' && (!ifsset() || - p[strcspn(p, ifsval())] == '\0')) { + /* Caller will handle '=' if necessary */ + if (p[strcspn(p, "|&;<>()$`\\\"' \t\n*?[~#")] == '\0' || + strcmp(p, "[") == 0) { outstr(p, file); return; } - out1c('\''); + inquotes = 0; 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); + /* Can't quote single quotes inside single quotes. */ + if (inquotes) + outc('\'', file); + inquotes = 0; + outstr("\\'", file); break; default: + if (!inquotes) + outc('\'', file); + inquotes = 1; outc(ch, file); } } - out1c('\''); + if (inquotes) + outc('\'', file); } STATIC char out_junk[16]; |
