Events and commands are now treated properly case-insensitively.

Sat, 14 Jul 2012 17:35:19 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 14 Jul 2012 17:35:19 +0300
changeset 17
b4fcc69e426a
parent 16
393359908179
child 18
dbcc3b784234

Events and commands are now treated properly case-insensitively.

commands.cxx file | annotate | diff | comparison | revisions
events.cxx file | annotate | diff | comparison | revisions
parser.cxx file | annotate | diff | comparison | revisions
str.cxx file | annotate | diff | comparison | revisions
--- a/commands.cxx	Sat Jul 14 17:24:21 2012 +0300
+++ b/commands.cxx	Sat Jul 14 17:35:19 2012 +0300
@@ -163,7 +163,7 @@
 	// (are they real floats or fixed? how are they
 	// stored?) and add proper floating point support.
 	// NOTE: Also, shouldn't use RETURNVAL for data types..
-	t.tolower();
+	t = t.tolower();
 	return	!t.compare ("int") ? RETURNVAL_INT :
 		!t.compare ("float") ? RETURNVAL_INT :
 		!t.compare ("str") ? RETURNVAL_STRING :
@@ -183,14 +183,11 @@
 	return "";
 }
 
-CommandDef* GetCommandByName (str a) {
-	a.tolower ();
-	CommandDef* c;
-	ITERATE_COMMANDS (c) {
-		str b = c->name;
-		b.tolower ();
-		if (!a.compare (b))
-			return c;
+CommandDef* GetCommandByName (str fname) {
+	CommandDef* comm;
+	ITERATE_COMMANDS (comm) {
+		if (!fname.icompare (comm->name))
+			return comm;
 	}
 	
 	return NULL;
--- a/events.cxx	Sat Jul 14 17:24:21 2012 +0300
+++ b/events.cxx	Sat Jul 14 17:35:19 2012 +0300
@@ -93,14 +93,9 @@
 }
 
 EventDef* FindEventByName (str a) {
-	a.tolower();
-	
 	EventDef* e;
 	for (e = g_EventDef; e->next != NULL; e = e->next) {
-		str b = e->name;
-		b.tolower();
-		
-		if (!a.compare (b))
+		if (!a.icompare (e->name))
 			return e;
 	}
 	
--- a/parser.cxx	Sat Jul 14 17:24:21 2012 +0300
+++ b/parser.cxx	Sat Jul 14 17:35:19 2012 +0300
@@ -62,7 +62,7 @@
 	bool gotMainLoop = false;
 	while (Next()) {
 		// printf ("got token %s\n", token.chars());
-		if (!token.compare ("#include")) {
+		if (!token.icompare ("#include")) {
 			MustString ();
 			
 			// First ensure that the file can be opened
@@ -72,7 +72,7 @@
 			fclose (newfile);
 			ScriptReader* newreader = new ScriptReader (token.chars());
 			newreader->BeginParse (w);
-		} else if (!token.compare ("state")) {
+		} else if (!token.icompare ("state")) {
 			MUST_TOPLEVEL
 			
 			MustString ();
@@ -92,7 +92,7 @@
 			
 			// If the previous state did not define a mainloop,
 			// define a dummy one now, since one has to be present.
-			if (g_CurState.compare ("") != 0 && !gotMainLoop) {
+			if (g_CurState.len() && !gotMainLoop) {
 				w->Write (DH_MAINLOOP);
 				w->Write (DH_ENDMAINLOOP);
 			}
@@ -106,7 +106,7 @@
 			g_NumStates++;
 			g_CurState = token;
 			gotMainLoop = false;
-		} else if (!token.compare ("event")) {
+		} else if (!token.icompare ("event")) {
 			MUST_TOPLEVEL
 			
 			// Event definition
@@ -123,13 +123,13 @@
 			w->Write (DH_EVENT);
 			w->Write<long> (e->number);
 			g_NumEvents++;
-		} else if (!token.compare ("mainloop")) {
+		} else if (!token.icompare ("mainloop")) {
 			MUST_TOPLEVEL
 			MustNext ("{");
 			g_CurMode = MODE_MAINLOOP;
 			w->Write (DH_MAINLOOP);
 			gotMainLoop = true;
-		} else if (!token.compare ("onenter") || !token.compare ("onexit")) {
+		} else if (!token.icompare ("onenter") || !token.icompare ("onexit")) {
 			MUST_TOPLEVEL
 			bool onenter = !token.compare ("onenter");
 			
@@ -155,12 +155,12 @@
 			if (comm)
 				ParseCommand (comm, w);
 			else
-				ParserError ("unknown keyword `%s`!", token.chars());
+				ParserError ("unknown keyword `%s`", token.chars());
 		}
 	}
 	
 	if (g_CurMode != MODE_TOPLEVEL)
-		ParserError ("script did not end at top level! did you forget a `}`?");
+		ParserError ("script did not end at top level; did you forget a `}`?");
 	
 	// stateSpawn must be defined!
 	if (!g_stateSpawnDefined)
--- a/str.cxx	Sat Jul 14 17:24:21 2012 +0300
+++ b/str.cxx	Sat Jul 14 17:35:19 2012 +0300
@@ -344,12 +344,8 @@
 	return icompare (str ((char*)c));
 }
 
-int str::icompare (str c) {
-	str a = text;
-	a.tolower();
-	str b = c;
-	b.tolower();
-	return strcmp (a.chars(), b.chars());
+int str::icompare (str b) {
+	return strcmp (tolower().chars(), b.tolower().chars());
 }
 
 // ============================================================================

mercurial