[Scummvm-cvs-logs] SF.net SVN: scummvm: [27960] scummvm/trunk/engines/parallaction/parser.cpp

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sun Jul 8 11:22:08 CEST 2007


Revision: 27960
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27960&view=rev
Author:   peres001
Date:     2007-07-08 02:22:08 -0700 (Sun, 08 Jul 2007)

Log Message:
-----------
Made parseNextToken *really* work this time.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/parser.cpp

Modified: scummvm/trunk/engines/parallaction/parser.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser.cpp	2007-07-08 08:34:19 UTC (rev 27959)
+++ scummvm/trunk/engines/parallaction/parser.cpp	2007-07-08 09:22:08 UTC (rev 27960)
@@ -126,13 +126,52 @@
 
 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 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++;
 	}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list