diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-01 01:02:43 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-01 01:02:43 +0200 |
| commit | 4f3a56dc12a2126bdacff73f1cfe586d06e800c0 (patch) | |
| tree | 863d23f2fc3d2bf6b77213ef729a6ebda7101244 /libbb | |
| parent | bb18473216253b8602ce081dd944f854aad9e572 (diff) | |
| download | busybox-w32-4f3a56dc12a2126bdacff73f1cfe586d06e800c0.tar.gz busybox-w32-4f3a56dc12a2126bdacff73f1cfe586d06e800c0.tar.bz2 busybox-w32-4f3a56dc12a2126bdacff73f1cfe586d06e800c0.zip | |
ls: fix -Q to match GNU
function old new delta
print_name 137 229 +92
display_files 375 402 +27
c_escape_conv_str00 - 24 +24
display 1476 1485 +9
conv_str 33 - -33
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 3/0 up/down: 152/-33) Total: 119 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/c_escape.c | 20 | ||||
| -rw-r--r-- | libbb/dump.c | 39 |
2 files changed, 39 insertions, 20 deletions
diff --git a/libbb/c_escape.c b/libbb/c_escape.c new file mode 100644 index 000000000..6c109f2e0 --- /dev/null +++ b/libbb/c_escape.c | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2025 by Denys Vlasenko <vda.linux@googlemail.com> | ||
| 4 | * | ||
| 5 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
| 6 | */ | ||
| 7 | //kbuild:lib-y += c_escape.o | ||
| 8 | |||
| 9 | #include "libbb.h" | ||
| 10 | |||
| 11 | const char c_escape_conv_str00[] ALIGN1 = | ||
| 12 | "\\""0""\0" // [0]:00 | ||
| 13 | "\\""a""\0" // [1]:07 | ||
| 14 | "\\""b""\0" // [2]:08 | ||
| 15 | "\\""t""\0" // [3]:09 | ||
| 16 | "\\""n""\0" // [4]:0a | ||
| 17 | "\\""v""\0" // [5]:0b | ||
| 18 | "\\""f""\0" // [6]:0c | ||
| 19 | "\\""r" // [7]:0d | ||
| 20 | ; | ||
diff --git a/libbb/dump.c b/libbb/dump.c index ac5d47d9e..0cc7775d6 100644 --- a/libbb/dump.c +++ b/libbb/dump.c | |||
| @@ -478,37 +478,36 @@ static void bpad(PR *pr) | |||
| 478 | continue; | 478 | continue; |
| 479 | } | 479 | } |
| 480 | 480 | ||
| 481 | static const char conv_str[] ALIGN1 = | ||
| 482 | "\0" "\\""0""\0" | ||
| 483 | "\007""\\""a""\0" | ||
| 484 | "\b" "\\""b""\0" | ||
| 485 | "\f" "\\""f""\0" | ||
| 486 | "\n" "\\""n""\0" | ||
| 487 | "\r" "\\""r""\0" | ||
| 488 | "\t" "\\""t""\0" | ||
| 489 | "\v" "\\""v""\0" | ||
| 490 | ; | ||
| 491 | |||
| 492 | static void conv_c(PR *pr, unsigned char *p) | 481 | static void conv_c(PR *pr, unsigned char *p) |
| 493 | { | 482 | { |
| 494 | const char *str = conv_str; | 483 | const char *str; |
| 495 | 484 | unsigned char ch; | |
| 496 | do { | 485 | |
| 497 | if (*p == *str) { | 486 | ch = *p; |
| 498 | ++str; | 487 | if (ch == 0 || (ch -= 6, (signed char)ch > 0 && ch <= 7)) { |
| 499 | goto strpr; /* map e.g. '\n' to "\\n" */ | 488 | /* map chars 0,7..13 to "\0","\{a,b,t,n,v,f,r}" */ |
| 500 | } | 489 | str = c_escape_conv_str00 + 3 * ch; |
| 501 | str += 4; | 490 | goto strpr; |
| 502 | } while (*str); | 491 | } |
| 503 | 492 | ||
| 504 | if (isprint_asciionly(*p)) { | 493 | if (isprint_asciionly(*p)) { |
| 505 | *pr->cchar = 'c'; | 494 | *pr->cchar = 'c'; |
| 506 | printf(pr->fmt, *p); | 495 | printf(pr->fmt, *p); |
| 507 | } else { | 496 | } else { |
| 497 | #if 1 | ||
| 508 | char buf[4]; | 498 | char buf[4]; |
| 509 | /* gcc-8.0.1 needs lots of casts to shut up */ | 499 | /* gcc-8.0.1 needs lots of casts to shut up */ |
| 510 | sprintf(buf, "%03o", (unsigned)(uint8_t)*p); | 500 | sprintf(buf, "%03o", (unsigned)(uint8_t)*p); |
| 511 | str = buf; | 501 | str = buf; |
| 502 | #else // use faster version? +20 bytes of code | ||
| 503 | char buf[4]; | ||
| 504 | buf[3] = '\0'; | ||
| 505 | ch = *p; | ||
| 506 | buf[2] = '0' + (ch & 7); ch >>= 3; | ||
| 507 | buf[1] = '0' + (ch & 7); ch >>= 3; | ||
| 508 | buf[0] = '0' + ch; | ||
| 509 | str = buf; | ||
| 510 | #endif | ||
| 512 | strpr: | 511 | strpr: |
| 513 | *pr->cchar = 's'; | 512 | *pr->cchar = 's'; |
| 514 | printf(pr->fmt, str); | 513 | printf(pr->fmt, str); |
