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

PATCH: %n value with format reuse



I wrote:
> 
> Any views on whether the count (as returned with %n) should be zeroed
> when reusing the format string?

At the time I wrote that, I hadn't realised that ksh supports %n because
it is not documented. Anyway, ksh does restart the count at zero when
reusing the format strings so for consistency, zsh should do the same.

Oliver

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.60
diff -u -r1.60 builtin.c
--- Src/builtin.c       2001/10/18 14:22:21     1.60
+++ Src/builtin.c       2001/10/23 11:07:55
@@ -2897,7 +2897,7 @@
     int flags[5], *len;
     char *start, *endptr, *c, *d, *flag, spec[11], *fmt = NULL;
     char **first, *curarg, *flagch = "0+- #", save, nullstr = '\0';
-    zlong count = 0;
+    zlong count;
     FILE *fout = stdout;
 
     mnumber mnumval;
@@ -3096,6 +3096,7 @@
     /* printf style output */
     *spec='%';
     do {
+       count = 0;
        if (maxarg) {
            first += maxarg;
            argc -= maxarg;
Index: Test/B03print.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/B03print.ztst,v
retrieving revision 1.3
diff -u -r1.3 B03print.ztst
--- Test/B03print.ztst  2001/10/18 14:22:21     1.3
+++ Test/B03print.ztst  2001/10/23 11:07:55
@@ -144,6 +144,11 @@
 >two   b:0x2%
 >three c:0x3%
 
+ printf '%d%n' 123 val val val > /dev/null
+ printf '%d\n' val
+0:%n count zeroed on format reuse
+>1
+
 # this should fill spec string with '%0+- #*.*d\0' - 11 characters
  printf '%1$0+- #-08.5dx\n' 123
 0:maximal length format specification



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