On Sun, Feb 23, 2025 at 8:03 PM Chet Ramey <chet.ra...@case.edu> wrote:
> On 2/22/25 12:38 AM, Phi Debian wrote: > > > The new semantic is simple > > - numbered are indexed args access (easy to understand) > > - unumbered are counting only the unumbered from the fmt string > > > > This way when you don't mix then the both work as expected. > > This isn't unreasonable. coreutils git chose the same interpretation. Too > bad FreeBSD went the other way. > Hum, not using FreeBSD so not spotted that one, may be they will support multi semantic with printf flags (again the docco will be epic) > > > Now the dare devil can still > > mix'n'match, it may not produce what they would like, but at least it > don't > > crash, and produce result as announced for this semantic. > > No one should mix numbered and unnumbered conversions unless they control > everything -- the shell, the shell version, the format string, and all the > arguments. > I know, so the proposal to refuse working on mix'n'match, but that one is problematic and require a full fmt scan before start working really, yet doable. For ksh93 the mix'n'match, though bugged, existed since long time, so the try to make something running without crashing, and still be usefull for full numbered, even that was broken, so at least full numbered works, and my guess is there is not that much mix'n'match out there that I may have broken if they were relaying on the erratic output. > > > Again the rule I used for ksh93 is that the next arg for fmt reuse is > > max( number_of_unumbered_occurences, highest_numberd_index ) > > So you make numbered conversion specifiers relative to some max base from > the previous scan through the format string, initializing that base to 0. > I had the same idea. > Yes, numbered are 1 based (0 is the fmt string :-) and don't move) and the next fmt roll start past the highest numbered index so for '%2*4$.*1$s' next roll arg1 is the 5th, for unumbered we count '%s %s %s' next roll start at 4. And the ugly mix '%s %3$s %s' next roll start at 4 (sigma(%s)=2 max(indexes)=3 ==> next is 4) '%s %s %3$s %s %s' next roll start at 5 (sigma(%s)=4 max(indexes)=3 ==>next is 5) And we have gaps in numbered. This mix is useless but easy to explain what result you will get, and full numbered and unumbered works. With my simplistic rule, documentation is reduced, no complicated case to explain, count your unumbered, and use your index. Simple predictable Now the docco may say mix'n'match is forbiden (with error trowing) or Mix'n'Match is the counting method not necessarilly producing something usefull but avoid lengthy explanation and avoiding crash. I also forgot to mention that C99 introduced this There may be no gaps in the numbers of arguments specified using '$'; for example, if argu‐ ments 1 and 3 are specified, argument 2 must also be specified some‐ where in the format string. Another rule that could be imported, for ksh93 I didn't implemented it, so I accept what so called gap, so the dance with consumed vs referenced, all thoses complications, again my choice for unumbered counting and numbered with gaps, and the rule to define how we reuse the fmt, make the docco simple, with the provision written in BOLD font, don't mix'n'match it may not produce what you expect (yet it will not crash) that being said, a full non mixed, numbered (with or without gap TBD) or unumbered works a specified.