Author: zaroth
Date: Thu Jun 9 11:52:39 2011
New Revision: 49807
URL: http://svn.gna.org/viewcvs/wesnoth?rev=49807&view=rev
Log:
Added logdomains, preprocess-output-macros and rng-seed to
commandline_options.
Modified:
trunk/src/commandline_options.cpp
trunk/src/commandline_options.hpp
trunk/src/game.cpp
trunk/src/tests/test_commandline_options.cpp
Modified: trunk/src/commandline_options.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/commandline_options.cpp?rev=49807&r1=49806&r2=49807&view=diff
==============================================================================
--- trunk/src/commandline_options.cpp (original)
+++ trunk/src/commandline_options.cpp Thu Jun 9 11:52:39 2011
@@ -103,9 +103,12 @@
("gzip", po::value<std::string>(), "compresses a file (<arg>)
in gzip format, stores it as <arg>.gz and removes <arg>.")
("help,h", "prints this message and exits.")
("load,l", po::value<std::string>(), "loads the save <arg> from
the standard save game directory.\nWhen launching the map editor via -e, the
map <arg> is loaded, relative to the current directory. If it is a directory,
the editor will start with a load map dialog opened there.")
+ ("logdomains",
po::value<std::string>()->implicit_value(std::string()), "lists defined log
domains (only the ones containing <arg> filter if provided) and exits.")
("new-syntax", "enables the new campaign syntax parsing.")
("nocache", "disables caching of game data.")
("path", "prints the path to the data directory and exits.")
+ ("preprocess-output-macros",
po::value<std::string>()->implicit_value(std::string()), "used only by the
'--preprocess' command. Will output all preprocessed macros in the target file
<arg>. If the file is not specified the output will be file '_MACROS_.cfg' in
the target directory of preprocess's command.")
+ ("rng-seed", po::value<unsigned int>(), "seeds the random
number generator with number <arg>. Example: --rng-seed 0")
("validcache", "assumes that the cache is valid. (dangerous)")
("version,v", "prints the game's version number and exits.")
("with-replay", "replays the file loaded with the --load
option.")
@@ -156,6 +159,8 @@
help = true;
if (vm.count("load"))
load = vm["load"].as<std::string>();
+ if (vm.count("logdomains"))
+ logdomains = vm["logdomains"].as<std::string>();
if (vm.count("max-fps"))
max_fps = vm["max-fps"].as<int>();
if (vm.count("multiplayer"))
@@ -170,6 +175,10 @@
nocache = true;
if (vm.count("path"))
path = true;
+ if (vm.count("preprocess-output-macros"))
+ preprocess_output_macros =
vm["preprocess-output-macros"].as<std::string>();
+ if (vm.count("rng-seed"))
+ rng_seed = vm["rng-seed"].as<unsigned int>();
if (vm.count("validcache"))
validcache = true;
if (vm.count("version"))
Modified: trunk/src/commandline_options.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/commandline_options.hpp?rev=49807&r1=49806&r2=49807&view=diff
==============================================================================
--- trunk/src/commandline_options.hpp (original)
+++ trunk/src/commandline_options.hpp Thu Jun 9 11:52:39 2011
@@ -122,7 +122,7 @@
boost::optional<std::string> preprocess_output_macros;
/// Path to parse that was given to the --preprocess option.
boost::optional<std::string> preprocess_path;
- /// Target (output) path tha was given to the --preprocess option.
+ /// Target (output) path that was given to the --preprocess option.
boost::optional<std::string> preprocess_target;
/// True if --proxy was given on the command line. Enables proxy mode.
bool proxy;
@@ -137,7 +137,7 @@
/// Pair of AxB values specified after --resolution. Changes Wesnoth
resolution.
boost::optional<boost::tuple<int,int> > resolution;
/// RNG seed specified by --rng-seed option. Initializes RNG with given
seed.
- boost::optional<int> rng_seed;
+ boost::optional<unsigned int> rng_seed;
/// Non-empty if --server was given on the command line. Connects
Wesnoth to specified server. If no server was specified afterwards, contains an
empty string.
boost::optional<std::string> server;
/// True if --screenshot was given on the command line. Starts Wesnoth
in screenshot mode.
Modified: trunk/src/game.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=49807&r1=49806&r2=49807&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Thu Jun 9 11:52:39 2011
@@ -213,12 +213,25 @@
std::cout << cmdline_opts;
return 0;
}
+ if(cmdline_opts.logdomains) {
+ std::cout << lg::list_logdomains(*cmdline_opts.logdomains);
+ return 0;
+ }
if(cmdline_opts.new_syntax) {
game_config::new_syntax = true;
}
if(cmdline_opts.path) {
std::cout << game_config::path << "\n";
return 0;
+ }
+ if (cmdline_opts.preprocess_output_macros) {
+ if (cmdline_opts.preprocess_output_macros->empty())
+ preproc.output_macros_path_ = "true";
+ else
+ preproc.output_macros_path_ =
*cmdline_opts.preprocess_output_macros;
+ }
+ if(cmdline_opts.rng_seed) {
+ srand(*cmdline_opts.rng_seed);
}
if(cmdline_opts.version) {
std::cout << "Battle for Wesnoth" << " " <<
game_config::version << "\n";
@@ -263,20 +276,6 @@
}
p = q;
}
- } else if(val == "--logdomains") {
- std::string filter;
- if(arg + 1 != argc) {
- ++arg;
- filter = argv[arg];
- }
- std::cout << lg::list_logdomains(filter);
- return 0;
- } else if(val == "--rng-seed") {
- if (argc <= ++arg) {
- std::cerr << "format of \" " << val << " " <<
argv[arg] << " \" is bad\n";
- return 2;
- }
- srand(lexical_cast_default<unsigned int>(argv[arg]));
} else if (val == "--preprocess-input-macros") {
if (arg + 1 < argc)
{
@@ -307,13 +306,6 @@
else {
std::cerr << "please specify input macros
file.\n";
return 2;
- }
- } else if (val == "--preprocess-output-macros") {
- preproc.output_macros_path_ = "true";
- if (arg + 1 < argc && argv[arg+1][0] != '-')
- {
- ++arg;
- preproc.output_macros_path_ = argv[arg];
}
} else if (val.find("--preprocess") == 0 || val.find("-p") ==
0){
if (arg + 2 < argc){
Modified: trunk/src/tests/test_commandline_options.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/test_commandline_options.cpp?rev=49807&r1=49806&r2=49807&view=diff
==============================================================================
--- trunk/src/tests/test_commandline_options.cpp (original)
+++ trunk/src/tests/test_commandline_options.cpp Thu Jun 9 11:52:39 2011
@@ -93,6 +93,83 @@
}
+BOOST_AUTO_TEST_CASE (test_default_options)
+{
+ const char *argv[] =
+ {
+ "wesnoth",
+ "--logdomains",
+ "--preprocess-output-macros"
+ };
+ const int argc = sizeof(argv)/sizeof(const char *);
+ commandline_options co(argc,const_cast<char**>(argv));
+
+ BOOST_CHECK(!co.bpp);
+ BOOST_CHECK(!co.campaign);
+ BOOST_CHECK(!co.campaign_difficulty);
+ BOOST_CHECK(!co.campaign_scenario);
+ BOOST_CHECK(!co.clock);
+ BOOST_CHECK(!co.config_path);
+ BOOST_CHECK(!co.config_dir);
+ BOOST_CHECK(!co.data_dir);
+ BOOST_CHECK(!co.debug);
+#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
+ BOOST_CHECK(!co.debug_dot_level);
+ BOOST_CHECK(!co.debug_dot_domain);
+#endif
+ BOOST_CHECK(!co.editor);
+ BOOST_CHECK(!co.fps);
+ BOOST_CHECK(!co.fullscreen);
+ BOOST_CHECK(!co.gunzip);
+ BOOST_CHECK(!co.gzip);
+ BOOST_CHECK(!co.help);
+ BOOST_CHECK(!co.log);
+ BOOST_CHECK(!co.load);
+ BOOST_CHECK(co.logdomains && co.logdomains->empty());
+ BOOST_CHECK(!co.multiplayer);
+ BOOST_CHECK(!co.multiplayer_ai_config);
+ BOOST_CHECK(!co.multiplayer_algorithm);
+ BOOST_CHECK(!co.multiplayer_controller);
+ BOOST_CHECK(!co.multiplayer_era);
+ BOOST_CHECK(!co.multiplayer_label);
+ BOOST_CHECK(!co.multiplayer_parm);
+ BOOST_CHECK(!co.multiplayer_side);
+ BOOST_CHECK(!co.multiplayer_turns);
+ BOOST_CHECK(!co.max_fps);
+ BOOST_CHECK(!co.nocache);
+ BOOST_CHECK(!co.nodelay);
+ BOOST_CHECK(!co.nogui);
+ BOOST_CHECK(!co.nomusic);
+ BOOST_CHECK(!co.nosound);
+ BOOST_CHECK(!co.new_storyscreens);
+ BOOST_CHECK(!co.new_syntax);
+ BOOST_CHECK(!co.new_widgets);
+ BOOST_CHECK(!co.path);
+ BOOST_CHECK(!co.preprocess);
+ BOOST_CHECK(!co.preprocess_defines);
+ BOOST_CHECK(!co.preprocess_input_macros);
+ BOOST_CHECK(co.preprocess_output_macros &&
co.preprocess_output_macros->empty());
+ BOOST_CHECK(!co.preprocess_path);
+ BOOST_CHECK(!co.preprocess_target);
+ BOOST_CHECK(!co.proxy);
+ BOOST_CHECK(!co.proxy_address);
+ BOOST_CHECK(!co.proxy_password);
+ BOOST_CHECK(!co.proxy_port);
+ BOOST_CHECK(!co.proxy_user);
+ BOOST_CHECK(!co.resolution);
+ BOOST_CHECK(!co.rng_seed);
+ BOOST_CHECK(!co.server);
+ BOOST_CHECK(!co.screenshot);
+ BOOST_CHECK(!co.screenshot_map_file);
+ BOOST_CHECK(!co.screenshot_output_file);
+ BOOST_CHECK(!co.smallgui);
+ BOOST_CHECK(!co.test);
+ BOOST_CHECK(!co.validcache);
+ BOOST_CHECK(!co.version);
+ BOOST_CHECK(!co.windowed);
+ BOOST_CHECK(!co.with_replay);
+}
+
BOOST_AUTO_TEST_CASE (test_full_options)
{
const char *argv[] =
@@ -110,6 +187,7 @@
"--gzip=gzipfoo",
"--help",
"--load=loadfoo",
+ "--logdomains=filterfoo",
"--max-fps=100",
"--multiplayer",
"--new-storyscreens",
@@ -117,6 +195,8 @@
"--new-widgets",
"--nocache",
"--path",
+ "--preprocess-output-macros=outmfoo",
+ "--rng-seed=1234",
"--validcache",
"--version",
"--with-replay"
@@ -145,7 +225,7 @@
BOOST_CHECK(co.help);
BOOST_CHECK(!co.log);
BOOST_CHECK(co.load && *co.load == "loadfoo");
- BOOST_CHECK(!co.logdomains);
+ BOOST_CHECK(co.logdomains && *co.logdomains == "filterfoo");
BOOST_CHECK(co.multiplayer);
BOOST_CHECK(co.multiplayer_ai_config);
BOOST_CHECK((*co.multiplayer_ai_config).size() == 2);
@@ -171,7 +251,7 @@
BOOST_CHECK(!co.preprocess);
BOOST_CHECK(!co.preprocess_defines);
BOOST_CHECK(!co.preprocess_input_macros);
- BOOST_CHECK(!co.preprocess_output_macros);
+ BOOST_CHECK(co.preprocess_output_macros && *co.preprocess_output_macros
== "outmfoo");
BOOST_CHECK(!co.preprocess_path);
BOOST_CHECK(!co.preprocess_target);
BOOST_CHECK(!co.proxy);
@@ -180,7 +260,7 @@
BOOST_CHECK(!co.proxy_port);
BOOST_CHECK(!co.proxy_user);
BOOST_CHECK(!co.resolution);
- BOOST_CHECK(!co.rng_seed);
+ BOOST_CHECK(co.rng_seed && *co.rng_seed == 1234);
BOOST_CHECK(!co.server);
BOOST_CHECK(!co.screenshot);
BOOST_CHECK(!co.screenshot_map_file);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits