diff --git a/src/basic/main.c b/src/basic/main.c index ad567a8d0..7973cd47a 100644 --- a/src/basic/main.c +++ b/src/basic/main.c @@ -4,13 +4,14 @@ #include #include #include +#include #include static const char * luafile = "init.lua"; static const char * entry_point = NULL; static int memdebug = 0; -static void load_config(const char * filename) +static void parse_config(const char * filename) { dictionary * d = iniparser_new(filename); if (d) { @@ -26,12 +27,84 @@ static void load_config(const char * filename) global.inifile = d; } +static int +usage(const char * prog, const char * arg) +{ + if (arg) { + fprintf(stderr, "unknown argument: %s\n\n", arg); + } + fprintf(stderr, "Usage: %s [options]\n" + "-t : read this datafile, not the most current one\n" + "-q : be quite (same as -v 0)\n" + "-v : verbosity level\n" + "-C : run in interactive mode\n" + "--color : force curses to use colors even when not detected\n" + "--help : help\n", prog); + return -1; +} + +static int +parse_args(int argc, char **argv) +{ + int i; + + for (i=1;i!=argc;++i) { + if (argv[i][0]!='-') { + return usage(argv[0], argv[i]); + } else if (argv[i][1]=='-') { /* long format */ + if (strcmp(argv[i]+2, "version")==0) { + printf("\n%s PBEM host\n" + "Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" + "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version()); + } + else if (strcmp(argv[i]+2, "color")==0) { + /* force the editor to have colors */ + force_color = 1; + } + else if (strcmp(argv[i]+2, "help")==0) { + return usage(argv[0], NULL); + } + else { + return usage(argv[0], argv[i]); + } + } else switch(argv[i][1]) { + case 'C': + entry_point = NULL; + break; + case 'e': + entry_point = argv[++i]; + break; + case 't': + turn = atoi(argv[++i]); + break; + case 'q': + verbosity = 0; + break; + case 'v': + verbosity = atoi(argv[++i]); + break; + case 'h': + return usage(argv[0], NULL); + default: + return usage(argv[0], argv[i]); + } + } + + return 0; +} + + int main(int argc, char ** argv) { int err; log_open("eressea.log"); - load_config("eressea.ini"); + parse_config("eressea.ini"); + + err = parse_args(argc, argv); + if (err) { + return err; + } err = eressea_init(); if (err) { @@ -46,5 +119,6 @@ int main(int argc, char ** argv) } eressea_done(); + log_close(); return 0; } diff --git a/src/common/eressea.c b/src/common/eressea.c index 3c94593ac..f3fd48f5a 100644 --- a/src/common/eressea.c +++ b/src/common/eressea.c @@ -187,7 +187,6 @@ void eressea_done(void) game_done(); kernel_done(); lua_done((lua_State *)global.vm_state); - log_close(); } static int diff --git a/src/common/kernel/curse.c b/src/common/kernel/curse.c index 80eef1fc8..c700817c7 100644 --- a/src/common/kernel/curse.c +++ b/src/common/kernel/curse.c @@ -217,7 +217,7 @@ curse_read(attrib * a, struct storage * store) if (result!=0) { log_error(("missing curse %s, no compatibility code either.\n", cursename)); } - assert(result!=0); + assert(result==0); return AT_READ_FAIL; } if (store->version < CURSEFLAGS_VERSION) { diff --git a/src/common/kernel/move.c b/src/common/kernel/move.c index d20719bae..6ca51f2e1 100644 --- a/src/common/kernel/move.c +++ b/src/common/kernel/move.c @@ -687,12 +687,15 @@ ship_allowed(const struct ship * sh, const region * r) static boolean flying_ship(const ship * sh) { + static int init = 0; static const curse_type * ct_flyingship; - if (!ct_flyingship) { - ct_flyingship = ct_find("flyingship"); - assert(ct_flyingship); - } + if (sh->type->flags & SFL_FLY) return true; + if (!init) { + ct_flyingship = ct_find("flyingship"); + init = 1; + } + if (!ct_flyingship) return false; if (curse_active(get_curse(sh->attribs, ct_flyingship))) return true; return false; } diff --git a/src/eressea/main.c b/src/eressea/main.c index f8f3795f0..51ffe86b9 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -154,7 +154,6 @@ static boolean g_ignore_errors = false; static const char * luafile = "init.lua"; static const char * entry_point = NULL; static int memdebug = 0; -static int g_console = 1; #if defined(HAVE_SIGACTION) && defined(HAVE_EXECINFO) #include #include @@ -302,14 +301,12 @@ read_args(int argc, char **argv, lua_State * luaState) return usage(argv[0], argv[i]); } else switch(argv[i][1]) { case 'C': - g_console = 1; entry_point = NULL; break; case 'R': g_reportdir = argv[++i]; break; case 'e': - g_console = 0; entry_point = argv[++i]; break; case 'd': @@ -322,7 +319,6 @@ read_args(int argc, char **argv, lua_State * luaState) game_name = argv[++i]; break; case 't': - g_console = 0; turn = atoi(argv[++i]); break; case 'q':