diff options
author | Haru <haru@dotalux.com> | 2014-11-09 02:07:09 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2015-01-18 21:35:36 +0100 |
commit | ce08d6238d902590dbfb650f889a8ab8887356bf (patch) | |
tree | 218266957f961e71a51a307b432b02ed9647243a /src/common/core.h | |
parent | 0285ddf7cee2f6569a513fe6118c43f99fd71279 (diff) | |
download | hercules-ce08d6238d902590dbfb650f889a8ab8887356bf.tar.gz hercules-ce08d6238d902590dbfb650f889a8ab8887356bf.tar.bz2 hercules-ce08d6238d902590dbfb650f889a8ab8887356bf.tar.xz hercules-ce08d6238d902590dbfb650f889a8ab8887356bf.zip |
Command line arguments handling overhaul
- login_server, char_server, map_server as well as the tools (mapcache)
now have a common command line arguments handling mechanism.
- All of them now accept `--help` (`-h`), `--version` (`-v`) and
`--load-plugin`.
- login_server now accepts `--login-config` and `--lan-config` instead
of relying on positional arguments to override those files. The old
syntax will no longer work, please update your custom startup scripts.
- char_server now accepts `--char-config`, `--inter-config`,
`--lan-config` instead of relying on positional arguments. The old
syntax will no longer work, please update your custom startup scripts.
- mapcache now accepts `--grf-list`, `--map-list`, `--map-cache`,
`--rebuild` in place of, respectively, `-grf`, `-list`, `-cache`,
`-rebuild`.
- A new macro `CMDLINEARG()` is provided, to help defining new command
line argument handlers (i.e. in plugins). the `addArg()` call is still
required, but its syntax has changed. The `help` argument is now of type
`const char *` rather than a function pointer, and it is supposed to
contain the message to show in the `--help` screen. Pass `NULL` if no
help message is desired.
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/core.h')
-rw-r--r-- | src/common/core.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/common/core.h b/src/common/core.h index 025f636e9..827d345ba 100644 --- a/src/common/core.h +++ b/src/common/core.h @@ -5,6 +5,7 @@ #ifndef COMMON_CORE_H #define COMMON_CORE_H +#include "../common/cbasetypes.h" #include "../common/db.h" #include "../common/mmo.h" @@ -39,6 +40,7 @@ extern char *SERVER_NAME; enum server_types SERVER_TYPE; +extern void cmdline_args_init_local(void); extern int do_init(int,char**); extern void set_server_type(void); extern void do_abort(void); @@ -49,4 +51,46 @@ extern int do_final(void); extern void (*shutdown_callback)(void); #endif // HERCULES_CORE +/// Options for command line argument handlers. +enum cmdline_options { + CMDLINE_OPT_NORMAL = 0x0, ///< No special options. + CMDLINE_OPT_PARAM = 0x1, ///< An additional value parameter is expected. + CMDLINE_OPT_SILENT = 0x2, ///< If this command-line argument is passed, the server won't print any messages. + CMDLINE_OPT_PREINIT = 0x4, ///< This command-line argument is executed before initializing the HPM. +}; +typedef bool (*CmdlineExecFunc)(const char *name, const char *params); +struct CmdlineArgData { + unsigned int pluginID; ///< Plugin ID (HPM_PID_CORE if used by the core) + unsigned int options; ///< Command line argument options (@see enum cmdline_options) + char *name; ///< Command-line argument (i.e. "--my-arg", "--version", "--whatever") + char shortname; ///< Short form (i.e. "-v") - only store the 'v' part. + CmdlineExecFunc func; ///< Function to call + char *help; ///< Help message +}; + +struct cmdline_interface { + struct CmdlineArgData *args_data; + int args_data_count; + + void (*init) (void); + void (*final) (void); + bool (*arg_add) (unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options); + int (*exec) (int argc, char **argv, unsigned int options); + bool (*arg_next_value) (const char *name, int current_arg, int argc); + const char *(*arg_source) (struct CmdlineArgData *arg); +}; + +struct cmdline_interface *cmdline; + +#define CMDLINEARG(x) bool cmdline_arg_ ## x (const char *name, const char *params) +#ifdef HERCULES_CORE +/// Special plugin ID assigned to the Hercules core +#define HPM_PID_CORE ((unsigned int)-1) + +#define CMDLINEARG_DEF(name, shortname, help, options) cmdline->arg_add(HPM_PID_CORE, "--" EXPAND_AND_QUOTE(name), shortname, cmdline_arg_ ## name, help, options) +#define CMDLINEARG_DEF2(name, funcname, help, options) cmdline->arg_add(HPM_PID_CORE, "--" EXPAND_AND_QUOTE(name), '\0', cmdline_arg_ ## funcname, help, options) + +void cmdline_defaults(void); +#endif // HERCULES_CORE + #endif /* COMMON_CORE_H */ |