comparison th_string.c @ 383:39464ba52032

Add debug prints when TH_PRINTF_DEBUG is defined.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 03 Mar 2016 11:45:48 +0200
parents 62a83d6d7be5
children 20716f7e5d86
comparison
equal deleted inserted replaced
382:28d66757a87a 383:39464ba52032
165 #define TH_PFUNC_TYPE_S int64_t 165 #define TH_PFUNC_TYPE_S int64_t
166 #define TH_PFUNC_TYPE_U uint64_t 166 #define TH_PFUNC_TYPE_U uint64_t
167 #include "th_printf1.c" 167 #include "th_printf1.c"
168 168
169 169
170 #ifdef TH_PRINTF_DEBUG
171 static void pflag(char *buf, const char *str, const int sep, const int flags, const int flg)
172 {
173 strcat(buf, (flags & flg) ? str : " ");
174 if (sep)
175 strcat(buf, "|");
176 }
177
178
179 static const char *get_flags(const int flags)
180 {
181 static char buf[256];
182
183 buf[0] = 0;
184
185 pflag(buf, "ALT", 1, flags, TH_PF_ALT);
186 pflag(buf, "SGN", 1, flags, TH_PF_SIGN);
187 pflag(buf, "SPC", 1, flags, TH_PF_SPACE);
188 pflag(buf, "GRP", 1, flags, TH_PF_GROUP);
189 pflag(buf, "ZER", 1, flags, TH_PF_ZERO);
190 pflag(buf, "LFT", 0, flags, TH_PF_LEFT);
191
192 return buf;
193 }
194 #endif
195
196
170 static int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, 197 static int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
171 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, 198 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec,
172 const BOOL f_unsig, char *(f_alt)(const char *buf, const int vret, const int flags)) 199 const BOOL f_unsig, char *(f_alt)(const char *buf, const int vret, const int flags))
173 { 200 {
174 char buf[64]; 201 char buf[64];
184 else 211 else
185 { 212 {
186 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, va_arg(ap, unsigned int), 213 vret = th_vprintf_buf_int(buf, sizeof(buf), &f_len, va_arg(ap, unsigned int),
187 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); 214 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg);
188 } 215 }
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", vret, get_flags(f_flags), f_width, f_prec, f_unsig, f_neg);
219 #endif
189 220
190 if (vret == EOF) 221 if (vret == EOF)
191 return ret; 222 return ret;
192 223
193 // Special case for value of 0 224 // Special case for value of 0
221 if ((f_flags & TH_PF_ZERO) && f_prec < 0 && (f_flags & TH_PF_LEFT) == 0) 252 if ((f_flags & TH_PF_ZERO) && f_prec < 0 && (f_flags & TH_PF_LEFT) == 0)
222 f_prec = f_width; 253 f_prec = f_width;
223 254
224 f_prec = (f_prec > f_len) ? f_prec - f_len : 0; 255 f_prec = (f_prec > f_len) ? f_prec - f_len : 0;
225 nwidth = f_width - f_len - f_prec - (f_altstr ? strlen(f_altstr) : 0); 256 nwidth = f_width - f_len - f_prec - (f_altstr ? strlen(f_altstr) : 0);
257 #ifdef TH_PRINTF_DEBUG
258 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);
259 #endif
226 260
227 // Prefix padding? 261 // Prefix padding?
228 if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) 262 if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF)
229 return ret; 263 return ret;
230 264