diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2021-01-07 22:08:40 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2021-01-07 22:08:40 +0200 |
commit | e33ab738045b82db7b449e92c8633ef1d44bb8a7 (patch) | |
tree | 7942c2f074014a3125024d1616bfda95566cd0e6 /builtin.c | |
parent | 3c8d0097afa139003c55612eaa89340b70f16ee7 (diff) | |
download | egawk-e33ab738045b82db7b449e92c8633ef1d44bb8a7.tar.gz egawk-e33ab738045b82db7b449e92c8633ef1d44bb8a7.tar.bz2 egawk-e33ab738045b82db7b449e92c8633ef1d44bb8a7.zip |
Improve handling of unsupported format modifiers.
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 60 |
1 files changed, 19 insertions, 41 deletions
@@ -693,7 +693,7 @@ format_tree( NODE *arg; long fw, prec, argnum; bool used_dollar; - bool lj, alt, big_flag, bigbig_flag, small_flag, have_prec, need_format; + bool lj, alt, have_prec, need_format; long *cur = NULL; uintmax_t uval; bool sgn; @@ -735,6 +735,11 @@ format_tree( static const char zero_string[] = "0"; static const char lchbuf[] = "0123456789abcdef"; static const char Uchbuf[] = "0123456789ABCDEF"; + static const char bad_modifiers[] = "hjlLtz"; + static bool warned[sizeof(bad_modifiers)-1]; // auto-init to zero + + bool modifier_seen[sizeof(bad_modifiers)-1]; +#define modifier_index(c) (strchr(bad_modifiers, c) - bad_modifiers) #define INITIAL_OUT_SIZE 64 emalloc(obuf, char *, INITIAL_OUT_SIZE, "format_tree"); @@ -830,7 +835,8 @@ format_tree( #endif fmt_type = MP_NONE; - lj = alt = big_flag = bigbig_flag = small_flag = false; + lj = alt = false; + memset(modifier_seen, 0, sizeof(modifier_seen)); magic_posix_flag = false; fill = sp; cp = cend; @@ -1014,57 +1020,29 @@ check_pos: #else goto retry; #endif + case 'h': + case 'j': case 'l': - if (big_flag) - break; - else { - static bool warned = false; - - if (do_lint && ! warned) { - lintwarn(_("`l' is meaningless in awk formats; ignored")); - warned = true; - } - if (do_posix) { - msg(_("fatal: `l' is not permitted in POSIX awk formats")); - goto out; - } - } - big_flag = true; - goto retry; case 'L': - if (bigbig_flag) + case 't': + case 'z': + if (modifier_seen[modifier_index(cs1)]) break; else { - static bool warned = false; + int ind = modifier_index(cs1); - if (do_lint && ! warned) { - lintwarn(_("`L' is meaningless in awk formats; ignored")); - warned = true; + if (do_lint && ! warned[ind]) { + lintwarn(_("`%c' is meaningless in awk formats; ignored"), cs1); + warned[ind] = true; } if (do_posix) { - msg(_("fatal: `L' is not permitted in POSIX awk formats")); + msg(_("fatal: `%c' is not permitted in POSIX awk formats"), cs1); goto out; } } - bigbig_flag = true; + modifier_seen[modifier_index(cs1)] = true; goto retry; - case 'h': - if (small_flag) - break; - else { - static bool warned = false; - if (do_lint && ! warned) { - lintwarn(_("`h' is meaningless in awk formats; ignored")); - warned = true; - } - if (do_posix) { - msg(_("fatal: `h' is not permitted in POSIX awk formats")); - goto out; - } - } - small_flag = true; - goto retry; case 'P': if (magic_posix_flag) break; |