changeset 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 84eb35251849
children e95eaf2f7fe0
files lwasm/input.c lwasm/lwasm.h lwasm/main.c
diffstat 3 files changed, 25 insertions(+), 3 deletions(-) [+]
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;
--- a/lwasm/lwasm.h	Tue Apr 12 14:16:36 2011 -0600
+++ b/lwasm/lwasm.h	Tue Apr 12 17:56:51 2011 -0600
@@ -65,6 +65,7 @@
 	FLAG_LIST = 0x0001,
 	FLAG_DEPEND = 0x0002,
 	FLAG_SYMBOLS = 0x004,
+	FLAG_DEPENDNOERR = 0x0008,
 	FLAG_NONE = 0
 };
 
--- a/lwasm/main.c	Tue Apr 12 14:16:36 2011 -0600
+++ b/lwasm/main.c	Tue Apr 12 17:56:51 2011 -0600
@@ -49,6 +49,7 @@
 	{ "raw",		'r',	0,			0,							"Generate raw binary format output, equivalent of --format=raw"},
 	{ "obj",		0x100,	0,			0,							"Generate proprietary object file format for later linking, equivalent of --format=obj" },
 	{ "depend",		0x101,	0,			0,							"Output a dependency list to stdout; do not do any actual output though assembly is completed as usual" },
+	{ "dependnoerr", 0x102,	0,			0,							"Output a dependency list to stdout; do not do any actual output though assembly is completed as usual; don't bail on missing include files" },
 	{ "pragma",		'p',	"PRAGMA",	0,							"Set an assembler pragma to any value understood by the \"pragma\" pseudo op"},
 	{ "6809",		'9',	0,			0,							"Set assembler to 6809 only mode" },
 	{ "6309",		'3',	0,			0,							"Set assembler to 6309 mode (default)" },
@@ -110,6 +111,10 @@
 		as -> flags |= FLAG_DEPEND;
 		break;
 
+	case 0x102:
+		as -> flags |= FLAG_DEPEND | FLAG_DEPENDNOERR;
+		break;
+
 	case 'f':
 		if (!strcasecmp(arg, "decb"))
 			as -> output_format = OUTPUT_DECB;
@@ -240,6 +245,12 @@
 		
 		if (asmstate.errorcount > 0)
 		{
+			if (asmstate.flags & FLAG_DEPEND)
+			{
+				// don't show errors during dependency scanning but
+				// stop processing immediately
+				break;
+			}
 			lwasm_show_errors(&asmstate);
 			exit(1);
 		}