Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison place.c @ 10:800f3a560a3b
move seenfiles to place.c too
author | David A. Holland |
---|---|
date | Sun, 19 Dec 2010 19:27:14 -0500 |
parents | 97243badae69 |
children | b9d50e786322 |
comparison
equal
deleted
inserted
replaced
9:1fbcbd58742e | 10:800f3a560a3b |
---|---|
2 #include <stdarg.h> | 2 #include <stdarg.h> |
3 #include <stdio.h> | 3 #include <stdio.h> |
4 #include <stdlib.h> | 4 #include <stdlib.h> |
5 | 5 |
6 #include "utils.h" | 6 #include "utils.h" |
7 #include "array.h" | |
7 #include "place.h" | 8 #include "place.h" |
8 | |
9 static bool overall_failure; | |
10 | 9 |
11 #define NOWHERE_LINE 0 | 10 #define NOWHERE_LINE 0 |
12 #define BUILTIN_LINE 1 | 11 #define BUILTIN_LINE 1 |
13 #define COMMANDLINE_LINE 2 | 12 #define COMMANDLINE_LINE 2 |
14 | 13 |
14 struct seenfile { | |
15 struct place includedfrom; | |
16 char *name; | |
17 bool fromsystemdir; | |
18 }; | |
19 DECLARRAY(seenfile); | |
20 DEFARRAY(seenfile, ); | |
21 | |
22 static bool overall_failure; | |
23 | |
15 static struct place scratchplace; | 24 static struct place scratchplace; |
16 static bool scratchplace_inuse; | 25 static bool scratchplace_inuse; |
26 | |
27 static struct seenfilearray seenfiles; | |
28 | |
29 //////////////////////////////////////////////////////////// | |
30 // seenfiles | |
31 | |
32 static | |
33 struct seenfile * | |
34 seenfile_create(const struct place *from, char *name, bool fromsystemdir) | |
35 { | |
36 struct seenfile *sf; | |
37 | |
38 sf = domalloc(sizeof(*sf)); | |
39 sf->includedfrom = *from; | |
40 sf->name = name; | |
41 sf->fromsystemdir = fromsystemdir; | |
42 return sf; | |
43 } | |
44 | |
45 static | |
46 void | |
47 seenfile_destroy(struct seenfile *sf) | |
48 { | |
49 free(sf->name); | |
50 free(sf); | |
51 } | |
52 | |
53 DESTROYALL_ARRAY(seenfile, ); | |
54 | |
55 struct seenfile * | |
56 place_seen_file(const struct place *place, char *file, bool issystem) | |
57 { | |
58 struct seenfile *sf; | |
59 | |
60 sf = seenfile_create(place, file, issystem); | |
61 seenfilearray_add(&seenfiles, sf, NULL); | |
62 return sf; | |
63 } | |
64 | |
65 //////////////////////////////////////////////////////////// | |
66 // places | |
17 | 67 |
18 static | 68 static |
19 bool | 69 bool |
20 place_isnowhere(const struct place *p) | 70 place_isnowhere(const struct place *p) |
21 { | 71 { |
109 if (place_iscommandline(p)) { | 159 if (place_iscommandline(p)) { |
110 fprintf(stderr, "<command-line>:1:%u", p->column); | 160 fprintf(stderr, "<command-line>:1:%u", p->column); |
111 } else if (place_isbuiltin(p)) { | 161 } else if (place_isbuiltin(p)) { |
112 fprintf(stderr, "<built-in>:%u:1", p->column); | 162 fprintf(stderr, "<built-in>:%u:1", p->column); |
113 } else { | 163 } else { |
114 fprintf(stderr, "%s:%u:%u", seenfile_getname(p->file), | 164 fprintf(stderr, "%s:%u:%u", p->file->name, |
115 p->line, p->column); | 165 p->line, p->column); |
116 } | 166 } |
117 } | 167 } |
118 | 168 |
119 static | 169 static |
120 void | 170 void |
121 place_printfrom(const struct place *p) | 171 place_printfrom(const struct place *p) |
122 { | 172 { |
123 const struct place *from; | 173 const struct place *from; |
124 | 174 |
125 from = seenfile_getincludeplace(p->file); | 175 from = &p->file->includedfrom; |
126 if (!place_isnowhere(from)) { | 176 if (!place_isnowhere(from)) { |
127 place_printfrom(from); | 177 place_printfrom(from); |
128 } | 178 } |
129 fprintf(stderr, "In file included from "); | 179 fprintf(stderr, "In file included from "); |
130 place_print(p); | 180 place_print(p); |
131 fprintf(stderr, ":\n"); | 181 fprintf(stderr, ":\n"); |
132 } | 182 } |
133 | 183 |
184 //////////////////////////////////////////////////////////// | |
185 // complaints | |
186 | |
134 void | 187 void |
135 complain(const struct place *p, const char *fmt, ...) | 188 complain(const struct place *p, const char *fmt, ...) |
136 { | 189 { |
137 va_list ap; | 190 va_list ap; |
138 const struct place *from; | 191 const struct place *from; |
139 | 192 |
140 from = seenfile_getincludeplace(p->file); | 193 from = &p->file->includedfrom; |
141 if (!place_isnowhere(from)) { | 194 if (!place_isnowhere(from)) { |
142 place_printfrom(from); | 195 place_printfrom(from); |
143 } | 196 } |
144 place_print(p); | 197 place_print(p); |
145 fprintf(stderr, ": "); | 198 fprintf(stderr, ": "); |
159 complain_failed(void) | 212 complain_failed(void) |
160 { | 213 { |
161 return overall_failure; | 214 return overall_failure; |
162 } | 215 } |
163 | 216 |
217 //////////////////////////////////////////////////////////// | |
218 // module init and cleanup | |
219 | |
220 void | |
221 place_init(void) | |
222 { | |
223 seenfilearray_init(&seenfiles); | |
224 } | |
225 | |
226 void | |
227 place_cleanup(void) | |
228 { | |
229 seenfilearray_destroyall(&seenfiles); | |
230 seenfilearray_cleanup(&seenfiles); | |
231 } |