From 39cd310f18074231e3400e53f7e5234a8615a87e Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Thu, 5 Jan 2012 11:52:03 +0100 Subject: [PATCH] Removed the non-LOCALE character code and the #ifdefs and simplified. POSIX says: tolower() won't change its argument if it is not isupper(). And isupper() doesn't need an additional check for isalpha(). --- sbr/fmt_compile.c | 4 ---- sbr/fmt_scan.c | 32 ++++---------------------------- sbr/gans.c | 8 +------- sbr/m_atoi.c | 4 ---- sbr/uprf.c | 14 +------------- 5 files changed, 6 insertions(+), 56 deletions(-) diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index bcd7b3d..cf5c497 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -237,11 +237,7 @@ compile_error(char *str, char *cp) usr_fstring[errpos] = '\0'; for (i = errpos-errctx; i < errpos; i++) { -#ifdef LOCALE if (iscntrl(usr_fstring[i])) -#else - if (usr_fstring[i] < 32) -#endif usr_fstring[i] = '_'; } diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index 4f9bce0..2c16dfe 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -57,32 +57,17 @@ match(char *str, char *sub) int c1, c2; char *s1, *s2; -#ifdef LOCALE while ((c1 = *sub)) { - c1 = (isalpha(c1) && isupper(c1)) ? tolower(c1) : c1; - while ((c2 = *str++) && c1 != ((isalpha(c2) && isupper(c2)) ? tolower(c2) : c2)) + while ((c2 = *str++) && tolower(c1) != tolower(c2)) ; if (! c2) return 0; s1 = sub + 1; s2 = str; - while ((c1 = *s1++) && ((isalpha(c1) && isupper(c1)) ? tolower(c1) : c1) == ((isalpha(c2 =*s2++) && isupper(c2)) ? tolower(c2) : c2)) + while ((c1 = *s1++) && tolower(c1) == tolower(*s2++)) ; if (! c1) return 1; } -#else - while ((c1 = *sub)) { - while ((c2 = *str++) && (c1 | 040) != (c2 | 040)) - ; - if (! c2) - return 0; - s1 = sub + 1; s2 = str; - while ((c1 = *s1++) && (c1 | 040) == (*s2++ | 040)) - ; - if (! c1) - return 1; - } -#endif return 1; } @@ -217,12 +202,7 @@ cpstripped(char **start, char *end, char *str) return; /* skip any initial control characters or spaces */ - while ((c = (unsigned char) *s) && -#ifdef LOCALE - (iscntrl(c) || isspace(c))) -#else - (c <= 32)) -#endif + while ((c = (unsigned char) *s) && (iscntrl(c) || isspace(c))) s++; /* compact repeated control characters and spaces into a single space */ @@ -231,11 +211,7 @@ cpstripped(char **start, char *end, char *str) *(*start)++ = c; else { while ((c = (unsigned char) *s) && -#ifdef LOCALE - (iscntrl(c) || isspace(c))) -#else - (c <= 32)) -#endif + (iscntrl(c) || isspace(c))) s++; *(*start)++ = ' '; } diff --git a/sbr/gans.c b/sbr/gans.c index 2b9a015..c90bfef 100644 --- a/sbr/gans.c +++ b/sbr/gans.c @@ -25,13 +25,7 @@ gans(char *prompt, struct swit *ansp) if (i == EOF) return 0; if (cp < &ansbuf[sizeof ansbuf - 1]) { -#ifdef LOCALE - i = (isalpha(i) && isupper(i)) ? tolower(i) : i; -#else - if (i >= 'A' && i <= 'Z') - i += 'a' - 'A'; -#endif - *cp++ = i; + *cp++ = tolower(i); } } *cp = '\0'; diff --git a/sbr/m_atoi.c b/sbr/m_atoi.c index 03bf0d0..b903b7e 100644 --- a/sbr/m_atoi.c +++ b/sbr/m_atoi.c @@ -18,11 +18,7 @@ m_atoi(char *str) unsigned char *cp; for (i = 0, cp = str; *cp; cp++) { -#ifdef LOCALE if (!isdigit(*cp)) -#else - if (*cp < '0' || *cp > '9') -#endif return 0; i *= 10; diff --git a/sbr/uprf.c b/sbr/uprf.c index 836a98b..77137c9 100644 --- a/sbr/uprf.c +++ b/sbr/uprf.c @@ -8,9 +8,6 @@ #include -#define TO_LOWER 040 -#define NO_MASK 000 - int uprf(char *c1, char *c2) @@ -21,16 +18,7 @@ uprf(char *c1, char *c2) return 0; while ((c = *c2++)) { -#ifdef LOCALE - c &= 0xff; - mask = *c1 & 0xff; - c = (isalpha(c) && isupper(c)) ? tolower(c) : c; - mask = (isalpha(mask) && isupper(mask)) ? tolower(mask) : mask; - if (c != mask) -#else - mask = (isalpha(c) && isalpha(*c1)) ? TO_LOWER : NO_MASK; - if ((c | mask) != (*c1 | mask)) -#endif + if (tolower(c &= 0xff) != tolower(*c1 & 0xff)) return 0; else c1++; -- 1.7.10.4