emit QCHAR '\n' reentrancy-safe

This commit is contained in:
tg 2016-06-26 00:07:31 +00:00
parent a3cc4ffacb
commit c52133cc4e
1 changed files with 22 additions and 14 deletions

36
tree.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.83 2016/03/04 14:26:16 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/tree.c,v 1.84 2016/06/26 00:07:31 tg Exp $");
#define INDENT 8 #define INDENT 8
@ -322,26 +322,34 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
++wp; ++wp;
goto wdvarput_csubst; goto wdvarput_csubst;
} }
/* FALLTHROUGH */
case CHAR: case CHAR:
c = *wp++; c = *wp++;
shf_putc(c, shf); shf_putc(c, shf);
break; break;
case QCHAR: { case QCHAR:
bool doq;
c = *wp++; c = *wp++;
doq = (c == '"' || c == '`' || c == '$' || c == '\\'); if (opmode & WDS_TPUTS)
if (opmode & WDS_TPUTS) { switch (c) {
if (quotelevel == 0) case '\n':
doq = true; if (quotelevel == 0) {
} else { c = '\'';
doq = false; shf_putc(c, shf);
} shf_putc('\n', shf);
if (doq) }
shf_putc('\\', shf); break;
default:
if (quotelevel == 0)
/* FALLTHROUGH */
case '"':
case '`':
case '$':
case '\\':
shf_putc('\\', shf);
break;
}
shf_putc(c, shf); shf_putc(c, shf);
break; break;
}
case COMSUB: case COMSUB:
shf_puts("$(", shf); shf_puts("$(", shf);
cs = ")"; cs = ")";