diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index f347bee61..c680c3268 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -631,12 +631,17 @@ cr_output_ship(FILE * F, const ship * sh, const unit * u, int fcaptain, const fa } static void -fwriteorder(FILE * F, const struct order * ord, const struct locale * lang) +fwriteorder(FILE * F, const struct order * ord, const struct locale * lang, boolean escape) { + char ebuf[1024]; char obuf[1024]; + const char * str = obuf; fputc('"', F); write_order(ord, obuf, sizeof(obuf)); - if (obuf[0]) fputs(obuf, F); + if (escape) { + str = escape_string(obuf, ebuf, sizeof(ebuf)); + } + if (str[0]) fputs(str, F); fputc('"', F); } @@ -842,14 +847,14 @@ cr_output_unit(FILE * F, const region * r, for (ord = u->old_orders; ord; ord = ord->next) { /* this new order will replace the old defaults */ if (is_persistent(ord)) { - fwriteorder(F, ord, f->locale); + fwriteorder(F, ord, f->locale, true); fputc('\n', F); } } for (ord = u->orders; ord; ord = ord->next) { if (u->old_orders && is_repeated(ord)) continue; /* unit has defaults */ if (is_persistent(ord)) { - fwriteorder(F, ord, f->locale); + fwriteorder(F, ord, f->locale, true); fputc('\n', F); } } diff --git a/src/common/util/strings.c b/src/common/util/strings.c index eb0829093..236a81848 100644 --- a/src/common/util/strings.c +++ b/src/common/util/strings.c @@ -34,26 +34,82 @@ hashstring(const char* s) return key & 0x7FFFFFFF; } +/* +static const char * +escape_string_inplace(char * buffer, unsigned int len, unsigned int offset) +{ +#define MAXQUOTES 32 + char * o; + char * d[MAXQUOTES+1]; + int i = 0; + + o = strchr(buffer, '"'); + if (!o) { + return buffer; + } + + while (*o && i0) { + const char * src = d[i]; + char * dst = d[i] + i + offset; + size_t mlen = d[i+1] - d[i]; + memmove(dst--, src, mlen); + *dst = '\\'; + } + return buffer; +} +*/ + INLINE_FUNCTION const char * escape_string(const char * str, char * buffer, unsigned int len) { - static char s_buffer[4096]; /* STATIC_RESULT: used for return, not across calls */ - const char * p = str; - char * o; - if (buffer==NULL) { - buffer = s_buffer; - len = sizeof(s_buffer); - } - o = buffer; - do { - switch (*p) { - case '\"': - case '\\': - (*o++) = '\\'; - } - (*o++) = (*p); - } while (*p++); - return buffer; + const char * start = strchr(str, '\"'); + if (start) { + static char s_buffer[4096]; /* STATIC_RESULT: used for return, not across calls */ + const char * p; + char * o; + size_t skip = start-str; + + if (buffer==NULL) { + buffer = s_buffer; + len = sizeof(s_buffer); + } + memcpy(buffer, str, skip); + o = buffer + skip; + p = str + skip; + do { + if (*p == '\"') { + if (len<2) { + *o = '\0'; + break; + } + (*o++) = '\\'; + len -= 2; + } else { + if (len<1) { + *o = '\0'; + break; + } + --len; + } + (*o++) = (*p); + } while (*p++); + return buffer; + } + return str; } INLINE_FUNCTION unsigned int jenkins_hash(unsigned int a) diff --git a/src/res/de/strings.xml b/src/res/de/strings.xml index 5efbc30f4..996a42715 100644 --- a/src/res/de/strings.xml +++ b/src/res/de/strings.xml @@ -5338,7 +5338,7 @@ ingots and disintegrate afterwards. - Diese Ritual verstärkt die Wirkung des + Dieses Ritual verstärkt die Wirkung des magischen Trankes um ein vielfaches. Wo sonst aus einem Stecken nur ein Baum sprießen konnte, so treibt nun jeder Ast Wurzeln.