forked from github/server
Ä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:
parent
f4e49c0894
commit
7a036598fe
|
@ -378,8 +378,22 @@ cr_order(const void * v, char * buffer, const void * userdata)
|
||||||
{
|
{
|
||||||
order * ord = (order*)v;
|
order * ord = (order*)v;
|
||||||
if (ord!=NULL) {
|
if (ord!=NULL) {
|
||||||
|
char * wp = buffer;
|
||||||
char * cmd = getcommand(ord);
|
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, "\"\"");
|
else strcpy(buffer, "\"\"");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -3876,7 +3876,7 @@ do_battle(void)
|
||||||
/* Auswirkungen berechnen: */
|
/* Auswirkungen berechnen: */
|
||||||
aftermath(b);
|
aftermath(b);
|
||||||
/*
|
/*
|
||||||
#if MALLOCDBG
|
#ifdef MALLOCDBG
|
||||||
assert(_CrtCheckMemory());
|
assert(_CrtCheckMemory());
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -63,6 +63,7 @@
|
||||||
#include <umlaut.h>
|
#include <umlaut.h>
|
||||||
#include <translation.h>
|
#include <translation.h>
|
||||||
#include <crmessage.h>
|
#include <crmessage.h>
|
||||||
|
#include <log.h>
|
||||||
#include <sql.h>
|
#include <sql.h>
|
||||||
#include <xml.h>
|
#include <xml.h>
|
||||||
|
|
||||||
|
@ -3290,3 +3291,86 @@ entertainmoney(const region *r)
|
||||||
|
|
||||||
return n;
|
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;
|
||||||
|
}
|
|
@ -1180,6 +1180,9 @@ extern int AllianceRestricted(void); /* flags restricted to allied factions */
|
||||||
extern struct order * default_order(const struct locale * lang);
|
extern struct order * default_order(const struct locale * lang);
|
||||||
extern int entertainmoney(const struct region * r);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2251,7 +2251,7 @@ movement(void)
|
||||||
if (u->ship && fval(u, UFL_OWNER)) {
|
if (u->ship && fval(u, UFL_OWNER)) {
|
||||||
init_tokens(u->thisorder);
|
init_tokens(u->thisorder);
|
||||||
skip_token();
|
skip_token();
|
||||||
if (move(u, true)!=0) repeat = true;
|
if (move(u, false)!=0) repeat = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (u->ship==NULL || !fval(u, UFL_OWNER)) {
|
if (u->ship==NULL || !fval(u, UFL_OWNER)) {
|
||||||
|
|
|
@ -341,7 +341,7 @@ ri36(FILE * F)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAXLINE 4096*16
|
#define MAXLINE 4096*16
|
||||||
char *
|
static char *
|
||||||
getbuf(FILE * F)
|
getbuf(FILE * F)
|
||||||
{
|
{
|
||||||
char lbuf[MAXLINE];
|
char lbuf[MAXLINE];
|
||||||
|
@ -376,16 +376,17 @@ getbuf(FILE * F)
|
||||||
cont = false;
|
cont = false;
|
||||||
while (cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE && *bp) {
|
while (cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE && *bp) {
|
||||||
if (isspace(*bp)) {
|
if (isspace(*bp)) {
|
||||||
if (eatwhite)
|
if (eatwhite) {
|
||||||
{
|
|
||||||
do { ++bp; } while ((char*)bp!=lbuf+MAXLINE && isspace(*bp));
|
do { ++bp; } while ((char*)bp!=lbuf+MAXLINE && isspace(*bp));
|
||||||
if (!quote && !start && !comment) *(cp++)=' ';
|
if (!quote && !start && !comment) *(cp++)=' ';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
do {
|
if (!comment) *(cp++)=*(bp++);
|
||||||
if (!comment) *(cp++)=SPACE_REPLACEMENT;
|
while (cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE && isspace(*bp)) {
|
||||||
|
if (!comment) *(cp++)=*bp;
|
||||||
++bp;
|
++bp;
|
||||||
} while (cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE && isspace(*bp));
|
}
|
||||||
|
if (*bp==0) --cp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (iscntrl(*bp)) {
|
else if (iscntrl(*bp)) {
|
||||||
|
@ -400,6 +401,7 @@ getbuf(FILE * F)
|
||||||
else {
|
else {
|
||||||
if (*bp=='"') {
|
if (*bp=='"') {
|
||||||
quote = (boolean)!quote;
|
quote = (boolean)!quote;
|
||||||
|
*cp++ = *bp;
|
||||||
eatwhite=true;
|
eatwhite=true;
|
||||||
}
|
}
|
||||||
else if (*bp=='\\') cont=true;
|
else if (*bp=='\\') cont=true;
|
||||||
|
@ -1521,9 +1523,7 @@ readfaction(FILE * F)
|
||||||
|
|
||||||
rds(F, &f->name);
|
rds(F, &f->name);
|
||||||
|
|
||||||
#ifndef AMIGA
|
|
||||||
if (!quiet) printf(" - Lese Partei %s (%s)\n", f->name, factionid(f));
|
if (!quiet) printf(" - Lese Partei %s (%s)\n", f->name, factionid(f));
|
||||||
#endif
|
|
||||||
|
|
||||||
rds(F, &f->banner);
|
rds(F, &f->banner);
|
||||||
rds(F, &f->email);
|
rds(F, &f->email);
|
||||||
|
@ -1941,9 +1941,6 @@ readgame(const char * filename, int backup)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fclose(F);
|
fclose(F);
|
||||||
#ifdef AMIGA
|
|
||||||
fputs("Ok.", stderr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Unaufgeloeste Zeiger initialisieren */
|
/* Unaufgeloeste Zeiger initialisieren */
|
||||||
printf("\n - Referenzen initialisieren...\n");
|
printf("\n - Referenzen initialisieren...\n");
|
||||||
|
@ -1964,23 +1961,20 @@ readgame(const char * filename, int backup)
|
||||||
}
|
}
|
||||||
resolve_IDs();
|
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) {
|
for (r=regions;r;r=r->next) {
|
||||||
building * b;
|
building * b;
|
||||||
for (b=r->buildings;b;b=b->next) update_lighthouse(b);
|
for (b=r->buildings;b;b=b->next) update_lighthouse(b);
|
||||||
}
|
}
|
||||||
printf(" - Regionen initialisieren & verbinden...\n");
|
printf(" - Regionen initialisieren & verbinden...\n");
|
||||||
for (r = regions; r; r = r->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = f->units; u; u = u->nextF) {
|
||||||
u->faction->alive = 1;
|
if (u->number>0) {
|
||||||
|
f->alive = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(findfaction(0)) {
|
}
|
||||||
|
if (findfaction(0)) {
|
||||||
findfaction(0)->alive = 1;
|
findfaction(0)->alive = 1;
|
||||||
}
|
}
|
||||||
if (loadplane || maxregions>=0) {
|
if (loadplane || maxregions>=0) {
|
||||||
|
|
|
@ -73,7 +73,6 @@ extern struct region * readregion(FILE * stream, int x, int y);
|
||||||
|
|
||||||
extern void writefaction(FILE * stream, const struct faction * f);
|
extern void writefaction(FILE * stream, const struct faction * f);
|
||||||
extern struct faction * readfaction(FILE * stream);
|
extern struct faction * readfaction(FILE * stream);
|
||||||
extern char * getbuf(FILE * F);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -6148,8 +6148,8 @@ sp_fetchastral(castorder *co)
|
||||||
double power = co->force;
|
double power = co->force;
|
||||||
int remaining_cap = (int)((power-3) * 1500);
|
int remaining_cap = (int)((power-3) * 1500);
|
||||||
region_list * rtl = NULL;
|
region_list * rtl = NULL;
|
||||||
region * rt = co->rt;
|
region * rt = co->rt; /* region to which we are fetching */
|
||||||
region * ro = NULL;
|
region * ro = NULL; /* region in which the target is */
|
||||||
|
|
||||||
if (rplane(rt)!=get_normalplane()) {
|
if (rplane(rt)!=get_normalplane()) {
|
||||||
ADDMSG(&mage->faction->msgs, msg_message("error190",
|
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
|
/* this can happen several times if the units are from different astral
|
||||||
* regions. Only possible on the intersections of schemes */
|
* regions. Only possible on the intersections of schemes */
|
||||||
region_list * rfind;
|
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);
|
if (rtl!=NULL) free_regionlist(rtl);
|
||||||
rtl = astralregions(rt, NULL);
|
rtl = astralregions(u->region, NULL);
|
||||||
for (rfind=rtl;rfind!=NULL;rfind=rfind->next) {
|
for (rfind=rtl;rfind!=NULL;rfind=rfind->next) {
|
||||||
if (rfind->data==mage->region) break;
|
if (rfind->data==mage->region) break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,8 @@ unitmessage_write(const trigger * t, FILE * F)
|
||||||
{
|
{
|
||||||
unitmessage_data * td = (unitmessage_data*)t->data.v;
|
unitmessage_data * td = (unitmessage_data*)t->data.v;
|
||||||
fprintf(F, "%s ", itoa36(td->target->no));
|
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
|
static int
|
||||||
|
@ -91,7 +92,8 @@ unitmessage_read(trigger * t, FILE * F)
|
||||||
td->target = findunit(i);
|
td->target = findunit(i);
|
||||||
if (td->target==NULL) ur_add((void*)i, (void**)&td->target, resolve_unit);
|
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);
|
td->string = strdup(zText);
|
||||||
|
|
||||||
return AT_READ_OK;
|
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);
|
trigger * t = t_new(&tt_unitmessage);
|
||||||
unitmessage_data * td = (unitmessage_data*)t->data.v;
|
unitmessage_data * td = (unitmessage_data*)t->data.v;
|
||||||
td->target = target;
|
td->target = target;
|
||||||
td->string = space_replace(strdup(string), SPACE_REPLACEMENT);
|
td->string = strdup(string);
|
||||||
td->type = type;
|
td->type = type;
|
||||||
td->level = level;
|
td->level = level;
|
||||||
return t;
|
return t;
|
||||||
|
|
|
@ -86,14 +86,6 @@ hashstring(const char* s)
|
||||||
return key % 0x7FFFFFFF;
|
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 *
|
const char *
|
||||||
escape_string(const char * str, char * buffer, unsigned int len)
|
escape_string(const char * str, char * buffer, unsigned int len)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,6 @@ extern int *intlist_add(int *i_p, int i);
|
||||||
extern int *intlist_find(int *i_p, int i);
|
extern int *intlist_find(int *i_p, int i);
|
||||||
extern unsigned int hashstring(const char* s);
|
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 const char *escape_string(const char * str, char * buffer, unsigned int len);
|
||||||
extern boolean locale_check(void);
|
extern boolean locale_check(void);
|
||||||
extern char *fstrncat(char * buffer, const char * str, unsigned int size);
|
extern char *fstrncat(char * buffer, const char * str, unsigned int size);
|
||||||
|
|
10
src/config.h
10
src/config.h
|
@ -55,15 +55,11 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_DEBUG) && defined(_MSC_VER)
|
#if defined(_DEBUG) && defined(_MSC_VER)
|
||||||
# ifndef MALLOCDBG
|
/* define MALLOCDBG in project settings, not here! */
|
||||||
# define MALLOCDBG 1
|
# ifdef MALLOCDBG
|
||||||
# endif
|
|
||||||
# include <crtdbg.h>
|
# include <crtdbg.h>
|
||||||
# define _CRTDBG_MAP_ALLOC
|
# define _CRTDBG_MAP_ALLOC
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
#ifndef MALLOCDBG
|
|
||||||
# define MALLOCDBG 0
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**** ****
|
/**** ****
|
||||||
|
|
|
@ -464,7 +464,9 @@ usage(const char * prog, const char * arg)
|
||||||
"-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 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"
|
"-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"
|
||||||
|
|
|
@ -439,10 +439,8 @@ NeuePartei(region * r)
|
||||||
|
|
||||||
if(late) give_latestart_bonus(r, u, late);
|
if(late) give_latestart_bonus(r, u, late);
|
||||||
|
|
||||||
#ifndef AMIGA
|
|
||||||
sprintf(buf, "newuser %s", email);
|
sprintf(buf, "newuser %s", email);
|
||||||
system(buf);
|
system(buf);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -83,13 +83,8 @@ extern char *datadir;
|
||||||
extern struct unit *clipunit;
|
extern struct unit *clipunit;
|
||||||
extern struct region *clipregion;
|
extern struct region *clipregion;
|
||||||
extern struct ship *clipship;
|
extern struct ship *clipship;
|
||||||
#ifdef AMIGA
|
|
||||||
#define SX (stdscr->_maxx)
|
|
||||||
#define SY (stdscr->_maxy)
|
|
||||||
#else
|
|
||||||
#define SX (stdscr->_maxx-1)
|
#define SX (stdscr->_maxx-1)
|
||||||
#define SY (stdscr->_maxy-1)
|
#define SY (stdscr->_maxy-1)
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NL(S) adddbllist(&S," ")
|
#define NL(S) adddbllist(&S," ")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue