diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 710168cc8..48a762c1e 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -489,9 +489,8 @@ render_messages(FILE * F, faction * f, message_list *msgs) if (nr_render(m->msg, f->locale, nrbuffer, sizeof(nrbuffer), f)==0 && nrbuffer[0]) { fprintf(F, "MESSAGE %u\n", (unsigned int)m->msg);/*++msgno); */ fprintf(F, "%d;type\n", hash); - fputs("\"", F); - fputs(nrbuffer, F); - fputs("\";rendered\n", F); + fwritestr(F, nrbuffer); + fputs(";rendered\n", F); printed = true; } #endif @@ -700,7 +699,6 @@ cr_output_unit(FILE * F, const region * r, if (u->faction == f || omniscient(f)) { order * ord; const char *c; - char * cmd; int i; const attrib * a; @@ -738,15 +736,13 @@ cr_output_unit(FILE * F, const region * r, /* default commands */ fprintf(F, "COMMANDS\n"); if (u->lastorder) { - cmd = getcommand(u->lastorder); - fprintf(F, "\"%s\"\n", cmd); - free(cmd); + fwriteorder(F, u->lastorder, f->locale); + fputc('\n', F); } for (ord = u->orders; ord; ord = ord->next) { if (is_persistent(ord) && ord!=u->lastorder) { - cmd = getcommand(ord); - fprintf(F, "\"%s\"\n", cmd); - free(cmd); + fwriteorder(F, ord, f->locale); + fputc('\n', F); } } diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index f91934e56..8cffb2519 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -3356,6 +3356,7 @@ fwritestr(FILE * F, const char * str) while (*str) { int c = (int)(unsigned char)*str++; switch (c) { + case '"': case '\\': fputc('\\', F); fputc(c, F); diff --git a/src/common/kernel/order.c b/src/common/kernel/order.c index 21ab9fe21..0ecf081a3 100644 --- a/src/common/kernel/order.c +++ b/src/common/kernel/order.c @@ -163,7 +163,7 @@ write_order(const order * ord, const struct locale * lang, char * buffer, size_t } else { char * s = getcommand(ord); strncpy(buffer, s, size); - free(s); + free(s); } return buffer; } diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 4aef0c398..f19765bca 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -988,18 +988,10 @@ write_faction_reference(const faction * f, FILE * F) } void -fwrite_order(const order * ord, const struct locale * lang, FILE * F) +fwriteorder(FILE * F, const order * ord, const struct locale * lang) { - write_order(ord, lang, buf, sizeof(buf)); - fputs(buf, F); -} - -static void -writeorder(const order * ord, const struct locale * lang, FILE * F) -{ - fputc('\"', F); - fwrite_order(ord, lang, F); - fputs("\" ", F); + write_order(ord, lang, buf, sizeof(buf)); + fwritestr(F, buf); } unit * @@ -1093,11 +1085,11 @@ readunit(FILE * F) u->flags = ri(F) & ~UFL_DEBUG; /* Kurze persistente Befehle einlesen */ free_orders(&u->orders); - rs(F, buf); + freadstr(F, buf, sizeof(buf)); while(*buf != 0) { order * ord = parse_order(buf, u->faction->locale); if (ord!=NULL) addlist(&u->orders, ord); - rs(F, buf); + freadstr(F, buf, sizeof(buf)); } rs(F, buf); u->lastorder = parse_order(buf, u->faction->locale); @@ -1202,11 +1194,12 @@ writeunit(FILE * F, const unit * u) wnl(F); for (ord = u->orders; ord; ord=ord->next) { if (is_persistent(ord)) { - writeorder(ord, u->faction->locale, F); + fwriteorder(F, ord, u->faction->locale); + fputc(' ', F); } } - ws(F, ""); /* Abschluß der persistenten Befehle */ - writeorder(u->lastorder, u->faction->locale, F); + wnl(F); + fwriteorder(F, u->lastorder, u->faction->locale); wnl(F); assert(u->number >= 0); diff --git a/src/common/kernel/save.h b/src/common/kernel/save.h index 1b65d24ee..b37063b5c 100644 --- a/src/common/kernel/save.h +++ b/src/common/kernel/save.h @@ -74,6 +74,8 @@ 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 void fwriteorder(FILE * F, const struct order * ord, const struct locale * lang); + #ifdef __cplusplus } #endif