diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-05-29 10:55:40 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-05-29 10:55:40 +0200 |
commit | 721bf6eaf4739a2865b071b38d3478f334234d26 (patch) | |
tree | f5c5779522dc246b33186022ab54dcfd2f9902a9 | |
parent | 4d7339204f9f823f592562d9903db3ae79a6c640 (diff) | |
download | busybox-w32-721bf6eaf4739a2865b071b38d3478f334234d26.tar.gz busybox-w32-721bf6eaf4739a2865b071b38d3478f334234d26.tar.bz2 busybox-w32-721bf6eaf4739a2865b071b38d3478f334234d26.zip |
awk: printf(INVALID_FMT) prints it verbatim
function old new delta
awk_printf 628 640 +12
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/editors/awk.c b/editors/awk.c index b5774a339..c49ad6e02 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -2389,7 +2389,7 @@ static char *awk_printf(node *n, size_t *len) | |||
2389 | while (1) { | 2389 | while (1) { |
2390 | if (isalpha(c)) | 2390 | if (isalpha(c)) |
2391 | break; | 2391 | break; |
2392 | if (c == '*') | 2392 | if (c == '*') /* gawk supports %*d and %*.*f, we don't... */ |
2393 | syntax_error("%*x formats are not supported"); | 2393 | syntax_error("%*x formats are not supported"); |
2394 | c = *++f; | 2394 | c = *++f; |
2395 | if (!c) { /* "....%...." and no letter found after % */ | 2395 | if (!c) { /* "....%...." and no letter found after % */ |
@@ -2422,12 +2422,18 @@ static char *awk_printf(node *n, size_t *len) | |||
2422 | double d = getvar_i(arg); | 2422 | double d = getvar_i(arg); |
2423 | if (strchr("diouxX", c)) { | 2423 | if (strchr("diouxX", c)) { |
2424 | //TODO: make it wider here (%x -> %llx etc)? | 2424 | //TODO: make it wider here (%x -> %llx etc)? |
2425 | //Can even print the value into a temp string with %.0f, | ||
2426 | //then replace diouxX with s and print that string. | ||
2427 | //This will correctly print even very large numbers, | ||
2428 | //but some replacements are not equivalent: | ||
2429 | //%09d -> %09s: breaks zero-padding; | ||
2430 | //%+d -> %+s: won't prepend +; etc | ||
2425 | s = xasprintf(s, (int)d); | 2431 | s = xasprintf(s, (int)d); |
2426 | } else if (strchr("eEfFgGaA", c)) { | 2432 | } else if (strchr("eEfFgGaA", c)) { |
2427 | s = xasprintf(s, d); | 2433 | s = xasprintf(s, d); |
2428 | } else { | 2434 | } else { |
2429 | //TODO: GNU Awk 5.0.1: printf "%W" prints "%W", does not error out | 2435 | /* gawk 5.1.1 printf("%W") prints "%W", does not error out */ |
2430 | syntax_error(EMSG_INV_FMT); | 2436 | s = xstrndup(s, f - s); |
2431 | } | 2437 | } |
2432 | } | 2438 | } |
2433 | slen = strlen(s); | 2439 | slen = strlen(s); |