Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison 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 |
comparison
equal
deleted
inserted
replaced
111:36dd4701e0ba | 112:2b0b61fd1a36 |
---|---|
29 | 29 |
30 #include <assert.h> | 30 #include <assert.h> |
31 #include <stdarg.h> | 31 #include <stdarg.h> |
32 #include <stdio.h> | 32 #include <stdio.h> |
33 #include <stdlib.h> | 33 #include <stdlib.h> |
34 #include <string.h> | |
34 | 35 |
35 #include "utils.h" | 36 #include "utils.h" |
36 #include "array.h" | 37 #include "array.h" |
37 #include "place.h" | 38 #include "place.h" |
38 | 39 |
39 struct placefile { | 40 struct placefile { |
40 struct place includedfrom; | 41 struct place includedfrom; |
42 char *dir; | |
41 char *name; | 43 char *name; |
42 int depth; | 44 int depth; |
43 bool fromsystemdir; | 45 bool fromsystemdir; |
44 }; | 46 }; |
45 DECLARRAY(placefile, static UNUSED); | 47 DECLARRAY(placefile, static UNUSED); |
55 struct placefile * | 57 struct placefile * |
56 placefile_create(const struct place *from, const char *name, | 58 placefile_create(const struct place *from, const char *name, |
57 bool fromsystemdir) | 59 bool fromsystemdir) |
58 { | 60 { |
59 struct placefile *pf; | 61 struct placefile *pf; |
62 const char *s; | |
63 size_t len; | |
60 | 64 |
61 pf = domalloc(sizeof(*pf)); | 65 pf = domalloc(sizeof(*pf)); |
62 pf->includedfrom = *from; | 66 pf->includedfrom = *from; |
67 | |
68 s = strrchr(name, '/'); | |
69 len = (s == NULL) ? 0 : s - name; | |
70 pf->dir = dostrndup(name, len); | |
71 | |
63 pf->name = dostrdup(name); | 72 pf->name = dostrdup(name); |
64 pf->fromsystemdir = fromsystemdir; | 73 pf->fromsystemdir = fromsystemdir; |
74 | |
65 if (from->file != NULL) { | 75 if (from->file != NULL) { |
66 pf->depth = from->file->depth + 1; | 76 pf->depth = from->file->depth + 1; |
67 } else { | 77 } else { |
68 pf->depth = 1; | 78 pf->depth = 1; |
69 } | 79 } |
77 dostrfree(pf->name); | 87 dostrfree(pf->name); |
78 dofree(pf, sizeof(*pf)); | 88 dofree(pf, sizeof(*pf)); |
79 } | 89 } |
80 | 90 |
81 DESTROYALL_ARRAY(placefile, ); | 91 DESTROYALL_ARRAY(placefile, ); |
92 | |
93 const char * | |
94 place_getparsedir(const struct place *place) | |
95 { | |
96 if (place->file == NULL) { | |
97 return "."; | |
98 } | |
99 return place->file->dir; | |
100 } | |
82 | 101 |
83 const struct placefile * | 102 const struct placefile * |
84 place_addfile(const struct place *place, const char *file, bool issystem) | 103 place_addfile(const struct place *place, const char *file, bool issystem) |
85 { | 104 { |
86 struct placefile *pf; | 105 struct placefile *pf; |