diff options
-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); |