When I prepared the \c handling patch for the print builtin, I noticed
a couple of other (mostly minor) issues, which I've addressed in the
attached patch. They are:
- The '%b' specifier of printf gets the character count wrong when a
width is given:
% printf '%5b%n\n' abc count; echo $count
abc
3
- The output of a '%%' specifier and padding spaces from '%b' go to
stdout even if output has been redirected with one of the -u, -p,
-z, -s options:
% print -u3 -f 'a%3bc%%d\n' 'b' 3>fd3.out
%
% cat fd3.out
abcd
- When there's no argument left for a '%b', it does not behave as if
the argument were an empty string, but rather nothing is output at
all. This makes a difference if a width is given:
% printf '%s!%5b!\n' abc
abc!!
vs.
% printf '%s!%5b!\n' abc ''
abc! !
- The argument to a '%b' specifier gets passed to getkeystring() in
unmetafied form, and that may lead to wrong output:
% printf '%b\n' $'\x83 ' | od -tx1
0000000 00 0a
0000002
vs.
% echo $'\x83 ' | od -tx1
0000000 83 20 0a
0000003
- If both the -f and -c/-C options are given to print, the -f inhibits
the initial expansion of escape sequences in the argument strings,
but is then simply ignored:
% print -f 'arg: %b\n' -C2 '\x41' '\x42' '\x43'
\x41 \x43
\x42
vs.
% print -C2 '\x41' '\x42' '\x43'
A C
B
I've resolved this strange interaction by having -f completely
override -c/-C.
- If print -f output has been redirected with -u, -p, -z, or -s, and
an error aborts execution, the fout file isn't closed.
- In the builtins[] table, the BINF_PRINTOPTS flag is not necessary
for the echo and pushln commands, since these don't support the -R
option.
- I've replaced two (unsigned char) casts to STOUC invocations,
according to the advice in the zsh-development-guide.
- I've removed the 'count=mcount' assignment (in the last hunk)
because it is (a) unnecessary and (b) off by one, I think.
- I've slightly tweaked formatting in a few places.
Regards,
Thorsten Dahlheimer
Attachment:
print1.patch
Description: Binary data