- Fix CR-escaping.
This commit is contained in:
Enno Rehling 2009-07-16 20:30:42 +00:00
parent 3b861d6a33
commit 29e423fab4
3 changed files with 83 additions and 22 deletions

View File

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

View File

@ -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 && i<MAXQUOTES) {
char * next = strchr(o, '"');
d[i++] = o;
o = next?next:(o+strlen(o));
}
d[i] = o;
if (i<MAXQUOTES) {
// more than 32 hits! must go recursive
char * start = d[i];
unsigned int nlen = len - (start-buffer) - MAXQUOTES;
escape_string_inplace(start, nlen, MAXQUOTES);
}
o[i] = '\0';
while (--i>0) {
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)

View File

@ -5338,7 +5338,7 @@
ingots and disintegrate afterwards. </text>
</string>
<string name="treegrow">
<text locale="de">Diese Ritual verstärkt die Wirkung des
<text locale="de">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. </text>