Mercurial > hg > th-libs
diff th_string.c @ 453:efd33accdc81
Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Introduce optional but default use of stdbool.h.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Jan 2018 22:56:03 +0200 |
parents | db45d6d2e576 |
children | 347bfd3e017e |
line wrap: on
line diff
--- a/th_string.c Wed Oct 25 22:32:07 2017 +0300 +++ b/th_string.c Tue Jan 02 22:56:03 2018 +0200 @@ -200,7 +200,7 @@ int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, char *buf, int f_flags, int f_width, int f_prec, int f_len, int vret, - BOOL f_neg, BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) + bool f_neg, bool f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) { int ret = 0, nwidth, nprec; char f_sign, *f_altstr; @@ -297,11 +297,11 @@ 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 size_t blen, const int vret, const int flags)) + const bool f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) { char buf[64]; int f_len = 0, vret; - BOOL f_neg = FALSE; + bool f_neg = false; if (f_flags & TH_PF_LONGLONG) { @@ -364,7 +364,7 @@ memcpy(&val, &pval, sizeof(int64_t)); // We have sign, exponent and mantissa - BOOL f_sign = (val >> 63) & 0x01; + bool f_sign = (val >> 63) & 0x01; int64_t d_exp = (val >> 52) & 0x7ff; uint64_t d_man = val & 0x0fffffffffffff; @@ -408,7 +408,7 @@ else { int f_width = -1, f_prec = -1, f_flags = 0; - BOOL end = FALSE; + bool end = false; fmt++; @@ -442,7 +442,7 @@ break; default: - end = TRUE; + end = true; break; } if (!end) fmt++; @@ -525,7 +525,7 @@ break; case 'o': - if ((ret = th_vprintf_put_int(ctx, vputch, ap, 8, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_oct)) == EOF) + if ((ret = th_vprintf_put_int(ctx, vputch, ap, 8, f_flags, f_width, f_prec, true, th_vprintf_altfmt_oct)) == EOF) goto out; break; @@ -540,7 +540,7 @@ case 'X': if (*fmt == 'X') f_flags |= TH_PF_UPCASE; - if ((ret = th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex)) == EOF) + if ((ret = th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, true, th_vprintf_altfmt_hex)) == EOF) goto out; break; @@ -554,7 +554,7 @@ f_flags |= TH_PF_LONGLONG; #endif f_flags |= TH_PF_ALT | TH_PF_POINTER; - if ((ret = th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, TRUE, th_vprintf_altfmt_hex)) == EOF) + if ((ret = th_vprintf_put_int(ctx, vputch, ap, 16, f_flags, f_width, f_prec, true, th_vprintf_altfmt_hex)) == EOF) goto out; break; @@ -990,15 +990,15 @@ } -BOOL th_get_boolean(const char *str, BOOL *value) +bool th_get_boolean(const char *str, bool *value) { if (!th_strcasecmp(str, "yes") || !th_strcasecmp(str, "on") || !th_strcasecmp(str, "true") || !th_strcasecmp(str, "1")) { - *value = TRUE; - return TRUE; + *value = true; + return true; } else if (!th_strcasecmp(str, "no") || @@ -1006,11 +1006,11 @@ !th_strcasecmp(str, "false") || !th_strcasecmp(str, "0")) { - *value = FALSE; - return TRUE; + *value = false; + return true; } else - return FALSE; + return false; } @@ -1024,14 +1024,14 @@ void th_print_wrap(FILE *fh, const char *str, int spad, int rpad, int width) { size_t pos = 0; - BOOL first = TRUE; + bool first = true; while (str[pos]) { // Pre-pad line int linelen = first ? spad : rpad; th_pad(fh, first ? 0 : rpad); - first = FALSE; + first = false; // Skip whitespace at line start while (th_isspace(str[pos]) || str[pos] == '\n') pos++;