summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-10-23 22:28:14 -0700
committerMatthew Cline <zelgadis@sourceforge.net>2009-10-23 22:28:14 -0700
commit9c08ad575dfa4fbfcbdff5280a582a7846094f60 (patch)
tree576b45acc07815c4413b8f4c920db7ce47ee5df6
parent068459aa20c4a7c7abb759ca42a1caabf3e58750 (diff)
downloadcrawl-ref-9c08ad575dfa4fbfcbdff5280a582a7846094f60.tar.gz
crawl-ref-9c08ad575dfa4fbfcbdff5280a582a7846094f60.zip
Specify arbitrary options on the command line
This introduces two new command line options, -extra-opt-first and -extra-opt-last, which make crawl think that the specified options were (respectively) at the start and end of the options file. For example: crawl -extra-opt-last wiz_mode=yes The two options can be used multiple times to specify multiple options.
-rw-r--r--crawl-ref/docs/options_guide.txt53
-rw-r--r--crawl-ref/source/acr.cc8
-rw-r--r--crawl-ref/source/initfile.cc93
-rw-r--r--crawl-ref/source/initfile.h3
-rwxr-xr-xcrawl-ref/source/misc/grind.sh3
5 files changed, 149 insertions, 11 deletions
diff --git a/crawl-ref/docs/options_guide.txt b/crawl-ref/docs/options_guide.txt
index 65ea8d1def..d992fd7b27 100644
--- a/crawl-ref/docs/options_guide.txt
+++ b/crawl-ref/docs/options_guide.txt
@@ -10,8 +10,9 @@ The contents of this text are:
0- Generalities.
0-a Standard and additional option files.
-0-b Options and how to set them.
-0-c Aliases and variables.
+0-b Options on the command line
+0-c Options and how to set them.
+0-d Aliases and variables.
1- Starting Screen.
name, remember_name, use_old_selection_order,
weapon, book, wand, chaos_knight, death_knight, priest,
@@ -125,7 +126,7 @@ The contents of this text are:
7- Inline Lua.
7-a Executing lua.
7-b Conditional options.
-7-c Including external files.
+7-c Conditional option caveats.
------------------------------------------------------------------------
@@ -162,7 +163,21 @@ additional option files coming with this release; these allow to set
many options to old defaults, i.e. those of Crawl 0.3.4 and before.
See the header of the default init.txt for more details.
-0-b Options and how to set them.
+0-b Options on the command line
+-----------------------------------
+
+A quick way to make small changes to the options, without having to
+switch to a different option file, is to use the command line options
+-extra-opt-first or -extra-opt-last, which make it as if the given
+option was (repsecitvely) at the top or bottom of the option file. For
+example,
+
+ -extra-opt-last wiz_mode=yes
+
+will cause any new game to start in wizard mode. -extra-opt-first and
+-extra-opt-last can be used multiple times on the same command line.
+
+0-c Options and how to set them.
------------------------------------
There are three broad types of Crawl options: true/false values
@@ -208,7 +223,7 @@ are as follows:
and, for Tiles,
tile_tag_pref = tutorial
-0-c Aliases and variables.
+0-d Aliases and variables.
------------------------------
For long option names, you can define option aliases by doing:
@@ -2125,7 +2140,7 @@ function ch_autopickup(it) [ ... body omitted ... ] end
You can use Lua to selectively include parts of your init.txt (based
on character type, for instance) using the same syntax.
-Examples:
+Example:
: if you.race() == "Mummy" then
autopickup = $?+"/
@@ -2133,6 +2148,27 @@ autopickup = $?+"/
autopickup = $?+"/!%
: end
+Options can be rerefenced by lua via "options.option_name". For
+example:
+
+:if string.find(options.autopickup, "!") then
+# Do something here if potions are included in autopickup
+:end
+
+"options.option_name" can even be used for options that crawl itself
+doesn't recognize. This can be combined with setting options on the
+command line (see section 0-b) to use the command line to control
+conditionalization of options in the options files. For example, on the
+command line you could set the option "foobar" with "-extra-opt-first
+foobar=true", and then do:
+
+:if options.foobar then
+# Do things here
+:end
+
+7-c Conditional option caveats.
+-----------------------------------
+
Note that none of the options listed under "Starting Screen" (section 1)
can be set conditionally. This is because the options files are
actually read in twice: once before character creation with Lua turned
@@ -2141,4 +2177,7 @@ you attempt to set a starting-screen option conditionally then the value
furthest down in the options file will be used regardless of what
conditions you set.
-The above caveat applies to the "wiz_mode" option as well.
+The above caveat applies to the "wiz_mode" option as well. Instead of
+conditionalized wiz_mode, you can add to the command line
+"-extra-opt-last wiz_mode=yes" to make any new game start in wizard
+mode.
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 "$@"