From 20a79b31c9897f825323eedee4c0eb01922d53da Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 22 Mar 2018 18:37:52 +0200 Subject: Add support for %a and %A in printf. --- builtin.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 6927205c..c54be9b2 100644 --- a/builtin.c +++ b/builtin.c @@ -1493,6 +1493,17 @@ mpf1: case 'e': case 'f': case 'E': +#if defined(PRINTF_HAS_A_FORMAT) && PRINTF_HAS_A_FORMAT == 1 + case 'A': + case 'a': + { + static bool warned = false; + if (do_lint && tolower(cs1) == 'a' && ! warned) { + warned = true; + lintwarn(_("%%%c format is POSIX standard but not portable to other awks"), cs1); + } + } +#endif need_format = false; parse_next_arg(); (void) force_number(arg); @@ -1557,11 +1568,21 @@ mpf1: break; #endif default: - sprintf(cp, "*.*%c", cs1); - while ((nc = snprintf(obufout, ofre, cpbuf, - (int) fw, (int) prec, - (double) tmpval)) >= ofre) - chksize(nc) + if (have_prec || tolower(cs1) != 'a') { + sprintf(cp, "*.*%c", cs1); + while ((nc = snprintf(obufout, ofre, cpbuf, + (int) fw, (int) prec, + (double) tmpval)) >= ofre) + chksize(nc) + } else { + // For %a and %A, use the default precision if it + // wasn't supplied by the user. + sprintf(cp, "*%c", cs1); + while ((nc = snprintf(obufout, ofre, cpbuf, + (int) fw, + (double) tmpval)) >= ofre) + chksize(nc) + } } #if defined(LC_NUMERIC) -- cgit v1.2.3