diff options
author | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-03-30 06:16:08 +0000 |
---|---|---|
committer | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-03-30 06:16:08 +0000 |
commit | 2d33d82794559b83131b83528279ce898716c112 (patch) | |
tree | 0cf9f625341314a54010e027a9c01305de797c08 /src | |
parent | 5b5afa7bb6cad66880bbbeee26d0851f25f85d45 (diff) | |
download | hercules-2d33d82794559b83131b83528279ce898716c112.tar.gz hercules-2d33d82794559b83131b83528279ce898716c112.tar.bz2 hercules-2d33d82794559b83131b83528279ce898716c112.tar.xz hercules-2d33d82794559b83131b83528279ce898716c112.zip |
* Added all the missing defines for ctype.h functions and converted all the direct uses to the defines.
Ref: http://www.eathena.ws/board/index.php?showtopic=145235
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10091 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r-- | src/common/cbasetypes.h | 19 | ||||
-rw-r--r-- | src/common/core.c | 2 | ||||
-rw-r--r-- | src/common/showmsg.c | 4 | ||||
-rw-r--r-- | src/common/strlib.c | 4 | ||||
-rw-r--r-- | src/map/atcommand.c | 56 | ||||
-rw-r--r-- | src/map/charcommand.c | 6 | ||||
-rw-r--r-- | src/map/irc.c | 4 | ||||
-rw-r--r-- | src/map/npc.c | 3 | ||||
-rw-r--r-- | src/map/script.c | 14 |
9 files changed, 61 insertions, 51 deletions
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index 1a1cd22a9..b513b7fa3 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -297,9 +297,22 @@ typedef char bool; ////////////////////////////////////////////////////////////////////////// // Has to be unsigned to avoid problems in some systems -#define TOLOWER(c) ((char)tolower((unsigned char)(c))) -#define ISSPACE(c) (isspace((unsigned char)(c))) -#define ISALPHA(c) (isalpha((unsigned char)(c))) +// Problems arise when these functions expect an argument in the range [0,256[ and are feed a signed char. +// NOTE: <ctype.h> needs to be included when using these defines #define ISALNUM(c) (isalnum((unsigned char)(c))) +#define ISALPHA(c) (isalpha((unsigned char)(c))) +#define ISCNTRL(c) (iscntrl((unsigned char)(c))) +#define ISDIGIT(c) (isdigit((unsigned char)(c))) +#define ISGRAPH(c) (isgraph((unsigned char)(c))) +#define ISLOWER(c) (islower((unsigned char)(c))) +#define ISPRINT(c) (isprint((unsigned char)(c))) +#define ISPUNCT(c) (ispunct((unsigned char)(c))) +#define ISSPACE(c) (isspace((unsigned char)(c))) +#define ISUPPER(c) (isupper((unsigned char)(c))) +#define ISXDIGIT(c) (isxdigit((unsigned char)(c))) +#define TOASCII(c) (toascii((unsigned char)(c))) +#define TOLOWER(c) (tolower((unsigned char)(c))) +#define TOUPPER(c) (toupper((unsigned char)(c))) + #endif /* _CBASETYPES_H_ */ diff --git a/src/common/core.c b/src/common/core.c index 60d25546a..8c57f98ea 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -152,7 +152,7 @@ const char* get_svn_revision(void) // Check the version if (fgets(line,sizeof(line),fp)) { - if(!isdigit(line[0])) + if(!ISDIGIT(line[0])) { // XML File format while (fgets(line,sizeof(line),fp)) diff --git a/src/common/showmsg.c b/src/common/showmsg.c index 9323efa3f..dd8cfb07a 100644 --- a/src/common/showmsg.c +++ b/src/common/showmsg.c @@ -242,7 +242,7 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) q=q+2; while(1) { - if( isdigit((int)((unsigned char)*q)) ) + if( ISDIGIT(*q) ) { // add number to number array, only accept 2digits, shift out the rest // so // \033[123456789m will become \033[89m numbers[numpoint] = (numbers[numpoint]<<4) | (*q-'0'); @@ -565,7 +565,7 @@ int VFPRINTF(FILE *file, const char *fmt, va_list argptr) q=q+2; while(1) { - if( isdigit((int)((unsigned char)*q)) ) + if( ISDIGIT(*q) ) { ++q; // and next character diff --git a/src/common/strlib.c b/src/common/strlib.c index ee37cb9ae..dd10d655e 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -150,7 +150,7 @@ const char *stristr(const char *haystack, const char *needle) } for ( ; *haystack; ++haystack ) { - if ( toupper(*haystack) == toupper(*needle) ) + if ( TOUPPER(*haystack) == TOUPPER(*needle) ) { /* * Matched starting char -- loop through remaining chars. @@ -158,7 +158,7 @@ const char *stristr(const char *haystack, const char *needle) const char *h, *n; for ( h = haystack, n = needle; *h && *n; ++h, ++n ) { - if ( toupper(*h) != toupper(*n) ) + if ( TOUPPER(*h) != TOUPPER(*n) ) { break; } diff --git a/src/map/atcommand.c b/src/map/atcommand.c index e47deeb25..1b12d336c 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -798,12 +798,12 @@ AtCommandType is_atcommand_sub(const int fd, struct map_session_data* sd, const memset(command, '\0', sizeof(command)); memset(atcmd_output, '\0', sizeof(atcmd_output)); - while (*p && !isspace(*p)) + while (*p && !ISSPACE(*p)) p++; if (p - str >= sizeof(command)) // too long return AtCommand_Unknown; strncpy(command, str, p - str); - while (isspace(*p)) + while (ISSPACE(*p)) p++; if (type == AtCommand_Unknown || info.proc == NULL) { @@ -842,7 +842,7 @@ AtCommandType is_atcommand(const int fd, struct map_session_data* sd, const char return AtCommand_None; str += strlen(sd->status.name); - while (*str && (isspace(*str) || (s_flag == 0 && *str == ':'))) { + while (*str && (ISSPACE(*str) || (s_flag == 0 && *str == ':'))) { if (*str == ':') s_flag = 1; str++; @@ -1107,8 +1107,8 @@ int atcommand_send(const int fd, struct map_session_data* sd, const char* comman #define SKIP_VALUE(p) \ {\ - while(*(p) && !isspace(*(p))) ++(p); /* non-space */\ - while(*(p) && isspace(*(p))) ++(p); /* space */\ + while(*(p) && !ISSPACE(*(p))) ++(p); /* non-space */\ + while(*(p) && ISSPACE(*(p))) ++(p); /* space */\ } //define SKIP_VALUE @@ -1148,30 +1148,30 @@ int atcommand_send(const int fd, struct map_session_data* sd, const char* comman // parse packet contents SKIP_VALUE(message); while(*message != 0 && off < len){ - if(isdigit(*message) || *message == '-' || *message == '+') + if(ISDIGIT(*message) || *message == '-' || *message == '+') {// default (byte) GET_VALUE(message,num); WFIFOB(fd,off)=TOB(num); ++off; - } else if(toupper(*message) == 'B') + } else if(TOUPPER(*message) == 'B') {// byte ++message; GET_VALUE(message,num); WFIFOB(fd,off)=TOB(num); ++off; - } else if(toupper(*message) == 'W') + } else if(TOUPPER(*message) == 'W') {// word (2 bytes) ++message; GET_VALUE(message,num); WFIFOW(fd,off)=TOW(num); off+=2; - } else if(toupper(*message) == 'L') + } else if(TOUPPER(*message) == 'L') {// long word (4 bytes) ++message; GET_VALUE(message,num); WFIFOL(fd,off)=TOL(num); off+=4; - } else if(toupper(*message) == 'S') + } else if(TOUPPER(*message) == 'S') {// string - escapes are valid // get string length - num <= 0 means not fixed length (default) ++message; @@ -1181,7 +1181,7 @@ int atcommand_send(const int fd, struct map_session_data* sd, const char* comman GET_VALUE(message,num); while(*message != '"') {// find start of string - if(*message == 0 || isspace(*message)){ + if(*message == 0 || ISSPACE(*message)){ PARSE_ERROR("Not a string:",message); return -1; } @@ -1211,16 +1211,16 @@ int atcommand_send(const int fd, struct map_session_data* sd, const char* comman { ++message; CHECK_EOS(message); - if(!isxdigit(*message)){ + if(!ISXDIGIT(*message)){ PARSE_ERROR("Not a hexadecimal digit:",message); return -1; } - num=(isdigit(*message)?*message-'0':tolower(*message)-'a'+10); - if(isxdigit(*message)){ + num=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10); + if(ISXDIGIT(*message)){ ++message; CHECK_EOS(message); num<<=8; - num+=(isdigit(*message)?*message-'0':tolower(*message)-'a'+10); + num+=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10); } WFIFOB(fd,off)=TOB(num); ++message; @@ -1239,12 +1239,12 @@ int atcommand_send(const int fd, struct map_session_data* sd, const char* comman num=*message-'0'; // 1st octal digit ++message; CHECK_EOS(message); - if(isdigit(*message) && *message < '8'){ + if(ISDIGIT(*message) && *message < '8'){ num<<=3; num+=*message-'0'; // 2nd octal digit ++message; CHECK_EOS(message); - if(isdigit(*message) && *message < '8'){ + if(ISDIGIT(*message) && *message < '8'){ num<<=3; num+=*message-'0'; // 3rd octal digit ++message; @@ -1492,7 +1492,7 @@ int atcommand_who3(const int fd, struct map_session_data* sd, const char* comman if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); for (j = 0; match_text[j]; j++) - match_text[j] = tolower(match_text[j]); + match_text[j] = TOLOWER(match_text[j]); count = 0; GM_level = pc_isGM(sd); @@ -1503,7 +1503,7 @@ int atcommand_who3(const int fd, struct map_session_data* sd, const char* comman if (!((battle_config.hide_GM_session || (pl_sd->sc.option & OPTION_INVISIBLE)) && (pl_GM_level > GM_level))) { // you can look only lower or same level memcpy(player_name, pl_sd->status.name, NAME_LENGTH); for (j = 0; player_name[j]; j++) - player_name[j] = tolower(player_name[j]); + player_name[j] = TOLOWER(player_name[j]); if (strstr(player_name, match_text) != NULL) { // search with no case sensitive if (battle_config.who_display_aid > 0 && pc_isGM(sd) >= battle_config.who_display_aid) { @@ -1565,7 +1565,7 @@ int atcommand_who2(const int fd, struct map_session_data* sd, const char* comman if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); for (j = 0; match_text[j]; j++) - match_text[j] = tolower(match_text[j]); + match_text[j] = TOLOWER(match_text[j]); count = 0; GM_level = pc_isGM(sd); @@ -1576,7 +1576,7 @@ int atcommand_who2(const int fd, struct map_session_data* sd, const char* comman if (!((battle_config.hide_GM_session || (pl_sd->sc.option & OPTION_INVISIBLE)) && (pl_GM_level > GM_level))) { // you can look only lower or same level memcpy(player_name, pl_sd->status.name, NAME_LENGTH); for (j = 0; player_name[j]; j++) - player_name[j] = tolower(player_name[j]); + player_name[j] = TOLOWER(player_name[j]); if (strstr(player_name, match_text) != NULL) { // search with no case sensitive //Players Name //sprintf(atcmd_output, "Name: %s ", pl_sd->status.name); @@ -1636,7 +1636,7 @@ int atcommand_who(const int fd, struct map_session_data* sd, const char* command if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); for (j = 0; match_text[j]; j++) - match_text[j] = tolower(match_text[j]); + match_text[j] = TOLOWER(match_text[j]); count = 0; GM_level = pc_isGM(sd); @@ -1647,7 +1647,7 @@ int atcommand_who(const int fd, struct map_session_data* sd, const char* command if (!((battle_config.hide_GM_session || (pl_sd->sc.option & OPTION_INVISIBLE)) && (pl_GM_level > GM_level))) { // you can look only lower or same level memcpy(player_name, pl_sd->status.name, NAME_LENGTH); for (j = 0; player_name[j]; j++) - player_name[j] = tolower(player_name[j]); + player_name[j] = TOLOWER(player_name[j]); if (strstr(player_name, match_text) != NULL) { // search with no case sensitive g = guild_search(pl_sd->status.guild_id); p = party_search(pl_sd->status.party_id); @@ -1901,7 +1901,7 @@ int atcommand_whogm(const int fd, struct map_session_data* sd, const char* comma if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); for (j = 0; match_text[j]; j++) - match_text[j] = tolower(match_text[j]); + match_text[j] = TOLOWER(match_text[j]); count = 0; GM_level = pc_isGM(sd); @@ -1913,7 +1913,7 @@ int atcommand_whogm(const int fd, struct map_session_data* sd, const char* comma if (!((battle_config.hide_GM_session || (pl_sd->sc.option & OPTION_INVISIBLE)) && (pl_GM_level > GM_level))) { // you can look only lower or same level memcpy(player_name, pl_sd->status.name, NAME_LENGTH); for (j = 0; player_name[j]; j++) - player_name[j] = tolower(player_name[j]); + player_name[j] = TOLOWER(player_name[j]); if (strstr(player_name, match_text) != NULL) { // search with no case sensitive sprintf(atcmd_output, "Name: %s (GM:%d) | Location: %s %d %d", pl_sd->status.name, pl_GM_level, mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); clif_displaymessage(fd, atcmd_output); @@ -1968,7 +1968,7 @@ int atcommand_whozeny(const int fd, struct map_session_data* sd, const char* com if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); for (j = 0; match_text[j]; j++) - match_text[j] = tolower(match_text[j]); + match_text[j] = TOLOWER(match_text[j]); count = 0; pl_allsd = map_getallusers(&users); @@ -1983,7 +1983,7 @@ int atcommand_whozeny(const int fd, struct map_session_data* sd, const char* com if ((pl_sd = pl_allsd[i])) { memcpy(player_name, pl_sd->status.name, NAME_LENGTH); for (j = 0; player_name[j]; j++) - player_name[j] = tolower(player_name[j]); + player_name[j] = TOLOWER(player_name[j]); if (strstr(player_name, match_text) != NULL) { // search with no case sensitive zeny[count]=pl_sd->status.zeny; counted[i]=0; @@ -3248,7 +3248,7 @@ int atcommand_go(const int fd, struct map_session_data* sd, const char* command, // get possible name of the city map_name[MAP_NAME_LENGTH-1] = '\0'; for (i = 0; map_name[i]; i++) - map_name[i] = tolower(map_name[i]); + map_name[i] = TOLOWER(map_name[i]); // try to see if it's a name, and not a number (try a lot of possibilities, write errors and abbreviations too) if (strncmp(map_name, "prontera", 3) == 0) { // 3 first characters town = 0; diff --git a/src/map/charcommand.c b/src/map/charcommand.c index 696abd7c7..f241148c3 100644 --- a/src/map/charcommand.c +++ b/src/map/charcommand.c @@ -145,12 +145,12 @@ is_charcommand_sub(const int fd, struct map_session_data* sd, const char* str, i memset(command, '\0', sizeof(command)); memset(output, '\0', sizeof(output)); - while (*p && !isspace(*p)) + while (*p && !ISSPACE(*p)) p++; if (p - str >= sizeof(command)) // too long return CharCommand_Unknown; strncpy(command, str, p - str); - while (isspace(*p)) + while (ISSPACE(*p)) p++; if (type == CharCommand_Unknown || info.proc == NULL) { @@ -188,7 +188,7 @@ is_charcommand(const int fd, struct map_session_data* sd, const char* message) { return CharCommand_None; str += strlen(sd->status.name); - while (*str && (isspace(*str) || (s_flag == 0 && *str == ':'))) { + while (*str && (ISSPACE(*str) || (s_flag == 0 && *str == ':'))) { if (*str == ':') s_flag = 1; str++; diff --git a/src/map/irc.c b/src/map/irc.c index 7228da81a..8760efc11 100644 --- a/src/map/irc.c +++ b/src/map/irc.c @@ -99,7 +99,7 @@ void irc_announce_shop(struct map_session_data *sd, int flag) strcpy(mapname, map[sd->bl.m].name); maplen = strcspn(mapname,"."); mapname[maplen] = '\0'; - mapname[0]=toupper(mapname[0]); + mapname[0]=TOUPPER(mapname[0]); sprintf(send_string,"PRIVMSG %s :%s has opened a shop, %s, at <%d,%d> in %s.",irc_trade_channel,sd->status.name,sd->message,sd->bl.x,sd->bl.y,mapname); } else @@ -123,7 +123,7 @@ void irc_announce_mvp(struct map_session_data *sd, struct mob_data *md) strcpy(mapname, map[md->bl.m].name); maplen = strcspn(mapname,"."); mapname[maplen] = '\0'; - mapname[0]=toupper(mapname[0]); + mapname[0]=TOUPPER(mapname[0]); sprintf(send_string,"PRIVMSG %s :%s the %s has MVP'd %s in %s.",irc_channel,sd->status.name,job_name(sd->status.class_),md->name, mapname); irc_send(send_string); diff --git a/src/map/npc.c b/src/map/npc.c index edeb6d8d4..0a6277894 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -32,9 +32,6 @@ #include "unit.h" #ifdef _WIN32 -#undef isspace -#define isspace(x) (x == ' ' || x == '\t') -#endif struct npc_src_list { struct npc_src_list * next; diff --git a/src/map/script.c b/src/map/script.c index 55a0eb23e..513d3be6f 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -353,18 +353,18 @@ static unsigned int calc_hash2(const unsigned char *p) #if defined(SCRIPT_HASH_DJB2) unsigned int h = 5381; while( *p ) // hash*33 + c - h = ( h << 5 ) + h + ((unsigned char)tolower(*p++)); + h = ( h << 5 ) + h + ((unsigned char)TOLOWER(*p++)); return h; #elif defined(SCRIPT_HASH_SDBM) unsigned int h = 0; while( *p ) - h = ( h << 6 ) + ( h << 16 ) - h + ((unsigned char)tolower(*p++)); + h = ( h << 6 ) + ( h << 16 ) - h + ((unsigned char)TOLOWER(*p++)); return h; #elif defined(SCRIPT_HASH_ELF) unsigned int h = 0; unsigned int g; while( *p ){ // UNIX ELF hash - h = ( h << 4 ) + ((unsigned char)tolower(*p++)); + h = ( h << 4 ) + ((unsigned char)TOLOWER(*p++)); if ( g = h & 0xF0000000 ) h ^= g >> 24; h &= ~g; @@ -374,7 +374,7 @@ static unsigned int calc_hash2(const unsigned char *p) unsigned int h = 0; unsigned int g; while( *p ){ - h = ( h << 4 ) + ((unsigned char)tolower(*p++)); + h = ( h << 4 ) + ((unsigned char)TOLOWER(*p++)); if ( (g=h&0xF0000000) ) { h ^= g>>24; h ^= g; @@ -385,7 +385,7 @@ static unsigned int calc_hash2(const unsigned char *p) unsigned int h = 0; while( *p ){ h = ( h << 1 ) + ( h >> 3 ) + ( h >> 5 ) + ( h >> 8 ); - h+=(unsigned char)tolower(*p++); + h+=(unsigned char)TOLOWER(*p++); } return h; #endif @@ -783,7 +783,7 @@ const char* parse_simpleexpr(const char *p) if( *p != ')' ) disp_error_message("parse_simpleexpr: unmatch ')'",p); ++p; - } else if(isdigit(*p) || ((*p=='-' || *p=='+') && isdigit(p[1]))){ + } else if(ISDIGIT(*p) || ((*p=='-' || *p=='+') && ISDIGIT(p[1]))){ char *np; i=strtoul(p,&np,0); add_scripti(i); @@ -1123,7 +1123,7 @@ const char* parse_syntax(const char* p) v = str_data[v].val; p = skip_word(p); } else { //Numeric value - if((*p == '-' || *p == '+') && isdigit(p[1])) // pre-skip because '-' can not skip_word + if((*p == '-' || *p == '+') && ISDIGIT(p[1])) // pre-skip because '-' can not skip_word p++; p = skip_word(p); if(np != p) |