annotate place.c @ 11:b9d50e786322

simplify places
author David A. Holland
date Sun, 19 Dec 2010 19:30:24 -0500
parents 800f3a560a3b
children 6c15ca895585
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
1 #include <assert.h>
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
2 #include <stdarg.h>
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
3 #include <stdio.h>
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
4 #include <stdlib.h>
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
5
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
6 #include "utils.h"
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
7 #include "array.h"
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
8 #include "place.h"
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
9
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
10 #define NOWHERE_LINE 0
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
11 #define BUILTIN_LINE 1
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
12 #define COMMANDLINE_LINE 2
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
13
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
14 struct seenfile {
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
15 struct place includedfrom;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
16 char *name;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
17 bool fromsystemdir;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
18 };
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
19 DECLARRAY(seenfile);
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
20 DEFARRAY(seenfile, );
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
21
11
b9d50e786322 simplify places
David A. Holland
parents: 10
diff changeset
22 static struct seenfilearray seenfiles;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
23 static bool overall_failure;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
24
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
25 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
26 // seenfiles
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
27
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
28 static
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
29 struct seenfile *
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
30 seenfile_create(const struct place *from, char *name, bool fromsystemdir)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
31 {
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
32 struct seenfile *sf;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
33
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
34 sf = domalloc(sizeof(*sf));
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
35 sf->includedfrom = *from;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
36 sf->name = name;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
37 sf->fromsystemdir = fromsystemdir;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
38 return sf;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
39 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
40
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
41 static
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
42 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
43 seenfile_destroy(struct seenfile *sf)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
44 {
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
45 free(sf->name);
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
46 free(sf);
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
47 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
48
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
49 DESTROYALL_ARRAY(seenfile, );
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
50
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
51 struct seenfile *
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
52 place_seen_file(const struct place *place, char *file, bool issystem)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
53 {
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
54 struct seenfile *sf;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
55
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
56 sf = seenfile_create(place, file, issystem);
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
57 seenfilearray_add(&seenfiles, sf, NULL);
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
58 return sf;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
59 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
60
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
61 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
62 // places
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
63
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
64 static
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
65 bool
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
66 place_isnowhere(const struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
67 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
68 return p->file == NULL && p->line == NOWHERE_LINE;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
69 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
70
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
71 static
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
72 bool
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
73 place_isbuiltin(const struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
74 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
75 return p->file == NULL && p->line == BUILTIN_LINE;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
76 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
77
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
78 static
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
79 bool
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
80 place_iscommandline(const struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
81 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
82 return p->file == NULL && p->line == COMMANDLINE_LINE;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
83 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
84
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
85 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
86 place_setnowhere(struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
87 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
88 p->file = NULL;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
89 p->line = NOWHERE_LINE;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
90 p->column = 0;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
91 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
92
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
93 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
94 place_setbuiltin(struct place *p, unsigned num)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
95 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
96 p->file = NULL;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
97 p->line = BUILTIN_LINE;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
98 p->column = num;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
99 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
100
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
101 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
102 place_setcommandline(struct place *p, unsigned column)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
103 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
104 p->file = NULL;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
105 p->line = COMMANDLINE_LINE;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
106 p->column = column;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
107 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
108
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
109 static
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
110 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
111 place_print(const struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
112 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
113 if (place_iscommandline(p)) {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
114 fprintf(stderr, "<command-line>:1:%u", p->column);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
115 } else if (place_isbuiltin(p)) {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
116 fprintf(stderr, "<built-in>:%u:1", p->column);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
117 } else {
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
118 fprintf(stderr, "%s:%u:%u", p->file->name,
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
119 p->line, p->column);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
120 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
121 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
122
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
123 static
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
124 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
125 place_printfrom(const struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
126 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
127 const struct place *from;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
128
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
129 from = &p->file->includedfrom;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
130 if (!place_isnowhere(from)) {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
131 place_printfrom(from);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
132 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
133 fprintf(stderr, "In file included from ");
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
134 place_print(p);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
135 fprintf(stderr, ":\n");
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
136 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
137
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
138 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
139 // complaints
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
140
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
141 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
142 complain(const struct place *p, const char *fmt, ...)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
143 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
144 va_list ap;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
145 const struct place *from;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
146
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
147 from = &p->file->includedfrom;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
148 if (!place_isnowhere(from)) {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
149 place_printfrom(from);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
150 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
151 place_print(p);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
152 fprintf(stderr, ": ");
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
153 va_start(ap, fmt);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
154 vfprintf(stderr, fmt, ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
155 va_end(ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
156 fprintf(stderr, "\n");
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
157 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
158
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
159 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
160 complain_fail(void)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
161 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
162 overall_failure = true;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
163 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
164
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
165 bool
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
166 complain_failed(void)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
167 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
168 return overall_failure;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
169 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
170
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
171 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
172 // module init and cleanup
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
173
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
174 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
175 place_init(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
176 {
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
177 seenfilearray_init(&seenfiles);
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
178 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
179
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
180 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
181 place_cleanup(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
182 {
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
183 seenfilearray_destroyall(&seenfiles);
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
184 seenfilearray_cleanup(&seenfiles);
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
185 }