comparison place.c @ 176:a2f047301c15

Replace Joerg's place_setfile with something that at least sort of works.
author David A. Holland
date Fri, 12 Jun 2015 02:55:02 -0400
parents d6e6b3940780
children 16b4451e34b8
comparison
equal deleted inserted replaced
175:ffdb0b73856f 176:a2f047301c15
51 static bool overall_failure; 51 static bool overall_failure;
52 52
53 static const char *myprogname; 53 static const char *myprogname;
54 54
55 //////////////////////////////////////////////////////////// 55 ////////////////////////////////////////////////////////////
56 // seenfiles 56 // placefiles
57 57
58 static 58 static
59 struct placefile * 59 struct placefile *
60 placefile_create(const struct place *from, const char *name, 60 placefile_create(const struct place *from, const char *name,
61 bool fromsystemdir) 61 bool fromsystemdir)
97 { 97 {
98 if (place->file == NULL) { 98 if (place->file == NULL) {
99 return "."; 99 return ".";
100 } 100 }
101 return place->file->dir; 101 return place->file->dir;
102 }
103
104 static
105 bool
106 place_eq(const struct place *a, const struct place *b)
107 {
108 if (a->type != b->type) {
109 return false;
110 }
111 if (a->file != b->file) {
112 return false;
113 }
114 if (a->line != b->line || a->column != b->column) {
115 return false;
116 }
117 return true;
118 }
119
120 static
121 struct placefile *
122 placefile_find(const struct place *incfrom, const char *name)
123 {
124 unsigned i, num;
125 struct placefile *pf;
126
127 num = placefilearray_num(&placefiles);
128 for (i=0; i<num; i++) {
129 pf = placefilearray_get(&placefiles, i);
130 if (place_eq(incfrom, &pf->includedfrom) &&
131 !strcmp(name, pf->name)) {
132 return pf;
133 }
134 }
135 return NULL;
136 }
137
138 void
139 place_changefile(struct place *p, const char *name)
140 {
141 struct placefile *pf;
142
143 assert(p->type == P_FILE);
144 if (!strcmp(name, p->file->name)) {
145 return;
146 }
147 pf = placefile_find(&p->file->includedfrom, name);
148 if (pf == NULL) {
149 pf = placefile_create(&p->file->includedfrom, name,
150 p->file->fromsystemdir);
151 placefilearray_add(&placefiles, pf, NULL);
152 }
153 p->file = pf;
102 } 154 }
103 155
104 const struct placefile * 156 const struct placefile *
105 place_addfile(const struct place *place, const char *file, bool issystem) 157 place_addfile(const struct place *place, const char *file, bool issystem)
106 { 158 {
150 { 202 {
151 p->type = P_FILE; 203 p->type = P_FILE;
152 p->file = pf; 204 p->file = pf;
153 p->line = 1; 205 p->line = 1;
154 p->column = 1; 206 p->column = 1;
155 }
156
157 void
158 place_setfile(struct place *p, const char *name)
159 {
160 assert(p->type == P_FILE);
161 if (strcmp(name, p->file->name) == 0) {
162 return;
163 }
164 p->file = placefile_create(&p->file->includedfrom, name,
165 p->file->fromsystemdir);
166 } 207 }
167 208
168 const char * 209 const char *
169 place_getname(const struct place *p) 210 place_getname(const struct place *p)
170 { 211 {