eressea hat eine interaktive console (mit -C)

This commit is contained in:
Enno Rehling 2004-04-10 19:21:02 +00:00
parent 2a76decdb3
commit 2e8f8e28a3
6 changed files with 474 additions and 328 deletions

View File

@ -22,6 +22,7 @@ LUASERVER_SOURCES =
<lua>unit.cpp <lua>unit.cpp
server.cpp server.cpp
korrektur.c korrektur.c
console.c
; ;
LinkLibraries $(SERVER) : LinkLibraries $(SERVER) :

180
src/eressea/console.c Normal file
View File

@ -0,0 +1,180 @@
#include "console.h"
/* lua includes */
#include <lua50/lauxlib.h>
#include <lua50/lualib.h>
/* libc includes */
#include <assert.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/*** Lua Console ***/
/*
** this macro defines a function to show the prompt and reads the
** next line for manual input
*/
#ifndef lua_readline
#define lua_readline(L,prompt) readline(L,prompt)
/* maximum length of an input line */
#ifndef MAXINPUT
#define MAXINPUT 512
#endif
static int
readline(lua_State *l, const char *prompt)
{
static char buffer[MAXINPUT];
if (prompt) {
fputs(prompt, stdout);
fflush(stdout);
}
if (fgets(buffer, sizeof(buffer), stdin) == NULL)
return 0; /* read fails */
else {
lua_pushstring(l, buffer);
return 1;
}
}
#endif
#ifndef PROMPT
#define PROMPT "E> "
#endif
#ifndef PROMPT2
#define PROMPT2 "E>> "
#endif
static const char *
get_prompt(lua_State * L, int firstline)
{
const char *p = NULL;
lua_pushstring(L, firstline ? "_PROMPT" : "_PROMPT2");
lua_rawget(L, LUA_GLOBALSINDEX);
p = lua_tostring(L, -1);
if (p == NULL) p = (firstline ? PROMPT : PROMPT2);
lua_pop(L, 1); /* remove global */
return p;
}
static int
incomplete(lua_State * L, int status)
{
if (status!=LUA_ERRSYNTAX) return 0;
if (strstr(lua_tostring(L, -1), "near `<eof>'") == NULL) return 0;
lua_pop(L, 1);
return 1;
}
static void
l_message(const char *pname, const char *msg)
{
if (pname) fprintf(stderr, "%s: ", pname);
fprintf(stderr, "%s\n", msg);
}
static int
l_report(lua_State * L, int status)
{
const char *msg;
if (status) {
msg = lua_tostring(L, -1);
if (msg == NULL) msg = "(error with no message)";
l_message(NULL, msg);
lua_pop(L, 1);
}
return status;
}
/*
** this macro can be used by some `history' system to save lines
** read in manual input
*/
#ifndef lua_saveline
#define lua_saveline(L,line) /* empty */
#endif
static int
load_string(lua_State * L)
{
int status;
lua_settop(L, 0);
if (lua_readline(L, get_prompt(L, 1)) == 0) /* no input? */
return -1;
if (lua_tostring(L, -1)[0] == '=') { /* line starts with `=' ? */
lua_pushfstring(L, "return %s", lua_tostring(L, -1)+1);/* `=' -> `return' */
lua_remove(L, -2); /* remove original line */
}
for (;;) { /* repeat until gets a complete line */
status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
if (!incomplete(L, status)) break; /* cannot try to add lines? */
if (lua_readline(L, get_prompt(L, 0)) == 0) /* no more input? */
return -1;
lua_concat(L, lua_gettop(L)); /* join lines */
}
lua_saveline(L, lua_tostring(L, 1));
lua_remove(L, 1); /* remove line */
return status;
}
static void
lstop(lua_State *l, lua_Debug *ar)
{
(void)ar; /* unused arg. */
lua_sethook(l, NULL, 0, 0);
luaL_error(l, "interrupted!");
}
static lua_State * global_state = NULL;
static void
laction(int i)
{
signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
terminate process (default action) */
assert(global_state!=NULL);
lua_sethook(global_state, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
}
static int
lcall(lua_State * L, int narg, int clear)
{
int status;
int base = lua_gettop(L) - narg; /* function index */
lua_pushliteral(L, "_TRACEBACK");
lua_rawget(L, LUA_GLOBALSINDEX); /* get traceback function */
lua_insert(L, base); /* put it under chunk and args */
assert(global_state==NULL);
global_state = L; /* baaaad hack */
signal(SIGINT, laction);
status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
signal(SIGINT, SIG_DFL);
assert(global_state==L);
global_state=NULL;
lua_remove(L, base); /* remove traceback function */
return status;
}
int
lua_console(lua_State * L)
{
int status;
while ((status = load_string(L)) != -1) {
if (status == 0) status = lcall(L, 0, 0);
l_report(L, status);
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
lua_getglobal(L, "print");
lua_insert(L, 1);
if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
l_message(NULL, lua_pushfstring(L, "error calling `print' (%s)",
lua_tostring(L, -1)));
}
}
lua_settop(L, 0); /* clear stack */
fputs("\n", stdout);
return 0;
}

