# HG changeset patch # User Matti Hamalainen # Date 1456184554 -7200 # Node ID 0362ea9872f0c8ecc664f7e4bfa535e2cec3d4b9 # Parent f2af6049d958bc3555c874c00f9ec1cf87430dcf Some work on sign handling. diff -r f2af6049d958 -r 0362ea9872f0 th_printf1.c --- a/th_printf1.c Tue Feb 23 01:39:49 2016 +0200 +++ b/th_printf1.c Tue Feb 23 01:42:34 2016 +0200 @@ -20,7 +20,7 @@ { char buf[64]; size_t pos = 0; - int ret = 0; + char f_sign = 0; #ifdef TH_PFUNC_SIGNED BOOL neg = FALSE; #endif @@ -59,20 +59,11 @@ // Do we want a sign prefix? Not for unsigned values #ifdef TH_PFUNC_SIGNED if (!unsig) - { - char ch = (f_flags & TH_PF_SIGN) ? (neg ? '-' : '+') : (neg ? '-' : ((f_flags & TH_PF_SPACE) ? ' ' : 0)); - if (ch && (ret = vputch(ctx, ch)) == EOF) - goto out; - } + f_sign = (f_flags & TH_PF_SIGN) ? (neg ? '-' : '+') : (neg ? '-' : ((f_flags & TH_PF_SPACE) ? ' ' : 0)); #endif // Output the data - return th_printf_vput_intstr(ctx, vputch, buf, f_width, pos, f_prec, f_flags); - -#ifdef TH_PFUNC_SIGNED -out: -#endif - return ret; + return th_printf_vput_intstr(ctx, vputch, buf, f_width, pos, f_prec, f_flags, f_sign); } diff -r f2af6049d958 -r 0362ea9872f0 th_string.c --- a/th_string.c Tue Feb 23 01:39:49 2016 +0200 +++ b/th_string.c Tue Feb 23 01:42:34 2016 +0200 @@ -159,11 +159,15 @@ int th_printf_vput_intstr(th_printf_ctx *ctx, th_printf_vputch vputch, - const char *buf, const int f_width, int pos, int f_prec, int f_flags) + const char *buf, const int f_width, int pos, int f_prec, int f_flags, + const char f_sign) { // Calculate necessary padding, if any int ret, nwidth = f_width - pos; + if (f_sign) + nwidth--; + if (f_prec > 0 && f_prec > pos) { nwidth = nwidth - f_prec + 1; @@ -174,6 +178,9 @@ if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) return ret; + if (f_sign && (ret = vputch(ctx, f_sign)) == EOF) + return ret; + if (f_prec > 0 && f_prec > pos) { while (--f_prec)