mapper mit logging-kram

This commit is contained in:
Enno Rehling 2002-03-03 15:43:53 +00:00
parent 1e88605982
commit 036257d208
3 changed files with 41 additions and 6 deletions

View File

@ -29,8 +29,9 @@
static FILE * log; static FILE * log;
void void
readlog(FILE * log) log_read(const char * filename)
{ {
FILE * log = fopen(filename, "r");
faction **fp = &factions; faction **fp = &factions;
char buf[64]; char buf[64];
@ -67,14 +68,14 @@ readlog(FILE * log)
void void
log_faction(const struct faction * f) log_faction(const struct faction * f)
{ {
fprintf(log, "FACTION %s", factionid(f)); fprintf(log, "FACTION %s\n", factionid(f));
writefaction(log, f); writefaction(log, f);
} }
void void
log_unit(const struct unit * u) log_unit(const struct unit * u)
{ {
fprintf(log, "UNIT %s %d %d", unitid(u), u->region->x, u->region->y); fprintf(log, "UNIT %s %d %d\n", unitid(u), u->region->x, u->region->y);
writeunit(log, u); writeunit(log, u);
} }
@ -97,4 +98,4 @@ log_stop(void)
{ {
fclose(log); fclose(log);
log = NULL; log = NULL;
} }

View File

@ -13,7 +13,7 @@
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
extern void readlog(FILE * log); extern void log_read(const char * logname);
extern void log_region(const struct region * r); extern void log_region(const struct region * r);
extern void log_unit(const struct unit * r); extern void log_unit(const struct unit * r);
extern void log_faction(const struct faction * f); extern void log_faction(const struct faction * f);

View File

@ -1396,12 +1396,33 @@ makemonsters(void)
return f; return f;
} }
#include "logging.h"
static void
log_newstuff(void)
{
faction * f;
region * r;
for (f=factions;f;f=f->next) {
if (f->age==0) log_faction(f);
}
for (r=regions;r;r=r->next) {
unit * u;
if (r->age==0) log_region(r);
for (u=r->units;u;u=u->next) {
if (u->age==0) log_unit(u);
}
}
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int x = 0, y = 0, i; int x = 0, y = 0, i;
char *s; char *s;
boolean backup = true; boolean backup = true;
boolean logging = false;
boolean readlog = false;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
@ -1430,6 +1451,12 @@ main(int argc, char *argv[])
maxregions = (maxregions*81+80) / 81; maxregions = (maxregions*81+80) / 81;
break; break;
case 'q': quiet = true; break; case 'q': quiet = true; break;
case 'l':
logging = true;
break;
case 'R':
readlog = true;
break;
case 'n': case 'n':
switch (argv[i][2]) { switch (argv[i][2]) {
case 'b' : backup = false; break; case 'b' : backup = false; break;
@ -1499,7 +1526,13 @@ main(int argc, char *argv[])
if (findfaction(MONSTER_FACTION)==NULL) { if (findfaction(MONSTER_FACTION)==NULL) {
makemonsters(); makemonsters();
} }
if (readlog) {
log_read("mapper.log");
}
if (logging) {
log_start("mapper.log");
log_newstuff();
}
#ifdef OLD_ITEMS #ifdef OLD_ITEMS
make_xref(); make_xref();
#endif #endif
@ -1515,6 +1548,7 @@ main(int argc, char *argv[])
Tagged=NULL; Tagged=NULL;
movearound(x, y); movearound(x, y);
if (logging) log_stop();
if (modified) { if (modified) {
beep(); beep();
if (yes_no(0, "Daten wurden modifiziert! Abspeichern?", 'j')) { if (yes_no(0, "Daten wurden modifiziert! Abspeichern?", 'j')) {