diff options
author | Haru <haru@dotalux.com> | 2013-11-10 05:22:30 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2013-11-10 05:22:30 +0100 |
commit | dd05ae388d69e7df1dffcd393cea5e4cdc605e75 (patch) | |
tree | ac7454f83fb9d4e2adee0fed59c97c95e569da49 | |
parent | f7f10cf7bb600b6871ed37f493fef18110dc182b (diff) | |
download | hercules-dd05ae388d69e7df1dffcd393cea5e4cdc605e75.tar.gz hercules-dd05ae388d69e7df1dffcd393cea5e4cdc605e75.tar.bz2 hercules-dd05ae388d69e7df1dffcd393cea5e4cdc605e75.tar.xz hercules-dd05ae388d69e7df1dffcd393cea5e4cdc605e75.zip |
Added deprecation messages for incorrect capitalization in scripts
- These messages are temporary, only meant to help those with custom
scripts to transition them to the correct case-sensitive syntax. If
you ignore the deprecation messages you encounter, your scripts may
continue to work just as they did until now, but this will no longer
be true in the near future, and they may stop working at any time.
If you ignore this, and your scripts break, you'll get to keep the
pieces :)
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | src/map/npc.c | 25 | ||||
-rw-r--r-- | src/map/script.c | 59 | ||||
-rw-r--r-- | src/map/script.h | 6 |
3 files changed, 87 insertions, 3 deletions
diff --git a/src/map/npc.c b/src/map/npc.c index 03e4aa9fa..5ca96d587 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -3627,14 +3627,25 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit) { if( strcasecmp(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 ) { +#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 ) { +#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 +#endif // ENABLE_CASE_CHECK if( strcasecmp(w1,"function") == 0 ) p = npc->parse_function(w1, w2, w3, w4, p, buffer, filepath); else @@ -3642,14 +3653,25 @@ int npc_parsesrcfile(const char* filepath, bool 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 ) { +#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 ) { +#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 @@ -3719,6 +3741,9 @@ void npc_read_event_script(void) if( (p=strchr(p,':')) && p && strcmpi(name,p)==0 ) { +#ifdef ENABLE_CASE_CHECK + if( strcmp(name, p) != 0 ) DeprecationWarning2("npc_read_event_script", p, name, config[i].event_name); // TODO +#endif // ENABLE_CASE_CHECK script_event[i].event[count] = ed; script_event[i].event_name[count] = key.str; script_event[i].event_count++; diff --git a/src/map/script.c b/src/map/script.c index 1b5d888a4..ef3fbebd9 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -347,9 +347,18 @@ int script_search_str(const char* p) { int i; - for( i = script->str_hash[script->calc_hash(p)]; i != 0; i = script->str_data[i].next ) - if( strcasecmp(script->get_str(i),p) == 0 ) + for( i = script->str_hash[script->calc_hash(p)]; i != 0; i = script->str_data[i].next ) { + if( strcasecmp(script->get_str(i),p) == 0 ) { +#ifdef ENABLE_CASE_CHECK + if( strcasecmp(p, "disguise") != 0 && strcasecmp(p, "Poison_Spore") != 0 + && strcasecmp(p, "PecoPeco_Egg") != 0 && strcasecmp(p, "Soccer_Ball") != 0 + && strcasecmp(p, "Horn") != 0 && strcasecmp(p, "Treasure_Box_") != 0 + && strcasecmp(p, "Lord_of_Death") != 0 + && strcmp(script->get_str(i),p) != 0 ) DeprecationWarning2("script_search_str", p, script->get_str(i), "source not found"); +#endif // ENABLE_CASE_CHECK return i; + } + } return -1; } @@ -367,8 +376,16 @@ int script_add_str(const char* p) script->str_hash[h] = script->str_num; } else {// scan for end of list, or occurence of identical string for( i = script->str_hash[h]; ; i = script->str_data[i].next ) { - if( strcasecmp(script->get_str(i),p) == 0 ) + if( strcasecmp(script->get_str(i),p) == 0 ) { +#ifdef ENABLE_CASE_CHECK + if( strcasecmp(p, "disguise") != 0 && strcasecmp(p, "Poison_Spore") != 0 + && strcasecmp(p, "PecoPeco_Egg") != 0 && strcasecmp(p, "Soccer_Ball") != 0 + && strcasecmp(p, "Horn") != 0 && strcasecmp(p, "Treasure_Box_") != 0 + && strcasecmp(p, "Lord_of_Death") != 0 + && strcmp(script->get_str(i),p) != 0 ) DeprecationWarning2("script_add_str", p, script->get_str(i), "source not found"); // TODO +#endif // ENABLE_CASE_CHECK return i; // string already in list + } if( script->str_data[i].next == 0 ) break; // reached the end } @@ -1207,6 +1224,9 @@ const char* parse_syntax(const char* p) // 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); @@ -1243,6 +1263,9 @@ const char* parse_syntax(const char* p) if(p2 - p == 4 && !strncasecmp(p,"case",4)) { //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; @@ -1319,6 +1342,9 @@ const char* parse_syntax(const char* p) // 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); @@ -1353,6 +1379,9 @@ const char* parse_syntax(const char* p) if(p2 - p == 7 && !strncasecmp(p,"default",7)) { // 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) { @@ -1387,6 +1416,9 @@ const char* parse_syntax(const char* p) } else if(p2 - p == 2 && !strncasecmp(p,"do",2)) { 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; @@ -1407,6 +1439,9 @@ const char* parse_syntax(const char* p) 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++; @@ -1482,6 +1517,9 @@ const char* parse_syntax(const char* p) {// 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 ) @@ -1546,6 +1584,9 @@ const char* parse_syntax(const char* p) if(p2 - p == 2 && !strncasecmp(p,"if",2)) { // 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); @@ -1570,6 +1611,9 @@ const char* parse_syntax(const char* p) if(p2 - p == 6 && !strncasecmp(p,"switch",6)) { // 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); @@ -1597,6 +1641,9 @@ const char* parse_syntax(const char* p) if(p2 - p == 5 && !strncasecmp(p,"while",5)) { 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); @@ -1671,6 +1718,9 @@ const char* parse_syntax_close_sub(const char* p,int* flag) 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 // else or else - if p = script->skip_space(p2); p2 = script->skip_word(p); @@ -1727,6 +1777,9 @@ const char* parse_syntax_close_sub(const char* p,int* flag) if(p2 - p != 5 || strncasecmp(p,"while",5)) disp_error_message("parse_syntax: need 'while'",p); +#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); diff --git a/src/map/script.h b/src/map/script.h index 7fa8b92e4..bcc524401 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -20,6 +20,12 @@ struct eri; /** * Defines **/ +// 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 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'). If it is a local (.@) variable, and you're absolutely sure you used the correct case, please disragard this message, otherwise please correct your scripts, as 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 NUM_WHISPER_VAR 10 /// Maximum amount of elements in script arrays (soon getting ducked) |