Mercurial > hg > batmud > maputils
changeset 960:f2fcbf6ad2ef
Do initial changes for supporting area original names and flags for coder names (original, recoder, maintainer); these changes are in preparation for LOC file format 4.0.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 09 Jun 2010 21:08:54 +0000 |
parents | e5f9f23a7b89 |
children | 45497e8a7c90 |
files | mkloc.c |
diffstat | 1 files changed, 84 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/mkloc.c Wed Jun 09 20:33:45 2010 +0000 +++ b/mkloc.c Wed Jun 09 21:08:54 2010 +0000 @@ -76,6 +76,12 @@ #define LOC_MARKERS "?%C" #define LOC_MAX_FILES (64) + +#define NAME_ORIG (0x00001) /* Original area name or coder */ +#define NAME_RECODER (0x00002) /* Recoder of area */ +#define NAME_MAINTAINER (0x00004) /* Maintainer */ + + /* Structures */ typedef struct { @@ -93,12 +99,17 @@ } fileinfo_t; typedef struct { + char *name; + int flags; +} locname_t; + +typedef struct { int x, y, ox, oy; int dir, flags; tm_t added; BOOL addedValid; int nnames, ncoders; - char *names[LOC_MAX_NAMES], *coders[LOC_MAX_NAMES]; + locname_t *names[LOC_MAX_NAMES], *coders[LOC_MAX_NAMES]; char *uri, *freeform; fileinfo_t *file; } marker_t; @@ -362,10 +373,25 @@ } } +void addLocName(locname_t **dst, int *ndst, char **src, const int nsrc) +{ + if (src != NULL && src[nsrc] != NULL) { + int flags = 0; + int n = 0; + switch (src[nsrc][0]) { + case '@': n++; flags |= NAME_ORIG; break; + case '!': n++; flags |= NAME_RECODER; break; + case '%': n++; flags |= NAME_MAINTAINER; break; + } + dst[*ndst]->name = th_strdup(src[nsrc] + n); + dst[*ndst]->flags = flags; + (*ndst)++; + } +} BOOL addLocation(locations_t *l, int x, int y, int dir, int flags, char **names, char **coders, tm_t *added, BOOL addedValid, - char *uri, char *freeform, fileinfo_t *file) + const char *uri, const char *freeform, fileinfo_t *file) { marker_t *tmp; int i; @@ -379,22 +405,18 @@ tmp->dir = dir; tmp->flags = flags; tmp->file = file; + for (i = 0; i < LOC_MAX_NAMES; i++) { - if (names != NULL && names[i] != NULL) { - tmp->names[tmp->nnames] = th_strdup(names[i]); - tmp->nnames++; - } - if (coders != NULL && coders[i] != NULL) { - tmp->coders[tmp->ncoders] = th_strdup(coders[i]); - tmp->ncoders++; - } + addLocName(tmp->names, &tmp->nnames, names, i); + addLocName(tmp->coders, &tmp->ncoders, coders, i); } + if (added != NULL) { memcpy(&(tmp->added), added, sizeof(tmp->added)); tmp->addedValid = addedValid; } else { - time_t tmpT = time(NULL); - struct tm *tmpTime = localtime(&tmpT); + time_t stamp = time(NULL); + struct tm *tmpTime = localtime(&stamp); tmp->added.day = tmpTime->tm_mday; tmp->added.month = tmpTime->tm_mon + 1; tmp->added.year = tmpTime->tm_year + 1900; @@ -580,6 +602,10 @@ case '-': *flags |= LOCF_INVIS; break; + + case '!': + *flags |= LOCF_CLOSED; + break; default: endFlags = TRUE; @@ -623,8 +649,7 @@ int state, prev, next, field, subfield, sep; int tmpX, tmpY, tmpOrient, tmpFlags, i; char *fieldsep = NULL, *tmpStr, *tmpURI = NULL; - char *tmpLocNames[LOC_MAX_NAMES], - *tmpCoderNames[LOC_MAX_NAMES]; + char *tmpLocNames[LOC_MAX_NAMES], *tmpCoderNames[LOC_MAX_NAMES]; BOOL res, tmpTimeSet = FALSE, versionSet = FALSE; tm_t tmpTime; @@ -1004,7 +1029,7 @@ int y, x0, x1, len; marker_t *tmp = l->locations[i]; - len = strlen(tmp->names[0]); + len = strlen(tmp->names[0]->name); if (optLabelType) len += printLocType(NULL, tmp, FALSE); /* Compute text location */ @@ -1093,7 +1118,7 @@ tmpl = worldLoc->locations[n]; tmpFlags = LOCF_M_PCITY | LOCF_INVIS; snprintf(tmpDesc, sizeof(tmpDesc), - "%s", tmpl->names[0]); + "%s", tmpl->names[0]->name); } else { numNewLoc++; @@ -1146,8 +1171,8 @@ { marker_t *vp1 = *(marker_t **) p1, *vp2 = *(marker_t **) p2; - if (vp1->names[0] && vp2->names[0]) - return strcmp(vp1->names[0], vp2->names[0]); + if (vp1->names[0]->name && vp2->names[0]->name) + return strcmp(vp1->names[0]->name, vp2->names[0]->name); else return 0; } @@ -1236,11 +1261,11 @@ x += printLocType(outFile, tmp, TRUE); } - fputs(tmp->names[0], outFile); + fputs(tmp->names[0]->name, outFile); fputc(0xfe, outFile); if (!optNoAdjust) - x += strlen(tmp->names[0]) - 1; + x += strlen(tmp->names[0]->name) - 1; else fputc(d[(map->w * y) + x], outFile); } else { @@ -1269,7 +1294,7 @@ if ((tmp->flags & LOCF_INVIS) == 0) { fprintf(outFile, "<option value=\"loc%d_%d\">", tmp->ox, tmp->oy); printLocType(outFile, tmp, TRUE); - fprinte(outFile, tmp->names[0]); + fprinte(outFile, tmp->names[0]->name); fprintf(outFile, "</option>\n"); } } @@ -1278,6 +1303,18 @@ /* Output generated locations into given file stream */ +void printLocNameEsc(FILE *outFile, locname_t *name) +{ + char *prefix = ""; + switch (name->flags) { + case NAME_ORIG: prefix = "@"; break; + case NAME_RECODER: prefix = "!"; break; + case NAME_MAINTAINER: prefix = "%"; break; + } + fputs(prefix, outFile); + fprintEsc2(outFile, name->name); +} + void outputLocationFile(FILE *outFile, locations_t *l) { int i, n; @@ -1307,7 +1344,7 @@ if (s) { fprintf(outFile, "\n# %s #%d: %s\n", - s, i, tmp->names[0]); + s, i, tmp->names[0]->name); } } @@ -1329,23 +1366,26 @@ case LOCF_T_TRAINER: fputc('T', outFile); break; case LOCF_T_FORT: fputc('F', outFile); break; } + + if (tmp->flags & LOCF_CLOSED) + fputc('!', outFile); if (tmp->flags & LOCF_INVIS) fputc('-', outFile); fprintf(outFile, "\t;"); - fprintEsc2(outFile, tmp->names[0]); + printLocNameEsc(outFile, tmp->names[0]); for (n = 1; n < tmp->nnames; n++) { fprintf(outFile, "|"); - fprintEsc2(outFile, tmp->names[n]); + printLocNameEsc(outFile, tmp->names[n]); } fprintf(outFile, ";"); if (tmp->ncoders > 0) { - fprintEsc2(outFile, tmp->coders[0]); + printLocNameEsc(outFile, tmp->coders[0]); for (n = 1; n < tmp->ncoders; n++) { fprintf(outFile, ","); - fprintEsc2(outFile, tmp->coders[n]); + printLocNameEsc(outFile, tmp->coders[n]); } } @@ -1394,7 +1434,7 @@ /* Is location visible? */ if ((tmp->flags & LOCF_INVIS) == 0) { - leftMove = ((float) strlen(tmp->names[0])) * optFontScale; + leftMove = ((float) strlen(tmp->names[0]->name)) * optFontScale; switch (tmp->dir) { case LOCD_LEFTDOWN: @@ -1462,7 +1502,7 @@ fprintf(outFile, "-fill %s -box '#00000080' -draw \"text %d,%d '", cs, x, y); - fprintEsc1(outFile, tmp->names[0]); + fprintEsc1(outFile, tmp->names[0]->name); fprintf(outFile, "'\" "); } @@ -1538,7 +1578,7 @@ fprintf(outFile, "%d,%d,", tmp->x, tmp->y); printLocType(outFile, tmp, TRUE); - fprintf(outFile, "%s\n", tmp->names[0]); + fprintf(outFile, "%s\n", tmp->names[0]->name); } } @@ -1556,14 +1596,14 @@ char *str; /* Skip disabled / invisible locations */ - if (tmp->flags & LOCF_INVIS) continue; + if (tmp->flags & (LOCF_INVIS | LOCF_INVALID)) continue; /* Print out coordinates etc. */ fprintf(outFile, "<marker x=\"%d\" y=\"%d\" labeldir=\"%d\" name=\"", tmp->ox, tmp->oy, tmp->dir); /* Location name */ - str = (tmp->names[0] != NULL) ? tmp->names[0] : "UNKNOWN"; + str = (tmp->names[0]->name != NULL) ? tmp->names[0]->name : "UNKNOWN"; printLocType(outFile, tmp, TRUE); fprinte(outFile, str); fprintf(outFile, "\" html=\""); @@ -1576,9 +1616,11 @@ if (tmp->nnames > 1) { fprinte(outFile, "Also known as <i>"); for (n = 1; n < tmp->nnames; n++) { - fprinte(outFile, tmp->names[n]); + fprinte(outFile, tmp->names[n]->name); + if (tmp->names[n]->flags & NAME_ORIG) + fprintf(outFile, " (*)"); if (n < tmp->nnames - 1) - fprinte(outFile, " | "); + fprinte(outFile, " ; "); } fprinte(outFile, "</i>.<br>"); } @@ -1594,15 +1636,21 @@ if (tmp->flags & LOCF_M_PCITY) { fprinte(outFile, "Societies: "); for (n = 0; n < tmp->ncoders; n++) { - fprinte(outFile, tmp->coders[n]); + fprinte(outFile, tmp->coders[n]->name); if (n < tmp->ncoders - 1) fprinte(outFile, ", "); } } else { fprinte(outFile, "Coders: "); for (n = 0; n < tmp->ncoders; n++) { - fprintfe(outFile, "<a target=\"_blank\" href=\"http://www.bat.org/char/%s\">%s</a>", - tmp->coders[n], tmp->coders[n]); + char *info = ""; + switch (tmp->coders[n]->flags) { + case NAME_ORIG: info = " (O)"; break; + case NAME_RECODER: info = " (R)"; break; + case NAME_MAINTAINER: info = " (M)"; break; + } + fprintfe(outFile, "<a target=\"_blank\" href=\"http://www.bat.org/char/%s\">%s%s</a>", + tmp->coders[n]->name, tmp->coders[n]->name, info); if (n < tmp->ncoders - 1) fprinte(outFile, ", "); }