# HG changeset patch # User Matti Hamalainen # Date 1508958789 -10800 # Node ID 051226a06f707084fcee533635809019d26c325f # Parent eb78997a75747433192e7fab423d04d3fa990830 Split th_vprintf_put_int() partially into th_vprintf_put_int_format(), to separate va_arg() value fetching from most of the formatting code. diff -r eb78997a7574 -r 051226a06f70 th_string.c --- a/th_string.c Wed Oct 25 22:10:32 2017 +0300 +++ b/th_string.c Wed Oct 25 22:13:09 2017 +0300 @@ -198,28 +198,12 @@ #endif -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 char *buf, const size_t blen, const int vret, const int flags)) +static int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, + char *buf, int f_flags, int f_width, int f_prec, int f_len, int vret, + BOOL f_neg, BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) { - char buf[64]; - int f_len = 0, ret = 0, vret, nwidth, nprec; + int ret = 0, nwidth, nprec; char f_sign, *f_altstr; - BOOL f_neg = FALSE; - - if (f_flags & TH_PF_LONGLONG) - { - vret = th_vprintf_buf_int64(buf, sizeof(buf), &f_len, va_arg(ap, int64_t), - f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); - } - else - { - vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, va_arg(ap, unsigned int), - f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); - } - - if (vret == EOF) - return ret; // Special case for value of 0 if (vret == 0) @@ -311,6 +295,32 @@ } +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 char *buf, const size_t blen, const int vret, const int flags)) +{ + char buf[64]; + int f_len = 0, vret; + BOOL f_neg = FALSE; + + if (f_flags & TH_PF_LONGLONG) + { + vret = th_vprintf_buf_int64(buf, sizeof(buf), &f_len, va_arg(ap, int64_t), + f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); + } + else + { + vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, va_arg(ap, unsigned int), + f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); + } + + if (vret == EOF) + return 0; + + return th_vprintf_put_int_format(ctx, vputch, buf, f_flags, f_width, f_prec, f_len, vret, f_neg, f_unsig, f_alt); +} + + static int th_vprintf_put_str(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const char *str, int f_flags, const int f_width, const int f_prec) {