From 44ac1bcb897b3cd12a3257490a48b91ebade07d2 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 6 Nov 2011 14:37:59 +0900 Subject: [PATCH] abstracting to use sexp_ versions of isdigit, tolower, toupper consistently, and casting to avoid warnings in cygwin --- include/chibi/sexp.h | 10 ++++++++-- lib/srfi/69/hash.c | 2 +- main.c | 2 +- opt/bignum.c | 2 +- sexp.c | 19 +++++++++---------- vm.c | 4 ++-- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index a1072ec7..2362318c 100755 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -16,8 +16,11 @@ extern "C" { #if defined(_WIN32) || defined(__MINGW32__) #include -#define sexp_isalpha(x) ((isalpha)((unsigned char)(x))) -#define sexp_isxdigit(x) ((isxdigit)((unsigned char)(x))) +#define sexp_isalpha(x) ((isalpha)((int)(x))) +#define sexp_isxdigit(x) ((isxdigit)((int)(x))) +#define sexp_isdigit(x) ((isdigit)((int)(x))) +#define sexp_tolower(x) ((tolower)((int)(x))) +#define sexp_toupper(x) ((toupper)((int)(x))) #else #if SEXP_USE_DL #include @@ -29,6 +32,9 @@ extern "C" { #endif #define sexp_isalpha(x) (isalpha(x)) #define sexp_isxdigit(x) (isxdigit(x)) +#define sexp_isdigit(x) (isdigit(x)) +#define sexp_tolower(x) (tolower(x)) +#define sexp_toupper(x) (toupper(x)) #endif #ifdef PLAN9 diff --git a/lib/srfi/69/hash.c b/lib/srfi/69/hash.c index 81af8ad9..3b4ed788 100644 --- a/lib/srfi/69/hash.c +++ b/lib/srfi/69/hash.c @@ -34,7 +34,7 @@ static sexp sexp_string_hash (sexp ctx sexp_api_params(self, n), sexp str, sexp static sexp_uint_t string_ci_hash (char *str, sexp_uint_t bound) { sexp_uint_t acc = FNV_OFFSET_BASIS; - while (*str) {acc *= FNV_PRIME; acc ^= (tolower)(*str++);} + while (*str) {acc *= FNV_PRIME; acc ^= sexp_tolower(*str++);} return acc % bound; } diff --git a/main.c b/main.c index 39b08d78..ac3577bd 100644 --- a/main.c +++ b/main.c @@ -176,7 +176,7 @@ static void repl (sexp ctx, sexp env) { } static sexp_uint_t multiplier (char c) { - switch ((tolower)(c)) { + switch (sexp_tolower(c)) { case 'k': return 1024; case 'm': return (1024*1024); case 'g': return (1024*1024*1024); diff --git a/opt/bignum.c b/opt/bignum.c index e74f377b..06c3b31b 100644 --- a/opt/bignum.c +++ b/opt/bignum.c @@ -209,7 +209,7 @@ sexp sexp_read_bignum (sexp ctx, sexp in, sexp_uint_t init, res = sexp_make_bignum(ctx, SEXP_INIT_BIGNUM_SIZE); sexp_bignum_sign(res) = sign; sexp_bignum_data(res)[0] = init; - for (c=sexp_read_char(ctx, in); isxdigit(c); c=sexp_read_char(ctx, in)) { + for (c=sexp_read_char(ctx, in); sexp_isxdigit(c); c=sexp_read_char(ctx, in)) { digit = digit_value(c); if ((digit < 0) || (digit >= base)) break; diff --git a/sexp.c b/sexp.c index ffb6bc54..3caa6217 100644 --- a/sexp.c +++ b/sexp.c @@ -34,7 +34,7 @@ static const char sexp_separators[] = { }; static int digit_value (int c) { - return (((c)<='9') ? ((c) - '0') : ((toupper(c) - 'A') + 10)); + return (((c)<='9') ? ((c) - '0') : ((sexp_toupper(c) - 'A') + 10)); } static int hex_digit (int n) { @@ -1749,7 +1749,7 @@ sexp sexp_read_symbol (sexp ctx, sexp in, int init, int internp) { sexp res=SEXP_VOID; #if SEXP_USE_FOLD_CASE_SYMS int foldp = sexp_port_fold_casep(in); - init = (foldp ? tolower(init) : init); + init = (foldp ? sexp_tolower(init) : init); #endif if (init != EOF) @@ -1757,7 +1757,7 @@ sexp sexp_read_symbol (sexp ctx, sexp in, int init, int internp) { for (c = sexp_read_char(ctx, in); ; c = sexp_read_char(ctx, in)) { #if SEXP_USE_FOLD_CASE_SYMS - if (foldp) c = tolower(c); + if (foldp) c = sexp_tolower(c); #endif if (c == '\\') c = sexp_read_char(ctx, in); if (c == EOF || is_separator(c)) { @@ -1848,8 +1848,7 @@ sexp sexp_read_float_tail (sexp ctx, sexp in, double whole, int negp) { sexp exponent=SEXP_VOID; double val=0.0, scale=0.1, e=0.0; int c; - for (c=sexp_read_char(ctx, in); - isdigit(c); + for (c=sexp_read_char(ctx, in); sexp_isdigit(c); c=sexp_read_char(ctx, in), scale*=0.1) val += digit_value(c)*scale; #if SEXP_USE_PLACEHOLDER_DIGITS @@ -2243,7 +2242,7 @@ sexp sexp_read_raw (sexp ctx, sexp in) { case 't': case 'T': c2 = sexp_read_char(ctx, in); if (c2 == EOF || is_separator(c2)) { - res = (tolower(c1) == 't' ? SEXP_TRUE : SEXP_FALSE); + res = (sexp_tolower(c1) == 't' ? SEXP_TRUE : SEXP_FALSE); sexp_push_char(ctx, c2, in); } else { sexp_push_char(ctx, c2, in); @@ -2396,7 +2395,7 @@ sexp sexp_read_raw (sexp ctx, sexp in) { sexp_push_char(ctx, c1, in); if (c1 == EOF || is_separator(c1)) { res = SEXP_RAWDOT; - } else if (isdigit(c1)) { + } else if (sexp_isdigit(c1)) { res = sexp_read_float_tail(ctx, in, 0, 0); } else { res = sexp_read_symbol(ctx, in, '.', 1); @@ -2418,7 +2417,7 @@ sexp sexp_read_raw (sexp ctx, sexp in) { case '+': case '-': c2 = sexp_read_char(ctx, in); - if (c2 == '.' || isdigit(c2)) { + if (c2 == '.' || sexp_isdigit(c2)) { sexp_push_char(ctx, c2, in); res = sexp_read_number(ctx, in, 10); if ((c1 == '-') && ! sexp_exceptionp(res)) { @@ -2527,12 +2526,12 @@ sexp sexp_string_to_number_op (sexp ctx sexp_api_params(self, n), sexp str, sexp if (((base=sexp_unbox_fixnum(b)) < 2) || (base > 36)) return sexp_user_exception(ctx, self, "invalid numeric base", b); if (sexp_string_data(str)[0]=='\0' - || (sexp_string_data(str)[1]=='\0' && !isdigit(sexp_string_data(str)[0]))) + || (sexp_string_data(str)[1]=='\0' && !sexp_isdigit(sexp_string_data(str)[0]))) return SEXP_FALSE; sexp_gc_preserve1(ctx, in); in = sexp_make_input_string_port(ctx, str); if (sexp_string_data(str)[0] == '+') { - if (isdigit(sexp_string_data(str)[1]) + if (sexp_isdigit(sexp_string_data(str)[1]) || sexp_string_data(str)[1] == '.' || sexp_string_data(str)[1] == '#') sexp_read_char(ctx, in); } diff --git a/vm.c b/vm.c index f4c5aca3..5dc82304 100644 --- a/vm.c +++ b/vm.c @@ -1696,12 +1696,12 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) { case SEXP_OP_CHAR_UPCASE: if (! sexp_charp(_ARG1)) sexp_raise("char-upcase: not a character", sexp_list1(ctx, _ARG1)); - _ARG1 = sexp_make_character(toupper(sexp_unbox_character(_ARG1))); + _ARG1 = sexp_make_character(sexp_toupper(sexp_unbox_character(_ARG1))); break; case SEXP_OP_CHAR_DOWNCASE: if (! sexp_charp(_ARG1)) sexp_raise("char-downcase: not a character", sexp_list1(ctx, _ARG1)); - _ARG1 = sexp_make_character(tolower(sexp_unbox_character(_ARG1))); + _ARG1 = sexp_make_character(sexp_tolower(sexp_unbox_character(_ARG1))); break; case SEXP_OP_WRITE_CHAR: if (! sexp_charp(_ARG1))