Author: zaroth
Date: Thu Jun  9 11:52:37 2011
New Revision: 49806

URL: http://svn.gna.org/viewcvs/wesnoth?rev=49806&view=rev
Log:
Added config-path, gunzip and gzip options to commandline_options class

Modified:
    trunk/src/commandline_options.cpp
    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=49806&r1=49805&r2=49806&view=diff
==============================================================================
--- trunk/src/commandline_options.cpp (original)
+++ trunk/src/commandline_options.cpp Thu Jun  9 11:52:37 2011
@@ -96,8 +96,11 @@
        po::options_description general_opts("General options");
        general_opts.add_options()
                ("config-dir", po::value<std::string>(), "sets the path of the 
user config directory to $HOME/<arg> or My Documents\\My Games\\<arg> for 
Windows. You can specify also an absolute path outside the $HOME or My 
Documents\\My Games directory.")
+               ("config-path", "prints the path of the user config directory 
and exits.")
                ("data-dir", po::value<std::string>(), "overrides the data 
directory with the one specified.")
                ("debug,d", "enables additional command mode options in-game.")
+               ("gunzip", po::value<std::string>(), "decompresses a file 
(<arg>.gz) in gzip format and stores it without the .gz suffix. <arg>.gz will 
be removed.")
+               ("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.")
                ("new-syntax", "enables the new campaign syntax parsing.")
@@ -137,12 +140,18 @@
                bpp = vm["bpp"].as<int>();
        if (vm.count("config-dir"))
                config_dir = vm["config-dir"].as<std::string>();
+       if (vm.count("config-path"))
+               config_path = true;
        if (vm.count("data-dir"))
                data_dir = vm["data-dir"].as<std::string>();
        if (vm.count("debug"))
                debug = true;
        if (vm.count("fps"))
                fps = true;
+       if (vm.count("gunzip"))
+               gunzip = vm["gunzip"].as<std::string>();
+       if (vm.count("gzip"))
+               gzip = vm["gzip"].as<std::string>();
        if (vm.count("help"))
                help = true;
        if (vm.count("load"))

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=49806&r1=49805&r2=49806&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Thu Jun  9 11:52:37 2011
@@ -170,6 +170,10 @@
        if(cmdline_opts.config_dir) {
                set_preferences_dir(*cmdline_opts.config_dir);
        }
+       if(cmdline_opts.config_path) {
+               std::cout << get_user_data_dir() << '\n';
+               return 0;
+       }
        if(cmdline_opts.data_dir) {
                const std::string datadir = *cmdline_opts.data_dir;
                std::cerr << "Overriding data directory with " << datadir << 
std::endl;
@@ -190,6 +194,21 @@
                }
        // don't update font as we already updating it in game ctor
        }
+       if(cmdline_opts.gunzip) {
+               const std::string input_file(*cmdline_opts.gunzip);
+               if(!is_gzip_file(input_file)) {
+                       std::cerr << "file '" << input_file << "'isn't a .gz 
file\n";
+                       return 2;
+               }
+               const std::string output_file(
+                       input_file, 0, input_file.length() - 3);
+               gzip_decode(input_file, output_file);
+       }
+       if(cmdline_opts.gzip) {
+               const std::string input_file(*cmdline_opts.gzip);
+               const std::string output_file(*cmdline_opts.gzip + ".gz");
+               gzip_encode(input_file, output_file);
+       }
        if(cmdline_opts.help) {
                std::cout << cmdline_opts;
                return 0;
@@ -212,11 +231,7 @@
                const std::string val(argv[arg]);
                if(val.empty()) {
                        continue;
-               } else if (val == "--config-path") {
-                       std::cout << get_user_data_dir() << '\n';
-                       return 0;
-               }
-               else if (val == "--screenshot" ) {
+               } else if (val == "--screenshot" ) {
                        if(!(argc > arg + 2)) {
                                std::cerr << "format of " << val << " command: 
" << val << " <map file> <output file>\n";
                                return 2;
@@ -248,33 +263,6 @@
                                }
                                p = q;
                        }
-               } else if(val == "--gzip") {
-                       if(argc != arg + 2) {
-                               std::cerr << "format of " << val << " command: 
" << val << " <input file>\n";
-                               return 2;
-                       }
-
-                       const std::string input_file(argv[arg + 1]);
-                       const std::string output_file(input_file + ".gz");
-                       gzip_encode(input_file, output_file);
-
-               } else if(val == "--gunzip") {
-                       if(argc != arg + 2) {
-                               std::cerr << "format of " << val << " command: 
" << val << " <input file>\n";
-                               return 2;
-                       }
-
-                       const std::string input_file(argv[arg + 1]);
-                       if(! is_gzip_file(input_file)) {
-
-                               std::cerr << "file '" << input_file << "'isn't 
a .gz file\n";
-                               return 2;
-                       }
-                       const std::string output_file(
-                               input_file, 0, input_file.length() - 3);
-
-                       gzip_decode(input_file, output_file);
-
                } else if(val == "--logdomains") {
                        std::string filter;
                        if(arg + 1 != argc) {

Modified: trunk/src/tests/test_commandline_options.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/test_commandline_options.cpp?rev=49806&r1=49805&r2=49806&view=diff
==============================================================================
--- trunk/src/tests/test_commandline_options.cpp (original)
+++ trunk/src/tests/test_commandline_options.cpp Thu Jun  9 11:52:37 2011
@@ -102,9 +102,12 @@
                "--ai-config=2:aibar",
                "--bpp=32",
                "--config-dir=configdirfoo",
+               "--config-path",
                "--data-dir=datadirfoo",
                "--debug",
                "--fps",
+               "--gunzip=gunzipfoo.gz",
+               "--gzip=gzipfoo",
                "--help",
                "--load=loadfoo",
                "--max-fps=100",
@@ -126,7 +129,7 @@
        BOOST_CHECK(!co.campaign_difficulty);
        BOOST_CHECK(!co.campaign_scenario);
        BOOST_CHECK(!co.clock);
-       BOOST_CHECK(!co.config_path);
+       BOOST_CHECK(co.config_path);
        BOOST_CHECK(co.config_dir && *co.config_dir == "configdirfoo");
        BOOST_CHECK(co.data_dir && *co.data_dir == "datadirfoo");
        BOOST_CHECK(co.debug);
@@ -137,8 +140,8 @@
        BOOST_CHECK(!co.editor);
        BOOST_CHECK(co.fps);
        BOOST_CHECK(!co.fullscreen);
-       BOOST_CHECK(!co.gunzip);
-       BOOST_CHECK(!co.gzip);
+       BOOST_CHECK(co.gunzip && *co.gunzip == "gunzipfoo.gz");
+       BOOST_CHECK(co.gzip && *co.gzip == "gzipfoo");
        BOOST_CHECK(co.help);
        BOOST_CHECK(!co.log);
        BOOST_CHECK(co.load && *co.load == "loadfoo");


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to