From 49d2dff6314486758832cad3403e1775c3fd7af3 Mon Sep 17 00:00:00 2001 From: Haru Date: Sat, 9 Nov 2013 20:29:23 +0100 Subject: Changed builtin keywords in the script engine to case sensitive. - Any scripts using the wrong case, that were throwing deprecation warnings until now, will become invalid. - Related to bugreport:7810. Signed-off-by: Haru --- src/map/npc.c | 65 +++++++++++++++----------------- src/map/script.c | 113 ++++++++++++++++++++++++++++++------------------------- src/map/script.h | 4 +- 3 files changed, 94 insertions(+), 88 deletions(-) (limited to 'src/map') diff --git a/src/map/npc.c b/src/map/npc.c index 30cb94efe..8d71ee20a 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2218,7 +2218,7 @@ const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const char* s return strchr(start,'\n');;//try next } - if( !strcasecmp(w2,"cashshop") ) + if( strcmp(w2,"cashshop") == 0 ) type = CASHSHOP; else type = SHOP; @@ -2971,7 +2971,7 @@ const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const char* st memset(&mobspawn, 0, sizeof(struct spawn_data)); - mobspawn.state.boss = !strcmpi(w2,"boss_monster"); + mobspawn.state.boss = (strcmp(w2,"boss_monster") == 0 ? 1 : 0); // w1=,,,, // w3={,} @@ -3593,7 +3593,7 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit) { break; } - if( strcmp(w1,"-") !=0 && strcasecmp(w1,"function") != 0 ) + if( strcmp(w1,"-") != 0 && strcmp(w1,"function") != 0 ) {// w1 = ,,, char mapname[MAP_NAME_LENGTH*2]; x = y = 0; @@ -3601,7 +3601,7 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit) { if( !mapindex_name2id(mapname) ) {// Incorrect map, we must skip the script info... ShowError("npc_parsesrcfile: Unknown map '%s' in file '%s', line '%d'. Skipping line...\n", mapname, filepath, strline(buffer,p-buffer)); - if( strcasecmp(w2,"script") == 0 && count > 3 ) + if( strcmp(w2,"script") == 0 && count > 3 ) { if((p = npc->skip_script(p,buffer,filepath)) == NULL) { @@ -3614,7 +3614,7 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit) { m = map->mapname2mapid(mapname); if( m < 0 ) { // "mapname" is not assigned to this server, we must skip the script info... - if( strcasecmp(w2,"script") == 0 && count > 3 ) + if( strcmp(w2,"script") == 0 && count > 3 ) { if((p = npc->skip_script(p,buffer,filepath)) == NULL) { @@ -3626,7 +3626,7 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit) { } if (x < 0 || x >= map->list[m].xs || y < 0 || y >= map->list[m].ys) { ShowError("npc_parsesrcfile: Unknown coordinates ('%d', '%d') for map '%s' in file '%s', line '%d'. Skipping line...\n", x, y, mapname, filepath, strline(buffer,p-buffer)); - if( strcasecmp(w2,"script") == 0 && count > 3 ) + if( strcmp(w2,"script") == 0 && count > 3 ) { if((p = npc->skip_script(p,buffer,filepath)) == NULL) { @@ -3638,57 +3638,54 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit) { } } - if( strcasecmp(w2,"warp") == 0 && count > 3 ) + if( strcmp(w2,"warp") == 0 && count > 3 ) { -#ifdef ENABLE_CASE_CHECK - if( strcmp(w2, "warp") != 0 ) DeprecationWarning("npc_parsesrcfile", w2, "warp", filepath, strline(buffer, p-buffer)); // TODO -#endif // ENABLE_CASE_CHECK p = npc->parse_warp(w1,w2,w3,w4, p, buffer, filepath); } - else if( (!strcasecmp(w2,"shop") || !strcasecmp(w2,"cashshop")) && count > 3 ) + else if( (strcmp(w2,"shop") == 0 || strcmp(w2,"cashshop") == 0) && count > 3 ) { -#ifdef ENABLE_CASE_CHECK - if( strcasecmp(w2,"shop") == 0 && strcmp(w2, "shop") != 0 ) DeprecationWarning("npc_parsesrcfile", w2, "shop", filepath, strline(buffer, p-buffer)) // TODO - else if( strcasecmp(w2,"cashshop") == 0 && strcmp(w2, "cashshop") != 0 ) DeprecationWarning("npc_parsesrcfile", w2, "cashshop", filepath, strline(buffer, p-buffer)); // TODO -#endif // ENABLE_CASE_CHECK p = npc->parse_shop(w1,w2,w3,w4, p, buffer, filepath); } - else if( strcasecmp(w2,"script") == 0 && count > 3 ) + else if( strcmp(w2,"script") == 0 && count > 3 ) { + if( strcmp(w1,"function") == 0 ) { + p = npc->parse_function(w1, w2, w3, w4, p, buffer, filepath); + } else { #ifdef ENABLE_CASE_CHECK - if( strcmp(w2, "script") != 0 ) DeprecationWarning("npc_parsesrcfile", w2, "script", filepath, strline(buffer, p-buffer)); // TODO - if( strcasecmp(w1, "function") == 0 && strcmp(w1, "function") != 0 ) DeprecationWarning("npc_parsesrcfile", w1, "function", filepath, strline(buffer, p-buffer)); // TODO + if( strcasecmp(w1, "function") == 0 ) DeprecationWarning("npc_parsesrcfile", w1, "function", filepath, strline(buffer, p-buffer)); // TODO #endif // ENABLE_CASE_CHECK - if( strcasecmp(w1,"function") == 0 ) - p = npc->parse_function(w1, w2, w3, w4, p, buffer, filepath); - else p = npc->parse_script(w1,w2,w3,w4, p, buffer, filepath,runOnInit); + } } else if( (i=0, sscanf(w2,"duplicate%n",&i), (i > 0 && w2[i] == '(')) && count > 3 ) { -#ifdef ENABLE_CASE_CHECK - char temp[10]; safestrncpy(temp, w2, 10); - if( strcmp(temp, "duplicate") != 0 ) DeprecationWarning("npc_parsesrcfile", temp, "duplicate", filepath, strline(buffer, p-buffer)); // TODO -#endif // ENABLE_CASE_CHECK p = npc->parse_duplicate(w1,w2,w3,w4, p, buffer, filepath); } - else if( (strcmpi(w2,"monster") == 0 || strcmpi(w2,"boss_monster") == 0) && count > 3 ) + else if( (strcmp(w2,"monster") == 0 || strcmp(w2,"boss_monster") == 0) && count > 3 ) { -#ifdef ENABLE_CASE_CHECK - if( strcasecmp(w2,"monster") == 0 && strcmp(w2, "monster") != 0 ) DeprecationWarning("npc_parsesrcfile", w2, "monster", filepath, strline(buffer, p-buffer)) // TODO: - else if( strcasecmp(w2,"boss_monster") == 0 && strcmp(w2, "boss_monster") != 0 ) DeprecationWarning("npc_parsesrcfile", w2, "boss_monster", filepath, strline(buffer, p-buffer)); // TODO -#endif // ENABLE_CASE_CHECK p = npc->parse_mob(w1, w2, w3, w4, p, buffer, filepath); } - else if( strcmpi(w2,"mapflag") == 0 && count >= 3 ) + else if( strcmp(w2,"mapflag") == 0 && count >= 3 ) { -#ifdef ENABLE_CASE_CHECK - if( strcmp(w2, "mapflag") != 0 ) DeprecationWarning("npc_parsesrcfile", w2, "mapflag", filepath, strline(buffer, p-buffer)); // TODO -#endif // ENABLE_CASE_CHECK p = npc->parse_mapflag(w1, w2, trim(w3), trim(w4), p, buffer, filepath); } else { +#ifdef ENABLE_CASE_CHECK + if( strcasecmp(w2, "warp") == 0 ) { DeprecationWarning("npc_parsesrcfile", w2, "warp", filepath, strline(buffer, p-buffer)); } // TODO + else if( strcasecmp(w2,"shop") == 0 ) { DeprecationWarning("npc_parsesrcfile", w2, "shop", filepath, strline(buffer, p-buffer)); } // TODO + else if( strcasecmp(w2,"cashshop") == 0 ) { DeprecationWarning("npc_parsesrcfile", w2, "cashshop", filepath, strline(buffer, p-buffer)); } // TODO + else if( strcasecmp(w2, "script") == 0 ) { DeprecationWarning("npc_parsesrcfile", w2, "script", filepath, strline(buffer, p-buffer)); } // TODO + else if( strncasecmp(w2, "duplicate", 9) == 0 ) { + char temp[10]; + safestrncpy(temp, w2, 10); + DeprecationWarning("npc_parsesrcfile", temp, "duplicate", filepath, strline(buffer, p-buffer)); // TODO + } + else if( strcasecmp(w2,"monster") == 0 ) { DeprecationWarning("npc_parsesrcfile", w2, "monster", filepath, strline(buffer, p-buffer)); } // TODO: + else if( strcasecmp(w2,"boss_monster") == 0 ) { DeprecationWarning("npc_parsesrcfile", w2, "boss_monster", filepath, strline(buffer, p-buffer)); } // TODO + else if( strcasecmp(w2, "mapflag") == 0 ) { DeprecationWarning("npc_parsesrcfile", w2, "mapflag", filepath, strline(buffer, p-buffer)); } // TODO + else +#endif // ENABLE_CASE_CHECK ShowError("npc_parsesrcfile: Unable to parse, probably a missing or extra TAB in file '%s', line '%d'. Skipping line...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,p-buffer), w1, w2, w3, w4); p = strchr(p,'\n');// skip and continue } diff --git a/src/map/script.c b/src/map/script.c index d0b69d594..75ef841d0 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1343,13 +1343,10 @@ const char* parse_syntax(const char* p) switch(*p) { case 'B': case 'b': - if(p2 - p == 5 && !strncasecmp(p,"break",5)) { + if( p2 - p == 5 && strncmp(p,"break",5) == 0 ) { // break Processing char label[256]; int pos = script->syntax.curly_count - 1; -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "break", 5) != 0 ) disp_deprecation_message("parse_syntax", "break", p); // TODO -#endif // ENABLE_CASE_CHECK while(pos >= 0) { if(script->syntax.curly[pos].type == TYPE_DO) { sprintf(label,"goto __DO%x_FIN;",script->syntax.curly[pos].index); @@ -1379,16 +1376,17 @@ const char* parse_syntax(const char* p) // Closing decision if, for , while p = script->parse_syntax_close(p + 1); return p; +#ifdef ENABLE_CASE_CHECK + } else if( p2 - p == 5 && strncasecmp(p, "break", 5) == 0 ) { + disp_deprecation_message("parse_syntax", "break", p); // TODO +#endif // ENABLE_CASE_CHECK } break; case 'c': case 'C': - if(p2 - p == 4 && !strncasecmp(p,"case",4)) { + if( p2 - p == 4 && strncmp(p, "case", 4) == 0 ) { //Processing case int pos = script->syntax.curly_count-1; -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "case", 4) != 0 ) disp_deprecation_message("parse_syntax", "case", p); // TODO -#endif // ENABLE_CASE_CHECK if(pos < 0 || script->syntax.curly[pos].type != TYPE_SWITCH) { disp_error_message("parse_syntax: unexpected 'case' ",p); return p+1; @@ -1461,13 +1459,10 @@ const char* parse_syntax(const char* p) script->syntax.curly[pos].count++; } return p + 1; - } else if(p2 - p == 8 && !strncasecmp(p,"continue",8)) { + } else if( p2 - p == 8 && strncmp(p, "continue", 8) == 0 ) { // Processing continue char label[256]; int pos = script->syntax.curly_count - 1; -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "continue", 8) != 0 ) disp_deprecation_message("parse_syntax", "continue", p); // TODO -#endif // ENABLE_CASE_CHECK while(pos >= 0) { if(script->syntax.curly[pos].type == TYPE_DO) { sprintf(label,"goto __DO%x_NXT;",script->syntax.curly[pos].index); @@ -1495,16 +1490,19 @@ const char* parse_syntax(const char* p) //Closing decision if, for , while p = script->parse_syntax_close(p + 1); return p; +#ifdef ENABLE_CASE_CHECK + } else if( p2 - p == 4 && strncasecmp(p, "case", 4) == 0 ) { + disp_deprecation_message("parse_syntax", "case", p); // TODO + } else if( p2 - p == 8 && strncasecmp(p, "continue", 8) == 0 ) { + disp_deprecation_message("parse_syntax", "continue", p); // TODO +#endif // ENABLE_CASE_CHECK } break; case 'd': case 'D': - if(p2 - p == 7 && !strncasecmp(p,"default",7)) { + if( p2 - p == 7 && strncmp(p, "default", 7) == 0 ) { // Switch - default processing int pos = script->syntax.curly_count-1; -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "default", 7) != 0 ) disp_deprecation_message("parse_syntax", "default", p); // TODO -#endif // ENABLE_CASE_CHECK if(pos < 0 || script->syntax.curly[pos].type != TYPE_SWITCH) { disp_error_message("parse_syntax: unexpected 'default'",p); } else if(script->syntax.curly[pos].flag) { @@ -1536,12 +1534,9 @@ const char* parse_syntax(const char* p) script->syntax.curly[pos].count++; } return p + 1; - } else if(p2 - p == 2 && !strncasecmp(p,"do",2)) { + } else if( p2 - p == 2 && strncmp(p, "do", 2) == 0 ) { int l; char label[256]; -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "do", 2) != 0 ) disp_deprecation_message("parse_syntax", "do", p); // TODO -#endif // ENABLE_CASE_CHECK p=script->skip_space(p2); script->syntax.curly[script->syntax.curly_count].type = TYPE_DO; @@ -1554,17 +1549,20 @@ const char* parse_syntax(const char* p) script->set_label(l,script->pos,p); script->syntax.curly_count++; return p; +#ifdef ENABLE_CASE_CHECK + } else if( p2 - p == 7 && strncasecmp(p, "default", 7) == 0 ) { + disp_deprecation_message("parse_syntax", "default", p); // TODO + } else if( p2 - p == 2 && strncasecmp(p, "do", 2) == 0 ) { + disp_deprecation_message("parse_syntax", "do", p); // TODO +#endif // ENABLE_CASE_CHECK } break; case 'f': case 'F': - if(p2 - p == 3 && !strncasecmp(p,"for",3)) { + if( p2 - p == 3 && strncmp(p, "for", 3) == 0 ) { int l; char label[256]; int pos = script->syntax.curly_count; -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "for", 3) != 0 ) disp_deprecation_message("parse_syntax", "for", p); // TODO -#endif // ENABLE_CASE_CHECK script->syntax.curly[script->syntax.curly_count].type = TYPE_FOR; script->syntax.curly[script->syntax.curly_count].count = 1; script->syntax.curly[script->syntax.curly_count].index = script->syntax.index++; @@ -1635,14 +1633,10 @@ const char* parse_syntax(const char* p) l=script->add_str(label); script->set_label(l,script->pos,p); return p; - } - else if( p2 - p == 8 && strncasecmp(p,"function",8) == 0 ) - {// internal script function + } else if( p2 - p == 8 && strncmp(p, "function", 8) == 0 ) { + // internal script function const char *func_name; -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "function", 8) != 0 ) disp_deprecation_message("parse_syntax", "function", p); // TODO -#endif // ENABLE_CASE_CHECK func_name = script->skip_space(p2); p = script->skip_word(func_name); if( p == func_name ) @@ -1700,16 +1694,19 @@ const char* parse_syntax(const char* p) { disp_error_message("expect ';' or '{' at function syntax",p); } +#ifdef ENABLE_CASE_CHECK + } else if( p2 - p == 3 && strncasecmp(p, "for", 3) == 0 ) { + disp_deprecation_message("parse_syntax", "for", p); // TODO + } else if( p2 - p == 8 && strncasecmp(p, "function", 8) == 0 ) { + disp_deprecation_message("parse_syntax", "function", p); // TODO +#endif // ENABLE_CASE_CHECK } break; case 'i': case 'I': - if(p2 - p == 2 && !strncasecmp(p,"if",2)) { + if( p2 - p == 2 && strncmp(p, "if", 2) == 0 ) { // If process char label[256]; -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "if", 2) != 0 ) disp_deprecation_message("parse_syntax", "if", p); // TODO -#endif // ENABLE_CASE_CHECK p=script->skip_space(p2); if(*p != '(') { //Prevent if this {} non-c script->syntax. from Rayce (jA) disp_error_message("need '('",p); @@ -1727,16 +1724,17 @@ const char* parse_syntax(const char* p) script->addl(script->add_str(label)); script->addc(C_FUNC); return p; +#ifdef ENABLE_CASE_CHECK + } else if( p2 - p == 2 && strncasecmp(p, "if", 2) == 0 ) { + disp_deprecation_message("parse_syntax", "if", p); // TODO +#endif // ENABLE_CASE_CHECK } break; case 's': case 'S': - if(p2 - p == 6 && !strncasecmp(p,"switch",6)) { + if( p2 - p == 6 && strncmp(p, "switch", 6) == 0 ) { // Processing of switch () char label[256]; -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "switch", 6) != 0 ) disp_deprecation_message("parse_syntax", "switch", p); // TODO -#endif // ENABLE_CASE_CHECK p=script->skip_space(p2); if(*p != '(') { disp_error_message("need '('",p); @@ -1757,16 +1755,17 @@ const char* parse_syntax(const char* p) } script->addc(C_FUNC); return p + 1; +#ifdef ENABLE_CASE_CHECK + } else if( p2 - p == 6 && strncasecmp(p, "switch", 6) == 0 ) { + disp_deprecation_message("parse_syntax", "switch", p); // TODO +#endif // ENABLE_CASE_CHECK } break; case 'w': case 'W': - if(p2 - p == 5 && !strncasecmp(p,"while",5)) { + if( p2 - p == 5 && strncmp(p, "while", 5) == 0 ) { int l; char label[256]; -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "while", 5) != 0 ) disp_deprecation_message("parse_syntax", "while", p); // TODO -#endif // ENABLE_CASE_CHECK p=script->skip_space(p2); if(*p != '(') { disp_error_message("need '('",p); @@ -1790,6 +1789,10 @@ const char* parse_syntax(const char* p) script->addl(script->add_str(label)); script->addc(C_FUNC); return p; +#ifdef ENABLE_CASE_CHECK + } else if( p2 - p == 5 && strncasecmp(p, "while", 5) == 0 ) { + disp_deprecation_message("parse_syntax", "while", p); // TODO +#endif // ENABLE_CASE_CHECK } break; } @@ -1840,14 +1843,11 @@ const char* parse_syntax_close_sub(const char* p,int* flag) script->syntax.curly[pos].count++; p = script->skip_space(p); p2 = script->skip_word(p); - if(!script->syntax.curly[pos].flag && p2 - p == 4 && !strncasecmp(p,"else",4)) { -#ifdef ENABLE_CASE_CHECK - if( strncmp(p, "else", 4) != 0 ) disp_deprecation_message("parse_syntax", "else", p); // TODO -#endif // ENABLE_CASE_CHECK + if( !script->syntax.curly[pos].flag && p2 - p == 4 && strncmp(p, "else", 4) == 0 ) { // else or else - if p = script->skip_space(p2); p2 = script->skip_word(p); - if(p2 - p == 2 && !strncasecmp(p,"if",2)) { + if( p2 - p == 2 && strncmp(p, "if", 2) == 0 ) { // else - if p=script->skip_space(p2); if(*p != '(') { @@ -1862,6 +1862,10 @@ const char* parse_syntax_close_sub(const char* p,int* flag) script->addc(C_FUNC); *flag = 0; return p; +#ifdef ENABLE_CASE_CHECK + } else if( p2 - p == 2 && strncasecmp(p, "if", 2) == 0 ) { + disp_deprecation_message("parse_syntax", "if", p); // TODO +#endif // ENABLE_CASE_CHECK } else { // else if(!script->syntax.curly[pos].flag) { @@ -1870,6 +1874,10 @@ const char* parse_syntax_close_sub(const char* p,int* flag) return p; } } +#ifdef ENABLE_CASE_CHECK + } else if( !script->syntax.curly[pos].flag && p2 - p == 4 && strncasecmp(p, "else", 4) == 0 ) { + disp_deprecation_message("parse_syntax", "else", p); // TODO +#endif // ENABLE_CASE_CHECK } // Close if script->syntax.curly_count--; @@ -1897,12 +1905,13 @@ const char* parse_syntax_close_sub(const char* p,int* flag) // Skip to the end point if the condition is false p = script->skip_space(p); p2 = script->skip_word(p); - if(p2 - p != 5 || strncasecmp(p,"while",5)) - disp_error_message("parse_syntax: need 'while'",p); - + if( p2 - p != 5 || strncmp(p, "while", 5) != 0 ) { #ifdef ENABLE_CASE_CHECK - if( strncmp(p, "while", 5) != 0 ) disp_deprecation_message("parse_syntax", "while", p); // TODO + if( p2 - p == 5 && strncasecmp(p, "while", 5) == 0 ) disp_deprecation_message("parse_syntax", "while", p); // TODO #endif // ENABLE_CASE_CHECK + disp_error_message("parse_syntax: need 'while'",p); + } + p = script->skip_space(p2); if(*p != '(') { disp_error_message("need '('",p); @@ -2295,7 +2304,7 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o disp_error_message("unexpected end of script",p); // Special handling only label tmpp=script->skip_space(script->skip_word(p)); - if(*tmpp==':' && !(!strncasecmp(p,"default:",8) && p + 7 == tmpp)){ + if(*tmpp==':' && !(strncmp(p,"default:",8) == 0 && p + 7 == tmpp)) { i=script->add_word(p); script->set_label(i,script->pos,p); if( script->parse_options&SCRIPT_USE_LABEL_DB ) diff --git a/src/map/script.h b/src/map/script.h index 75a57d82b..aace388ff 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -22,9 +22,9 @@ struct eri; **/ // TODO: Remove temporary code #define ENABLE_CASE_CHECK -#define DeprecationWarning(func, bad, good, file, line) ShowWarning("%s: use of deprecated keyword '%s' (use '%s' instead) in file '%s', line '%d'. This will be a critical error in a near future.\n", (func), (bad), (good), (file), (line)); +#define DeprecationWarning(func, bad, good, file, line) ShowWarning("%s: use of deprecated keyword '%s' (use '%s' instead) in file '%s', line '%d'.\n", (func), (bad), (good), (file), (line)); #define DeprecationWarning2(func, bad, good, where) ShowWarning("%s: detected possible use of wrong case in a script. Found '%s', probably meant to be '%s' (in '%s'). This will become fatal in a near future.\n", (func), (bad), (good), (where)); -#define disp_deprecation_message(func, good, p) disp_warning_message(func": use of deprecated keyword (use '"good"' instead). This will be a critical error in a near future.", (p)); +#define disp_deprecation_message(func, good, p) disp_warning_message(func": use of deprecated keyword (use '"good"' instead).", (p)); #define NUM_WHISPER_VAR 10 -- cgit v1.2.3-60-g2f50