diff lwasm/pragma.c @ 384:6ee9c67a0f8d

Add conditional for testing if a pragma is in effect An obvious addition that took someone else to notice... Thanks to Erik G <erik@6809.org> for the patch.
author William Astle <lost@l-w.ca>
date Mon, 13 Jul 2015 21:20:30 -0600
parents d791d47afc48
children 4fd16faa4d93
line wrap: on
line diff
--- a/lwasm/pragma.c	Mon Jul 13 21:19:38 2015 -0600
+++ b/lwasm/pragma.c	Mon Jul 13 21:20:30 2015 -0600
@@ -73,40 +73,48 @@
 	{ 0, 0, 0 }
 };
 
+int parse_pragma_helper(char *p)
+{
+	int i;
+
+	for (i = 0; set_pragmas[i].setstr; i++)
+	{
+		if (!strcasecmp(p, set_pragmas[i].setstr))
+		{
+			return set_pragmas[i].flag;
+			return 1;
+		}
+		if (!strcasecmp(p, set_pragmas[i].resetstr))
+		{
+			return set_pragmas[i].flag | PRAGMA_CLEARBIT;
+			return 2;
+		}
+	}
+
+	return 0;
+}
+
 int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr)
 {
 	char *p;
-	int i;
 	const char *np = str;
-	int pragmas = as -> pragmas;
+	int pragma;
 
 	while (np)
 	{
 		p = lw_token(np, ',', &np);
-		debug_message(as, 200, "Setting pragma %s", p);
-		for (i = 0; set_pragmas[i].setstr; i++)
-		{
-			if (!strcasecmp(p, set_pragmas[i].setstr))
-			{
-				pragmas |= set_pragmas[i].flag;
-				goto out;
-			}
-			if (!strcasecmp(p, set_pragmas[i].resetstr))
-			{
-				pragmas &= ~(set_pragmas[i].flag);
-				goto out;
-			}
-		}
-		/* unrecognized pragma here */
-		if (!ignoreerr)
-		{
-			lw_free(p);
+		debug_message(as, 200, "Setting/resetting pragma %s", p);
+		pragma = parse_pragma_helper(p);
+		lw_free(p);
+
+		if (pragma == 0 && !ignoreerr)
 			return 0;
-		}
-	out:	
-		lw_free(p);
+
+		if (pragma & PRAGMA_CLEARBIT)
+			as->pragmas &= ~pragma;
+		else
+			as->pragmas |= pragma;
 	}
-	as -> pragmas = pragmas;
 	return 1;
 }