Mercurial > hg > th-libs
comparison th_string.c @ 410:04cb03baf114
Improve printf implementation debugging.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 09 Mar 2016 12:07:10 +0200 |
parents | 9b1b21954952 |
children | 371567cf0a38 |
comparison
equal
deleted
inserted
replaced
409:9b1b21954952 | 410:04cb03baf114 |
---|---|
189 pflag(buf, "ZER", 1, flags, TH_PF_ZERO); | 189 pflag(buf, "ZER", 1, flags, TH_PF_ZERO); |
190 pflag(buf, "LFT", 0, flags, TH_PF_LEFT); | 190 pflag(buf, "LFT", 0, flags, TH_PF_LEFT); |
191 | 191 |
192 return buf; | 192 return buf; |
193 } | 193 } |
194 | |
195 #define PP_PRINTF(...) fprintf(stdout, __VA_ARGS__) | |
196 #else | |
197 #define PP_PRINTF(...) /* stub */ | |
194 #endif | 198 #endif |
195 | 199 |
196 | 200 |
197 static int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, | 201 static int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
198 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, | 202 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, |
211 else | 215 else |
212 { | 216 { |
213 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, va_arg(ap, unsigned int), | 217 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, va_arg(ap, unsigned int), |
214 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); | 218 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); |
215 } | 219 } |
216 | |
217 #ifdef TH_PRINTF_DEBUG | |
218 printf("W1: vret=%3d, f_flags=[%s], f_width=%3d, f_prec=%3d, f_unsig=%d, f_neg=%d\n", | |
219 vret, get_flags(f_flags), f_width, f_prec, f_unsig, f_neg); | |
220 #endif | |
221 | 220 |
222 if (vret == EOF) | 221 if (vret == EOF) |
223 return ret; | 222 return ret; |
224 | 223 |
225 // Special case for value of 0 | 224 // Special case for value of 0 |
251 int qlen = (f_prec > f_len ? f_prec : f_len) + nlen; | 250 int qlen = (f_prec > f_len ? f_prec : f_len) + nlen; |
252 | 251 |
253 if (f_flags & TH_PF_LEFT) | 252 if (f_flags & TH_PF_LEFT) |
254 f_flags &= ~TH_PF_ZERO; | 253 f_flags &= ~TH_PF_ZERO; |
255 | 254 |
256 #ifdef TH_PRINTF_DEBUG | |
257 printf("W2: vret=%3d, f_flags=[%s], f_width=%3d, f_prec=%3d, f_sign='%c', nwidth=%d\n", | |
258 vret, get_flags(f_flags), f_width, f_prec, f_unsig, f_neg, f_sign, nwidth); | |
259 #endif | |
260 if (f_flags & TH_PF_POINTER && vret == 0) | 255 if (f_flags & TH_PF_POINTER && vret == 0) |
261 { | 256 { |
257 PP_PRINTF("^"); | |
262 qlen = f_len + nlen; | 258 qlen = f_len + nlen; |
263 nwidth = f_width > qlen ? f_width - qlen : 0; | 259 nwidth = f_width > qlen ? f_width - qlen : 0; |
264 nprec = 0; | 260 nprec = 0; |
265 } | 261 } |
266 else | 262 else |
267 if ((f_flags & TH_PF_ZERO) && f_prec < 0 && f_width > 0) | 263 if ((f_flags & TH_PF_ZERO) && f_prec < 0 && f_width > 0) |
268 { | 264 { |
265 PP_PRINTF("#"); | |
269 nprec = f_width - qlen; | 266 nprec = f_width - qlen; |
270 nwidth = 0; | 267 nwidth = 0; |
271 } | 268 } |
272 else | 269 else |
273 { | 270 { |
271 PP_PRINTF("$"); | |
274 nprec = (f_prec >= 0) ? f_prec - f_len : 0; | 272 nprec = (f_prec >= 0) ? f_prec - f_len : 0; |
275 nwidth = (f_width >= 0) ? f_width - qlen : 0; | 273 nwidth = (f_width >= 0) ? f_width - qlen : 0; |
276 } | 274 } |
275 | |
276 PP_PRINTF(": vret=%3d, f_flags=[%s], f_unsig=%d, f_sign='%c', f_len=%3d, f_width=%3d, f_prec=%3d, nwidth=%3d, nprec=%3d, qlen=%3d\n", | |
277 vret, get_flags(f_flags), f_unsig, f_sign ? f_sign : '?', f_len, f_width, f_prec, nwidth, nprec, qlen); | |
277 | 278 |
278 // Prefix padding | 279 // Prefix padding |
279 if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) | 280 if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) |
280 return ret; | 281 return ret; |
281 | 282 |
355 | 356 |
356 static char * th_printf_altfmt_oct(const char *buf, const size_t len, const int vret, const int flags) | 357 static char * th_printf_altfmt_oct(const char *buf, const size_t len, const int vret, const int flags) |
357 { | 358 { |
358 (void) vret; | 359 (void) vret; |
359 (void) flags; | 360 (void) flags; |
361 PP_PRINTF("BUF='%s', '%c'\n", buf, buf[len - 1]); | |
360 return (buf[len - 1] != '0') ? "0" : ""; | 362 return (buf[len - 1] != '0') ? "0" : ""; |
361 } | 363 } |
362 | 364 |
363 | 365 |
364 static char * th_printf_altfmt_hex(const char *buf, const size_t len, const int vret, const int flags) | 366 static char * th_printf_altfmt_hex(const char *buf, const size_t len, const int vret, const int flags) |