comparison place.c @ 178:0d5b9651b240

Merge Joerg's changes into upstream. (now that they've been thrashed out a bit, include CHANGES entries, etc.)
author David A. Holland
date Fri, 12 Jun 2015 03:05:49 -0400
parents a2f047301c15
children 16b4451e34b8
comparison
equal deleted inserted replaced
156:e8f7ae63844f 178:0d5b9651b240
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 {
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 } 207 }
156 208
157 static
158 const char * 209 const char *
159 place_getname(const struct place *p) 210 place_getname(const struct place *p)
160 { 211 {
161 switch (p->type) { 212 switch (p->type) {
162 case P_NOWHERE: return "<nowhere>"; 213 case P_NOWHERE: return "<nowhere>";