Bug #4818
closedprintf(1) should support n$ width and precision specifiers
100%
Description
This was pointed out by folks looking to integrate printf(1) into FreeBSD, who noted that the n$ support in my printf is not quite complete:
+ if (dollar) \\
+ *f = '$'; \\
} while (0)static int asciicode(void);
This looks useful, but is incomplete. The n$ syntax can also be used
after an asterisk, and in fact this is required: positional (n$) and
non-positional arguments may not be mixed in a single format directive.
For example:
printf '[%3$*1$.*2$s]\\n' 20 10 abcdefghijklmn
and
printf '[%1$*2$.*3$s]\\n' abcdefghijklmn 20 10
do the same thing as
printf '[%*.*s]\\n' 20 10 abcdefghijklmn
Of the printf(1)s I have tried, this works in zsh's and ksh93's builtin.
This certainly needs quite a bit of additional code, but I think the n$
and * syntaxes are most useful together, since they are both meant for
situations where the format string is translated. If the format string
is not translated, * can be replaced by a parameter substitution (or
even hard-coding) and n$ can be replaced by reordering the arguments.
Updated by Garrett D'Amore about 8 years ago
Updated by Electric Monk about 8 years ago
- Status changed from New to Closed
- % Done changed from 90 to 100
git commit 598f4ceed9327d2d6c2325dd67cae3aa06f7fea6
commit 598f4ceed9327d2d6c2325dd67cae3aa06f7fea6 Author: Garrett D'Amore <garrett@damore.org> Date: 2014-05-13T22:44:40.000Z 4818 printf(1) should support n$ width and precision specifiers 4854 printf(1) doesn't support %b and \\\\c properly Reviewed by: Keith Wesolowski <keith.wesolowski@joyent.com> Approved by: Gordon Ross <gordon.ross@nexenta.com>