changeset 112:2b0b61fd1a36

Fix handling of relative includes.
author David A. Holland
date Tue, 11 Jun 2013 13:50:07 -0400
parents 36dd4701e0ba
children 1e7144176a42
files CHANGES files.c main.c place.c place.h
diffstat 5 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES	Tue Jun 11 13:11:01 2013 -0400
+++ b/CHANGES	Tue Jun 11 13:50:07 2013 -0400
@@ -8,6 +8,7 @@
    - clean out usage of sys/cdefs.h macros and don't use the implementation
      namespace
    - make -Wcomment work again
+   - fix handling of relative includes
    - provide a man page
 
 release 0.1 (20130610)
--- a/files.c	Tue Jun 11 13:11:01 2013 -0400
+++ b/files.c	Tue Jun 11 13:50:07 2013 -0400
@@ -290,12 +290,16 @@
 
 static
 char *
-mkfilename(const char *dir, const char *file)
+mkfilename(struct place *place, const char *dir, const char *file)
 {
 	size_t dlen, flen, rlen;
 	char *ret;
 	bool needslash = false;
 
+	if (dir == NULL) {
+		dir = place_getparsedir(place);
+	}
+
 	dlen = strlen(dir);
 	flen = strlen(file);
 	if (dlen > 0 && dir[dlen-1] != '/') {
@@ -352,7 +356,7 @@
 		num = incdirarray_num(path);
 		for (i=0; i<num; i++) {
 			id = incdirarray_get(path, i);
-			file = mkfilename(id->name, name);
+			file = mkfilename(place, id->name, name);
 			fd = file_tryopen(file);
 			if (fd >= 0) {
 				pf = place_addfile(place, file, id->issystem);
--- a/main.c	Tue Jun 11 13:11:01 2013 -0400
+++ b/main.c	Tue Jun 11 13:50:07 2013 -0400
@@ -391,7 +391,7 @@
 		dir = stringarray_get(&incpath_quote, i);
 		files_addquotepath(dir, false);
 	}
-	files_addquotepath(".", false);
+	files_addquotepath(NULL, false);
 
 	num = stringarray_num(&incpath_user);
 	for (i=0; i<num; i++) {
--- a/place.c	Tue Jun 11 13:11:01 2013 -0400
+++ b/place.c	Tue Jun 11 13:50:07 2013 -0400
@@ -31,6 +31,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "utils.h"
 #include "array.h"
@@ -38,6 +39,7 @@
 
 struct placefile {
 	struct place includedfrom;
+	char *dir;
 	char *name;
 	int depth;
 	bool fromsystemdir;
@@ -57,11 +59,19 @@
 		 bool fromsystemdir)
 {
 	struct placefile *pf;
+	const char *s;
+	size_t len;
 
 	pf = domalloc(sizeof(*pf));
 	pf->includedfrom = *from;
+
+	s = strrchr(name, '/');
+	len = (s == NULL) ? 0 : s - name;
+	pf->dir = dostrndup(name, len);
+
 	pf->name = dostrdup(name);
 	pf->fromsystemdir = fromsystemdir;
+
 	if (from->file != NULL) {
 		pf->depth = from->file->depth + 1;
 	} else {
@@ -80,6 +90,15 @@
 
 DESTROYALL_ARRAY(placefile, );
 
+const char *
+place_getparsedir(const struct place *place)
+{
+	if (place->file == NULL) {
+		return ".";
+	}
+	return place->file->dir;
+}
+
 const struct placefile *
 place_addfile(const struct place *place, const char *file, bool issystem)
 {
--- a/place.h	Tue Jun 11 13:11:01 2013 -0400
+++ b/place.h	Tue Jun 11 13:50:07 2013 -0400
@@ -50,5 +50,7 @@
 void place_setcommandline(struct place *p, unsigned word, unsigned column);
 void place_setfilestart(struct place *p, const struct placefile *pf);
 
+const char *place_getparsedir(const struct place *incplace);
+
 const struct placefile *place_addfile(const struct place *incplace,
 				      const char *name, bool fromsystemdir);