On 2/23/25 10:48 PM, Phi Debian wrote:
> 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.
I think we're saying the same thing, and POSIX says it, too, it its own way.
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,
POSIX requires that: "Unlike the printf() function, when numbered conversion specifications are used, specifying the Nth argument does not require that all the leading arguments, from the first to the (N-1)th, are specified in the format string. For example, "%3$s %1$d\n" is an acceptable format operand which evaluates the first and third argument operands but not the second." -- ``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