aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-11 19:52:25 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-11 19:52:25 +0100
commit9f657e0f7deae5e27f95d783f52f897f42eafa57 (patch)
treedd85f9dfc4095c047b7b8bd8c6087c6d78c48832 /miscutils
parent259137d0f0600150cd783c796e4011164c44a7f0 (diff)
downloadbusybox-9f657e0f7deae5e27f95d783f52f897f42eafa57.tar.gz
bc: shrink bc_program_printString
function old new delta zbc_program_print 665 642 -23 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bc.c110
1 files changed, 39 insertions, 71 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index be118d81d..5f1baf431 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -5585,87 +5585,55 @@ static char *bc_program_name(char *code, size_t *bgn)
static void bc_program_printString(const char *str)
{
- size_t i, len = strlen(str);
-
#if ENABLE_DC
- if (len == 0) {
+ // Huh? Example when this happens?
+ if (!str[0]) {
bb_putchar('\0');
return;
}
#endif
-
- for (i = 0; i < len; ++i, ++G.prog.nchars) {
-
- int c = str[i];
-
- if (c != '\\' || i == len - 1)
+ while (*str) {
+ int c = *str++;
+ if (c != '\\' || !*str)
bb_putchar(c);
else {
-
- c = str[++i];
-
+ c = *str++;
switch (c) {
-
- case 'a':
- {
- bb_putchar('\a');
- break;
- }
-
- case 'b':
- {
- bb_putchar('\b');
- break;
- }
-
- case '\\':
- case 'e':
- {
- bb_putchar('\\');
- break;
- }
-
- case 'f':
- {
- bb_putchar('\f');
- break;
- }
-
- case 'n':
- {
- bb_putchar('\n');
- G.prog.nchars = SIZE_MAX;
- 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;
- }
+ case 'a':
+ bb_putchar('\a');
+ break;
+ case 'b':
+ bb_putchar('\b');
+ break;
+ case '\\':
+ case 'e':
+ bb_putchar('\\');
+ break;
+ case 'f':
+ bb_putchar('\f');
+ break;
+ case 'n':
+ bb_putchar('\n');
+ G.prog.nchars = SIZE_MAX;
+ 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;
}
}