Änderungen am Parser. Quotes ("") werden jetzt mit \\ escaped.
  SPACE_REPLACEMENT (~) gibts noch, wird aber nur gelesen, nicht erzeugt.

Muss dringend ausgiebiger getestet werden.
This commit is contained in:
Enno Rehling 2004-07-02 05:41:47 +00:00
parent f4e49c0894
commit 7a036598fe
15 changed files with 152 additions and 71 deletions

View File

@ -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;

View File

@ -3876,7 +3876,7 @@ do_battle(void)
/* Auswirkungen berechnen: */
aftermath(b);
/*
#if MALLOCDBG
#ifdef MALLOCDBG
assert(_CrtCheckMemory());
#endif
*/

View File

@ -63,6 +63,7 @@
#include <umlaut.h>
#include <translation.h>
#include <crmessage.h>
#include <log.h>
#include <sql.h>
#include <xml.h>
@ -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)<size) {
*str++ = '\n';
}
break;
default:
if ((size_t)(str-start+1)<size) {
*str++ = (char)c;
}
}
break;
default:
*str++ = (char)c;
}
}
}
int
fwritestr(FILE * F, const char * str)
{
int nwrite = 0;
fputc('\"', F);
while (*str) {
int c = (int)(unsigned char)*str++;
switch (c) {
case '\\':
fputc('\\', F);
fputc(c, F);
nwrite+=2;
break;
case '\n':
fputc('\\', F);
fputc('n', F);
nwrite+=2;
break;
default:
fputc(c, F);
++nwrite;
}
}
fputc('\"', F);
return nwrite + 2;
}

View File

@ -1180,6 +1180,9 @@ extern int AllianceRestricted(void); /* flags restricted to allied factions */
extern struct order * default_order(const struct locale * lang);
extern int entertainmoney(const struct region * r);
extern int freadstr(FILE * F, char * str, size_t size);
extern int fwritestr(FILE * F, const char * str);
#ifdef __cplusplus
}
#endif

View File

@ -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)) {

View File

@ -341,7 +341,7 @@ ri36(FILE * F)
}
#define MAXLINE 4096*16
char *
static char *
getbuf(FILE * F)
{
char lbuf[MAXLINE];
@ -376,16 +376,17 @@ getbuf(FILE * F)
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) {

View File

@ -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
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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)
{

View File

@ -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);

View File

@ -55,15 +55,11 @@ extern "C" {
#endif
#if defined(_DEBUG) && defined(_MSC_VER)
# ifndef MALLOCDBG
# define MALLOCDBG 1
# endif
/* define MALLOCDBG in project settings, not here! */
# ifdef MALLOCDBG
# include <crtdbg.h>
# define _CRTDBG_MAP_ALLOC
#endif
#ifndef MALLOCDBG
# define MALLOCDBG 0
# endif
#endif
/**** ****

View File

@ -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"

View File

@ -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

View File

@ -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," ")