diff options
author | Nicola Mettifogo | 2007-07-08 09:22:08 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2007-07-08 09:22:08 +0000 |
commit | a7a62d3c9ddbb66c19035144a827b7ce832d9e90 (patch) | |
tree | a2647d18b597ec69282631961cc5607618a4d410 /engines | |
parent | cdae0280bee62f5d98e1834d51bb5dc2cd7aa4d1 (diff) | |
download | scummvm-rg350-a7a62d3c9ddbb66c19035144a827b7ce832d9e90.tar.gz scummvm-rg350-a7a62d3c9ddbb66c19035144a827b7ce832d9e90.tar.bz2 scummvm-rg350-a7a62d3c9ddbb66c19035144a827b7ce832d9e90.zip |
Made parseNextToken *really* work this time.
svn-id: r27960
Diffstat (limited to 'engines')
-rw-r--r-- | engines/parallaction/parser.cpp | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/engines/parallaction/parser.cpp b/engines/parallaction/parser.cpp index 812f48c821..a7c4cbad4b 100644 --- a/engines/parallaction/parser.cpp +++ b/engines/parallaction/parser.cpp @@ -126,13 +126,52 @@ void clearTokens() { char *parseNextToken(char *s, char *tok, uint16 count, const char *brk) { - while (*s != '\0') { - if (strchr(brk, *s)) break; - *tok++ = *s++; + enum STATES { NORMAL, QUOTED }; + + STATES state = NORMAL; + + while (count > 0) { + + switch (state) { + case NORMAL: + if (*s == '\0') { + *tok = '\0'; + return s; + } + + if (strchr(brk, *s)) { + *tok = '\0'; + return ++s; + } + + if (*s == '"') { + state = QUOTED; + s++; + } else { + *tok++ = *s++; + count--; + } + break; + + case QUOTED: + if (*s == '\0') { + *tok = '\0'; + return s; + } + if (*s == '"' || strchr(brk, *s)) { + *tok = '\0'; + return ++s; + } + + *tok++ = *s++; + count--; + break; + } + } - *tok = '\0'; - return s; + return 0; + } uint16 fillTokens(char* line) { @@ -140,15 +179,6 @@ uint16 fillTokens(char* line) { uint16 i = 0; while (strlen(line) > 0 && i < 20) { line = parseNextToken(line, _tokens[i], 40, " \t\n\a"); - if (_tokens[i][0] == '"' && _tokens[i][strlen(_tokens[i]) - 1] != '"') { - - line = parseNextToken(line, _tokens[i+1], 40, "\""); - strcat(_tokens[i], _tokens[i+1]); - _tokens[i][0] = ' '; - line++; - - } - line = Common::ltrim(line); i++; } |