On 2/21/25 7:52 PM, Robert Elz wrote:
| There is no user who would think that using a numbered conversion | specifier is not an absolute position in the original argument list.Probably not, but it doesn't matter if the application doesn't mix numbered and unnumbered conversions, and it shouldn't.
Which of course runs headlong into format reuse requirements (mixing numbered and unnumbered conversion specifiers, I mean).
But there are plenty of other differences between the implementations when it comes to mixing numbered and numbered args, one being what is the sequence of the unnumbered args when interleaved with numbered args.
Yes, that's the main one. Do you maintain a separate counter for unnumbered conversions, or do you pick up the count after the last numbered one? There are implementations that have chosen each.
That is, in the example printf '%s %3$s %s\n' A B C D The updated ksh93 seems to ignore the numbered conversions when counting the args for the unnumbered ones (so "A C B" (for the first line anyway, I won't go on about repeating the format string again).
Like coreutils git and zsh.
The previous version made an unnumbered arg conversion use the next arg after the last one used (which would give "A C D" using a more reasonable interpretation of %3$).
Like FreeBSD/macOS.
A third possibility is to simply observe that it is the third conversion,and so should use the third arg, thus giving "A C C".
Just keep marching sequentially forward counting the number of arguments consumed.
It might be tempting to say "except skip any args used by numbered conversions" but that leads to bizarre special cases,
There will be bizarre boundary conditions no matter what interpretation an implementation chooses.
When I was looking at implementing this (I actually had an implementation that I ended up discarding, as I was never going to to the "rescan the format" in the numbered conversion case) I tested all the printf implementations which implemented numbered conversions that I could find, and they were all amazingly different
And that was before coreutils got into the mix. I had to go to the git repo to find that implementation. There aren't all that many.
- it is no surprise at all that POSIX made mixing the things unspecified (it is also an amazingly useless thing to support in general, and simply issuing an error and not proceeding with any further conversions once the first "different" style of arg reference is encountered is not at all a bad choice).
I'll probably add a warning there to make it annoying to do.
that format string reuse is simply wrong in the numbered conversion case, no-one really needs that.
POSIX chose another direction. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature