From 97001710c06ed7053d18c8baaac602eb563b64b3 Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 27 Aug 2013 08:08:34 +0200 Subject: Introducing the Hercules Standalone Script Syntax Checker - Added a command line argument '--script-check' to check a script's syntax without running the server (and without requiring a SQL connection). Usage: ./map-server --script-check /path/to/the/script.txt - For convenience, a script-checker bash script is provided, to set the path correctly when called from a different directory. Usage: /path/to/Hercules/script-checker /path/to/the/script/to/check.txt - While the script checker will supposedly work under windows as well, no convenience scripts are currently provided for platforms other than UNIX (feel free to open a pull request with a .bat launcher or whatever you like) - Integration with IDEs or text editors is possible. In fact, I already have a fully functional plugin for vim (through vim-syntastic), and if there's enough interest, I'll publish it. - screenshot: http://d.pr/i/NOBD - If you want an online checker, http://haru.ws/scriptchecker/ is running this code, without modifications and will be kept up to date (without any warranty though.) - Special thanks to Ind, Yommy, Streusel, who helped making this possible, in a way or another. --- src/common/mapindex.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/common/mapindex.c') diff --git a/src/common/mapindex.c b/src/common/mapindex.c index 83de21b2b..a95e143c3 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -21,7 +21,12 @@ int max_index = 0; char mapindex_cfgfile[80] = "db/map_index.txt"; -#define mapindex_exists(id) (indexes[id].name[0] != '\0') +#define mapindex_exists_sub(id) (indexes[id].name[0] != '\0') + +bool mapindex_exists(int id) { + return mapindex_exists_sub(id); +} + /// Retrieves the map name from 'string' (removing .gat extension if present). /// Result gets placed either into 'buf' or in a static local buffer. const char* mapindex_getmapname(const char* string, char* output) { @@ -102,7 +107,7 @@ int mapindex_addmap(int index, const char* name) { return 0; } - if (mapindex_exists(index)) { + if (mapindex_exists_sub(index)) { ShowWarning("(mapindex_add) Overriding index %d: map \"%s\" -> \"%s\"\n", index, indexes[index].name, map_name); strdb_remove(mapindex_db, indexes[index].name); } @@ -129,18 +134,18 @@ unsigned short mapindex_name2id(const char* name) { } const char* mapindex_id2name_sub(unsigned short id,const char *file, int line, const char *func) { - if (id > MAX_MAPINDEX || !mapindex_exists(id)) { + if (id > MAX_MAPINDEX || !mapindex_exists_sub(id)) { ShowDebug("mapindex_id2name: Requested name for non-existant map index [%d] in cache. %s:%s:%d\n", id,file,func,line); return indexes[0].name; // dummy empty string so that the callee doesn't crash } return indexes[id].name; } -void mapindex_init(void) { +int mapindex_init(void) { FILE *fp; char line[1024]; int last_index = -1; - int index; + int index, total = 0; char map_name[12]; if( ( fp = fopen(mapindex_cfgfile,"r") ) == NULL ){ @@ -158,6 +163,7 @@ void mapindex_init(void) { index = last_index+1; case 2: //Map with ID given mapindex_addmap(index,map_name); + total++; break; default: continue; @@ -169,6 +175,7 @@ void mapindex_init(void) { if( !strdb_iget(mapindex_db, MAP_DEFAULT) ) { ShowError("mapindex_init: MAP_DEFAULT '%s' not found in cache! update mapindex.h MAP_DEFAULT var!!!\n",MAP_DEFAULT); } + return total; } int mapindex_removemap(int index){ -- cgit v1.2.3-60-g2f50