Changed all toupper, tolower, isupper, islower and isalpha to internal defined function. Case insensitive regexp should work on Win9x now.

This commit is contained in:
Ianos Gnatiuc
2005-10-31 22:18:26 +00:00
parent ad8b2a9d36
commit 21b44b65d2
69 changed files with 228 additions and 192 deletions

View File

@@ -69,7 +69,7 @@ void gbmh::init(const char* pattern, bool ignorecase) {
strupr(pat);
#else /* strupr() is wrong on windows 9x (patch from Ianos Gnatiuc 2:469/335.155) */
for(char *ptr = pat; *ptr; ptr++)
*ptr = toupper(*ptr);
*ptr = g_toupper(*ptr);
#endif
}
@@ -80,12 +80,12 @@ void gbmh::init(const char* pattern, bool ignorecase) {
for(i=0; i<patlen; i++) {
skip[pat[i] & 0xff] = patlen - i - 1;
if(ignore_case)
skip[tolower((uint8_t)pat[i])] = patlen - i - 1;
skip[g_tolower((uint8_t)pat[i])] = patlen - i - 1;
}
char lastpatchar = pat[patlen - 1];
skip[lastpatchar & 0xff] = INT_MAX;
if(ignore_case)
skip[tolower((uint8_t)lastpatchar)] = INT_MAX;
skip[g_tolower((uint8_t)lastpatchar)] = INT_MAX;
// Horspool's fixed second shift
skip2 = patlen;
@@ -120,7 +120,7 @@ bool gbmh::find(const char* buffer) {
const char* s = buffer + (i - j);
if(ignore_case) {
while(--j >= 0 and toupper((uint8_t)s[j]) == pat[j])
while(--j >= 0 and g_toupper((uint8_t)s[j]) == pat[j])
;
}
else {

View File

@@ -46,7 +46,7 @@ dword strHash32(const char* s, bool __case) {
while(*p) {
hash = (hash << 4) + (__case ? tolower(*p) : *p);
hash = (hash << 4) + (__case ? g_tolower(*p) : *p);
g = hash & 0xF0000000UL;
if(g) {

View File

@@ -145,7 +145,7 @@ word getkeyvalcrc(char** key, char** val) {
// Calculate CRC16 of keyword
while(*p)
c = updCrc16((byte)toupper(*p++), c);
c = updCrc16((byte)g_toupper(*p++), c);
// Return keyword CRC
return c;

View File

@@ -39,7 +39,7 @@ word memCrc16(const void* _m, long l, bool __case, word mask) {
if(__case) {
for(n=0; n<l; n++)
crc = updCrc16(toupper(*m++), crc);
crc = updCrc16(g_toupper(*m++), crc);
}
else {
for(n=0; n<l; n++)

View File

@@ -40,7 +40,7 @@ dword memCrc32(const void* _m, long l, bool __case, dword mask) {
if(__case) {
for(n=0; n<l; n++)
crc = updCrc32(toupper(*m++), crc);
crc = updCrc32(g_toupper(*m++), crc);
}
else {
for(n=0; n<l; n++)

View File

@@ -38,7 +38,7 @@ word strCrc16(const char* s, bool __case, word mask) {
if(__case) {
while(*s)
crc = updCrc16(toupper(*s++), crc);
crc = updCrc16(g_toupper(*s++), crc);
}
else {
while(*s)
@@ -58,7 +58,7 @@ word strCrc16c(const char* s, bool __case, word mask) {
if(__case) {
while(*s)
crc = updCrc16c(toupper(*s++), crc);
crc = updCrc16c(g_toupper(*s++), crc);
}
else {
while(*s)

View File

@@ -38,7 +38,7 @@ dword strCrc32(const char* s, bool __case, dword mask) {
if(__case) {
while(*s)
crc = updCrc32(toupper(*s++), crc);
crc = updCrc32(g_toupper(*s++), crc);
}
else {
while(*s)

View File

@@ -41,19 +41,19 @@
#include <ctype.h>
#if defined(__EMX__)
#include <sys/nls.h>
#define tolower(c) _nls_tolower((uint8_t)(c))
#define toupper(c) _nls_toupper((uint8_t)(c))
#define g_tolower(c) _nls_tolower((uint8_t)(c))
#define g_toupper(c) _nls_toupper((uint8_t)(c))
#elif defined(__WIN32__)
#ifdef __cplusplus
extern "C" {
extern char tl[256], tu[256];
__inline__ int tolower(int c) { return tl[c]; }
__inline__ int toupper(int c) { return tu[c]; }
__inline__ int g_tolower(int c) { return tl[c]; }
__inline__ int g_toupper(int c) { return tu[c]; }
}
#else
extern char tl[256], tu[256];
#define tolower(c) tl[(int)(uint8_t)(c)]
#define toupper(c) tu[(int)(uint8_t)(c)]
#define g_tolower(c) tl[(int)(uint8_t)(c)]
#define g_toupper(c) tu[(int)(uint8_t)(c)]
#endif
#endif
@@ -64,14 +64,47 @@ extern char tl[256], tu[256];
* they don't match they treated as characters
*/
#if defined(__WIN32__)
#ifdef __cplusplus
extern "C" {
#endif
extern __inline__ int isxalnum(char c) {
return isascii(c) ? isalnum(c) : (c != tolower(c)) || (c != toupper(c));
__inline__ int g_islower(int c)
{
return isascii(c) ? islower(c) : (c == g_tolower(c)) && (c != g_toupper(c));
}
__inline__ int g_isupper(int c)
{
return isascii(c) ? isupper(c) : (c != g_tolower(c)) && (c == g_toupper(c));
}
__inline__ int g_isalpha(int c)
{
return isascii(c) ? isalpha(c) : (c != g_tolower(c)) || (c != g_toupper(c));
}
}
#else
#define g_islower(c) (isascii(c) ? islower(c) : ((c) == g_tolower(c)) && ((c) != g_toupper(c)))
#define g_isupper(c) (isascii(c) ? isupper(c) : ((c) != g_tolower(c)) && ((c) == g_toupper(c)))
#define g_isalpha(c) (isascii(c) ? isalpha(c) : ((c) != g_tolower(c)) || ((c) != g_toupper(c)))
#endif //#ifdef __cplusplus
#else
#define g_islower islower
#define g_isupper isupper
#define g_isalpha isalpha
#endif //#if defined(__WIN32__)
#ifdef __cplusplus
extern "C" {
__inline__ int isxalnum(int c)
{
return isascii(c) ? isalnum(c) : (c != g_tolower(c)) || (c != g_toupper(c));
}
}
#else
#define isxalnum(c) (isascii(c) ? isalnum(c) : ((c) != g_tolower(c)) || ((c) != g_toupper(c)))
#endif
#ifdef __BEOS__

View File

@@ -168,7 +168,7 @@ int is_dir(const char* path) {
// Check if it's a root path (X:\)
#if defined(__HAVE_DRIVES__)
if(isalpha(path[0]) and (path[1] == ':') and isslash(path[2]) and (path[3] == NUL))
if(g_isalpha(path[0]) and (path[1] == ':') and isslash(path[2]) and (path[3] == NUL))
return true; // The root is a directory
#endif
@@ -226,7 +226,7 @@ void MakePathname(char* pathname, const char* path, const char* name) {
have_path = true;
#if defined(__HAVE_DRIVES__)
// Check if it's a root path (X:\)
else if(isalpha(tmpname[0]) and (tmpname[1] == ':') and isslash(tmpname[2]))
else if(g_isalpha(tmpname[0]) and (tmpname[1] == ':') and isslash(tmpname[2]))
have_path = true; // The root is a directory
#endif
@@ -416,7 +416,7 @@ int gchdir(const char* dir) {
_chdrive(*dir);
#else
uint drives;
_dos_setdrive(toupper(*dir)-'@', &drives);
_dos_setdrive(g_toupper(*dir)-'@', &drives);
#endif
}
#endif

View File

@@ -75,7 +75,7 @@ int ftn_fidouser_nodelist_index::namecmp() const {
int n = 1;
int d;
while(1) {
d = tolower(*a) - tolower(*b);
d = g_tolower(*a) - g_tolower(*b);
if((d != 0) or (*a == NUL) or (*b == NUL))
break;
a++;

View File

@@ -172,7 +172,7 @@ int ftn_golded_nodelist_index::namecmp() const {
int n = 1;
int d;
while(1) {
d = tolower(*a) - tolower(*b);
d = g_tolower(*a) - g_tolower(*b);
if((d != 0) or (*a == NUL) or (*b == NUL))
break;
a++;

View File

@@ -141,7 +141,7 @@ int ftn_version7_nodelist_index::namecmp() const {
int n = 1;
int d;
while(1) {
d = tolower((uint8_t)*a) - tolower((uint8_t)*b);
d = g_tolower((uint8_t)*a) - g_tolower((uint8_t)*b);
if((d != 0) or (*a == NUL) or (*b == NUL))
break;
a++;

View File

@@ -140,7 +140,7 @@ bool gfuzzy::findnext() {
if(casing)
charmatch = pattern[i] == text[textloc];
else
charmatch = toupper(pattern[i]) == toupper(text[textloc]);
charmatch = g_toupper(pattern[i]) == g_toupper(text[textloc]);
int a = ldiff[i] + (charmatch ? 0 : 1);
int b = ldiff[i+1] + 1;
int c = rdiff[i] + 1;

View File

@@ -940,7 +940,7 @@ int gkbd_nt2bios(INPUT_RECORD& inp) {
else {
// If it is a letter key, use the ASCII value supplied
// by NT to take into account the CapsLock state.
if(isupper(keycode) or (k->normal == -1))
if(g_isupper(keycode) or (k->normal == -1))
c = ascii;
else
c = k->normal;
@@ -1087,7 +1087,7 @@ gkey kbxget_raw(int mode) {
k = 0x7800 + ((key2 - '1') << 8);
else if(key2 == '0')
k = 0x8100;
else if(isalpha(key2))
else if(g_isalpha(key2))
k = (scancode_table[key2]);
else if(key2 == '\010')
k = Key_A_BS;
@@ -1807,8 +1807,8 @@ int setonkey(gkey keycode, VfvCP func, gkey pass) {
gkey key_tolower(gkey __keycode) {
byte &ascii = KCodAsc(__keycode);
if(isupper(ascii))
ascii = tolower(ascii);
if(g_isupper(ascii))
ascii = g_tolower(ascii);
return __keycode;
}

View File

@@ -37,7 +37,7 @@ static char touplow(char* str, char* pos, char ch) {
char i;
if(pos == str)
return toupper(ch);
return g_toupper(ch);
switch(*(pos-1)) { // check previous character
case ' ': // see if it is a separator
@@ -46,10 +46,10 @@ static char touplow(char* str, char* pos, char ch) {
case ',':
case '.':
case '/':
i = (char)toupper(ch); // if it is, convert to upper
i = (char)g_toupper(ch); // if it is, convert to upper
break;
default:
i = (char)tolower(ch); // otherwise, convert to lower
i = (char)g_tolower(ch); // otherwise, convert to lower
break;
}

View File

@@ -127,7 +127,7 @@ int strnicmpw(const char* str1, const char* str2, int len) {
else if(str1[n] == '*')
return 0;
// Compare chars
else if((cmp = compare_two(toupper(str1[n]), toupper(str2[n]))) != 0)
else if((cmp = compare_two(g_toupper(str1[n]), g_toupper(str2[n]))) != 0)
return cmp;
}
@@ -605,7 +605,7 @@ char* strupr(char* s) {
char* p = s;
while(*p) {
*p = toupper(*p);
*p = g_toupper(*p);
p++;
}
return s;
@@ -615,7 +615,7 @@ char* strlwr(char* s) {
char* p = s;
while(*p) {
*p = tolower(*p);
*p = g_tolower(*p);
p++;
}
return s;

View File

@@ -283,9 +283,9 @@ int str2mon(const char* ptr) {
int mon;
switch(toupper(*ptr)) {
switch(g_toupper(*ptr)) {
case 'A':
if(toupper(ptr[1]) == 'P')
if(g_toupper(ptr[1]) == 'P')
mon = 4;
else
mon = 8;
@@ -297,15 +297,15 @@ int str2mon(const char* ptr) {
mon = 2;
break;
case 'J':
if(toupper(ptr[1]) == 'A')
if(g_toupper(ptr[1]) == 'A')
mon = 1;
else if(toupper(ptr[2]) == 'L')
else if(g_toupper(ptr[2]) == 'L')
mon = 7;
else
mon = 6;
break;
case 'M':
if(toupper(ptr[2]) == 'R')
if(g_toupper(ptr[2]) == 'R')
mon = 3;
else
mon = 5;
@@ -405,7 +405,7 @@ time32_t FidoTimeToUnix(char* ptr) {
if(isdigit(*ptr)) {
day = atoi(ptr);
ptr = strskip_wht(strskip_txt(ptr));
if(isalpha(*ptr)) {
if(g_isalpha(*ptr)) {
month = str2mon(ptr);
if(month) {
ptr = strskip_wht(strskip_txt(ptr));

View File

@@ -38,7 +38,7 @@ int GetYesno(const char* value) {
if(isdigit(*value))
return atoi(value);
switch(toupper(*value)) {
switch(g_toupper(*value)) {
case NUL: // Blank
case 'T': // True
@@ -50,15 +50,15 @@ int GetYesno(const char* value) {
return NO;
case 'O': // On or Off
if(toupper(value[1]) == 'N')
if(g_toupper(value[1]) == 'N')
return YES;
else
return NO;
case 'A': // Always, Ask or Auto
if(toupper(value[1]) == 'L')
if(g_toupper(value[1]) == 'L')
return ALWAYS;
else if(toupper(value[1]) == 'S')
else if(g_toupper(value[1]) == 'S')
return ASK;
else
return GAUTO;

View File

@@ -42,7 +42,7 @@
uint32_t atoulx(const char* s);
inline word atow(const char* p) { return (word)atoi(p); }
inline int xtoi(char c) { return isdigit(c) ? (c - '0') : (toupper(c) - ('A' - 10)); }
inline int xtoi(char c) { return isdigit(c) ? (c - '0') : (g_toupper(c) - ('A' - 10)); }
inline int atox(const char* s) { return (int)atoulx(s); }
char* ltob(char* dst, uint32_t value, int fill=32);

View File

@@ -64,9 +64,6 @@ int g_put_clip_text(const char *cd);
void g_get_ostitle_name(char *);
void g_set_ostitle_name(char *, int);
char g_tolower(char);
char g_toupper(char);
#ifdef __cplusplus
}
#endif

View File

@@ -105,7 +105,7 @@ int gwildmatch::match_internal(const char* text, const char* pattern, bool ignor
matched = false;
if(p[1] == ']' or p[1] == '-') {
if(ignorecase) {
if(tolower(*++p) == tolower(*text))
if(g_tolower(*++p) == g_tolower(*text))
matched = true;
}
else {
@@ -116,7 +116,7 @@ int gwildmatch::match_internal(const char* text, const char* pattern, bool ignor
for(last = *p; *++p and *p != ']'; last = *p) {
// This next line requires a good C compiler
if(ignorecase) {
if(*p == '-' and p[1] != ']' ? tolower(*text) <= tolower(*++p) and tolower(*text) >= tolower(last) : tolower(*text) == tolower(*p))
if(*p == '-' and p[1] != ']' ? g_tolower(*text) <= g_tolower(*++p) and g_tolower(*text) >= g_tolower(last) : g_tolower(*text) == g_tolower(*p))
matched = true;
}
else {
@@ -133,7 +133,7 @@ int gwildmatch::match_internal(const char* text, const char* pattern, bool ignor
// FALLTHROUGH
default:
if(ignorecase) {
if(tolower(*text) != tolower(*p))
if(g_tolower(*text) != g_tolower(*p))
return false;
}
else {
@@ -186,7 +186,7 @@ bool strwild(const char* str, const char* wild) {
break;
}
}
else if(toupper(*str) == toupper(*wild) or *wild == '?') {
else if(g_toupper(*str) == g_toupper(*wild) or *wild == '?') {
wild++;
str++;
}

View File

@@ -1216,7 +1216,7 @@ int wmenuget() {
item=citem->next;
for(;;) {
while(item!=NULL) {
if ((toupper(ch)==toupper(item->schar)) && !(item->fmask & M_NOSEL))
if ((g_toupper(ch)==g_toupper(item->schar)) && !(item->fmask & M_NOSEL))
{
if (!gwin.menu->hotkey) _overtagid = item->tagid;
goto FARBREAK;

View File

@@ -678,15 +678,15 @@ int wpickstr(int srow, int scol, int erow, int ecol, int btype, int bordattr, in
// position for the item that begins with the same ASCII
// character as the keypress. If not found after current
// position, search from the beginning for a match
ch = (char)toupper((char)xch);
ch = (char)g_toupper((char)xch);
if(!ch)
break;
for(i=r.curr+1; i<r.numelems; i++)
if(ch==toupper(strarr[i][quickpos]))
if(ch==g_toupper(strarr[i][quickpos]))
break;
if(i==r.numelems) {
for(i=0;i<r.curr;i++)
if(ch==toupper(strarr[i][quickpos]))
if(ch==g_toupper(strarr[i][quickpos]))
break;
if(i==r.curr)
continue;

View File

@@ -1053,10 +1053,10 @@ bool gwinput::field::overwrite_char(char ch) {
switch(conversion) {
case gwinput::cvt_lowercase:
ch = (char)tolower(ch);
ch = (char)g_tolower(ch);
break;
case gwinput::cvt_uppercase:
ch = (char)toupper(ch);
ch = (char)g_toupper(ch);
break;
}