bc: shrink bc_program_printString

function                                             old     new   delta
zbc_program_print                                    665     642     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-12-11 19:52:25 +01:00
parent 259137d0f0
commit 9f657e0f7d

View File

@ -5585,87 +5585,55 @@ static char *bc_program_name(char *code, size_t *bgn)
static void bc_program_printString(const char *str) static void bc_program_printString(const char *str)
{ {
size_t i, len = strlen(str);
#if ENABLE_DC #if ENABLE_DC
if (len == 0) { // Huh? Example when this happens?
if (!str[0]) {
bb_putchar('\0'); bb_putchar('\0');
return; return;
} }
#endif #endif
while (*str) {
for (i = 0; i < len; ++i, ++G.prog.nchars) { int c = *str++;
if (c != '\\' || !*str)
int c = str[i];
if (c != '\\' || i == len - 1)
bb_putchar(c); bb_putchar(c);
else { else {
c = *str++;
c = str[++i];
switch (c) { switch (c) {
case 'a':
case 'a': bb_putchar('\a');
{ break;
bb_putchar('\a'); case 'b':
break; bb_putchar('\b');
} break;
case '\\':
case 'b': case 'e':
{ bb_putchar('\\');
bb_putchar('\b'); break;
break; case 'f':
} bb_putchar('\f');
break;
case '\\': case 'n':
case 'e': bb_putchar('\n');
{ G.prog.nchars = SIZE_MAX;
bb_putchar('\\'); break;
break; case 'r':
} bb_putchar('\r');
break;
case 'f': case 'q':
{ bb_putchar('"');
bb_putchar('\f'); break;
break; case 't':
} bb_putchar('\t');
break;
case 'n': default:
{ // Just print the backslash and following character.
bb_putchar('\n'); bb_putchar('\\');
G.prog.nchars = SIZE_MAX; ++G.prog.nchars;
break; bb_putchar(c);
} break;
case 'r':
{
bb_putchar('\r');
break;
}
case 'q':
{
bb_putchar('"');
break;
}
case 't':
{
bb_putchar('\t');
break;
}
default:
{
// Just print the backslash and following character.
bb_putchar('\\');
++G.prog.nchars;
bb_putchar(c);
break;
}
} }
} }
++G.prog.nchars;
} }
} }