Mercurial > hg > batmud > maputils
changeset 772:e6dcd7a659f1
Improve parsing of line continuations.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 01 Jun 2009 04:54:34 +0000 |
parents | 034aabc63022 |
children | 2b8e29cef145 |
files | mkloc.c |
diffstat | 1 files changed, 50 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/mkloc.c Mon Jun 01 03:07:35 2009 +0000 +++ b/mkloc.c Mon Jun 01 04:54:34 2009 +0000 @@ -390,21 +390,50 @@ } -char * parseFieldString(fileinfo_t *f, const char *end) +char * parseFieldString(fileinfo_t *f, const char *endch) { char res[4096]; + BOOL end = FALSE; size_t pos = 0; - if (strchr(end, f->c)) + int i; + + if (strchr(endch, f->c)) return NULL; - while (!strchr(end, f->c) && pos < 4095) { + while (!end && !strchr(endch, f->c) && pos < 4095) { switch (f->c) { - case EOF: case '\n': case '\r': break; + case '\n': + case '\r': + THERR("Unexpected EOL inside text field on line #%d of '%s'.\n", + f->lineNum, f->filename); + return NULL; + break; + case EOF: + THERR("Unexpected EOF inside text field on line #%d of '%s'.\n", + f->lineNum, f->filename); + return NULL; + break; + 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", + f->lineNum, f->filename); + return NULL; + } else { + f->c = fgetc(f->f); + if (i == '\r' && f->c == '\n') + f->c = fgetc(f->f); + } + break; default: res[pos++] = f->c; + f->c = fgetc(f->f); break; } - f->c = fgetc(f->f); } while (pos > 0 && isspace(res[pos - 1])) { pos--; @@ -505,7 +534,7 @@ char *fieldsep = NULL, *tmpStr, *tmpURI = NULL; char *tmpLocNames[LOC_MAX_NAMES], *tmpCoderNames[LOC_MAX_NAMES]; - BOOL cont, res, tmpTimeSet = FALSE; + BOOL res, tmpTimeSet = FALSE; tm_t tmpTime; f.filename = filename; @@ -523,7 +552,6 @@ memset(tmpCoderNames, 0, sizeof(tmpCoderNames)); state = STATE_IDLE; next = prev = STATE_ERROR; - cont = FALSE; field = subfield = sep = -1; res = FALSE; f.c = fgetc(f.f); @@ -576,26 +604,27 @@ break; case 32: case 9: f.c = fgetc(f.f); - cont = FALSE; break; case '\\': /* Enable continuation via '\' at EOL */ - f.c = fgetc(f.f); - cont = TRUE; + i = fgetc(f.f); + if (i != '\n' && i != '\r') { + state = STATE_ERROR; + THERR("Expected EOL on line #%d of '%s'.\n", + f.lineNum, f.filename); + } else { + f.c = fgetc(f.f); + if (i == '\r' && f.c == '\n') + f.c = fgetc(f.f); + } break; case '\n': - if (!cont) { - state = STATE_ERROR; - THERR("Unexpected end of line on line #%d of '%s'.\n", - f.lineNum, f.filename); - } else { - f.lineNum++; - f.c = fgetc(f.f); - } - cont = FALSE; + case '\r': + state = STATE_ERROR; + THERR("Unexpected EOL on line #%d of '%s'.\n", + f.lineNum, f.filename); break; default: - cont = FALSE; prev = state; state = next; break; @@ -1311,7 +1340,7 @@ th_memset(&worldLoc, 0, sizeof(worldLoc)); /* Initialize */ - th_init("mkloc", "Add locations to ASCII map", "0.9", NULL, NULL); + th_init("mkloc", "Add locations to ASCII map", "0.9.5", NULL, NULL); th_verbosityLevel = 0; /* Parse arguments */