diff lwasm/pseudo.c @ 257:e27279180a73 2.x

Added support for include path to LWASM
author lost
date Tue, 22 Dec 2009 04:53:20 +0000
parents c7a41b4c89b3
children c79b3c88adbc
line wrap: on
line diff
--- a/lwasm/pseudo.c	Tue Dec 22 04:52:59 2009 +0000
+++ b/lwasm/pseudo.c	Tue Dec 22 04:53:20 2009 +0000
@@ -130,6 +130,38 @@
 	if (**p == '"')
 		(*p)++;
 
+	// resolve file name
+	if (*fn != '/')
+	{
+		char *path;
+		int i;
+		FILE *fp;
+		
+		fp = fopen(fn, "r");
+		if (!fp)
+		{
+				
+			
+			for (i = 0; i < as -> nincludedirs; i++)
+			{
+				0 == asprintf(&path, "%s/%s", as -> includedirs[i], fn);
+				fp = fopen(path, "r");
+				if (fp)
+				{
+					fclose(fp);
+					lwasm_free(fn);
+					fn = path;
+					break;
+				}
+				lwasm_free(path);
+			}
+		}
+		else
+		{
+			fclose(fp);
+		}
+	}
+
 	// end local label context on include	
 	as -> context = lwasm_next_context(as);
 	if (lwasm_read_file(as, fn) < 0)