diff lwasm/pseudo.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 80d615a6642c
children f2decd9b276d
line wrap: on
line diff
--- a/lwasm/pseudo.c	Mon Jul 13 21:19:38 2015 -0600
+++ b/lwasm/pseudo.c	Mon Jul 13 21:20:30 2015 -0600
@@ -1369,6 +1369,58 @@
 	}
 }
 
+PARSEFUNC(pseudo_parse_ifpragma)
+{
+	char *pstr;
+	int i;
+	int pragma;
+	int compare;
+
+	l -> len = 0;
+	l -> hideline = 1;
+
+	if (as -> skipcond && !(as -> skipmacro))
+	{
+		as -> skipcount++;
+		skip_operand(p);
+		return;
+	}
+
+again:
+	for (i = 0; (*p)[i] && !isspace((*p)[i]) && (*p)[i] != '|' && (*p)[i] != '&'; i++)
+		/* do nothing */;
+
+	pstr = lw_strndup(*p, i);
+	(*p) += i;
+
+	pragma = parse_pragma_helper(pstr);
+	if (!pragma) lwasm_register_error(as, l, E_PRAGMA_UNRECOGNIZED);
+
+	lw_free(pstr);
+
+	if (pragma & PRAGMA_CLEARBIT)
+	{
+		pragma &= ~PRAGMA_CLEARBIT;			/* strip off flag bit */
+		compare = l -> pragmas & pragma ? 0 : 1;
+	}
+	else
+	{
+		compare = l -> pragmas & pragma;
+	}
+
+	if (!compare)
+	{
+		if (**p == '|')
+		{
+			(*p)++;
+			goto again;
+		}
+		as -> skipcond = 1;
+		as -> skipcount = 1;
+	}
+	skip_operand(p);
+}
+
 PARSEFUNC(pseudo_parse_error)
 {
 	lwasm_register_error2(as, l, E_USER_SPECIFIED, "%s", *p);