changeset 376:ff8a991fdb2d

Pass also numeric buffer and return value from th_printf_vbuf_int*() to altfmt helper functions.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 29 Feb 2016 16:49:34 +0200
parents 04a273cce4fa
children 62a83d6d7be5
files th_string.c
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Mon Feb 29 16:35:05 2016 +0200
+++ b/th_string.c	Mon Feb 29 16:49:34 2016 +0200
@@ -169,7 +169,7 @@
 
 static int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
     va_list ap, const int f_radix, int f_flags, int f_width, int f_prec,
-    const BOOL f_unsig, char *(f_alt)(const int flags))
+    const BOOL f_unsig, char *(f_alt)(const char *buf, const int vret, const int flags))
 {
     char buf[64];
     int f_len = 0, ret = 0, vret, nwidth;
@@ -207,7 +207,7 @@
         }
     }
 
-    f_altstr = vret != 0 && (f_flags & TH_PF_ALT) && f_alt != NULL ? f_alt(f_flags) : NULL;
+    f_altstr = vret != 0 && (f_flags & TH_PF_ALT) && f_alt != NULL ? f_alt(buf, vret, f_flags) : NULL;
 
     // Are we using a sign prefix?
     f_sign = f_unsig ? 0 : ((f_flags & TH_PF_SIGN) ?
@@ -300,15 +300,19 @@
 }
 
 
-static char * th_printf_altfmt_oct(const int flags)
+static char * th_printf_altfmt_oct(const char *buf, const int vret, const int flags)
 {
+    (void) vret;
     (void) flags;
-    return "0";
+    return (buf[0] != '0') ? "0" : "";
+;
 }
 
 
-static char * th_printf_altfmt_hex(const int flags)
+static char * th_printf_altfmt_hex(const char *buf, const int vret, const int flags)
 {
+    (void) buf;
+    (void) vret;
     return (flags & TH_PF_UPCASE) ? "0X" : "0x";
 }