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

[RFC PATCH] Allow grouping of thousands in format string



Putting an apostrophe before i, d, u, f, F, g or G is specified in POSIX
albeit noted as an extension to ISO C.
---

Bash handles this this and from what I can tell implements it much in the same
way so that stuff like %'s is passed straight on to the system's printf().
However POSIX also says that using the grouping specifier with other flags is
undefined. It works just fine on the limited range of systems I've tested it on
(all GNU).

If desired I could set a flag and then handle it further on by checking that
type == 2 or type == 3 or something like that, but that needs some rearranging.

If the idea behind the patch itself is undesired then I think the documentation
for zsh's printf should be updated.

 Src/builtin.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Src/builtin.c b/Src/builtin.c
index 614b17d..225c034 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3735,7 +3735,7 @@ bin_print(char *name, char **args, Options ops, int func)
     int nnl = 0, fmttrunc = 0, ret = 0, maxarg = 0, nc = 0;
     int flags[5], *len;
     char *start, *endptr, *c, *d, *flag, *buf = NULL, spec[13], *fmt = NULL;
-    char **first, **argp, *curarg, *flagch = "0+- #", save = '\0', nullstr = '\0';
+    char **first, **argp, *curarg, *flagch = "'0+- #", save = '\0', nullstr = '\0';
     size_t rcount, count = 0;
 #ifdef HAVE_OPEN_MEMSTREAM
     size_t mcount;
@@ -4312,8 +4312,8 @@ bin_print(char *name, char **args, Options ops, int func)
 		if (prec >= 0) *d++ = '.', *d++ = '*';
 	    }
 
-	    /* ignore any size modifier */
-	    if (*c == 'l' || *c == 'L' || *c == 'h') c++;
+	    /* ignore any size modifier and grouping specifier */
+	    if (*c == 'l' || *c == 'L' || *c == 'h' || *c == '\'') c++;
 
 	    if (!curarg && *argp) {
 		curarg = *argp;
-- 
2.2.0



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