From 8b41b24415d56a008530a549e7df31b730d5d96c Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 27 Jun 2013 19:55:18 -0700 Subject: Make callfunc/callsub in an if an error Also make all errors fatal and clean up messages a bit. --- src/map/npc.cpp | 6 ++++++ src/map/script.cpp | 12 ++++++++++-- src/map/script.hpp | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 37f3f62..68b5ad7 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -1800,5 +1800,11 @@ int do_init_npc(void) PRINTF("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d] %20s\n", npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob, ""); + if (script_errors) + { + PRINTF("Cowardly refusing to continue after %d errors\n", script_errors); + abort(); + } + return 0; } diff --git a/src/map/script.cpp b/src/map/script.cpp index 8957e60..854a42f 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -325,6 +325,7 @@ const char *startptr; static int startline; +int script_errors = 0; /*========================================== * エラーメッセージ出力 *------------------------------------------ @@ -332,6 +333,8 @@ int startline; static void disp_error_message(const char *mes, const char *pos_) { + script_errors++; + int line; const char *p; @@ -348,7 +351,7 @@ void disp_error_message(const char *mes, const char *pos_) } if (lineend == NULL || pos_ < lineend) { - PRINTF("%s line %d : ", mes, line); + PRINTF("\n%s\nline %d : ", mes, line); for (int i = 0; (linestart[i] != '\r') && (linestart[i] != '\n') && linestart[i]; i++) @@ -432,7 +435,12 @@ const char *ScriptBuffer::parse_simpleexpr(const char *p) disp_error_message("unexpected character", p); exit(1); } - str_data_t *ld = add_strp(std::string(p, p2)); + std::string word(p, p2); + if (parse_cmd_if && (word == "callsub" || word == "callfunc")) + { + disp_error_message("callsub/callfunc not allowed in an if statement", p); + } + str_data_t *ld = add_strp(word); parse_cmdp = ld; // warn_*_mismatch_paramnumのために必要 // why not just check l->str == "if" or std::string(p, p2) == "if"? diff --git a/src/map/script.hpp b/src/map/script.hpp index 0e63add..66939aa 100644 --- a/src/map/script.hpp +++ b/src/map/script.hpp @@ -157,4 +157,6 @@ void do_final_script(void); extern char mapreg_txt[256]; +extern int script_errors; + #endif // SCRIPT_HPP -- cgit v1.2.3-60-g2f50