diff options
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/acr.cc | 8 | ||||
-rw-r--r-- | crawl-ref/source/initfile.cc | 93 | ||||
-rw-r--r-- | crawl-ref/source/initfile.h | 3 | ||||
-rwxr-xr-x | crawl-ref/source/misc/grind.sh | 3 |
4 files changed, 103 insertions, 4 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 3349f7f0fe..9873519f4c 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -309,6 +309,14 @@ static void _show_commandline_options_help() puts("Command line options override init file options, which override"); puts("environment options (CRAWL_NAME, CRAWL_DIR, CRAWL_RC)."); puts(""); + + puts(" -extra-opt-first optname=optval"); + puts(" -extra-opt-last optname=optval"); + puts(""); + puts("Acts as if 'optname=optval' was at the top or bottom of the init"); + puts("file. Can be used multiple times."); + puts(""); + puts("Highscore list options: (Can be redirected to more, etc.)"); puts(" -scores [N] highscore list"); puts(" -tscores [N] terse highscore list"); diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 1ddbd0ed5b..d55bfd5e0c 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -1307,6 +1307,15 @@ std::string read_init_file(bool runscript) { Options.reset_options(); + Options.filename = "extra opts first"; + Options.basefilename = "extra opts first"; + Options.line_num = 0; + for (unsigned int i = 0; i < SysEnv.extra_opts_first.size(); i++) + { + Options.line_num++; + Options.read_option_line(SysEnv.extra_opts_first[i], true); + } + const std::string init_file_name( _find_crawlrc() ); FILE* f = fopen(init_file_name.c_str(), "r"); @@ -1333,9 +1342,18 @@ std::string read_init_file(bool runscript) read_options(f, runscript); fclose(f); - Options.filename = "unknown"; + Options.filename = "extra opts last"; + Options.basefilename = "extra opts last"; + Options.line_num = 0; + for (unsigned int i = 0; i < SysEnv.extra_opts_last.size(); i++) + { + Options.line_num++; + Options.read_option_line(SysEnv.extra_opts_last[i], false); + } + + Options.filename = "unknown"; Options.basefilename = "unknown"; - Options.line_num = -1; + Options.line_num = -1; return (""); } @@ -3533,6 +3551,8 @@ enum commandline_option_type { CLO_TEST, CLO_HELP, CLO_VERSION, + CLO_EXTRA_OPT_FIRST, + CLO_EXTRA_OPT_LAST, CLO_NOPS }; @@ -3540,7 +3560,8 @@ enum commandline_option_type { static const char *cmd_ops[] = { "scores", "name", "species", "job", "plain", "dir", "rc", "rcdir", "tscores", "vscores", "scorefile", "morgue", "macro", - "mapstat", "arena", "test", "help", "version" + "mapstat", "arena", "test", "help", "version", "extra-opt-first", + "extra-opt-last" }; const int num_cmd_ops = CLO_NOPS; @@ -3580,6 +3601,44 @@ static void _print_version() printf("%s", compilation_info().c_str()); } +static bool _check_extra_opt(char* _opt) +{ + std::string opt(_opt); + trim_string(opt); + + if (opt[0] == ':' || opt[0] == '<' || opt[0] == '{' + || starts_with(opt, "L<") || starts_with(opt, "Lua{")) + { + fprintf(stderr, "An extra option can't use Lua (%s)\n", + _opt); + return (false); + } + + if (opt[0] == '#') + { + fprintf(stderr, "An extra option can't be a comment (%s)\n", + _opt); + return (false); + } + + if (opt.find_first_of('=') == std::string::npos) + { + fprintf(stderr, "An extra opt must contain a '=' (%s)\n", + _opt); + return (false); + } + + std::vector<std::string> parts = split_string(opt, "="); + if (opt.find_first_of('=') == 0 || parts[0].length() == 0) + { + fprintf(stderr, "An extra opt must have an option name (%s)\n", + _opt); + return (false); + } + + return (true); +} + bool parse_args( int argc, char **argv, bool rc_only ) { COMPILE_CHECK(ARRAYSZ(cmd_ops) == CLO_NOPS, c1); @@ -3828,6 +3887,34 @@ bool parse_args( int argc, char **argv, bool rc_only ) case CLO_VERSION: _print_version(); end(0); + + case CLO_EXTRA_OPT_FIRST: + if (!next_is_param) + return (false); + + if (!_check_extra_opt(next_arg)) + // Don't print the help message if the opt was wrong + return (true); + SysEnv.extra_opts_first.push_back(next_arg); + nextUsed = true; + + // Can be used multiple times. + arg_seen[o] = false; + break; + + case CLO_EXTRA_OPT_LAST: + if (!next_is_param) + return false; + + if (!_check_extra_opt(next_arg)) + // Don't print the help message if the opt was wrong + return (true); + SysEnv.extra_opts_last.push_back(next_arg); + nextUsed = true; + + // Can be used multiple times. + arg_seen[o] = false; + break; } // Update position. diff --git a/crawl-ref/source/initfile.h b/crawl-ref/source/initfile.h index acc5b27111..84e29ffe5c 100644 --- a/crawl-ref/source/initfile.h +++ b/crawl-ref/source/initfile.h @@ -74,6 +74,9 @@ public: std::string arena_teams; + std::vector<std::string> extra_opts_first; + std::vector<std::string> extra_opts_last; + public: void add_rcdir(const std::string &dir); }; diff --git a/crawl-ref/source/misc/grind.sh b/crawl-ref/source/misc/grind.sh index e23f13df70..fa4df0201b 100755 --- a/crawl-ref/source/misc/grind.sh +++ b/crawl-ref/source/misc/grind.sh @@ -3,4 +3,5 @@ # Convenience caller for the valgrind memory debugger nice -n 7 valgrind --tool=memcheck --leak-check=full --log-file=grind.log \ - --suppressions=misc/valgrind-suppress.txt ./crawl "$@" + --suppressions=misc/valgrind-suppress.txt \ + ./crawl -extra-opt-first grind=true "$@" |