Some fixes for Linux and removing some dead code.

This commit is contained in:
Enno Rehling 2008-04-19 16:56:15 +00:00
parent 6739d5ff7e
commit a2ae6a0ea9
4 changed files with 14 additions and 242 deletions

View file

@ -39,7 +39,6 @@ SHARED_BINDINGS =
Library luabindings : $(SHARED_BINDINGS) ;
LUASERVER_SOURCES =
<common!iniparser>iniparser.c
<common!iniparser>iniparser.c
<lua>gm.cpp
<lua>script.cpp

View file

@ -60,8 +60,6 @@
#include <util/log.h>
#include <util/base36.h>
#include <iniparser/iniparser.h>
#include <libxml/encoding.h>
#include <string.h>
@ -84,8 +82,7 @@ extern const char * g_basedir;
extern const char * g_resourcedir;
static int g_quit;
static const char * g_logfile = "gmtool.log";
static int force_color = 0;
int force_color = 0;
state * current_state = NULL;
@ -96,165 +93,6 @@ state * current_state = NULL;
static WINDOW * hstatus;
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"
"-b basedir : gibt das basisverzeichnis an\n"
"-d datadir : gibt das datenverzeichnis an\n"
"-r resdir : gibt das resourceverzeichnis an\n"
"-t turn : read this datafile\n"
"-v : be verbose\n"
"-l logfile : write messages to <logfile>\n"
"--xml xmlfile : read settings from <xmlfile>.\n"
"--lomem : save RAM\n"
"--color : force color mode\n"
"--current : read the most current datafile\n"
"--help : help\n", prog);
return -1;
}
static int
read_args(int argc, char **argv)
{
int i;
quiet = 0xFF; /* no printing whatsoever */
turn = first_turn;
for (i=1;i!=argc;++i) {
if (argv[i][0]!='-') {
return usage(argv[0], argv[i]);
} else if (argv[i][1]=='-') { /* long format */
if (strncmp(argv[i]+2, "xml", 3)==0) {
if (argv[i][5]=='=') xmlfile = argv[i]+6;
else xmlfile = argv[++i];
} else if (strncmp(argv[i]+2, "log", 3)==0) {
if (argv[i][5]=='=') g_logfile = argv[i]+6;
else g_logfile = argv[++i];
} else if (strncmp(argv[i]+2, "res", 3)==0) {
if (argv[i][5]=='=') g_resourcedir = argv[i]+6;
else g_resourcedir = argv[++i];
} else if (strncmp(argv[i]+2, "base", 4)==0) {
if (argv[i][6]=='=') g_basedir = argv[i]+7;
else g_basedir = argv[++i];
} else if (strncmp(argv[i]+2, "turn", 4)==0) {
if (argv[i][6]=='=') turn = atoi(argv[i]+7);
else turn = atoi(argv[++i]);
} else if (strncmp(argv[i]+2, "data", 4)==0) {
if (argv[i][6]=='=') g_datadir = argv[i]+7;
else g_datadir = argv[++i];
} else if (strcmp(argv[i]+2, "lomem")==0) {
lomem = true;
} else if (strcmp(argv[i]+2, "color")==0) {
force_color = 1;
} else if (strcmp(argv[i]+2, "current")==0) {
turn = -1;
} else if (strcmp(argv[i]+2, "help")==0)
return usage(argv[0], NULL);
else
return usage(argv[0], argv[i]);
} else {
int k;
boolean next = false;
for (k=1;!next && argv[i][k];++k) {
int c = argv[i][k];
switch (c) {
case 'd':
g_datadir = argv[++i];
next = true;
break;
case 'r':
g_resourcedir = argv[++i];
next = true;
break;
case 'b':
g_basedir = argv[++i];
next = true;
break;
case 'i':
xmlfile = argv[++i];
next = true;
break;
case 't':
turn = atoi(argv[++i]);
next = true;
break;
case 'v':
quiet = 0;
break;
default:
usage(argv[0], argv[i]);
}
}
}
}
if (turn==-1) {
char fname[MAX_PATH];
FILE * F;
sprintf(fname, "%s/turn", basepath());
F = fopen(fname, "r+");
if (F) {
fgets(fname, sizeof(fname), F);
turn = atoi(fname);
fclose(F);
}
else turn = 0;
}
return 0;
}
static void
game_init(void)
{
init_triggers();
init_xmas();
register_names();
register_resources();
register_buildings();
register_ships();
register_spells();
#ifdef DUNGEON_MODULE
register_dungeon();
#endif
#ifdef MUSEUM_MODULE
register_museum();
#endif
#ifdef ARENA_MODULE
register_arena();
#endif
#ifdef WORMHOLE_MODULE
register_wormholes();
#endif
register_itemtypes();
register_xmlreader();
init_data(xmlfile);
init_locales();
/* init_resources(); must be done inside the xml-read, because requirements use items */
init_attributes();
init_rawmaterials();
init_gmcmd();
#ifdef INFOCMD_MODULE
init_info();
#endif
}
static void
game_done(void)
{
}
static void
init_curses(void)
{
@ -1299,81 +1137,3 @@ curses_readline(lua_State * L, const char * prompt)
return 1;
}
}
static dictionary * inifile;
static void
load_inifile(const char * filename)
{
dictionary * d = iniparser_new(filename);
if (d) {
const char * str;
g_basedir = iniparser_getstring(d, "common:base", g_basedir);
g_resourcedir = iniparser_getstring(d, "common:res", g_resourcedir);
xmlfile = iniparser_getstring(d, "common:xml", xmlfile);
str = iniparser_getstring(d, "common:encoding", NULL);
if (str) enc_gamedata = xmlParseCharEncoding(str);
str = iniparser_getstring(d, "common:locales", "de,en");
make_locales(str);
}
inifile = d;
}
#ifdef USE_C_MAIN
int
gmmain(int argc, char *argv[])
{
int i;
char * lc_ctype;
char * lc_numeric;
lc_ctype = setlocale(LC_ALL, "");
lc_numeric = setlocale(LC_NUMERIC, "C");
if (lc_ctype) lc_ctype = strdup(lc_ctype);
if (lc_numeric) lc_numeric = strdup(lc_numeric);
log_flags = LOG_FLUSH;
log_open(g_logfile);
global.data_version = RELEASE_VERSION;
kernel_init();
load_inifile("eressea.ini");
i = read_args(argc, argv);
if (i!=0) return i;
game_init();
if (turn>first_turn) {
char datafile[12];
sprintf(datafile, "%u", turn);
readgame(datafile, 0);
}
run_mapper();
game_done();
kernel_done();
log_close();
setlocale(LC_CTYPE, lc_ctype);
setlocale(LC_NUMERIC, lc_numeric);
free(lc_ctype);
free(lc_numeric);
if (inifile) iniparser_free(inifile);
return 0;
}
int
main(int argc, char *argv[])
{
return gmmain(argc, argv);
}
#endif