20
src/eressea/console.h Normal file
View File

@ -0,0 +1,20 @@
/* vi: set ts=2:
* Eressea PB(E)M host Christian Schlittchen (corwin@amber.kn-bremen.de)
* (C) 1998-2004 Katja Zedel (katze@felidae.kn-bremen.de)
* Enno Rehling (enno@eressea-pbem.de)
*
* This program may not be used, modified or distributed without
* prior permission by the authors of Eressea.
**/
#ifdef __cplusplus
extern "C" {
#endif
#include <lua50/lua.h>
extern int lua_console(lua_State * L);
#ifdef __cplusplus
}
#endif

View File

@ -339,6 +339,12 @@
</FileConfiguration> </FileConfiguration>
</File> </File>
</Filter> </Filter>
<File
RelativePath=".\console.c">
</File>
<File
RelativePath=".\console.h">
</File>
<File <File
RelativePath=".\korrektur.c"> RelativePath=".\korrektur.c">
<FileConfiguration <FileConfiguration

View File

@ -426,56 +426,6 @@ init_malloc_debug(void)
} }
#endif #endif
#if 0
static void
write_stats(void)
{
FILE * F;
char zText[MAX_PATH];
strcat(strcpy(zText, resourcepath()), "/spells");
F = fopen(zText, "wt");
if (F) {
int i, m = -1;
for (i=0;spelldaten[i].id;++i) {
if (spelldaten[i].magietyp!=m) {
m=spelldaten[i].magietyp;
fprintf(F, "\n%s\n", magietypen[m]);
}
fprintf(F, "%d\t%s\n", spelldaten[i].level, spelldaten[i].name);
}
fclose(F);
} else {
sprintf(buf, "fopen(%s): ", zText);
perror(buf);
}
strcat(strcpy(zText, resourcepath()), "/bonus");
F = fopen(buf, "wt");
if (F) {
race_t r;
for (r=0;r!=MAXRACES;++r) {
skill_t sk;
int i = 0;
fprintf(F, "const bonus %s_bonus = {\n\t", race[r].name[0]);
for (sk=0;sk!=MAXSKILLS;sk++) {
if (race[r].bonus[sk]) {
if (i==8) {
i = 0;
fputs("\n\t", F);
}
fprintf(F, "{ SK_%s, %d }, ", skillname(sk, NULL), race[r].bonus[sk]);
++i;
}
}
fputs("{ SK_NONE, 0 }\n};\n", F);
}
fclose(F);
} else {
sprintf(buf, "fopen(%s): ", zText);
perror(zText);
}
}
#endif
static int static int
usage(const char * prog, const char * arg) usage(const char * prog, const char * arg)
{ {

View File

@ -1,23 +1,23 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* *
* Eressea PB(E)M host Copyright (C) 1998-2003 * Eressea PB(E)M host Copyright (C) 1998-2003
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de) * Henning Peters (faroul@beyond.kn-bremen.de)
* Enno Rehling (enno@eressea-pbem.de) * Enno Rehling (enno@eressea-pbem.de)
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
* *
* based on: * based on:
* *
* Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace * Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace
* Atlantis v1.7 Copyright 1996 by Alex Schröder * Atlantis v1.7 Copyright 1996 by Alex Schröder
* *
* This program may not be used, modified or distributed without * This program may not be used, modified or distributed without
* prior permission by the authors of Eressea. * prior permission by the authors of Eressea.
* This program may not be sold or used commercially without prior written * This program may not be sold or used commercially without prior written
* permission from the authors. * permission from the authors.
*/ */
#define LOCALE_CHECK #define LOCALE_CHECK
#ifdef __LCC__ #ifdef __LCC__
@ -29,6 +29,7 @@
#include <eressea.h> #include <eressea.h>
#include "korrektur.h" #include "korrektur.h"
#include "console.h"
/* initialization - TODO: init in separate module */ /* initialization - TODO: init in separate module */
#include <attributes/attributes.h> #include <attributes/attributes.h>
@ -97,44 +98,43 @@
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
#include <clocale> #include <clocale>
/** /**
** global variables we are importing from other modules ** global variables we are importing from other modules
**/ **/
extern "C" { extern "C" {
extern char * g_reportdir; extern char * g_reportdir;
extern char * g_datadir; extern char * g_datadir;
extern char * g_basedir; extern char * g_basedir;
extern char * g_resourcedir; extern char * g_resourcedir;
extern item_type * i_silver; extern item_type * i_silver;
extern boolean nonr; extern boolean nonr;
extern boolean nocr; extern boolean nocr;
extern boolean noreports; extern boolean noreports;
extern boolean nomer; extern boolean nomer;
extern boolean nomsg; extern boolean nomsg;
extern boolean nobattle; extern boolean nobattle;
extern boolean nomonsters; extern boolean nomonsters;
extern boolean nobattledebug; extern boolean nobattledebug;
extern boolean dirtyload; extern boolean dirtyload;
extern int demonfix; extern int demonfix;
extern int loadplane; extern int loadplane;
extern void debug_messagetypes(FILE * out); extern void debug_messagetypes(FILE * out);
extern void free_region(region * r); extern void free_region(region * r);
extern void render_init(void); extern void render_init(void);
extern void free_borders(void); extern void free_borders(void);
extern boolean opt_cr_absolute_coords; extern boolean opt_cr_absolute_coords;
#ifdef FUZZY_BASE36 #ifdef FUZZY_BASE36
extern int fuzzy_hits; extern int fuzzy_hits;
#endif /* FUZZY_BASE36 */ #endif /* FUZZY_BASE36 */
} }
/** /**
** global variables that we are exporting ** global variables that we are exporting
**/ **/
static char * orders = NULL; static char * orders = NULL;
static int nowrite = 0; static int nowrite = 0;
static boolean g_writemap = false; static boolean g_writemap = false;
@ -142,27 +142,11 @@ static boolean opt_reportonly = false;
static const char * luafile = "default.lua"; static const char * luafile = "default.lua";
struct settings global = { struct settings global = {
"Eressea", /* gamename */ "Eressea", /* gamename */
"eressea", /* resourcepath */ "eressea", /* resourcepath */
1000, /* maxunits */ 1000, /* maxunits */
}; };
#if 0
static int
crwritemap(void)
{
FILE * F = fopen("world.cr", "w+");
region * r;
for (r=regions;r;r=r->next) {
plane * p = rplane(r);
fprintf(F, "REGION %d %d %d\n", r->x, r->y, p?p->id:0);
fprintf(F, "\"%s\";Name\n\"%s\";Terrain\n", rname(r, default_locale), LOC(default_locale, terrain[rterrain(r)].name));
}
fclose(F);
return 0;
}
#endif
static void static void
game_init(void) game_init(void)
{ {
@ -195,7 +179,7 @@ game_init(void)
init_data(xmlfile); init_data(xmlfile);
init_locales(); init_locales();
/* init_resources(); must be done inside the xml-read, because requirements use items */ /* init_resources(); must be done inside the xml-read, because requirements use items */
init_attributes(); init_attributes();
init_races(); init_races();
@ -223,24 +207,24 @@ game_init(void)
static void static void
getgarbage(void) getgarbage(void)
{ {
faction *f; faction *f;
/* Get rid of stuff that was only relevant last turn */ /* Get rid of stuff that was only relevant last turn */
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
/* memset(f->showdata, 0, sizeof f->showdata); */ /* memset(f->showdata, 0, sizeof f->showdata); */
freestrlist(f->mistakes); freestrlist(f->mistakes);
f->mistakes = 0; f->mistakes = 0;
/* TODO: free msgs */ /* TODO: free msgs */
} }
#if 0 #if 0
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
freestrlist(r->comments); freestrlist(r->comments);
r->comments = 0; r->comments = 0;
freestrlist(r->botschaften); freestrlist(r->botschaften);
r->botschaften = 0; r->botschaften = 0;
} }
#endif #endif
} }
@ -340,27 +324,27 @@ update_subscriptions(void)
int int
process_orders() process_orders()
{ {
struct summary * begin, * end; struct summary * begin, * end;
#ifdef SHORTPWDS #ifdef SHORTPWDS
readshortpwds("passwords"); readshortpwds("passwords");
#endif #endif
begin = make_summary(false); begin = make_summary(false);
printf(" - Korrekturen Runde %d\n", turn); printf(" - Korrekturen Runde %d\n", turn);
korrektur(); korrektur();
turn++; turn++;
puts(" - entferne Texte der letzten Runde"); puts(" - entferne Texte der letzten Runde");
getgarbage(); getgarbage();
puts(" - Nehme Korrekturen am Datenbestand vor"); puts(" - Nehme Korrekturen am Datenbestand vor");
#if BENCHMARK #if BENCHMARK
exit(0); exit(0);
#endif #endif
processorders(); processorders();
score(); score();
#ifdef WACH_WAFF #ifdef WACH_WAFF
remove_unequipped_guarded(); remove_unequipped_guarded();
#endif #endif
korrektur_end(); korrektur_end();
end = make_summary(true); end = make_summary(true);
report_summary(end, begin, false); report_summary(end, begin, false);
@ -376,65 +360,65 @@ process_orders()
static void static void
game_done(void) game_done(void)
{ {
/* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur /* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur
* zum Debugging interessant, wenn man Leak Detection hat, und nach * zum Debugging interessant, wenn man Leak Detection hat, und nach
* nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt * nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt
* wird (temporäre Hilsstrukturen) */ * wird (temporäre Hilsstrukturen) */
unit *u, *u2; unit *u, *u2;
region *r, *r2; region *r, *r2;
building *b, *b2; building *b, *b2;
faction *f, *f2; faction *f, *f2;
ship *s, *s2; ship *s, *s2;
free(used_faction_ids); free(used_faction_ids);
for (r = regions; r; r = r2) { for (r = regions; r; r = r2) {
#if 0 #if 0
msg * m = r->msgs; msg * m = r->msgs;
while (m) { while (m) {
msg * x = m; msg * x = m;
m = m->next; m = m->next;
if (x->type->finalize) x->type->finalize(x); if (x->type->finalize) x->type->finalize(x);
free(x); free(x);
} }
rm = rm->next; rm = rm->next;
} }
#endif #endif
for (u = r->units; u; u = u2) { for (u = r->units; u; u = u2) {
u2 = u->next; u2 = u->next;
stripunit(u); stripunit(u);
uunhash(u); uunhash(u);
free(u); free(u);
} }
for (b = r->buildings; b; b = b2) { for (b = r->buildings; b; b = b2) {
free(b->name); free(b->name);
free(b->display); free(b->display);
b2 = b->next; b2 = b->next;
free(b); free(b);
} }
for (s = r->ships; s; s = s2) { for (s = r->ships; s; s = s2) {
free(s->name); free(s->name);
free(s->display); free(s->display);
s2 = s->next; s2 = s->next;
free(s); free(s);
} }
r2 = r->next; r2 = r->next;
free_region(r); free_region(r);
} }
for (f = factions; f; f = f2) { for (f = factions; f; f = f2) {
stripfaction(f); stripfaction(f);
f2 = f->next; f2 = f->next;
free(f); free(f);
} }
while (planes) { while (planes) {
plane * pl = planes; plane * pl = planes;
planes = planes->next; planes = planes->next;
free(pl); free(pl);
} }
#ifdef LEAK_DETECT #ifdef LEAK_DETECT
leak_report(stderr); leak_report(stderr);
#endif #endif
creport_cleanup(); creport_cleanup();
report_cleanup(); report_cleanup();
} }
#endif #endif
@ -459,30 +443,30 @@ init_malloc_debug(void)
static int static int
usage(const char * prog, const char * arg) usage(const char * prog, const char * arg)
{ {
if (arg) { if (arg) {
fprintf(stderr, "unknown argument: %s\n\n", arg); fprintf(stderr, "unknown argument: %s\n\n", arg);
} }
fprintf(stderr, "Usage: %s [options]\n" fprintf(stderr, "Usage: %s [options]\n"
"-x n : Lädt nur die ersten n regionen\n" "-x n : Lädt nur die ersten n regionen\n"
"-f x y : Lädt nur die regionen ab (x,y)\n" "-f x y : Lädt nur die regionen ab (x,y)\n"
"-v befehlsdatei : verarbeitet automatisch die angegebene Befehlsdatei\n" "-v befehlsdatei : verarbeitet automatisch die angegebene Befehlsdatei\n"
"-d datadir : gibt das datenverzeichnis an\n" "-d datadir : gibt das datenverzeichnis an\n"
"-b basedir : gibt das basisverzeichnis an\n" "-b basedir : gibt das basisverzeichnis an\n"
"-r resdir : gibt das resourceverzeichnis an\n" "-r resdir : gibt das resourceverzeichnis an\n"
"-t turn : read this datafile, not the most current one\n" "-t turn : read this datafile, not the most current one\n"
"-o reportdir : gibt das reportverzeichnis an\n" "-o reportdir : gibt das reportverzeichnis an\n"
"-l logfile : specify an alternative logfile\n" "-l logfile : specify an alternative logfile\n"
"-R : erstellt nur die Reports neu\n" "-R : erstellt nur die Reports neu\n"
"--nomsg : keine Messages (RAM sparen)\n" "--nomsg : keine Messages (RAM sparen)\n"
"--nobattle : keine Kämpfe\n" "--nobattle : keine Kämpfe\n"
"--nomonsters : keine monster KI\n" "--nomonsters : keine monster KI\n"
"--nodebug : keine Logfiles für Kämpfe\n" "--nodebug : keine Logfiles für Kämpfe\n"
"--debug : schreibt Debug-Ausgaben in die Datei debug\n" "--debug : schreibt Debug-Ausgaben in die Datei debug\n"
"--nocr : keine CRs\n" "--nocr : keine CRs\n"
"--nonr : keine Reports\n" "--nonr : keine Reports\n"
"--crabsolute : absolute Koordinaten im CR\n" "--crabsolute : absolute Koordinaten im CR\n"
"--help : help\n", prog); "--help : help\n", prog);
return -1; return -1;
} }
static void static void
@ -502,80 +486,84 @@ setLuaNumber(lua_State * luaState, const char * name, double value)
static int static int
read_args(int argc, char **argv, lua_State * luaState) read_args(int argc, char **argv, lua_State * luaState)
{ {
int i; int i;
char * c; char * c;
for (i=1;i!=argc;++i) { for (i=1;i!=argc;++i) {
if (argv[i][0]!='-') { if (argv[i][0]!='-') {
return usage(argv[0], argv[i]); return usage(argv[0], argv[i]);
} else if (argv[i][1]=='-') { /* long format */ } else if (argv[i][1]=='-') { /* long format */
if (strcmp(argv[i]+2, "nocr")==0) nocr = true; if (strcmp(argv[i]+2, "nocr")==0) nocr = true;
else if (strcmp(argv[i]+2, "nosave")==0) nowrite = true; else if (strcmp(argv[i]+2, "nosave")==0) nowrite = true;
else if (strcmp(argv[i]+2, "noreports")==0) { else if (strcmp(argv[i]+2, "noreports")==0) {
noreports = true; noreports = true;
nocr = true; nocr = true;
nocr = true; nocr = true;
} }
else if (strcmp(argv[i]+2, "xml")==0) xmlfile = argv[++i]; else if (strcmp(argv[i]+2, "xml")==0) xmlfile = argv[++i];
else if (strcmp(argv[i]+2, "dirtyload")==0) dirtyload = true; else if (strcmp(argv[i]+2, "dirtyload")==0) dirtyload = true;
else if (strcmp(argv[i]+2, "nonr")==0) nonr = true; else if (strcmp(argv[i]+2, "nonr")==0) nonr = true;
else if (strcmp(argv[i]+2, "nomsg")==0) nomsg = true; else if (strcmp(argv[i]+2, "nomsg")==0) nomsg = true;
else if (strcmp(argv[i]+2, "nobattle")==0) nobattle = true; else if (strcmp(argv[i]+2, "nobattle")==0) nobattle = true;
else if (strcmp(argv[i]+2, "nomonsters")==0) nomonsters = true; else if (strcmp(argv[i]+2, "nomonsters")==0) nomonsters = true;
else if (strcmp(argv[i]+2, "nodebug")==0) nobattledebug = true; else if (strcmp(argv[i]+2, "nodebug")==0) nobattledebug = true;
else if (strcmp(argv[i]+2, "crabsolute")==0) opt_cr_absolute_coords = true; else if (strcmp(argv[i]+2, "console")==0) luafile=NULL;
else if (strcmp(argv[i]+2, "help")==0) else if (strcmp(argv[i]+2, "crabsolute")==0) opt_cr_absolute_coords = true;
return usage(argv[0], NULL); else if (strcmp(argv[i]+2, "help")==0)
else return usage(argv[0], NULL);
return usage(argv[0], argv[i]); else
} else switch(argv[i][1]) { return usage(argv[0], argv[i]);
case 'o': } else switch(argv[i][1]) {
g_reportdir = argv[++i]; case 'C':
break; luafile=NULL;
break;
case 'o':
g_reportdir = argv[++i];
break;
case 'e': case 'e':
luafile = argv[++i]; luafile = argv[++i];
break; break;
case 'D': /* DEBUG */ case 'D': /* DEBUG */
demonfix = atoi(argv[++i]); demonfix = atoi(argv[++i]);
break; break;
case 'd': case 'd':
g_datadir = argv[++i]; g_datadir = argv[++i];
break; break;
case 'r': case 'r':
g_resourcedir = argv[++i]; g_resourcedir = argv[++i];
break; break;
case 'b': case 'b':
g_basedir = argv[++i]; g_basedir = argv[++i];
break; break;
case 'i': case 'i':
xmlfile = argv[++i]; xmlfile = argv[++i];
break; break;
case 't': case 't':
turn = atoi(argv[++i]); turn = atoi(argv[++i]);
break; break;
case 'f': case 'f':
firstx = atoi(argv[++i]); firstx = atoi(argv[++i]);
firsty = atoi(argv[++i]); firsty = atoi(argv[++i]);
break; break;
case 'q': case 'q':
quiet = 1; quiet = 1;
break; break;
case 'v': case 'v':
if (i<argc) { if (i<argc) {
orders = argv[++i]; orders = argv[++i];
} else { } else {
return usage(argv[0], argv[i]); return usage(argv[0], argv[i]);
} }
break; break;
case 'p': case 'p':
loadplane = atoi(argv[++i]); loadplane = atoi(argv[++i]);
break; break;
case 'x': case 'x':
maxregions = atoi(argv[++i]); maxregions = atoi(argv[++i]);
maxregions = (maxregions*81+80) / 81; maxregions = (maxregions*81+80) / 81;
break; break;
case 'X': case 'X':
dirtyload = true; dirtyload = true;
break; break;
case 's': case 's':
c = argv[++i]; c = argv[++i];
while (*c && (*c!='=')) ++c; while (*c && (*c!='=')) ++c;
@ -592,19 +580,19 @@ read_args(int argc, char **argv, lua_State * luaState)
setLuaNumber(luaState, argv[i], atof(c)); setLuaNumber(luaState, argv[i], atof(c));
} }
break; break;
case 'l': case 'l':
log_open(argv[++i]); log_open(argv[++i]);
break; break;
case 'w': case 'w':
g_writemap = true; g_writemap = true;
break; break;
case 'R': case 'R':
opt_reportonly = true; opt_reportonly = true;
break; break;
default: default:
usage(argv[0], argv[i]); usage(argv[0], argv[i]);
} }
} }
/* add some more variables to the lua globals */ /* add some more variables to the lua globals */
setLuaString(luaState, "datapath", datapath()); setLuaString(luaState, "datapath", datapath());
@ -623,55 +611,56 @@ extern int xml_writebuildings(void);
#endif #endif
typedef struct lostdata { typedef struct lostdata {
int x, y; int x, y;
int prevunit; int prevunit;
int building; int building;
int ship; int ship;
} lostdata; } lostdata;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int i; int i;
char zText[MAX_PATH]; char zText[MAX_PATH];
sqlpatch = true; sqlpatch = true;
updatelog = fopen("update.log", "w"); updatelog = fopen("update.log", "w");
log_open("eressea.log"); log_open("eressea.log");
printf("\n%s PBEM host\n" printf("\n%s PBEM host\n"
"Copyright (C) 1996-2003 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" "Copyright (C) 1996-2003 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version()); "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version());
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
#ifdef LOCALE_CHECK #ifdef LOCALE_CHECK
if (!locale_check()) { if (!locale_check()) {
log_error(("The current locale is not suitable for international Eressea.\n")); log_error(("The current locale is not suitable for international Eressea.\n"));
return -1; return -1;
} }
#endif #endif
#ifdef MALLOCDBG #ifdef MALLOCDBG
init_malloc_debug(); init_malloc_debug();
#endif #endif
lua_State * luaState = lua_init(); lua_State * luaState = lua_init();
if ((i=read_args(argc, argv, luaState))!=0) return i; if ((i=read_args(argc, argv, luaState))!=0) return i;
strcat(strcpy(zText, resourcepath()), "/timestrings"); strcat(strcpy(zText, resourcepath()), "/timestrings");
if ((i=read_datenames(zText))!=0) return i; if ((i=read_datenames(zText))!=0) return i;
kernel_init(); kernel_init();
game_init(); game_init();
// run the main script // run the main script
lua_dofile(luaState, luafile); if (luafile==NULL) lua_console(luaState);
else lua_dofile(luaState, luafile);
#ifdef CLEANUP_CODE #ifdef CLEANUP_CODE
game_done(); game_done();
#endif #endif
kernel_done(); kernel_done();
lua_done(luaState); lua_done(luaState);
log_close(); log_close();
fclose(updatelog); fclose(updatelog);
return 0; return 0;
} }