//format: print ["text"] at [time] qboolean _tourneyprint (parse_t parse, int clevel, int cevent) { char *mytok; int toknr; tourneyindex_t ti; toknr = 0; ti.taction = A_PRINT; _tourneysetsection (&ti, clevel); // mytok = ParseNextToken (&parse, "\""); strcpy (ti.info, mytok); strcat (ti.info, "\n"); while (toknr < 2 && (mytok = ParseNextToken (&parse, STDSEPERATOR))) { switch (toknr) { case 0: if (Q_stricmp (mytok, "at") == 0) toknr++; else { _tourneyparseerror (parse, "\"at\" expected, %s found", mytok); toknr = 1000; } break; case 1: ti.attime = atoi (mytok); toknr++; break; } } if (toknr == 2) { //anything was ok memcpy (&t_eventlist[cevent], &ti, sizeof (tourneyindex_t)); return true; } if (toknr < 2) { _tourneyparseerror (parse, "unexpected end of file in PRINT", NULL); } return false; }
void TourneyReadIni (void) { parse_t parse; int clevel; char *mytok; qboolean inevent; t_eventcount = 0; clevel = 0; inevent = false; if (ParseStartFile (GAMEVERSION "/" TOURNEYINI, &parse) == true) { while ((mytok = ParseNextToken (&parse, STDSEPERATOR))) { switch (clevel) { case 0: //we're not in any section clevel = _istourneysection (mytok); if (!clevel) _tourneyparseerror (parse, "unknown command %s", mytok); break; default: // we're are in any other section if (Q_stricmp (mytok, "set") == 0) { if (_tourneyset (parse, clevel, t_eventcount) == true) t_eventcount++; } else if (Q_stricmp (mytok, "play") == 0) { if (_tourneyplay (parse, clevel, t_eventcount) == true) t_eventcount++; } else if (Q_stricmp (mytok, "print") == 0) { if (_tourneyprint (parse, clevel, t_eventcount) == true) t_eventcount++; } else if (_istourneysection (mytok)) clevel = _istourneysection (mytok); else _tourneyparseerror (parse, "unknown command %s", mytok); } } ParseEndFile (&parse); } gi.dprintf ("%i tourney events...\n", t_eventcount); }
static void ParseNodes(TxtParser& parser) { TxtNode *currNode = NULL; for (;;) { ParseNextToken(parser); TokenVal& tok = parser.tok; if (TokenFinished == tok.type) { // we expect to end up with the implicit array node we created at start if (parser.nodes.Count() != 1) goto Failed; return; } if (TokenString == tok.type || TokenKeyVal == tok.type) { currNode = TxtNodeFromToken(parser.allocator, tok, TextNode); } else if (TokenArrayStart == tok.type) { currNode = AllocTxtNode(parser.allocator, ArrayNode); } else if (TokenStructStart == tok.type) { currNode = TxtNodeFromToken(parser.allocator, tok, StructNode); } else { CrashIf(TokenClose != tok.type); // if the only node left is the implict array node we created, // this is an error if (1 == parser.nodes.Count()) goto Failed; parser.nodes.Pop(); continue; } TxtNode *currParent = parser.nodes.At(parser.nodes.Count() - 1); currParent->children->Append(currNode); if (TextNode != currNode->type) parser.nodes.Append(currNode); } Failed: parser.failed = true; }
//format: set [starttime/startspawn/endtime] at [time] qboolean _tourneyset (parse_t parse, int clevel, int cevent) { char *mytok; int toknr; tourneyindex_t ti; toknr = 0; ti.taction = A_SET; while (toknr < 3 && (mytok = ParseNextToken (&parse, STDSEPERATOR))) { switch (toknr) { case 0: //"starttime" or "roundstart" expected if (Q_stricmp (mytok, "starttime") == 0) { toknr++; _tourneysetsection (&ti, clevel); } else if (Q_stricmp (mytok, "roundstart") == 0) { if (clevel != 1) { _tourneyparseerror (parse, "%s is only supported in section [START]", mytok); toknr = 1000; } else { ti.ttime = T_RSTART; toknr++; } } else { _tourneyparseerror (parse, "not supported set option %s", mytok); toknr = 1000; } break; case 1: if (Q_stricmp (mytok, "at") == 0) toknr++; else { _tourneyparseerror (parse, "\"at\" expected, %s found", mytok); toknr = 1000; } break; case 2: ti.attime = atoi (mytok); toknr++; break; } } if (toknr == 3) { //anything was ok memcpy (&t_eventlist[cevent], &ti, sizeof (tourneyindex_t)); return true; } if (toknr < 3) { _tourneyparseerror (parse, "unexpected end of file in SET", NULL); } return false; }