From 41785b1a222d34f4e0e0a3ab4fd15f94f988ca39 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Sun, 26 Jun 2016 20:26:05 -0400 Subject: Do not use OFMT or CONVFMT for strnum values. --- ChangeLog | 7 +++++++ builtin.c | 12 +++++------- test/ChangeLog | 5 +++++ test/strnum2.ok | 8 ++++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ce92921..82a688f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-06-26 Andrew J. Schorr + + * builtin.c (do_print): Do not use OFMT to print strnum values. We + accomplish this by calling format_val for a NUMBER only + if there is no string currently available, or if stfmt equals + neither -1 nor OFMTidx. + 2016-06-26 Arnold D. Robbins * awk.h: Edit some comments. Add others. Minor coding style changes. diff --git a/builtin.c b/builtin.c index 08ce3273..a0b6e79f 100644 --- a/builtin.c +++ b/builtin.c @@ -2202,13 +2202,11 @@ do_print(int nargs, int redirtype) } if (tmp->type == Node_typedregex) - args_array[i] = force_string(tmp); - else if ((fixtype(tmp)->flags & (NUMBER|STRING)) == NUMBER) { - if (OFMTidx == CONVFMTidx) - args_array[i] = force_string(tmp); - else - args_array[i] = format_val(OFMT, OFMTidx, tmp); - } + args_array[i] = force_string(tmp); + else if ((fixtype(tmp)->flags & (NUMBER|STRING)) == NUMBER && + !((tmp->flags & STRCUR) != 0 + && (tmp->stfmt == -1 || tmp->stfmt == OFMTidx))) + args_array[i] = format_val(OFMT, OFMTidx, tmp); } if (redir_exp != NULL) { diff --git a/test/ChangeLog b/test/ChangeLog index f5dbd571..cca91c53 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2016-06-26 Andrew J. Schorr + + * strnum2.ok: Fix results, since print for a strnum should not be + affected by OFMT or CONVFMT. + 2016-06-22 Andrew J. Schorr * strnum2.awk, strnum2.ok: Improve test case to show both OFMT and diff --git a/test/strnum2.ok b/test/strnum2.ok index 65cfbde2..63898bd4 100644 --- a/test/strnum2.ok +++ b/test/strnum2.ok @@ -1,4 +1,4 @@ -1.2 -1.23 -1.2 -1.23 + 1.234 + 1.234 + 1.234 + 1.234 -- cgit v1.2.3