From 7a036598fe827722f20ad1f0157f3b748284dc8b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 2 Jul 2004 05:41:47 +0000 Subject: [PATCH] =?UTF-8?q?-=20http://eressea.upb.de/mantis/bug=5Fview=5Fp?= =?UTF-8?q?age.php=3Fbug=5Fid=3D0000149=20=20=20=C3=84nderungen=20am=20Par?= =?UTF-8?q?ser.=20Quotes=20("")=20werden=20jetzt=20mit=20\\=20escaped.=20?= =?UTF-8?q?=20=20SPACE=5FREPLACEMENT=20(~)=20gibts=20noch,=20wird=20aber?= =?UTF-8?q?=20nur=20gelesen,=20nicht=20erzeugt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Muss dringend ausgiebiger getestet werden. --- src/common/gamecode/creport.c | 16 +++++- src/common/kernel/battle.c | 2 +- src/common/kernel/eressea.c | 84 +++++++++++++++++++++++++++++++ src/common/kernel/eressea.h | 3 ++ src/common/kernel/movement.c | 10 ++-- src/common/kernel/save.c | 54 +++++++++----------- src/common/kernel/save.h | 1 - src/common/kernel/spell.c | 13 +++-- src/common/triggers/unitmessage.c | 8 +-- src/common/util/goodies.c | 8 --- src/common/util/goodies.h | 1 - src/config.h | 12 ++--- src/eressea/server.cpp | 4 +- src/mapper/map_partei.c | 2 - src/mapper/mapper.h | 5 -- 15 files changed, 152 insertions(+), 71 deletions(-) diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 3885dae54..710168cc8 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -378,8 +378,22 @@ cr_order(const void * v, char * buffer, const void * userdata) { order * ord = (order*)v; if (ord!=NULL) { + char * wp = buffer; char * cmd = getcommand(ord); - sprintf(buffer, "\"%s\"", cmd); + const char * rp = cmd; + + *wp++ = '\"'; + while (*rp) { + switch (*rp) { + case '\"': + case '\\': + *wp++ = '\\'; + default: + *wp++ = *rp++; + } + } + *wp++ = '\"'; + *wp++ = 0; } else strcpy(buffer, "\"\""); return 0; diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 56a55adaa..9e7d57d0e 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -3876,7 +3876,7 @@ do_battle(void) /* Auswirkungen berechnen: */ aftermath(b); /* - #if MALLOCDBG + #ifdef MALLOCDBG assert(_CrtCheckMemory()); #endif */ diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 825fe6e85..f91934e56 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -3290,3 +3291,86 @@ entertainmoney(const region *r) return n; } + +int +freadstr(FILE * F, char * start, size_t size) +{ + char * str = start; + boolean quote = false; + int nread = 0; + for (;;) { + int c = fgetc(F); + + ++nread; + if (isspace(c)) { + if (str==start) { + continue; + } + if (!quote) { + *str = 0; + return nread; + } + } + switch (c) { + case EOF: + return EOF; + case '"': + if (!quote && str!=start) { + log_error(("datafile contains a \" that isn't at the start of a string.\n")); + assert(!"datafile contains a \" that isn't at the start of a string.\n"); + } + if (quote) { + *str = 0; + return nread; + } + quote = true; + break; + case '\\': + c = fgetc(F); + ++nread; + switch (c) { + case EOF: + return EOF; + case 'n': + if ((size_t)(str-start+1)terrain != T_OCEAN && !flying_ship(sh)) { - sh->coast = reldirection(rnext, r); - } else { - sh->coast = NODIRECTION; - } + sh->coast = reldirection(rnext, r); + } else { + sh->coast = NODIRECTION; + } damage_ship(sh, 0.02); if (sh->damage>=sh->size * DAMAGE_SCALE) { @@ -2251,7 +2251,7 @@ movement(void) if (u->ship && fval(u, UFL_OWNER)) { init_tokens(u->thisorder); skip_token(); - if (move(u, true)!=0) repeat = true; + if (move(u, false)!=0) repeat = true; } } else { if (u->ship==NULL || !fval(u, UFL_OWNER)) { diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 3ff16114f..4aef0c398 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -341,7 +341,7 @@ ri36(FILE * F) } #define MAXLINE 4096*16 -char * +static char * getbuf(FILE * F) { char lbuf[MAXLINE]; @@ -364,28 +364,29 @@ getbuf(FILE * F) end = bp + strlen((const char *)bp); if (*(end-1)=='\n') *(--end) = 0; - else { - while (bp && !lbuf[MAXLINE-1] && lbuf[MAXLINE-2]!='\n') { - /* wenn die zeile länger als erlaubt war, - * wird der rest weggeworfen: */ - bp = (unsigned char *)fgets(buf, 1024, F); - comment = false; - } - bp = (unsigned char *)lbuf; - } + else { + while (bp && !lbuf[MAXLINE-1] && lbuf[MAXLINE-2]!='\n') { + /* wenn die zeile länger als erlaubt war, + * wird der rest weggeworfen: */ + bp = (unsigned char *)fgets(buf, 1024, F); + comment = false; + } + bp = (unsigned char *)lbuf; + } cont = false; while (cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE && *bp) { if (isspace(*bp)) { - if (eatwhite) - { + if (eatwhite) { do { ++bp; } while ((char*)bp!=lbuf+MAXLINE && isspace(*bp)); if (!quote && !start && !comment) *(cp++)=' '; } else { - do { - if (!comment) *(cp++)=SPACE_REPLACEMENT; + if (!comment) *(cp++)=*(bp++); + while (cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE && isspace(*bp)) { + if (!comment) *(cp++)=*bp; ++bp; - } while (cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE && isspace(*bp)); + } + if (*bp==0) --cp; } } else if (iscntrl(*bp)) { @@ -400,6 +401,7 @@ getbuf(FILE * F) else { if (*bp=='"') { quote = (boolean)!quote; + *cp++ = *bp; eatwhite=true; } else if (*bp=='\\') cont=true; @@ -1521,9 +1523,7 @@ readfaction(FILE * F) rds(F, &f->name); -#ifndef AMIGA if (!quiet) printf(" - Lese Partei %s (%s)\n", f->name, factionid(f)); -#endif rds(F, &f->banner); rds(F, &f->email); @@ -1941,9 +1941,6 @@ readgame(const char * filename, int backup) } #endif fclose(F); -#ifdef AMIGA - fputs("Ok.", stderr); -#endif /* Unaufgeloeste Zeiger initialisieren */ printf("\n - Referenzen initialisieren...\n"); @@ -1964,23 +1961,20 @@ readgame(const char * filename, int backup) } resolve_IDs(); -#if 0 - /* speziell für Runde 199->200 */ - printf("Actions korrigieren...\n"); - iuw_fix_rest(); -#endif - for (r=regions;r;r=r->next) { building * b; for (b=r->buildings;b;b=b->next) update_lighthouse(b); } printf(" - Regionen initialisieren & verbinden...\n"); - for (r = regions; r; r = r->next) { - for (u = r->units; u; u = u->next) { - u->faction->alive = 1; + for (f = factions; f; f = f->next) { + for (u = f->units; u; u = u->nextF) { + if (u->number>0) { + f->alive = 1; + break; + } } } - if(findfaction(0)) { + if (findfaction(0)) { findfaction(0)->alive = 1; } if (loadplane || maxregions>=0) { diff --git a/src/common/kernel/save.h b/src/common/kernel/save.h index db7cfb992..1b65d24ee 100644 --- a/src/common/kernel/save.h +++ b/src/common/kernel/save.h @@ -73,7 +73,6 @@ extern struct region * readregion(FILE * stream, int x, int y); extern void writefaction(FILE * stream, const struct faction * f); extern struct faction * readfaction(FILE * stream); -extern char * getbuf(FILE * F); #ifdef __cplusplus } diff --git a/src/common/kernel/spell.c b/src/common/kernel/spell.c index 314177541..0c4ecb08f 100644 --- a/src/common/kernel/spell.c +++ b/src/common/kernel/spell.c @@ -6148,8 +6148,8 @@ sp_fetchastral(castorder *co) double power = co->force; int remaining_cap = (int)((power-3) * 1500); region_list * rtl = NULL; - region * rt = co->rt; - region * ro = NULL; + region * rt = co->rt; /* region to which we are fetching */ + region * ro = NULL; /* region in which the target is */ if (rplane(rt)!=get_normalplane()) { ADDMSG(&mage->faction->msgs, msg_message("error190", @@ -6174,9 +6174,12 @@ sp_fetchastral(castorder *co) /* this can happen several times if the units are from different astral * regions. Only possible on the intersections of schemes */ region_list * rfind; - rt = u->region; + if (getplane(u->region) != get_astralplane()) { + cmistake(mage, co->order, 193, MSG_MAGIC); + continue; + } if (rtl!=NULL) free_regionlist(rtl); - rtl = astralregions(rt, NULL); + rtl = astralregions(u->region, NULL); for (rfind=rtl;rfind!=NULL;rfind=rfind->next) { if (rfind->data==mage->region) break; } @@ -6186,7 +6189,7 @@ sp_fetchastral(castorder *co) "command region unit target", co->order, mage->region, mage, u)); continue; } - ro = u->region; + ro = u->region; } if (is_cursed(rt->attribs, C_ASTRALBLOCK, 0)) { diff --git a/src/common/triggers/unitmessage.c b/src/common/triggers/unitmessage.c index b75181fe7..070f98a38 100644 --- a/src/common/triggers/unitmessage.c +++ b/src/common/triggers/unitmessage.c @@ -76,7 +76,8 @@ unitmessage_write(const trigger * t, FILE * F) { unitmessage_data * td = (unitmessage_data*)t->data.v; fprintf(F, "%s ", itoa36(td->target->no)); - fprintf(F, "%s %d %d ", td->string, td->type, td->level); + fwritestr(F, td->string); + fprintf(F, "%d %d ", td->type, td->level); } static int @@ -91,7 +92,8 @@ unitmessage_read(trigger * t, FILE * F) td->target = findunit(i); if (td->target==NULL) ur_add((void*)i, (void**)&td->target, resolve_unit); - fscanf(F, "%s %d %d ", zText, &td->type, &td->level); + freadstr(F, zText, sizeof(zText)); + fscanf(F, "%d %d ", &td->type, &td->level); td->string = strdup(zText); return AT_READ_OK; @@ -112,7 +114,7 @@ trigger_unitmessage(unit * target, const char * string, int type, int level) trigger * t = t_new(&tt_unitmessage); unitmessage_data * td = (unitmessage_data*)t->data.v; td->target = target; - td->string = space_replace(strdup(string), SPACE_REPLACEMENT); + td->string = strdup(string); td->type = type; td->level = level; return t; diff --git a/src/common/util/goodies.c b/src/common/util/goodies.c index def595efb..90c0c0d29 100644 --- a/src/common/util/goodies.c +++ b/src/common/util/goodies.c @@ -86,14 +86,6 @@ hashstring(const char* s) return key % 0x7FFFFFFF; } -char * -space_replace(char * str, char replace) -{ - char * c = str; - while (*c) {if (isspace(*(unsigned char*)c)) *c = replace; c++;} - return str; -} - const char * escape_string(const char * str, char * buffer, unsigned int len) { diff --git a/src/common/util/goodies.h b/src/common/util/goodies.h index 6eb8b2e7a..e1d8e1b11 100644 --- a/src/common/util/goodies.h +++ b/src/common/util/goodies.h @@ -23,7 +23,6 @@ extern int *intlist_add(int *i_p, int i); extern int *intlist_find(int *i_p, int i); extern unsigned int hashstring(const char* s); -extern char *space_replace(char * str, char replace); extern const char *escape_string(const char * str, char * buffer, unsigned int len); extern boolean locale_check(void); extern char *fstrncat(char * buffer, const char * str, unsigned int size); diff --git a/src/config.h b/src/config.h index 4dcf49208..685c60403 100644 --- a/src/config.h +++ b/src/config.h @@ -55,15 +55,11 @@ extern "C" { #endif #if defined(_DEBUG) && defined(_MSC_VER) -# ifndef MALLOCDBG -# define MALLOCDBG 1 +/* define MALLOCDBG in project settings, not here! */ +# ifdef MALLOCDBG +# include +# define _CRTDBG_MAP_ALLOC # endif -# include -# define _CRTDBG_MAP_ALLOC -#endif - -#ifndef MALLOCDBG -# define MALLOCDBG 0 #endif /**** **** diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index ea268bd74..1979bc0c0 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -464,7 +464,9 @@ usage(const char * prog, const char * arg) "-r resdir : gibt das resourceverzeichnis an\n" "-t turn : read this datafile, not the most current one\n" "-o reportdir : gibt das reportverzeichnis an\n" - "-l logfile : specify an alternative logfile\n" + "-l path : specify the base script directory\n" + "-C : run in interactive mode\n" + "-e script : main lua script (default: default.lua)\n" "-R : erstellt nur die Reports neu\n" "--nomsg : keine Messages (RAM sparen)\n" "--nobattle : keine Kämpfe\n" diff --git a/src/mapper/map_partei.c b/src/mapper/map_partei.c index 67b15f181..6db3bf468 100644 --- a/src/mapper/map_partei.c +++ b/src/mapper/map_partei.c @@ -439,10 +439,8 @@ NeuePartei(region * r) if(late) give_latestart_bonus(r, u, late); -#ifndef AMIGA sprintf(buf, "newuser %s", email); system(buf); -#endif } static void diff --git a/src/mapper/mapper.h b/src/mapper/mapper.h index 360193569..6a83661b2 100644 --- a/src/mapper/mapper.h +++ b/src/mapper/mapper.h @@ -83,13 +83,8 @@ extern char *datadir; extern struct unit *clipunit; extern struct region *clipregion; extern struct ship *clipship; -#ifdef AMIGA -#define SX (stdscr->_maxx) -#define SY (stdscr->_maxy) -#else #define SX (stdscr->_maxx-1) #define SY (stdscr->_maxy-1) -#endif #define NL(S) adddbllist(&S," ")