changeset 386:af5f2c51db76

Bugfixing on includes
author lost@starbug
date Sun, 16 May 2010 13:03:17 -0600
parents cf8c92d70eb1
children a741d2e4869f
files lwasm/input.c lwasm/pseudo.c
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/input.c	Sun May 16 11:50:00 2010 -0600
+++ b/lwasm/input.c	Sun May 16 13:03:17 2010 -0600
@@ -168,6 +168,7 @@
 		{
 			/* absolute path */
 			IS -> data = fopen(s, "rb");
+			debug_message(as, 1, "Opening (abs) %s", s);
 			if (!IS -> data)
 			{
 				lw_error("Cannot open file '%s': %s", s, strerror(errno));
@@ -179,6 +180,7 @@
 		/* relative path, check relative to "current file" directory */
 		p = lw_stack_top(as -> file_dir);
 		0 == asprintf(&p2, "%s/%s", p, s);
+		debug_message(as, 1, "Open: (cd) %s\n", p2);
 		IS -> data = fopen(p2, "rb");
 		if (IS -> data)
 		{
@@ -193,6 +195,7 @@
 		while (p = lw_stringlist_current(as -> include_list))
 		{
 			0 == asprintf(&p2, "%s/%s", p, s);
+		debug_message(as, 1, "Open (sp): %s\n", p2);
 			IS -> data = fopen(p2, "rb");
 			if (IS -> data)
 			{
@@ -206,6 +209,7 @@
 		lw_error("Cannot open include file '%s': %s", s, strerror(errno));
 		
 	case input_type_file:
+		debug_message(as, 1, "Opening (reg): %s\n", s);
 		IS -> data = fopen(s, "rb");
 
 		if (!IS -> data)
@@ -229,6 +233,7 @@
 	if (*s == '/')
 	{
 		/* absolute path */
+		debug_message(as, 2, "Open file (st abs) %s", s);
 		fp = fopen(s, "rb");
 		if (!fp)
 		{
@@ -240,6 +245,7 @@
 	/* relative path, check relative to "current file" directory */
 	p = lw_stack_top(as -> file_dir);
 	0 == asprintf(&p2, "%s/%s", p, s);
+	debug_message(as, 2, "Open file (st cd) %s", p2);
 	fp = fopen(p2, "rb");
 	if (fp)
 	{
@@ -253,6 +259,7 @@
 	while (p = lw_stringlist_current(as -> include_list))
 	{
 		0 == asprintf(&p2, "%s/%s", p, s);
+		debug_message(as, 2, "Open file (st ip) %s", p2);
 		fp = fopen(p2, "rb");
 		if (fp)
 		{
--- a/lwasm/pseudo.c	Sun May 16 11:50:00 2010 -0600
+++ b/lwasm/pseudo.c	Sun May 16 13:03:17 2010 -0600
@@ -912,6 +912,7 @@
 		/* do nothing */ ;
 	
 	sym = lw_strndup(*p, i);
+	(*p) += i;
 	
 	s = lookup_symbol(as, l, sym);
 	
@@ -1005,6 +1006,7 @@
 PARSEFUNC(pseudo_parse_include)
 {
 	char *fn, *p2;
+	char *p3;
 	int delim = 0;
 	
 	if (!**p)
@@ -1027,11 +1029,13 @@
 			/* do nothing */ ;
 	}
 	fn = lw_strndup(*p, p2 - *p);
-	
+	(*p) = p2;
 	if (delim && **p)
 		(*p)++;
 	
-	input_open(as, fn);
+	0 == asprintf(&p3, "include:%s", fn);
+	input_open(as, p3);
+	lw_free(p3);
 
 	l -> len = 0;
 }