View file

@ -23,6 +23,8 @@ extern "C" {
extern void select_coordinate(struct selection * selected, int x, int y);
extern void run_mapper(void);
extern int force_color;
#ifdef __cplusplus
}
#endif

View file

@ -29,6 +29,7 @@
#include <kernel/eressea.h>
#include "console.h"
#include "gmtool.h"
/* initialization - TODO: init in separate module */
#include <attributes/attributes.h>
@ -432,6 +433,7 @@ usage(const char * prog, const char * arg)
"--nodebug : keine Logfiles für Kämpfe\n"
"--noreports : absolut keine Reporte schreiben\n"
"--debug : schreibt Debug-Ausgaben in die Datei debug\n"
"--color : force curses to use colors even when not detected\n"
"--nocr : keine CRs\n"
"--nonr : keine Reports\n"
"--crabsolute : absolute Koordinaten im CR\n"
@ -487,6 +489,12 @@ read_args(int argc, char **argv, lua_State * luaState)
else if (strcmp(argv[i]+2, "nodebug")==0) battledebug = false;
else if (strcmp(argv[i]+2, "console")==0) luafile=NULL;
else if (strcmp(argv[i]+2, "crabsolute")==0) opt_cr_absolute_coords = true;
else if (strcmp(argv[i]+2, "color")==0) {
/* force the editor to have colors */
force_color = 1;
} else if (strcmp(argv[i]+2, "current")==0) {
turn = -1;
}
else if (strcmp(argv[i]+2, "help")==0)
return usage(argv[0], NULL);
else
@ -621,6 +629,9 @@ load_inifile(const char * filename)
luafile = iniparser_getstring(d, "eressea:run", luafile);
g_reportdir = iniparser_getstring(d, "eressea:report", g_reportdir);
/* editor settings */
force_color = iniparser_getint(d, "editor:color", force_color);
str = iniparser_getstring(d, "common:locales", "de,en");
make_locales(str);
}