Effect of printf(3) `'` flag lost between 20200816 and 20240527
proofer opened this issue · 14 comments
$ cat test.awk
{fmt="Cost: %'d for %'d units\n"; printf fmt, cost, units; exit}
$ /usr/bin/awk --version
awk version 20200816
$ /usr/bin/awk -v cost=40969755 -v units=18471 -f test.awk
Cost: 40,969,755 for 18,471 units
$ /usr/local/bin/awk-20240527 --version
awk version 20240527
$ /usr/local/bin/awk-20240527 -v cost=40969755 -v units=18471 -f test.awk
Cost: 40969755 for 18471 units
macOS 14.5
thanks for noticing this.
this discrepancy is a mac-only issue. Arnold tells me OTA never
supported %'d and I'll go with his inimitable knowledge on these
matters.
$ ./a.out --version
awk version 20202008
$ cat t.a
BEGIN {printf "%'d\n", 123123000}
$ ./a.out -f t.a
123123000
Does this mean that the awk version 20200816
in my /usr/bin is not an OTA?
it is slightly different than the bsd-features version of OTA, for the same release date. i didn't have the time to investigate this fully, but I have compiled the apple version from source under mac os x, and verified this behaviour.
Where do you get the source for the macos version from? Just curious.
I feel a bit sheepish for not taking a careful look at the apple version much earlier.
I'll amend my issue to: both Apple and OTA should support more fulsome output for --version
so that their respective versions can be more readily distinguished.
this is the issue - apple version has uncommented this.
#if 0
// Doing this would comply with POSIX, but is not compatible with
// other awks and with what most users expect. So comment it out.
setlocale(LC_NUMERIC, ""); /* back to whatever it is locally */
#endif
Most users expect not to be able to render large integers for human consumption?
BTW, in Apple's awk-38, which is the so-called "20200816" version:
setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */
Most users expect not to be able to render large integers for human consumption?
I wasn't offering an editorial opinion, just pointing out the area of change. I haven't done all this investigation just to start an argument.
code: you're not looking at the right place.
yyparse();
setlocale(LC_NUMERIC, ""); /* back to whatever it is locally */
Well, I was concerned that Apple's changes would cause something like
echo 1.234,56 | LC_ALL=it_IT.utf8 ./a.out '{ print $1 + 1}'
to print 1235.56
but that doesn't seem to be the case.
In any case, they've done a bunch of work on awk. It'll be worth reviewing.
I'm working on my first multi-line (73 lines so far) awk program, so I'm not in a position to offer advice. I admire the diligence I see here. My copy of "the book" is scheduled for delivery tomorrow.
Well, I was concerned that Apple's changes would cause something like
echo 1.234,56 | LC_ALL=it_IT.utf8 ./a.out '{ print $1 + 1}'to print
1235.56
but that doesn't seem to be the case.In any case, they've done a bunch of work on awk. It'll be worth reviewing.
I tried this in the OTA code by enabling the ifdef-ed out block, and the test suite seems to pass and also I get a reasonable result (2
).
Just FYI.