summaryrefslogtreecommitdiff
path: root/src/tool/mapcache.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2014-11-09 02:07:09 +0100
committerHaru <haru@dotalux.com>2015-01-18 21:35:36 +0100
commitce08d6238d902590dbfb650f889a8ab8887356bf (patch)
tree218266957f961e71a51a307b432b02ed9647243a /src/tool/mapcache.c
parent0285ddf7cee2f6569a513fe6118c43f99fd71279 (diff)
downloadhercules-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/tool/mapcache.c')
-rw-r--r--src/tool/mapcache.c102
1 files changed, 73 insertions, 29 deletions
diff --git a/src/tool/mapcache.c b/src/tool/mapcache.c
index 2cc70ebf3..5376458dc 100644
--- a/src/tool/mapcache.c
+++ b/src/tool/mapcache.c
@@ -10,6 +10,7 @@
#include <string.h>
#include "../common/cbasetypes.h"
+#include "../common/core.h"
#include "../common/grfio.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
@@ -23,9 +24,9 @@
#define NO_WATER 1000000
-char grf_list_file[256] = "conf/grf-files.txt";
-char map_list_file[256] = "db/map_index.txt";
-char map_cache_file[256];
+char *grf_list_file;
+char *map_list_file;
+char *map_cache_file;
int rebuild = 0;
FILE *map_cache_fp;
@@ -184,25 +185,67 @@ char *remove_extension(char *mapname)
return mapname;
}
-// Processes command-line arguments
-void process_args(int argc, char *argv[])
+/**
+ * --grf-list handler
+ *
+ * Overrides the default grf list filename.
+ * @see cmdline->exec
+ */
+static CMDLINEARG(grflist)
{
- int i;
+ aFree(grf_list_file);
+ grf_list_file = aStrdup(params);
+ return true;
+}
- for(i = 0; i < argc; i++) {
- if(strcmp(argv[i], "-grf") == 0) {
- if(++i < argc)
- safestrncpy(grf_list_file, argv[i], sizeof(grf_list_file));
- } else if(strcmp(argv[i], "-list") == 0) {
- if(++i < argc)
- safestrncpy(map_list_file, argv[i], sizeof(map_list_file));
- } else if(strcmp(argv[i], "-cache") == 0) {
- if(++i < argc)
- safestrncpy(map_cache_file, argv[i], sizeof(map_cache_file));
- } else if(strcmp(argv[i], "-rebuild") == 0)
- rebuild = 1;
- }
+/**
+ * --map-list handler
+ *
+ * Overrides the default map list filename.
+ * @see cmdline->exec
+ */
+static CMDLINEARG(maplist)
+{
+ aFree(map_list_file);
+ map_list_file = aStrdup(params);
+ return true;
+}
+/**
+ * --map-cache handler
+ *
+ * Overrides the default map cache filename.
+ * @see cmdline->exec
+ */
+static CMDLINEARG(mapcache)
+{
+ aFree(map_cache_file);
+ map_cache_file = aStrdup(params);
+ return true;
+}
+
+/**
+ * --rebuild handler
+ *
+ * Forces a rebuild of the mapcache, rather than only adding missing maps.
+ * @see cmdline->exec
+ */
+static CMDLINEARG(rebuild)
+{
+ rebuild = 1;
+ return true;
+}
+
+/**
+ * Defines the local command line arguments
+ */
+void cmdline_args_init_local(void)
+{
+ CMDLINEARG_DEF2(grf-list, grflist, "Alternative grf list file", CMDLINE_OPT_NORMAL|CMDLINE_OPT_PARAM);
+ CMDLINEARG_DEF2(map-list, maplist, "Alternative map list file", CMDLINE_OPT_NORMAL|CMDLINE_OPT_PARAM);
+ CMDLINEARG_DEF2(map-cache, mapcache, "Alternative map cache file", CMDLINE_OPT_NORMAL|CMDLINE_OPT_PARAM);
+ CMDLINEARG_DEF2(rebuild, rebuild, "Forces a rebuild of the map cache, rather than only adding missing maps", CMDLINE_OPT_NORMAL);
+
}
int do_init(int argc, char** argv)
@@ -212,17 +255,13 @@ int do_init(int argc, char** argv)
struct map_data map;
char name[MAP_NAME_LENGTH_EXT];
+ grf_list_file = aStrdup("conf/grf-files.txt");
+ map_list_file = aStrdup("db/map_index.txt");
/* setup pre-defined, #define-dependant */
- sprintf(map_cache_file,"db/%s/map_cache.dat",
-#ifdef RENEWAL
- "re"
-#else
- "pre-re"
-#endif
- );
+ map_cache_file = aStrdup("db/"DBPATH"map_cache.dat");
- // Process the command-line arguments
- process_args(argc, argv);
+ cmdline->exec(argc, argv, CMDLINE_OPT_PREINIT);
+ cmdline->exec(argc, argv, CMDLINE_OPT_NORMAL);
ShowStatus("Initializing grfio with %s\n", grf_list_file);
grfio_init(grf_list_file);
@@ -302,9 +341,14 @@ int do_init(int argc, char** argv)
ShowInfo("%d maps now in cache\n", header.map_count);
+ aFree(grf_list_file);
+ aFree(map_list_file);
+ aFree(map_cache_file);
+
return 0;
}
-void do_final(void)
+int do_final(void)
{
+ return EXIT_SUCCESS;
}