Mercurial > hg > th-libs
comparison th_string.c @ 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 |
comparison
equal
deleted
inserted
replaced
375:04a273cce4fa | 376:ff8a991fdb2d |
---|---|
167 #include "th_printf1.c" | 167 #include "th_printf1.c" |
168 | 168 |
169 | 169 |
170 static int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, | 170 static int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
171 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, | 171 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, |
172 const BOOL f_unsig, char *(f_alt)(const int flags)) | 172 const BOOL f_unsig, char *(f_alt)(const char *buf, const int vret, const int flags)) |
173 { | 173 { |
174 char buf[64]; | 174 char buf[64]; |
175 int f_len = 0, ret = 0, vret, nwidth; | 175 int f_len = 0, ret = 0, vret, nwidth; |
176 char f_sign, *f_altstr; | 176 char f_sign, *f_altstr; |
177 BOOL f_neg = FALSE; | 177 BOOL f_neg = FALSE; |
205 buf[f_len++] = '0'; | 205 buf[f_len++] = '0'; |
206 buf[f_len] = 0; | 206 buf[f_len] = 0; |
207 } | 207 } |
208 } | 208 } |
209 | 209 |
210 f_altstr = vret != 0 && (f_flags & TH_PF_ALT) && f_alt != NULL ? f_alt(f_flags) : NULL; | 210 f_altstr = vret != 0 && (f_flags & TH_PF_ALT) && f_alt != NULL ? f_alt(buf, vret, f_flags) : NULL; |
211 | 211 |
212 // Are we using a sign prefix? | 212 // Are we using a sign prefix? |
213 f_sign = f_unsig ? 0 : ((f_flags & TH_PF_SIGN) ? | 213 f_sign = f_unsig ? 0 : ((f_flags & TH_PF_SIGN) ? |
214 (f_neg ? '-' : '+') : | 214 (f_neg ? '-' : '+') : |
215 (f_neg ? '-' : ((f_flags & TH_PF_SPACE) ? ' ' : 0))); | 215 (f_neg ? '-' : ((f_flags & TH_PF_SPACE) ? ' ' : 0))); |
298 | 298 |
299 return 0; | 299 return 0; |
300 } | 300 } |
301 | 301 |
302 | 302 |
303 static char * th_printf_altfmt_oct(const int flags) | 303 static char * th_printf_altfmt_oct(const char *buf, const int vret, const int flags) |
304 { | 304 { |
305 (void) vret; | |
305 (void) flags; | 306 (void) flags; |
306 return "0"; | 307 return (buf[0] != '0') ? "0" : ""; |
307 } | 308 ; |
308 | 309 } |
309 | 310 |
310 static char * th_printf_altfmt_hex(const int flags) | 311 |
311 { | 312 static char * th_printf_altfmt_hex(const char *buf, const int vret, const int flags) |
313 { | |
314 (void) buf; | |
315 (void) vret; | |
312 return (flags & TH_PF_UPCASE) ? "0X" : "0x"; | 316 return (flags & TH_PF_UPCASE) ? "0X" : "0x"; |
313 } | 317 } |
314 | 318 |
315 | 319 |
316 int th_vprintf_do(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const char *fmt, va_list ap) | 320 int th_vprintf_do(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const char *fmt, va_list ap) |