[PATCH] qbsp: Enable map file parser to return comment tokens

Change the boolean argument to parsetoken to a set of optional flags. Calls
that previously had crossline == false now pass PARSE_SAMELINE instead. Add
PARSE_COMMENT flag to parse the next token as a comment. If the token isn't a
comment, then return false.

Signed-off-by: Tyrann <tyrann@disenchant.net>
This commit is contained in:
Tyrann 2006-09-16 22:24:09 +09:30
parent e660c87c32
commit ad5e555e89
3 changed files with 37 additions and 21 deletions

View File

@ -107,7 +107,7 @@ ParseEpair(void)
if (strlen(token) >= MAX_KEY - 1)
Message(msgError, errEpairTooLong, linenum);
e->key = copystring(token);
ParseToken(false);
ParseToken(PARSE_SAMELINE);
if (strlen(token) >= MAX_VALUE - 1)
Message(msgError, errEpairTooLong, linenum);
e->value = copystring(token);
@ -174,40 +174,40 @@ ParseBrush(void)
map.rgBrushes[map.iBrushes].iFaceEnd = map.iFaces + 1;
while (ParseToken(true)) {
while (ParseToken(PARSE_NORMAL)) {
if (!strcmp(token, "}"))
break;
// read the three point plane definition
for (i = 0; i < 3; i++) {
if (i != 0)
ParseToken(true);
ParseToken(PARSE_NORMAL);
if (strcmp(token, "("))
Message(msgError, errInvalidMapPlane, linenum);
for (j = 0; j < 3; j++) {
ParseToken(false);
ParseToken(PARSE_SAMELINE);
planepts[i][j] = (vec_t)atoi(token);
}
ParseToken(false);
ParseToken(PARSE_SAMELINE);
if (strcmp(token, ")"))
Message(msgError, errInvalidMapPlane, linenum);
}
// read the texturedef
memset(&tx, 0, sizeof(tx));
ParseToken(false);
ParseToken(PARSE_SAMELINE);
tx.miptex = FindMiptex(token);
ParseToken(false);
ParseToken(PARSE_SAMELINE);
shift[0] = atoi(token);
ParseToken(false);
ParseToken(PARSE_SAMELINE);
shift[1] = atoi(token);
ParseToken(false);
ParseToken(PARSE_SAMELINE);
rotate = atoi(token);
ParseToken(false);
ParseToken(PARSE_SAMELINE);
scale[0] = atof(token);
ParseToken(false);
ParseToken(PARSE_SAMELINE);
scale[1] = atof(token);
// if the three points are all on a previous plane, it is a
@ -262,7 +262,6 @@ ParseBrush(void)
if (!scale[1])
scale[1] = 1;
// rotate axis
if (rotate == 0) {
sinv = 0;
@ -325,7 +324,7 @@ ParseBrush(void)
static bool
ParseEntity(mapentity_t *e)
{
if (!ParseToken(true))
if (!ParseToken(PARSE_NORMAL))
return false;
if (strcmp(token, "{"))
@ -337,7 +336,7 @@ ParseEntity(mapentity_t *e)
pCurEnt->iBrushEnd = map.iBrushes + 1;
do {
if (!ParseToken(true))
if (!ParseToken(PARSE_NORMAL))
Message(msgError, errUnexpectedEOF);
if (!strcmp(token, "}"))
break;

View File

@ -39,7 +39,7 @@ ParserInit(char *data)
bool
ParseToken(bool crossline)
ParseToken(int flags)
{
char *token_p;
@ -53,12 +53,12 @@ ParseToken(bool crossline)
/* skip space */
while (*script <= 32) {
if (!*script) {
if (!crossline)
if (flags & PARSE_SAMELINE)
Message(msgError, errLineIncomplete, linenum);
return false;
}
if (*script++ == '\n') {
if (!crossline)
if (flags & PARSE_SAMELINE)
Message(msgError, errLineIncomplete, linenum);
linenum++;
}
@ -66,16 +66,27 @@ ParseToken(bool crossline)
/* comment field */
if (script[0] == '/' && script[1] == '/') {
if (!crossline)
if (flags & PARSE_COMMENT) {
token_p = token;
while (*script && *script != '\n') {
*token_p++ = *script++;
if (token_p > &token[MAXTOKEN - 1])
Message(msgError, errTokenTooLarge, linenum);
}
goto out;
}
if (flags & PARSE_SAMELINE)
Message(msgError, errLineIncomplete, linenum);
while (*script++ != '\n')
if (!*script) {
if (!crossline)
if (flags & PARSE_SAMELINE)
Message(msgError, errLineIncomplete, linenum);
return false;
}
goto skipspace;
}
if (flags & PARSE_COMMENT)
return false;
/* copy token */
token_p = token;
@ -96,7 +107,7 @@ ParseToken(bool crossline)
if (token_p > &token[MAXTOKEN - 1])
Message(msgError, errTokenTooLarge, linenum);
}
out:
*token_p = 0;
return true;

View File

@ -29,7 +29,13 @@
extern int linenum;
extern char token[MAXTOKEN];
bool ParseToken(bool crossline);
enum parseflags {
PARSE_NORMAL = 0,
PARSE_SAMELINE = 1, /* The next token must be on the current line */
PARSE_COMMENT = 2 /* Return a // comment as the next token */
};
bool ParseToken(int flags);
void ParserInit(char *data);
#endif /* PARSER_H */