void ScriptManager::parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream) { Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); while (!stream.eos() && !line.contains('}')) { if (line.matchString("criteria {", true)) { parseCriteria(stream, puzzle->criteriaList); } else if (line.matchString("results {", true)) { parseResults(stream, puzzle->resultActions); } else if (line.matchString("flags {", true)) { setStateFlags(puzzle->key, parseFlags(stream)); } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } }
/* This routine is based on similiar code in glut_dstr.c */ static Criterion * parseGameModeString(const char *display, int *ncriteria, int *requestedMask) { Criterion *criteria = NULL; int n, parsed; char *copy, *word; /* Initially nothing requested. */ *requestedMask = 0; copy = __glutStrdup(display); /* Attempt to estimate how many criteria entries should be needed. */ n = 0; word = strtok(copy, " \t"); while (word) { n++; word = strtok(NULL, " \t"); } /* Allocate number of words of criteria. A word could contain as many as four criteria in the worst case. Example: 800x600:16@60. Also add four extra criteria for extra default queries. */ criteria = (Criterion *) malloc((4*n + 4) * sizeof(Criterion)); if (!criteria) { __glutFatalError("out of memory."); } /* Re-copy the copy of the display string. */ strcpy(copy, display); n = 0; word = strtok(copy, " \t"); while (word) { parsed = parseCriteria(word, &criteria[n], requestedMask); if (parsed >= 0) { n += parsed; } else { __glutWarning("Unrecognized game mode string word: %s (ignoring)\n", word); } word = strtok(NULL, " \t"); } free(copy); *ncriteria = n; return criteria; }