Mercurial > hg > th-libs
diff th_string.c @ 317:c532088b4f05
Fix float tests (type was int) :D
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 22 Feb 2016 23:43:50 +0200 |
parents | 7bce1e9fa397 |
children | 0362ea9872f0 |
line wrap: on
line diff
--- a/th_string.c Mon Feb 22 23:42:29 2016 +0200 +++ b/th_string.c Mon Feb 22 23:43:50 2016 +0200 @@ -164,10 +164,26 @@ // Calculate necessary padding, if any int ret, nwidth = f_width - pos; + if (f_prec > 0 && f_prec > pos) + { + nwidth = nwidth - f_prec + 1; + f_flags &= ~TH_PF_ZERO; + } + // Prefix padding? if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) return ret; + if (f_prec > 0 && f_prec > pos) + { + while (--f_prec) + { + int ret; + if ((ret = vputch(ctx, '0')) == EOF) + return ret; + } + } + // Output the value while (pos--) { @@ -202,19 +218,25 @@ static int th_printf_vput_str(th_printf_ctx *ctx, th_printf_vputch vputch, const char *str, int f_flags, const int f_width, const int f_prec) { - int nwidth, ret = 0; + int nwidth, slen, ret = 0; + + f_flags &= ~TH_PF_ZERO; // Check for null strings if (str == NULL) str = "(null)"; - nwidth = f_width - strlen(str); + slen = strlen(str); + if (f_prec >= 0 && slen > f_prec) + slen = f_prec; + + nwidth = f_width - slen; // Prefix padding? if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) goto out; - while (*str) + while (*str && slen--) { if ((ret = vputch(ctx, *str++)) == EOF) goto out; @@ -363,7 +385,12 @@ case 'f': case 'F': return -112; +/* + if ((ret = th_vput_float(ctx, vputch, va_arg(ap, double), + f_flags, f_width, f_prec)) == EOF) + goto out; break; +*/ case 's': if ((ret = th_printf_vput_str(ctx, vputch, va_arg(ap, char *),