diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2015-11-01 17:50:44 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2015-11-01 17:50:44 +0100 |
commit | fc2c3bda5c637b82d00b42e5da948a09b8bd9aed (patch) | |
tree | 2f7614b2eddd49fb1198d4188d94a2e8bfaf9ccc | |
parent | 281d6fac1edd4a5b06692b850c00db6a5a9bbb46 (diff) |
Fix arguments parsing in the main function
Fixes #2611 which was a regression from 692216b86ab97db91e7ff3903ffc9ac8e37433f6.
The bogus behaviour considered that if there were more than one arguments left to parse,
they would be a pair of arguments (switch and its parameter), and thus skipped the next
argument in all cases (thus potentially skipping a "-editor", which triggered #2611).
This is fixed by checking first for arguments that don't expect a parameter, and only
afterwards for arguments that expect a parameter. And if a "pair" of arguments is not
valid, we no longer increment the counter.
-rw-r--r-- | main/main.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/main/main.cpp b/main/main.cpp index 9cd190a0e8..3ef357e253 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1007,8 +1007,21 @@ bool Main::start() { bool export_debug=false; List<String> args = OS::get_singleton()->get_cmdline_args(); for (int i=0;i<args.size();i++) { + //parameters that do not have an argument to the right + if (args[i]=="-nodocbase") { + doc_base=false; + } else if (args[i]=="-noquit") { + noquit=true; + } else if (args[i]=="-convert_old") { + convert_old=true; + } else if (args[i]=="-editor" || args[i]=="-e") { + editor=true; + } else if (args[i].length() && args[i][0] != '-' && game_path == "") { + game_path=args[i]; + } //parameters that have an argument to the right - if (i < (args.size()-1)) { + else if (i < (args.size()-1)) { + bool parsed_pair=true; if (args[i]=="-doctool") { doc_tool=args[i+1]; } else if (args[i]=="-script" || args[i]=="-s") { @@ -1037,20 +1050,13 @@ bool Main::start() { } else if (args[i]=="-dumpstrings") { editor=true; //needs editor dumpstrings=args[i+1]; + } else { + // The parameter does not match anything known, don't skip the next argument + parsed_pair=false; + } + if (parsed_pair) { + i++; } - i++; - } - //parameters that do not have an argument to the right - if (args[i]=="-nodocbase") { - doc_base=false; - } else if (args[i]=="-noquit") { - noquit=true; - } else if (args[i]=="-convert_old") { - convert_old=true; - } else if (args[i]=="-editor" || args[i]=="-e") { - editor=true; - } else if (args[i].length() && args[i][0] != '-' && game_path == "") { - game_path=args[i]; } } |