diff lwasm/input.c @ 356:7166254491ed

Finished pseudo ops
author lost@starbug
date Wed, 31 Mar 2010 18:46:32 -0600
parents 67224d8d1024
children 38b50ce6967a
line wrap: on
line diff
--- a/lwasm/input.c	Tue Mar 30 23:12:41 2010 -0600
+++ b/lwasm/input.c	Wed Mar 31 18:46:32 2010 -0600
@@ -213,6 +213,53 @@
 	lw_error("Cannot figure out how to open '%s'.", t -> filespec);
 }
 
+FILE *input_open_standalone(asmstate_t *as, char *s)
+{
+	char *s2;
+	FILE *fp;
+	char *p, *p2;
+
+	/* first check for absolute path and if so, skip path */
+	if (*s == '/')
+	{
+		/* absolute path */
+		fp = fopen(s, "rb");
+		if (!fp)
+		{
+			return NULL;
+		}
+		return fp;
+	}
+
+	/* relative path, check relative to "current file" directory */
+	p = lw_stack_top(as -> file_dir);
+	0 == asprintf(&p2, "%s/%s", p, s);
+	fp = fopen(p2, "rb");
+	if (fp)
+	{
+		lw_free(p2);
+		return fp;
+	}
+	lw_free(p2);
+
+	/* now check relative to entries in the search path */
+	lw_stringlist_reset(as -> include_list);
+	while (p = lw_stringlist_current(as -> include_list))
+	{
+		0 == asprintf(&p2, "%s/%s", p, s);
+		fp = fopen(p2, "rb");
+		if (fp)
+		{
+			lw_free(p2);
+			return fp;
+		}
+		lw_free(p2);
+		lw_stringlist_next(as -> include_list);
+	}
+	
+	return NULL;
+}
+
 char *input_readline(asmstate_t *as)
 {
 	char *s;