Mercurial > hg > batmud > maputils
changeset 1499:d8228d32d764
Add helper function locFGetc().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 07 Feb 2015 05:55:50 +0200 |
parents | a3527785dac3 |
children | b83e1399d8b6 |
files | liblocfile.c |
diffstat | 1 files changed, 32 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/liblocfile.c Sat Feb 07 03:15:15 2015 +0200 +++ b/liblocfile.c Sat Feb 07 05:55:50 2015 +0200 @@ -138,6 +138,13 @@ } +static int locFGetc(LocFileInfo *f) +{ + f->linePos++; + return fgetc(f->fp); +} + + static BOOL checkFlag(int flags, int mask, int flag) { if (mask) @@ -146,6 +153,7 @@ return (flags & flag); } + static BOOL checkMutex(LocFileInfo *f, int *flags, int mask, int flag) { if (!checkFlag(*flags, mask, 0) && @@ -173,7 +181,7 @@ { res *= 10; res += f->ch - '0'; - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); } *val = res; return TRUE; @@ -207,7 +215,7 @@ break; case '\\': /* Enable continuation via '\' at EOL */ - i = fgetc(f->fp); + i = locFGetc(f); if (i == EOF) { THERR @@ -217,28 +225,31 @@ } else if (i == '\n' || i == '\r') { - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); if (i == '\r' && f->ch == '\n') - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); } else { res[pos++] = i; - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); } break; + default: res[pos++] = f->ch; - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); break; } } + while (pos > 0 && isspace(res[pos - 1])) { pos--; res[pos] = 0; } res[pos] = 0; + return (pos > 0) ? th_strdup(res) : NULL; } @@ -312,7 +323,7 @@ } if (!endFlags) - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); } return TRUE; @@ -361,7 +372,7 @@ nextMode = prevMode = PM_ERROR; field = subfield = sep = -1; res = FALSE; - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); do { switch (parseMode) @@ -372,14 +383,14 @@ else if (f->ch == '\r') { f->lineNum++; - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); if (f->ch == '\n') - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); } else if (f->ch == '\n') { f->lineNum++; - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); } else if (f->ch == '#') { @@ -395,7 +406,7 @@ } else if (isspace(f->ch)) { - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); } else { @@ -410,15 +421,15 @@ switch (f->ch) { case '\r': - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); if (f->ch == '\n') - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); f->lineNum++; prevMode = parseMode; parseMode = nextMode; break; case '\n': - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); f->lineNum++; prevMode = parseMode; parseMode = nextMode; @@ -427,7 +438,7 @@ parseMode = PM_EOF; break; default: - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); /* Because loc file identification should be the first * comment line, we check it here. @@ -490,11 +501,11 @@ break; case 32: case 9: - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); break; case '\\': /* Enable continuation via '\' at EOL */ - i = fgetc(f->fp); + i = locFGetc(f); if (i != '\n' && i != '\r') { parseMode = PM_ERROR; @@ -504,9 +515,9 @@ else { f->lineNum++; - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); if (i == '\r' && f->ch == '\n') - f->ch = fgetc(f->fp); + f->ch = locFGetc(f); } break; default: @@ -520,10 +531,10 @@ if (strchr(fieldsep, f->ch) != NULL) { sep = f->ch; - f->ch = fgetc(f->fp); prevMode = parseMode; nextMode = PM_FIELD; parseMode = PM_NEXT; + f->ch = locFGetc(f); } else {