# HG changeset patch # User Matti Hamalainen # Date 1456998348 -7200 # Node ID 39464ba520328b69e04d555f5476fc1571674980 # Parent 28d66757a87a6c48b3b8e536a6530fe71363283e Add debug prints when TH_PRINTF_DEBUG is defined. diff -r 28d66757a87a -r 39464ba52032 th_string.c --- a/th_string.c Thu Mar 03 11:45:23 2016 +0200 +++ b/th_string.c Thu Mar 03 11:45:48 2016 +0200 @@ -167,6 +167,33 @@ #include "th_printf1.c" +#ifdef TH_PRINTF_DEBUG +static void pflag(char *buf, const char *str, const int sep, const int flags, const int flg) +{ + strcat(buf, (flags & flg) ? str : " "); + if (sep) + strcat(buf, "|"); +} + + +static const char *get_flags(const int flags) +{ + static char buf[256]; + + buf[0] = 0; + + pflag(buf, "ALT", 1, flags, TH_PF_ALT); + pflag(buf, "SGN", 1, flags, TH_PF_SIGN); + pflag(buf, "SPC", 1, flags, TH_PF_SPACE); + pflag(buf, "GRP", 1, flags, TH_PF_GROUP); + pflag(buf, "ZER", 1, flags, TH_PF_ZERO); + pflag(buf, "LFT", 0, flags, TH_PF_LEFT); + + return buf; +} +#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 int vret, const int flags)) @@ -187,6 +214,10 @@ f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); } +#ifdef TH_PRINTF_DEBUG + printf("W1: vret=%3d, f_flags=[%s], f_width=%3d, f_prec=%3d, f_unsig=%d, f_neg=%d\n", vret, get_flags(f_flags), f_width, f_prec, f_unsig, f_neg); +#endif + if (vret == EOF) return ret; @@ -223,6 +254,9 @@ f_prec = (f_prec > f_len) ? f_prec - f_len : 0; nwidth = f_width - f_len - f_prec - (f_altstr ? strlen(f_altstr) : 0); +#ifdef TH_PRINTF_DEBUG + printf("W2: vret=%3d, f_flags=[%s], f_width=%3d, f_prec=%3d, f_unsig=%d, f_neg=%d, f_sign='%c', reg=%s\n", vret, get_flags(f_flags), f_width, f_prec, f_unsig, f_neg, f_sign, reg); +#endif // Prefix padding? if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF)