diff lwasm/input.c @ 73:1f77ae5c3590

Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
author lost@l-w.ca
date Tue, 12 Apr 2011 17:56:51 -0600
parents 127e5b1e01c0
children e95eaf2f7fe0
line wrap: on
line diff
--- a/lwasm/input.c	Tue Apr 12 14:16:36 2011 -0600
+++ b/lwasm/input.c	Tue Apr 12 17:56:51 2011 -0600
@@ -40,6 +40,8 @@
 Data type for storing input buffers
 */
 
+#define IGNOREERROR (errno == ENOENT && (as -> flags & FLAG_DEPENDNOERR))
+
 enum input_types_e
 {
 	input_type_file,			// regular file, no search path
@@ -179,7 +181,7 @@
 			/* absolute path */
 			IS -> data = fopen(s, "rb");
 			debug_message(as, 1, "Opening (abs) %s", s);
-			if (!IS -> data)
+			if (!IS -> data && !IGNOREERROR)
 			{
 				lw_error("Cannot open file '%s': %s", s, strerror(errno));
 			}
@@ -218,6 +220,11 @@
 			lw_free(p2);
 			lw_stringlist_next(as -> include_list);
 		}
+		if (IGNOREERROR)
+		{
+			input_pushpath(as, s);
+			return;
+		}
 		lw_error("Cannot open include file '%s': %s", s, strerror(errno));
 		break;
 		
@@ -312,13 +319,16 @@
 		for (;;)
 		{
 			int c, c2;
-			c = fgetc(IS -> data);
+			c = EOF;
+			if (IS -> data)
+				c = fgetc(IS -> data);
 			if (c == EOF)
 			{
 				if (lbloc == 0)
 				{
 					struct input_stack *t;
-					fclose(IS -> data);
+					if (IS -> data)
+						fclose(IS -> data);
 					lw_free(lw_stack_pop(as -> file_dir));
 					lw_free(IS -> filespec);
 					t = IS -> next;