Mercurial > ~dholland > hg > tradcpp > index.cgi
diff place.c @ 112:2b0b61fd1a36
Fix handling of relative includes.
author | David A. Holland |
---|---|
date | Tue, 11 Jun 2013 13:50:07 -0400 |
parents | 33954a07d013 |
children | 05d67dd74e1f |
line wrap: on
line diff
--- 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) {