diff lwcc/lex.c @ 300:8d6c47395653 ccdev

Implemented #include and #line Theoretically, directives are now implemented.
author William Astle <lost@l-w.ca>
date Sun, 15 Sep 2013 13:49:00 -0600
parents 856caf91ffaa
children d85d173ba120
line wrap: on
line diff
--- a/lwcc/lex.c	Sun Sep 15 13:06:00 2013 -0600
+++ b/lwcc/lex.c	Sun Sep 15 13:49:00 2013 -0600
@@ -291,7 +291,7 @@
 		pp -> eolseen = 1;
 		return c;
 	}
-	
+
 	pp -> eolseen = 0;
 	
 	/* convert comments to a single space here */
@@ -351,7 +351,9 @@
 	int cl;
 	struct strbuf *strbuf;
 	struct token *t;
-						
+	struct preproc_info *fs;
+					
+fileagain:
 	c = preproc_lex_fetch_byte(pp);
 	if (c == CPP_EOF)
 	{
@@ -363,8 +365,24 @@
 	
 	if (c == CPP_EOF)
 	{
-		ttype = TOK_EOF;
-		goto out;
+		/* check if we fell off the end of an include file */
+		if (pp -> filestack)
+		{
+			if (pp -> skip_level || pp -> found_level)
+			{
+				preproc_throw_error(pp, "Unbalanced conditionals in include file");
+			}
+			fclose(pp -> fp);
+			fs = pp -> filestack;
+			*pp = *fs;
+			pp -> filestack = fs -> n;
+			goto fileagain;
+		}
+		else
+		{
+			ttype = TOK_EOF;
+			goto out;
+		}
 	}
 	if (c == CPP_EOL)
 	{