Mercurial > hg > batmud > maputils
changeset 773:2b8e29cef145
Properly escape sequences in loc-format output. Allow escaping of characters inside strings.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 01 Jun 2009 05:04:16 +0000 |
parents | e6dcd7a659f1 |
children | 8645c41bddd1 |
files | mkloc.c |
diffstat | 1 files changed, 20 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/mkloc.c Mon Jun 01 04:54:34 2009 +0000 +++ b/mkloc.c Mon Jun 01 05:04:16 2009 +0000 @@ -275,6 +275,7 @@ while (*p) { switch (*p) { + case '\\': fputs("\\", f); break; case '\'': fputs("\\'", f); break; case '"': fputs("\\\"", f); break; default: fputc(*p, f); @@ -416,17 +417,17 @@ case '\\': /* Enable continuation via '\' at EOL */ i = fgetc(f->f); - if (i == '\\') { - res[pos++] = i; - f->c = fgetc(f->f); - } else if (i != '\n' && i != '\r') { - THERR("Expected EOL inside text field on line #%d of '%s'.\n", + if (i == EOF) { + THERR("Unexpected EOF inside text field on line #%d of '%s'.\n", f->lineNum, f->filename); return NULL; - } else { + } else if (i == '\n' || i == '\r') { f->c = fgetc(f->f); if (i == '\r' && f->c == '\n') f->c = fgetc(f->f); + } else { + res[pos++] = i; + f->c = fgetc(f->f); } break; default: @@ -1098,15 +1099,20 @@ if (tmp->flags & LOCF_INVIS) fputc('-', outFile); - fprintf(outFile, "\t;%s", tmp->names[0]); - for (n = 1; n < tmp->nnames; n++) - fprintf(outFile, "|%s", tmp->names[n]); + fprintf(outFile, "\t;"); + printEscString(outFile, tmp->names[0]); + for (n = 1; n < tmp->nnames; n++) { + fprintf(outFile, "|"); + printEscString(outFile, tmp->names[n]); + } fprintf(outFile, ";"); if (tmp->ncoders > 0) { - fprintf(outFile, "%s", tmp->coders[0]); - for (n = 1; n < tmp->ncoders; n++) - fprintf(outFile, ",%s", tmp->coders[n]); + printEscString(outFile, tmp->coders[0]); + for (n = 1; n < tmp->ncoders; n++) { + fprintf(outFile, ","); + printEscString(outFile, tmp->coders[n]); + } } fprintf(outFile, ";"); @@ -1119,12 +1125,12 @@ fprintf(outFile, ";"); if (tmp->uri) - fprintf(outFile, "%s", tmp->uri); + printEscString(outFile, tmp->uri); fprintf(outFile, ";"); if (tmp->freeform) - fprintf(outFile, "%s", tmp->freeform); + printEscString(outFile, tmp->freeform); fprintf(outFile, "\n"); }