From 3d8b6671b394ef6c4c5df3065a6123a5d6cacb93 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sun, 26 Jan 2014 14:03:20 -0800 Subject: Also do db/const.txt and data/resnametable.txt --- src/common/mmo.hpp | 2 -- src/login/login.cpp | 2 +- src/map/grfio.cpp | 23 +++++++++++++---------- src/map/grfio.hpp | 2 ++ src/map/magic-interpreter-lexer.lpp | 2 +- src/map/magic-interpreter-parser.ypp | 6 ++++++ src/map/magic.hpp | 2 -- src/map/map.cpp | 5 +++++ src/map/script.cpp | 20 ++++++++++---------- src/map/script.hpp | 2 ++ 10 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp index 178bb08..8b18181 100644 --- a/src/common/mmo.hpp +++ b/src/common/mmo.hpp @@ -41,8 +41,6 @@ constexpr int MAX_PARTY = 12; # define MIN_CLOTH_COLOR battle_config.min_cloth_color # define MAX_CLOTH_COLOR battle_config.max_cloth_color -# define CHAR_CONF_NAME "conf/char_athena.conf" - struct AccountName : VString<23> {}; struct AccountPass : VString<23> {}; struct AccountCrypt : VString<39> {}; diff --git a/src/login/login.cpp b/src/login/login.cpp index ea2d19c..beb09c2 100644 --- a/src/login/login.cpp +++ b/src/login/login.cpp @@ -90,7 +90,7 @@ ServerName main_server; static FString account_filename = "save/account.txt"; static -FString gm_account_filename = "conf/GM_account.txt"; +FString gm_account_filename = "save/gm_account.txt"; static FString login_log_filename = "log/login.log"; static diff --git a/src/map/grfio.cpp b/src/map/grfio.cpp index c5a55f5..ff73c90 100644 --- a/src/map/grfio.cpp +++ b/src/map/grfio.cpp @@ -23,16 +23,18 @@ #include "../poison.hpp" static -std::map load_resnametable() +std::map resnametable; + +bool load_resnametable(ZString filename) { - io::ReadFile in("data/resnametable.txt"); + io::ReadFile in(filename); if (!in.is_open()) { - fprintf(stderr, "Missing data/resnametable.txt"); - abort(); + FPRINTF(stderr, "Missing %s\n", filename); + return false; } - std::map out; + bool rv = true; FString line; while (in.getline(line)) { @@ -40,19 +42,20 @@ std::map load_resnametable() FString value; if (!extract(line, record<'#'>(&key, &value))) + { + PRINTF("Bad resnametable line: %s\n", line); + rv = false; continue; - out[key] = value; + } + resnametable[key] = value; } - return out; + return rv; } /// Change *.gat to *.wlk static FString grfio_resnametable(MapName rname) { - static - std::map resnametable = load_resnametable(); - return resnametable.at(rname); } diff --git a/src/map/grfio.hpp b/src/map/grfio.hpp index 17acfb6..3fde76a 100644 --- a/src/map/grfio.hpp +++ b/src/map/grfio.hpp @@ -7,6 +7,8 @@ # include "../common/mmo.hpp" +bool load_resnametable(ZString filename); + /// Load a resource into memory, subject to data/resnametable.txt. /// Normally, resourcename is xxx-y.gat and the file is xxx-y.wlk. /// Currently there is exactly one .wlk per .gat, but multiples are fine. diff --git a/src/map/magic-interpreter-lexer.lpp b/src/map/magic-interpreter-lexer.lpp index 83cb36f..38b7b1e 100644 --- a/src/map/magic-interpreter-lexer.lpp +++ b/src/map/magic-interpreter-lexer.lpp @@ -146,7 +146,7 @@ "#".*$ /* Ignore comments */ "//".*$ /* Ignore comments */ [ \n\t\r] /* ignore whitespace */ -. FPRINTF(stderr, "%s: Unexpected character in line %d\n", MAGIC_CONFIG_FILE, magic_frontend_lineno); +. FPRINTF(stderr, "%s: Unexpected character in line %d\n", current_magic_filename, magic_frontend_lineno); %% // nothing to see here, move along diff --git a/src/map/magic-interpreter-parser.ypp b/src/map/magic-interpreter-parser.ypp index 0e03afb..a86f1c8 100644 --- a/src/map/magic-interpreter-parser.ypp +++ b/src/map/magic-interpreter-parser.ypp @@ -1,6 +1,9 @@ %code requires { #include "magic-interpreter.hpp" + +extern +FString current_magic_filename; } // %code requires %code @@ -20,6 +23,8 @@ #include "itemdb.hpp" #include "magic-expr.hpp" +FString current_magic_filename; + // can't use src/warnings.hpp in generated code #pragma GCC diagnostic warning "-Wall" #pragma GCC diagnostic warning "-Wextra" @@ -1411,6 +1416,7 @@ bool magic_init0() // must be called after itemdb initialisation bool magic_init1(ZString conffile) { + current_magic_filename = conffile; magic_frontend_in = fopen(conffile.c_str(), "r"); if (!magic_frontend_in) { diff --git a/src/map/magic.hpp b/src/map/magic.hpp index 30c6e62..5d4e517 100644 --- a/src/map/magic.hpp +++ b/src/map/magic.hpp @@ -8,8 +8,6 @@ # include "map.hpp" # include "skill.t.hpp" -# define MAGIC_CONFIG_FILE "conf/magic.conf" - struct invocation; /* Spell invocation */ /** diff --git a/src/map/map.cpp b/src/map/map.cpp index e141ae1..d2b604f 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -1656,6 +1656,11 @@ bool map_confs(XString key, ZString value) return skill_readdb(value); if (key == "magic_conf") return magic_init1(value); + + if (key == "resnametable") + return load_resnametable(value); + if (key == "const_db") + return read_constdb(value); PRINTF("unknown map conf key: %s\n", FString(key)); return false; } diff --git a/src/map/script.cpp b/src/map/script.cpp index 51f228f..279e541 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -689,20 +689,16 @@ void add_builtin_functions(void) } } -/*========================================== - * 定数データベースの読み込み - *------------------------------------------ - */ -static -void read_constdb(void) +bool read_constdb(ZString filename) { - io::ReadFile in("db/const.txt"); + io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("can't read db/const.txt\n"); - return; + PRINTF("can't read %s\n", filename); + return false; } + bool rv = true; FString line; while (in.getline(line)) { @@ -714,11 +710,16 @@ void read_constdb(void) int type = 0; // if not provided // TODO get rid of SSCANF - this is the last serious use if (SSCANF(line, "%m[A-Za-z0-9_] %i %i", &name, &val, &type) < 2) + { + PRINTF("Bad const line: %s\n", line); + rv = false; continue; + } str_data_t *n = add_strp(name); n->type = type ? ByteCode::PARAM_ : ByteCode::INT; n->val = val; } + return rv; } std::unique_ptr parse_script(ZString src, int line) @@ -739,7 +740,6 @@ void ScriptBuffer::parse_script(ZString src, int line) if (first) { add_builtin_functions(); - read_constdb(); } first = 0; LABEL_NEXTLINE_.type = ByteCode::NOP; diff --git a/src/map/script.hpp b/src/map/script.hpp index a05ecf6..ec52f65 100644 --- a/src/map/script.hpp +++ b/src/map/script.hpp @@ -166,4 +166,6 @@ extern FString mapreg_txt; extern int script_errors; +bool read_constdb(ZString filename); + #endif // SCRIPT_HPP -- cgit v1.2.3-60-g2f50