Mercurial > hg > th-libs
comparison th_string.c @ 450:051226a06f70
Split th_vprintf_put_int() partially into th_vprintf_put_int_format(), to
separate va_arg() value fetching from most of the formatting code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 25 Oct 2017 22:13:09 +0300 |
parents | eb78997a7574 |
children | db45d6d2e576 |
comparison
equal
deleted
inserted
replaced
449:eb78997a7574 | 450:051226a06f70 |
---|---|
196 #else | 196 #else |
197 #define PP_PRINTF(...) /* stub */ | 197 #define PP_PRINTF(...) /* stub */ |
198 #endif | 198 #endif |
199 | 199 |
200 | 200 |
201 static int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, | 201 static int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
202 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, | 202 char *buf, int f_flags, int f_width, int f_prec, int f_len, int vret, |
203 const BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) | 203 BOOL f_neg, BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) |
204 { | 204 { |
205 char buf[64]; | 205 int ret = 0, nwidth, nprec; |
206 int f_len = 0, ret = 0, vret, nwidth, nprec; | |
207 char f_sign, *f_altstr; | 206 char f_sign, *f_altstr; |
208 BOOL f_neg = FALSE; | |
209 | |
210 if (f_flags & TH_PF_LONGLONG) | |
211 { | |
212 vret = th_vprintf_buf_int64(buf, sizeof(buf), &f_len, va_arg(ap, int64_t), | |
213 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); | |
214 } | |
215 else | |
216 { | |
217 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, va_arg(ap, unsigned int), | |
218 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); | |
219 } | |
220 | |
221 if (vret == EOF) | |
222 return ret; | |
223 | 207 |
224 // Special case for value of 0 | 208 // Special case for value of 0 |
225 if (vret == 0) | 209 if (vret == 0) |
226 { | 210 { |
227 if (f_flags & TH_PF_POINTER) | 211 if (f_flags & TH_PF_POINTER) |
306 return ret; | 290 return ret; |
307 } | 291 } |
308 | 292 |
309 // Postfix padding? | 293 // Postfix padding? |
310 return th_printf_pad_post(ctx, vputch, nwidth, f_flags); | 294 return th_printf_pad_post(ctx, vputch, nwidth, f_flags); |
295 } | |
296 | |
297 | |
298 static int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, | |
299 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, | |
300 const BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) | |
301 { | |
302 char buf[64]; | |
303 int f_len = 0, vret; | |
304 BOOL f_neg = FALSE; | |
305 | |
306 if (f_flags & TH_PF_LONGLONG) | |
307 { | |
308 vret = th_vprintf_buf_int64(buf, sizeof(buf), &f_len, va_arg(ap, int64_t), | |
309 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); | |
310 } | |
311 else | |
312 { | |
313 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, va_arg(ap, unsigned int), | |
314 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); | |
315 } | |
316 | |
317 if (vret == EOF) | |
318 return 0; | |
319 | |
320 return th_vprintf_put_int_format(ctx, vputch, buf, f_flags, f_width, f_prec, f_len, vret, f_neg, f_unsig, f_alt); | |
311 } | 321 } |
312 | 322 |
313 | 323 |
314 static int th_vprintf_put_str(th_vprintf_ctx *ctx, th_vprintf_putch vputch, | 324 static int th_vprintf_put_str(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
315 const char *str, int f_flags, const int f_width, const int f_prec) | 325 const char *str, int f_flags, const int f_width, const int f_prec) |