COMMON: Modify Base::processSettings, get rid of Common::kArgumentNotProcessed
Instead of defining a hacked up Common::Error code, split the return value of processSettings into two parts: An error code, and a value which indicates whether the specified command was completely handled by processSettings or not.
This commit is contained in:
parent
6f6051a9e1
commit
20cad6e8b6
7 changed files with 42 additions and 19 deletions
|
@ -23,6 +23,8 @@
|
||||||
// FIXME: Avoid using printf
|
// FIXME: Avoid using printf
|
||||||
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
|
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
|
||||||
|
|
||||||
|
#define FORBIDDEN_SYMBOL_EXCEPTION_exit
|
||||||
|
|
||||||
#include "engines/metaengine.h"
|
#include "engines/metaengine.h"
|
||||||
#include "base/commandLine.h"
|
#include "base/commandLine.h"
|
||||||
#include "base/plugins.h"
|
#include "base/plugins.h"
|
||||||
|
@ -885,7 +887,8 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
|
||||||
#endif // DISABLE_COMMAND_LINE
|
#endif // DISABLE_COMMAND_LINE
|
||||||
|
|
||||||
|
|
||||||
Common::Error processSettings(Common::String &command, Common::StringMap &settings) {
|
bool processSettings(Common::String &command, Common::StringMap &settings, Common::Error &err) {
|
||||||
|
err = Common::kNoError;
|
||||||
|
|
||||||
#ifndef DISABLE_COMMAND_LINE
|
#ifndef DISABLE_COMMAND_LINE
|
||||||
|
|
||||||
|
@ -894,33 +897,34 @@ Common::Error processSettings(Common::String &command, Common::StringMap &settin
|
||||||
// have been loaded.
|
// have been loaded.
|
||||||
if (command == "list-targets") {
|
if (command == "list-targets") {
|
||||||
listTargets();
|
listTargets();
|
||||||
return Common::kNoError;
|
return true;
|
||||||
} else if (command == "list-games") {
|
} else if (command == "list-games") {
|
||||||
listGames();
|
listGames();
|
||||||
return Common::kNoError;
|
return true;
|
||||||
} else if (command == "list-saves") {
|
} else if (command == "list-saves") {
|
||||||
return listSaves(settings["list-saves"].c_str());
|
err = listSaves(settings["list-saves"].c_str());
|
||||||
|
return true;
|
||||||
} else if (command == "list-themes") {
|
} else if (command == "list-themes") {
|
||||||
listThemes();
|
listThemes();
|
||||||
return Common::kNoError;
|
return true;
|
||||||
} else if (command == "version") {
|
} else if (command == "version") {
|
||||||
printf("%s\n", gScummVMFullVersion);
|
printf("%s\n", gScummVMFullVersion);
|
||||||
printf("Features compiled in: %s\n", gScummVMFeatures);
|
printf("Features compiled in: %s\n", gScummVMFeatures);
|
||||||
return Common::kNoError;
|
return true;
|
||||||
} else if (command == "help") {
|
} else if (command == "help") {
|
||||||
printf(HELP_STRING, s_appName);
|
printf(HELP_STRING, s_appName);
|
||||||
return Common::kNoError;
|
return true;
|
||||||
}
|
}
|
||||||
#ifdef DETECTOR_TESTING_HACK
|
#ifdef DETECTOR_TESTING_HACK
|
||||||
else if (command == "test-detector") {
|
else if (command == "test-detector") {
|
||||||
runDetectorTest();
|
runDetectorTest();
|
||||||
return Common::kNoError;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef UPGRADE_ALL_TARGETS_HACK
|
#ifdef UPGRADE_ALL_TARGETS_HACK
|
||||||
else if (command == "upgrade-targets") {
|
else if (command == "upgrade-targets") {
|
||||||
upgradeTargets();
|
upgradeTargets();
|
||||||
return Common::kNoError;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -972,7 +976,7 @@ Common::Error processSettings(Common::String &command, Common::StringMap &settin
|
||||||
ConfMan.set(key, value, Common::ConfigManager::kTransientDomain);
|
ConfMan.set(key, value, Common::ConfigManager::kTransientDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Common::kArgumentNotProcessed;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End of namespace Base
|
} // End of namespace Base
|
||||||
|
|
|
@ -32,9 +32,28 @@ class String;
|
||||||
|
|
||||||
namespace Base {
|
namespace Base {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register various defaults with the ConfigManager.
|
||||||
|
*/
|
||||||
void registerDefaults();
|
void registerDefaults();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the command line for options and a command; the options
|
||||||
|
* are stored in the map 'settings, the command (if any) is returned.
|
||||||
|
*/
|
||||||
Common::String parseCommandLine(Common::StringMap &settings, int argc, const char * const *argv);
|
Common::String parseCommandLine(Common::StringMap &settings, int argc, const char * const *argv);
|
||||||
Common::Error processSettings(Common::String &command, Common::StringMap &settings);
|
|
||||||
|
/**
|
||||||
|
* Process the command line options and arguments.
|
||||||
|
* Returns true if everything was handled and ScummVM should quit
|
||||||
|
* (e.g. because "--help" was specified, and handled).
|
||||||
|
*
|
||||||
|
* @param[in] command the command as returned by parseCommandLine
|
||||||
|
* @param[in] settings the settings as returned by parseCommandLine
|
||||||
|
* @param[out] err indicates whether any error occurred, and which
|
||||||
|
* @return true if the command was completely processed and ScummVM should quit, false otherwise
|
||||||
|
*/
|
||||||
|
bool processSettings(Common::String &command, Common::StringMap &settings, Common::Error &err);
|
||||||
|
|
||||||
} // End of namespace Base
|
} // End of namespace Base
|
||||||
|
|
||||||
|
|
|
@ -349,8 +349,7 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
|
||||||
Common::Error res;
|
Common::Error res;
|
||||||
|
|
||||||
// TODO: deal with settings that require plugins to be loaded
|
// TODO: deal with settings that require plugins to be loaded
|
||||||
res = Base::processSettings(command, settings);
|
if (Base::processSettings(command, settings, res)) {
|
||||||
if (res.getCode() != Common::kArgumentNotProcessed) {
|
|
||||||
if (res.getCode() != Common::kNoError)
|
if (res.getCode() != Common::kNoError)
|
||||||
warning("%s", res.getDesc().c_str());
|
warning("%s", res.getDesc().c_str());
|
||||||
return res.getCode();
|
return res.getCode();
|
||||||
|
|
|
@ -67,9 +67,6 @@ static String errorToString(ErrorCode errorCode) {
|
||||||
case kEnginePluginNotSupportSaves:
|
case kEnginePluginNotSupportSaves:
|
||||||
return _s("Engine plugin does not support save states");
|
return _s("Engine plugin does not support save states");
|
||||||
|
|
||||||
case kArgumentNotProcessed:
|
|
||||||
return _s("Command line argument not processed");
|
|
||||||
|
|
||||||
case kUnknownError:
|
case kUnknownError:
|
||||||
default:
|
default:
|
||||||
return _s("Unknown error");
|
return _s("Unknown error");
|
||||||
|
|
|
@ -47,7 +47,6 @@ enum ErrorCode {
|
||||||
kUnsupportedGameidError, ///< Engine initialization: Gameid not supported by this (Meta)Engine
|
kUnsupportedGameidError, ///< Engine initialization: Gameid not supported by this (Meta)Engine
|
||||||
kUnsupportedColorMode, ///< Engine initialization: Engine does not support backend's color mode
|
kUnsupportedColorMode, ///< Engine initialization: Engine does not support backend's color mode
|
||||||
|
|
||||||
|
|
||||||
kReadPermissionDenied, ///< Unable to read data due to missing read permission
|
kReadPermissionDenied, ///< Unable to read data due to missing read permission
|
||||||
kWritePermissionDenied, ///< Unable to write data due to missing write permission
|
kWritePermissionDenied, ///< Unable to write data due to missing write permission
|
||||||
|
|
||||||
|
@ -63,8 +62,6 @@ enum ErrorCode {
|
||||||
kEnginePluginNotFound, ///< Failed to find plugin to handle target
|
kEnginePluginNotFound, ///< Failed to find plugin to handle target
|
||||||
kEnginePluginNotSupportSaves, ///< Failed if plugin does not support listing save states
|
kEnginePluginNotSupportSaves, ///< Failed if plugin does not support listing save states
|
||||||
|
|
||||||
kArgumentNotProcessed, ///< Used in command line parsing
|
|
||||||
|
|
||||||
kUnknownError ///< Catch-all error, used if no other error code matches
|
kUnknownError ///< Catch-all error, used if no other error code matches
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,11 @@
|
||||||
#define system(a) FORBIDDEN_SYMBOL_REPLACEMENT
|
#define system(a) FORBIDDEN_SYMBOL_REPLACEMENT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_exit
|
||||||
|
#undef exit
|
||||||
|
#define exit(a) FORBIDDEN_SYMBOL_REPLACEMENT
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_getenv
|
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_getenv
|
||||||
#undef getenv
|
#undef getenv
|
||||||
#define getenv(a) FORBIDDEN_SYMBOL_REPLACEMENT
|
#define getenv(a) FORBIDDEN_SYMBOL_REPLACEMENT
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define FORBIDDEN_SYMBOL_EXCEPTION_exit
|
||||||
|
|
||||||
#include "common/textconsole.h"
|
#include "common/textconsole.h"
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
#include "common/str.h"
|
#include "common/str.h"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue