Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: printf, left-justification ignored in 5.0.8



Roman Neuhauser wrote:
> 
> 5.0.8:
> 
> % printf "x:%-20s:y\n" fubar
> x:               fubar:y

That'll be my fault for not checking thoroughly enough. The - flag is
fine for numeric values but for strings it seems there is separate code
to allow for UTF-8 which looks in the flags array. The patch should
fix this, adds a test and makes the maximum specification length test
include the ' flag.

Oliver

diff --git a/Src/builtin.c b/Src/builtin.c
index 9358e8b..8bfc419 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4461,7 +4461,7 @@ bin_print(char *name, char **args, Options ops, int func)
 			lleft -= chars;
 			ptr += chars;
 		    }
-		    if (width > 0 && flags[2]) width = -width;
+		    if (width > 0 && flags[3]) width = -width;
 		    if (width > 0 && lchars < width)
 		    	count += fprintf(fout, "%*c", width - lchars, ' ');
 		    count += fwrite(b, 1, lbytes, fout);
diff --git a/Test/B03print.ztst b/Test/B03print.ztst
index 48574c2..9360416 100644
--- a/Test/B03print.ztst
+++ b/Test/B03print.ztst
@@ -169,11 +169,15 @@
 0:%n count zeroed on format reuse
 >1
 
-# this may fill spec string with '%0+- #*.*lld\0' - 13 characters
- printf '%1$0+- #-08.5dx\n' 123
+# this may fill spec string with '%0'+- #*.*lld\0' - 14 characters
+ printf '%1$0'"'+- #-08.5dx\n" 123
 0:maximal length format specification
 >+00123  x
 
+ printf "x:%-20s:y\n" fubar
+0:left-justification of string
+>x:fubar               :y
+
  printf '%*smorning\n' -5 good
 0:negative width specified
 >good morning



Messages sorted by: Reverse Date, Date, Thread, Author