goawk icon indicating copy to clipboard operation
goawk copied to clipboard

Support for %i in format strings.

Open JohnEarnest opened this issue 1 year ago • 3 comments

The POSIX spec permits using %i as an alternative to %d. This is supported by most awk implementations:

% awk 'BEGIN{printf("%i\n",42)}' 
42
% mawk 'BEGIN{printf("%i\n",42)}'
42
% gawk 'BEGIN{printf("%i\n",42)}'
42

GoAWK v1.27.0 does not interpret %i correctly:

% goawk 'BEGIN{printf("%i\n",42)}'
%!i(int=42)

JohnEarnest avatar Apr 21 '24 19:04 JohnEarnest

Thanks for the report. Are you interested in fixing this? I suspect it'll be fairly trivial.

It looks like %a and %A don't work either (at a quick glance, looks like they should be equivalent to %x / %X). Not sure if that will be trivial or not.

benhoyt avatar Apr 21 '24 20:04 benhoyt

I don't program in Go; I'd rather not work up a PR. Just reporting an inconsistency I tripped over while testing the portability of my Awk scripts.

JohnEarnest avatar Apr 21 '24 20:04 JohnEarnest

@JohnEarnest That's fine, I'll get to it at some point. Thanks again for the report.

benhoyt avatar Apr 21 '24 20:04 benhoyt

Thanks again for the report. The fix is merged into master now. That fix also adds support for %a and %A and fixes the behaviour of %o, %x, %X (they should have been unsigned).

benhoyt avatar Sep 14 '24 04:09 benhoyt