comparison th_string.c @ 457:85fa3d333556

Actually, revert the boolean changes .. meh.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 02 Jan 2018 23:09:29 +0200
parents 347bfd3e017e
children 694c85f4e354
comparison
equal deleted inserted replaced
456:1bf886fa9db5 457:85fa3d333556
198 #endif 198 #endif
199 199
200 200
201 int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, 201 int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
202 char *buf, int f_flags, int f_width, int f_prec, int f_len, int vret, 202 char *buf, int f_flags, int f_width, int f_prec, int f_len, int vret,
203 bool f_neg, bool f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) 203 BOOL f_neg, BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags))
204 { 204 {
205 int ret = 0, nwidth, nprec; 205 int ret = 0, nwidth, nprec;
206 char f_sign, *f_altstr; 206 char f_sign, *f_altstr;
207 207
208 // Special case for value of 0 208 // Special case for value of 0
295 } 295 }
296 296
297 297
298 int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, 298 int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
299 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, 299 va_list ap, const int f_radix, int f_flags, int f_width, int f_prec,
300 const bool f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) 300 const BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags))
301 { 301 {
302 char buf[64]; 302 char buf[64];
303 int f_len = 0, vret; 303 int f_len = 0, vret;
304 bool f_neg = false; 304 BOOL f_neg = FALSE;
305 305
306 if (f_flags & TH_PF_LONGLONG) 306 if (f_flags & TH_PF_LONGLONG)
307 { 307 {
308 vret = th_vprintf_buf_int64(buf, sizeof(buf), &f_len, va_arg(ap, int64_t), 308 vret = th_vprintf_buf_int64(buf, sizeof(buf), &f_len, va_arg(ap, int64_t),
309 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg); 309 f_radix, f_flags & TH_PF_UPCASE, f_unsig, &f_neg);
362 // pointer and all that stuff related to strict aliasing (although 362 // pointer and all that stuff related to strict aliasing (although
363 // double and int64_t should be same size and have same aliasing rules.) 363 // double and int64_t should be same size and have same aliasing rules.)
364 memcpy(&val, &pval, sizeof(int64_t)); 364 memcpy(&val, &pval, sizeof(int64_t));
365 365
366 // We have sign, exponent and mantissa 366 // We have sign, exponent and mantissa
367 bool f_sign = (val >> 63) & 0x01; 367 BOOL f_sign = (val >> 63) & 0x01;
368 int64_t d_exp = (val >> 52) & 0x7ff; 368 int64_t d_exp = (val >> 52) & 0x7ff;
369 uint64_t d_man = val & 0x0fffffffffffff; 369 uint64_t d_man = val & 0x0fffffffffffff;
370 370
371 return 0; 371 return 0;
372 } 372 }
406 goto out; 406 goto out;
407 } 407 }
408 else 408 else
409 { 409 {
410 int f_width = -1, f_prec = -1, f_flags = 0; 410 int f_width = -1, f_prec = -1, f_flags = 0;
411 bool end = false; 411 BOOL end = FALSE;
412 412
413 fmt++; 413 fmt++;
414 414
415 // Check for flags 415 // Check for flags
416 while (!end) 416 while (!end)
440 case '\'': 440 case '\'':
441 f_flags |= TH_PF_GROUP; 441 f_flags |= TH_PF_GROUP;
442 break; 442 break;
443 443
444 default: 444 default:
445 end = true; 445 end = TRUE;
446 break; 446 break;
447 } 447 }
448 if (!end) fmt++; 448 if (!end) fmt++;
449 } 449 }
450 450
523 if ((ret = th_printf_pad_post(ctx, vputch, f_width - 1, f_flags)) == EOF) 523 if ((ret = th_printf_pad_post(ctx, vputch, f_width - 1, f_flags)) == EOF)
524 goto out; 524 goto out;
525 break; 525 break;
526 526
527 case 'o': 527 case 'o':
528 if ((ret = th_vprintf_put_int(ctx, vputch, ap, 8, f_flags, f_width, f_prec, true, th_vprintf_altfmt_oct)) == EOF) 528 if ((ret = th_vprintf_put_int(ctx, vputch, ap, 8, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_oct)) == EOF)
529 goto out; 529 goto out;
530 break; 530 break;
531 531
532 case 'u': 532 case 'u':
533 case 'i': 533 case 'i':
538 538
539 case 'x': 539 case 'x':
540 case 'X': 540 case 'X':
541 if (*fmt == 'X') 541 if (*fmt == 'X')
542 f_flags |= TH_PF_UPCASE; 542 f_flags |= TH_PF_UPCASE;
543 if ((ret = th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, true, th_vprintf_altfmt_hex)) == EOF) 543 if ((ret = th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex)) == EOF)
544 goto out; 544 goto out;
545 break; 545 break;
546 546
547 case 'p': 547 case 'p':
548 if (f_flags & (TH_PF_LONG | TH_PF_LONGLONG)) 548 if (f_flags & (TH_PF_LONG | TH_PF_LONGLONG))
552 f_flags |= TH_PF_LONG; 552 f_flags |= TH_PF_LONG;
553 #elif (TH_PTRSIZE == 64) 553 #elif (TH_PTRSIZE == 64)
554 f_flags |= TH_PF_LONGLONG; 554 f_flags |= TH_PF_LONGLONG;
555 #endif 555 #endif
556 f_flags |= TH_PF_ALT | TH_PF_POINTER; 556 f_flags |= TH_PF_ALT | TH_PF_POINTER;
557 if ((ret = th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, true, th_vprintf_altfmt_hex)) == EOF) 557 if ((ret = th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex)) == EOF)
558 goto out; 558 goto out;
559 break; 559 break;
560 560
561 #ifdef WIP_FLOAT_SUPPORT 561 #ifdef WIP_FLOAT_SUPPORT
562 case 'f': 562 case 'f':
988 988
989 return (len == 6) ? val : -1; 989 return (len == 6) ? val : -1;
990 } 990 }
991 991
992 992
993 bool th_get_boolean(const char *str, bool *value) 993 BOOL th_get_boolean(const char *str, BOOL *value)
994 { 994 {
995 if (!th_strcasecmp(str, "yes") || 995 if (!th_strcasecmp(str, "yes") ||
996 !th_strcasecmp(str, "on") || 996 !th_strcasecmp(str, "on") ||
997 !th_strcasecmp(str, "true") || 997 !th_strcasecmp(str, "true") ||
998 !th_strcasecmp(str, "1")) 998 !th_strcasecmp(str, "1"))
999 { 999 {
1000 *value = true; 1000 *value = TRUE;
1001 return true; 1001 return TRUE;
1002 } 1002 }
1003 else 1003 else
1004 if (!th_strcasecmp(str, "no") || 1004 if (!th_strcasecmp(str, "no") ||
1005 !th_strcasecmp(str, "off") || 1005 !th_strcasecmp(str, "off") ||
1006 !th_strcasecmp(str, "false") || 1006 !th_strcasecmp(str, "false") ||
1007 !th_strcasecmp(str, "0")) 1007 !th_strcasecmp(str, "0"))
1008 { 1008 {
1009 *value = false; 1009 *value = FALSE;
1010 return true; 1010 return TRUE;
1011 } 1011 }
1012 else 1012 else
1013 return false; 1013 return FALSE;
1014 } 1014 }
1015 1015
1016 1016
1017 static void th_pad(FILE *outFile, int count) 1017 static void th_pad(FILE *outFile, int count)
1018 { 1018 {
1022 1022
1023 1023
1024 void th_print_wrap(FILE *fh, const char *str, int spad, int rpad, int width) 1024 void th_print_wrap(FILE *fh, const char *str, int spad, int rpad, int width)
1025 { 1025 {
1026 size_t pos = 0; 1026 size_t pos = 0;
1027 bool first = true; 1027 BOOL first = TRUE;
1028 1028
1029 while (str[pos]) 1029 while (str[pos])
1030 { 1030 {
1031 // Pre-pad line 1031 // Pre-pad line
1032 int linelen = first ? spad : rpad; 1032 int linelen = first ? spad : rpad;
1033 th_pad(fh, first ? 0 : rpad); 1033 th_pad(fh, first ? 0 : rpad);
1034 first = false; 1034 first = FALSE;
1035 1035
1036 // Skip whitespace at line start 1036 // Skip whitespace at line start
1037 while (th_isspace(str[pos]) || str[pos] == '\n') pos++; 1037 while (th_isspace(str[pos]) || str[pos] == '\n') pos++;
1038 1038
1039 // Handle each word 1039 // Handle each word