Mercurial > hg > batmud > maputils
changeset 1498:a3527785dac3
Rename some variables, and do miscellaneous cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 07 Feb 2015 03:15:15 +0200 |
parents | 80df857831e8 |
children | d8228d32d764 |
files | liblocfile.c |
diffstat | 1 files changed, 99 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/liblocfile.c Sat Feb 07 03:02:23 2015 +0200 +++ b/liblocfile.c Sat Feb 07 03:15:15 2015 +0200 @@ -331,11 +331,11 @@ }; -static BOOL checkForEOL(LocFileInfo *f, int *state) +static BOOL locCheckForEOL(LocFileInfo *f, int *parseMode) { if (f->ch == '\n' || f->ch == '\r') { - *state = PM_ERROR; + *parseMode = PM_ERROR; THERR("Unexpected EOL on line #%d of '%s'.\n", f->lineNum, f->filename); return FALSE; @@ -347,7 +347,7 @@ BOOL locParseLocStream(LocFileInfo *f, MapLocations *l, int offX, int offY) { - int state, prev, next, field, subfield, sep; + int parseMode, prevMode, nextMode, field, subfield, sep; int tmpX, tmpY, tmpOrient, tmpFlags, i; char *fieldsep = NULL, *tmpStr, *tmpURI = NULL; char *tmpLocNames[LOC_MAX_NAMES], *tmpCoderNames[LOC_MAX_NAMES]; @@ -357,18 +357,18 @@ /* Parse data */ memset(tmpLocNames, 0, sizeof(tmpLocNames)); memset(tmpCoderNames, 0, sizeof(tmpCoderNames)); - state = PM_IDLE; - next = prev = PM_ERROR; + parseMode = PM_IDLE; + nextMode = prevMode = PM_ERROR; field = subfield = sep = -1; res = FALSE; f->ch = fgetc(f->fp); do { - switch (state) + switch (parseMode) { case PM_IDLE: if (f->ch == EOF) - state = PM_EOF; + parseMode = PM_EOF; else if (f->ch == '\r') { f->lineNum++; @@ -383,14 +383,14 @@ } else if (f->ch == '#') { - prev = state; - state = PM_COMMENT; - next = PM_IDLE; + prevMode = parseMode; + parseMode = PM_COMMENT; + nextMode = PM_IDLE; } else if (isdigit(f->ch)) { /* Start of a record */ - state = PM_FIELD; + parseMode = PM_FIELD; field = 1; } else if (isspace(f->ch)) @@ -400,7 +400,7 @@ else { /* Syntax error */ - state = PM_ERROR; + parseMode = PM_ERROR; THERR("Syntax error in '%s' line #%d.\n", f->filename, f->lineNum); } @@ -414,17 +414,17 @@ if (f->ch == '\n') f->ch = fgetc(f->fp); f->lineNum++; - prev = state; - state = next; + prevMode = parseMode; + parseMode = nextMode; break; case '\n': f->ch = fgetc(f->fp); f->lineNum++; - prev = state; - state = next; + prevMode = parseMode; + parseMode = nextMode; break; case EOF: - state = PM_EOF; + parseMode = PM_EOF; break; default: f->ch = fgetc(f->fp); @@ -446,11 +446,12 @@ if (verMajor != LOC_VERSION_MAJOR) { /* Major version mismatch, bail out with informative message */ - THERR("LOC file format version %d.%d detected, internal version is %d.%d. " - "Refusing to read due to potential incompatibilities. If you neverthless " - "wish to proceed, change the loc file's version to match internal version.\n", - verMajor, verMinor, LOC_VERSION_MAJOR, LOC_VERSION_MINOR); - state = PM_ERROR; + THERR( + "LOC file format version %d.%d detected, internal version is %d.%d. " + "Refusing to read due to potential incompatibilities. If you neverthless " + "wish to proceed, change the loc file's version to match internal version.\n", + verMajor, verMinor, LOC_VERSION_MAJOR, LOC_VERSION_MINOR); + parseMode = PM_ERROR; } else if (verMinor != LOC_VERSION_MINOR) { @@ -463,7 +464,7 @@ { THERR("Invalid or malformed LOC file, version not found (%s).\n", verStr); - state = PM_ERROR; + parseMode = PM_ERROR; } th_free(verStr); } @@ -471,7 +472,7 @@ { THERR("Invalid LOC file, the file ID is missing ('# %s (version %d.%d)' should be the first line.)\n", LOC_MAGIC, LOC_VERSION_MAJOR, LOC_VERSION_MINOR); - state = PM_ERROR; + parseMode = PM_ERROR; } th_free(tmp); versionSet = TRUE; @@ -483,7 +484,7 @@ switch (f->ch) { case EOF: - state = PM_ERROR; + parseMode = PM_ERROR; THERR("Unexpected end of file on line #%d of '%s'.\n", f->lineNum, f->filename); break; @@ -496,7 +497,7 @@ i = fgetc(f->fp); if (i != '\n' && i != '\r') { - state = PM_ERROR; + parseMode = PM_ERROR; THERR("Expected EOL on line #%d of '%s'.\n", f->lineNum, f->filename); } @@ -509,8 +510,8 @@ } break; default: - prev = state; - state = next; + prevMode = parseMode; + parseMode = nextMode; break; } break; @@ -520,21 +521,22 @@ { sep = f->ch; f->ch = fgetc(f->fp); - prev = state; - next = PM_FIELD; - state = PM_NEXT; + prevMode = parseMode; + nextMode = PM_FIELD; + parseMode = PM_NEXT; } else { - state = PM_ERROR; + parseMode = PM_ERROR; THERR("Expected field separator '%s', got '%c' on line #%d of '%s'.\n", fieldsep, f->ch, f->lineNum, f->filename); } break; case PM_FIELD: - if (field > 0 && field < 8 && !checkForEOL(f, &state)) + if (field > 0 && field < 8 && !locCheckForEOL(f, &parseMode)) break; + switch (field) { case 1: /* X-coordinate */ @@ -543,9 +545,9 @@ if (res) { field++; - prev = state; - next = PM_FIELD_SEP; - state = PM_NEXT; + prevMode = parseMode; + nextMode = PM_FIELD_SEP; + parseMode = PM_NEXT; } break; @@ -554,9 +556,9 @@ if (res) { field++; - prev = state; - next = PM_FIELD_SEP; - state = PM_NEXT; + prevMode = parseMode; + nextMode = PM_FIELD_SEP; + parseMode = PM_NEXT; } break; @@ -564,12 +566,13 @@ res = parseFieldInt(f, &tmpOrient); if (res) res = parseFlags(f, &tmpFlags); + if (res) { field++; - prev = state; - next = PM_FIELD_SEP; - state = PM_NEXT; + prevMode = parseMode; + nextMode = PM_FIELD_SEP; + parseMode = PM_NEXT; } break; @@ -585,25 +588,22 @@ if (subfield < LOC_MAX_NAMES) { th_free(tmpLocNames[subfield]); - tmpLocNames[subfield++] = - parseFieldString(f, fieldsep); - prev = state; - next = PM_FIELD_SEP; - state = PM_NEXT; + tmpLocNames[subfield++] = parseFieldString(f, fieldsep); + prevMode = parseMode; + nextMode = PM_FIELD_SEP; + parseMode = PM_NEXT; if (!strchr(fieldsep, f->ch)) { - state = PM_ERROR; - THERR - ("Expected field separator '%s' after LOCNAMES on line #%d of '%s'.\n", - fieldsep, f->lineNum, f->filename); + parseMode = PM_ERROR; + THERR("Expected field separator '%s' after LOCNAMES on line #%d of '%s'.\n", + fieldsep, f->lineNum, f->filename); } } else { - state = PM_ERROR; - THERR - ("Too many location names (max %d) on line #%d of '%s'.\n", - LOC_MAX_NAMES, f->lineNum, f->filename); + parseMode = PM_ERROR; + THERR("Too many location names (max %d) on line #%d of '%s'.\n", + LOC_MAX_NAMES, f->lineNum, f->filename); } } else @@ -611,8 +611,8 @@ fieldsep = ";"; subfield = -1; field++; - prev = state; - state = PM_FIELD; + prevMode = parseMode; + parseMode = PM_FIELD; } break; @@ -630,23 +630,23 @@ th_free(tmpCoderNames[subfield]); tmpCoderNames[subfield++] = parseFieldString(f, fieldsep); - prev = state; - next = PM_FIELD_SEP; - state = PM_NEXT; + prevMode = parseMode; + nextMode = PM_FIELD_SEP; + parseMode = PM_NEXT; if (!strchr(fieldsep, f->ch)) { - state = PM_ERROR; - THERR - ("Expected field separator '%s' after CODERNAMES on line #%d of '%s'.\n", - fieldsep, f->lineNum, f->filename); + parseMode = PM_ERROR; + THERR( + "Expected field separator '%s' after CODERNAMES on line #%d of '%s'.\n", + fieldsep, f->lineNum, f->filename); } } else { - state = PM_ERROR; - THERR - ("Too many coder names (max %d) on line #%d of '%s'.\n", - LOC_MAX_NAMES, f->lineNum, f->filename); + parseMode = PM_ERROR; + THERR( + "Too many coder names (max %d) on line #%d of '%s'.\n", + LOC_MAX_NAMES, f->lineNum, f->filename); } } else @@ -654,8 +654,8 @@ fieldsep = ";"; subfield = -1; field++; - prev = state; - state = PM_FIELD; + prevMode = parseMode; + parseMode = PM_FIELD; } break; @@ -670,25 +670,23 @@ tmpTimeSet = TRUE; else { - THERR - ("Warning, invalid timestamp '%s' in '%s' (line #%d in '%s')\n", - tmpStr, tmpLocNames[0], f->lineNum, f->filename); - state = PM_ERROR; + THERR("Warning, invalid timestamp '%s' in '%s' (line #%d in '%s')\n", + tmpStr, tmpLocNames[0], f->lineNum, f->filename); + parseMode = PM_ERROR; } } if (!strchr(fieldsep, f->ch)) { - state = PM_ERROR; - THERR - ("Expected field separator '%s' after DATE on line #%d of '%s'.\n", - fieldsep, f->lineNum, f->filename); + parseMode = PM_ERROR; + THERR("Expected field separator '%s' after DATE on line #%d of '%s'.\n", + fieldsep, f->lineNum, f->filename); } else { field++; - prev = state; - next = PM_FIELD_SEP; - state = PM_NEXT; + prevMode = parseMode; + nextMode = PM_FIELD_SEP; + parseMode = PM_NEXT; } th_free(tmpStr); break; @@ -697,9 +695,9 @@ th_free(tmpURI); tmpURI = parseFieldString(f, fieldsep); field++; - prev = state; - next = PM_FIELD_SEP; - state = PM_NEXT; + prevMode = parseMode; + nextMode = PM_FIELD_SEP; + parseMode = PM_NEXT; break; case 8: /* Freeform */ @@ -708,10 +706,9 @@ /* Check coordinates */ if (tmpX < 1 || tmpY < 1) { - THERR - ("Invalid X or Y coordinate (%d, %d), for location '%s' on line #%d of '%s'. Must be > 0.\n", - tmpX, tmpY, tmpLocNames[0], f->lineNum, f->filename); - state = PM_ERROR; + THERR("Invalid X or Y coordinate (%d, %d), for location '%s' on line #%d of '%s'. Must be > 0.\n", + tmpX, tmpY, tmpLocNames[0], f->lineNum, f->filename); + parseMode = PM_ERROR; } /* Check if location already exists */ @@ -722,12 +719,10 @@ if (i >= 0) { LocMarker *tloc = l->locations[i]; - - THERR - ("Warning, location already in list! (%d,%d) '%s' <-> (%d,%d) '%s'\n", - tloc->x, tloc->y, tloc->names[0].name, tmpX, tmpY, - tmpLocNames[0]); - state = PM_ERROR; + THERR("Warning, location already in list! (%d,%d) '%s' <-> (%d,%d) '%s'\n", + tloc->x, tloc->y, tloc->names[0].name, tmpX, tmpY, + tmpLocNames[0]); + parseMode = PM_ERROR; } else { @@ -735,8 +730,8 @@ locAddNew(l, tmpX, tmpY, tmpOrient, tmpFlags, tmpLocNames, tmpCoderNames, &tmpTime, tmpTimeSet, tmpURI, tmpStr, f); - prev = state; - state = PM_IDLE; + prevMode = parseMode; + parseMode = PM_IDLE; } for (i = 0; i < LOC_MAX_NAMES; i++) { @@ -748,25 +743,25 @@ break; default: - THERR("FATAL ERROR! Invalid state=%d!\n", state); - state = PM_ERROR; + THERR("FATAL ERROR! Invalid state=%d!\n", parseMode); + parseMode = PM_ERROR; } if (!res) { - state = PM_ERROR; + parseMode = PM_ERROR; THERR("Error parsing field %d on line #%d of '%s'.\n", field, f->lineNum, f->filename); } break; default: - THERR("Invalid state in loc-file parser - state=%d, prev=%d, next=%d, lineNum=%d, file='%s'.\n", - state, prev, next, f->lineNum, f->filename); - state = PM_ERROR; + THERR("Invalid state in loc-file parser - mode=%d, prev=%d, next=%d, line=%d, file='%s'.\n", + parseMode, prevMode, nextMode, f->lineNum, f->filename); + parseMode = PM_ERROR; break; } } - while (state != PM_ERROR && state != PM_EOF); + while (parseMode != PM_ERROR && parseMode != PM_EOF); for (i = 0; i < LOC_MAX_NAMES; i++) { @@ -775,7 +770,7 @@ } th_free(tmpURI); - return (state == PM_EOF); + return (parseMode == PM_EOF); }