Mercurial > hg > th-libs
comparison th_printf.c @ 735:31bc1ed07cf5
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Dec 2022 12:14:39 +0200 |
parents | 29e44a58bc73 |
children | c9a6fe116453 |
comparison
equal
deleted
inserted
replaced
734:2ae1045f6c18 | 735:31bc1ed07cf5 |
---|---|
6 * Please read file 'COPYING' for information on license and distribution. | 6 * Please read file 'COPYING' for information on license and distribution. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifdef TH_PRINTF_DEBUG | 10 #ifdef TH_PRINTF_DEBUG |
11 BOOL th_printf_debug = FALSE; | 11 bool th_printf_debug = false; |
12 char *th_printf_debug_prefix = NULL; | 12 char *th_printf_debug_prefix = NULL; |
13 | 13 |
14 | 14 |
15 static void pflag(char *buf, const char *str, const int sep, const int flags, const int flg) | 15 static void pflag(char *buf, const char *str, const int sep, const int flags, const int flg) |
16 { | 16 { |
150 } | 150 } |
151 | 151 |
152 | 152 |
153 int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, | 153 int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
154 th_char_t *buf, int f_flags, int f_width, int f_prec, int f_len, int vret, | 154 th_char_t *buf, int f_flags, int f_width, int f_prec, int f_len, int vret, |
155 BOOL f_neg, BOOL f_unsig, th_vprintf_altfmt_func f_alt) | 155 bool f_neg, bool f_unsig, th_vprintf_altfmt_func f_alt) |
156 { | 156 { |
157 int ret = 0, nspacepad, nzeropad, f_altstr_len = 0; | 157 int ret = 0, nspacepad, nzeropad, f_altstr_len = 0; |
158 th_char_t f_sign, *f_altstr; | 158 th_char_t f_sign, *f_altstr; |
159 | 159 |
160 // Special case for value of 0 | 160 // Special case for value of 0 |
250 } | 250 } |
251 | 251 |
252 | 252 |
253 int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, | 253 int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, |
254 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, | 254 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, |
255 const BOOL f_unsig, th_vprintf_altfmt_func f_alt) | 255 const bool f_unsig, th_vprintf_altfmt_func f_alt) |
256 { | 256 { |
257 th_char_t buf[32]; | 257 th_char_t buf[32]; |
258 int f_len = 0, vret; | 258 int f_len = 0, vret; |
259 BOOL f_neg = FALSE; | 259 bool f_neg = false; |
260 | 260 |
261 if (f_flags & TH_PF_LONGLONG) | 261 if (f_flags & TH_PF_LONGLONG) |
262 { | 262 { |
263 vret = th_vprintf_buf_int64(buf, sizeof(buf), &f_len, va_arg(ap, int64_t), | 263 vret = th_vprintf_buf_int64(buf, sizeof(buf), &f_len, va_arg(ap, int64_t), |
264 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); | 264 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); |
324 // pointer and all that stuff related to strict aliasing (although | 324 // pointer and all that stuff related to strict aliasing (although |
325 // double and int64_t should be same size and have same aliasing rules.) | 325 // double and int64_t should be same size and have same aliasing rules.) |
326 memcpy(&val, &pval, sizeof(int64_t)); | 326 memcpy(&val, &pval, sizeof(int64_t)); |
327 | 327 |
328 // We have sign, exponent and mantissa | 328 // We have sign, exponent and mantissa |
329 BOOL f_sign = (val >> 63) & 0x01; | 329 bool f_sign = (val >> 63) & 0x01; |
330 int64_t d_exp = (val >> 52) & 0x7ff; | 330 int64_t d_exp = (val >> 52) & 0x7ff; |
331 uint64_t d_man = val & 0x0fffffffffffff; | 331 uint64_t d_man = val & 0x0fffffffffffff; |
332 | 332 |
333 return 0; | 333 return 0; |
334 } | 334 } |
356 return ret; | 356 return ret; |
357 | 357 |
358 return th_printf_pad_post(ctx, vputch, f_width - 1, f_flags); | 358 return th_printf_pad_post(ctx, vputch, f_width - 1, f_flags); |
359 | 359 |
360 case 'o': | 360 case 'o': |
361 return th_vprintf_put_int(ctx, vputch, ap, 8, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_oct); | 361 return th_vprintf_put_int(ctx, vputch, ap, 8, f_flags, f_width, f_prec, true, th_vprintf_altfmt_oct); |
362 | 362 |
363 case 'u': | 363 case 'u': |
364 case 'i': | 364 case 'i': |
365 case 'd': | 365 case 'd': |
366 return th_vprintf_put_int(ctx, vputch, ap, 10, f_flags, f_width, f_prec, fmt == 'u', NULL); | 366 return th_vprintf_put_int(ctx, vputch, ap, 10, f_flags, f_width, f_prec, fmt == 'u', NULL); |
368 case 'x': | 368 case 'x': |
369 case 'X': | 369 case 'X': |
370 if (fmt == 'X') | 370 if (fmt == 'X') |
371 f_flags |= TH_PF_UPCASE; | 371 f_flags |= TH_PF_UPCASE; |
372 | 372 |
373 return th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex); | 373 return th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, true, th_vprintf_altfmt_hex); |
374 | 374 |
375 case 'p': | 375 case 'p': |
376 // Check for invalid flags | 376 // Check for invalid flags |
377 if (f_flags & (TH_PF_LONG | TH_PF_LONGLONG)) | 377 if (f_flags & (TH_PF_LONG | TH_PF_LONGLONG)) |
378 return -120; | 378 return -120; |
382 #elif (TH_PTRSIZE == 64) | 382 #elif (TH_PTRSIZE == 64) |
383 f_flags |= TH_PF_LONGLONG; | 383 f_flags |= TH_PF_LONGLONG; |
384 #endif | 384 #endif |
385 f_flags |= TH_PF_ALT | TH_PF_POINTER; | 385 f_flags |= TH_PF_ALT | TH_PF_POINTER; |
386 | 386 |
387 return th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex); | 387 return th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, true, th_vprintf_altfmt_hex); |
388 | 388 |
389 #ifdef TH_WIP_FLOAT_SUPPORT | 389 #ifdef TH_WIP_FLOAT_SUPPORT |
390 case 'f': | 390 case 'f': |
391 case 'F': | 391 case 'F': |
392 return th_vprintf_put_float(ctx, vputch, ap, | 392 return th_vprintf_put_float(ctx, vputch, ap, |
416 goto out; | 416 goto out; |
417 } | 417 } |
418 else | 418 else |
419 { | 419 { |
420 int f_width = -1, f_prec = -1, f_flags = 0; | 420 int f_width = -1, f_prec = -1, f_flags = 0; |
421 BOOL end = FALSE; | 421 bool end = false; |
422 | 422 |
423 fmt++; | 423 fmt++; |
424 | 424 |
425 // Check for flags | 425 // Check for flags |
426 while (!end) | 426 while (!end) |
450 case '\'': | 450 case '\'': |
451 f_flags |= TH_PF_GROUP; | 451 f_flags |= TH_PF_GROUP; |
452 break; | 452 break; |
453 | 453 |
454 default: | 454 default: |
455 end = TRUE; | 455 end = true; |
456 break; | 456 break; |
457 } | 457 } |
458 if (!end) fmt++; | 458 if (!end) fmt++; |
459 } | 459 } |
460 | 460 |