annotate place.c @ 185:16b4451e34b8

Add the ability to output line numbers, sort of. It is enabled with the intentionally undocumented -p option (similar to -P but reversed sense) and it might be vaguely useful but only prints the line number when the file changes and may not get the line numbers right.
author David A. Holland
date Fri, 12 Jun 2015 03:59:36 -0400
parents a2f047301c15
children 1d2bad7151f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
1 /*-
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
2 * Copyright (c) 2010 The NetBSD Foundation, Inc.
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
3 * All rights reserved.
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
4 *
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
5 * This code is derived from software contributed to The NetBSD Foundation
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
6 * by David A. Holland.
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
7 *
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
8 * Redistribution and use in source and binary forms, with or without
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
9 * modification, are permitted provided that the following conditions
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
10 * are met:
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
11 * 1. Redistributions of source code must retain the above copyright
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
12 * notice, this list of conditions and the following disclaimer.
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
13 * 2. Redistributions in binary form must reproduce the above copyright
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
14 * notice, this list of conditions and the following disclaimer in the
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
15 * documentation and/or other materials provided with the distribution.
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
16 *
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
27 * POSSIBILITY OF SUCH DAMAGE.
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
28 */
76c114899f63 copyrights
David A. Holland
parents: 28
diff changeset
29
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
30 #include <assert.h>
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
31 #include <stdarg.h>
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
32 #include <stdio.h>
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
33 #include <stdlib.h>
112
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
34 #include <string.h>
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
35
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
36 #include "utils.h"
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
37 #include "array.h"
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
38 #include "place.h"
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
39
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
40 struct placefile {
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
41 struct place includedfrom;
112
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
42 char *dir;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
43 char *name;
28
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
44 int depth;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
45 bool fromsystemdir;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
46 };
107
33954a07d013 __unused -> UNUSED
David A. Holland
parents: 95
diff changeset
47 DECLARRAY(placefile, static UNUSED);
47
2e25e55dba6b Fix inline usage as per the version in dholland-make2.
David A. Holland
parents: 39
diff changeset
48 DEFARRAY(placefile, static);
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
49
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
50 static struct placefilearray placefiles;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
51 static bool overall_failure;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
52
142
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
53 static const char *myprogname;
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
54
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
55 ////////////////////////////////////////////////////////////
176
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
56 // placefiles
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
57
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
58 static
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
59 struct placefile *
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
60 placefile_create(const struct place *from, const char *name,
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
61 bool fromsystemdir)
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
62 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
63 struct placefile *pf;
112
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
64 const char *s;
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
65 size_t len;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
66
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
67 pf = domalloc(sizeof(*pf));
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
68 pf->includedfrom = *from;
112
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
69
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
70 s = strrchr(name, '/');
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
71 len = (s == NULL) ? 0 : s - name;
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
72 pf->dir = dostrndup(name, len);
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
73
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
74 pf->name = dostrdup(name);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
75 pf->fromsystemdir = fromsystemdir;
112
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
76
28
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
77 if (from->file != NULL) {
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
78 pf->depth = from->file->depth + 1;
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
79 } else {
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
80 pf->depth = 1;
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
81 }
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
82 return pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
83 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
84
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
85 static
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
86 void
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
87 placefile_destroy(struct placefile *pf)
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
88 {
39
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
89 dostrfree(pf->name);
337110e7240a Pass the size to free; it makes debug checking easier.
David A. Holland
parents: 38
diff changeset
90 dofree(pf, sizeof(*pf));
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
91 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
92
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
93 DESTROYALL_ARRAY(placefile, );
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
94
112
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
95 const char *
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
96 place_getparsedir(const struct place *place)
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
97 {
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
98 if (place->file == NULL) {
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
99 return ".";
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
100 }
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
101 return place->file->dir;
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
102 }
2b0b61fd1a36 Fix handling of relative includes.
David A. Holland
parents: 107
diff changeset
103
176
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
104 static
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
105 struct placefile *
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
106 placefile_find(const struct place *incfrom, const char *name)
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
107 {
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
108 unsigned i, num;
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
109 struct placefile *pf;
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
110
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
111 num = placefilearray_num(&placefiles);
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
112 for (i=0; i<num; i++) {
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
113 pf = placefilearray_get(&placefiles, i);
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
114 if (place_eq(incfrom, &pf->includedfrom) &&
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
115 !strcmp(name, pf->name)) {
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
116 return pf;
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
117 }
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
118 }
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
119 return NULL;
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
120 }
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
121
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
122 void
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
123 place_changefile(struct place *p, const char *name)
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
124 {
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
125 struct placefile *pf;
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
126
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
127 assert(p->type == P_FILE);
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
128 if (!strcmp(name, p->file->name)) {
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
129 return;
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
130 }
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
131 pf = placefile_find(&p->file->includedfrom, name);
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
132 if (pf == NULL) {
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
133 pf = placefile_create(&p->file->includedfrom, name,
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
134 p->file->fromsystemdir);
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
135 placefilearray_add(&placefiles, pf, NULL);
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
136 }
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
137 p->file = pf;
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
138 }
a2f047301c15 Replace Joerg's place_setfile with something that at least sort of works.
David A. Holland
parents: 160
diff changeset
139
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
140 const struct placefile *
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
141 place_addfile(const struct place *place, const char *file, bool issystem)
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
142 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
143 struct placefile *pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
144
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
145 pf = placefile_create(place, file, issystem);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
146 placefilearray_add(&placefiles, pf, NULL);
114
05d67dd74e1f Reduce the maximum include depth from 128 to 120.
David A. Holland
parents: 112
diff changeset
147 if (pf->depth > 120) {
28
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
148 complain(place, "Maximum include nesting depth exceeded");
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
149 die();
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
150 }
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
151 return pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
152 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
153
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
154 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
155 // places
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
156
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
157 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
158 place_setnowhere(struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
159 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
160 p->type = P_NOWHERE;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
161 p->file = NULL;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
162 p->line = 0;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
163 p->column = 0;
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
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
166 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
167 place_setbuiltin(struct place *p, unsigned num)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
168 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
169 p->type = P_BUILTIN;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
170 p->file = NULL;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
171 p->line = num;
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
172 p->column = 1;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
173 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
174
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
175 void
14
David A. Holland
parents: 13
diff changeset
176 place_setcommandline(struct place *p, unsigned line, unsigned column)
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
177 {
14
David A. Holland
parents: 13
diff changeset
178 p->type = P_COMMANDLINE;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
179 p->file = NULL;
14
David A. Holland
parents: 13
diff changeset
180 p->line = line;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
181 p->column = column;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
182 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
183
14
David A. Holland
parents: 13
diff changeset
184 void
David A. Holland
parents: 13
diff changeset
185 place_setfilestart(struct place *p, const struct placefile *pf)
David A. Holland
parents: 13
diff changeset
186 {
28
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
187 p->type = P_FILE;
14
David A. Holland
parents: 13
diff changeset
188 p->file = pf;
David A. Holland
parents: 13
diff changeset
189 p->line = 1;
David A. Holland
parents: 13
diff changeset
190 p->column = 1;
David A. Holland
parents: 13
diff changeset
191 }
David A. Holland
parents: 13
diff changeset
192
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
193 const char *
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
194 place_getname(const struct place *p)
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
195 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
196 switch (p->type) {
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
197 case P_NOWHERE: return "<nowhere>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
198 case P_BUILTIN: return "<built-in>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
199 case P_COMMANDLINE: return "<command-line>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
200 case P_FILE: return p->file->name;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
201 }
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
202 assert(0);
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
203 return NULL;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
204 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
205
185
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
206 bool
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
207 place_samefile(const struct place *a, const struct place *b)
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
208 {
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
209 if (a->type != b->type) {
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
210 return false;
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
211 }
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
212 if (a->file != b->file) {
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
213 return false;
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
214 }
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
215 return true;
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
216 }
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
217
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
218 bool
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
219 place_eq(const struct place *a, const struct place *b)
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
220 {
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
221 if (!place_samefile(a, b)) {
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
222 return false;
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
223 }
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
224 if (a->line != b->line || a->column != b->column) {
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
225 return false;
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
226 }
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
227 return true;
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
228 }
16b4451e34b8 Add the ability to output line numbers, sort of.
David A. Holland
parents: 176
diff changeset
229
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
230 static
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
231 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
232 place_printfrom(const struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
233 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
234 const struct place *from;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
235
95
1c0575f7dd46 Don't crash printing the commandline place.
David A. Holland
parents: 47
diff changeset
236 if (p->file == NULL) {
1c0575f7dd46 Don't crash printing the commandline place.
David A. Holland
parents: 47
diff changeset
237 return;
1c0575f7dd46 Don't crash printing the commandline place.
David A. Holland
parents: 47
diff changeset
238 }
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
239 from = &p->file->includedfrom;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
240 if (from->type != P_NOWHERE) {
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
241 place_printfrom(from);
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
242 fprintf(stderr, "In file included from %s:%u:%u:\n",
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
243 place_getname(from), from->line, from->column);
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
244 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
245 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
246
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
247 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
248 // complaints
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
249
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
250 void
142
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
251 complain_init(const char *pn)
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
252 {
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
253 myprogname = pn;
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
254 }
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
255
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
256 void
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
257 complain(const struct place *p, const char *fmt, ...)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
258 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
259 va_list ap;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
260
142
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
261 if (p != NULL) {
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
262 place_printfrom(p);
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
263 fprintf(stderr, "%s:%u:%u: ", place_getname(p),
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
264 p->line, p->column);
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
265 } else {
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
266 fprintf(stderr, "%s: ", myprogname);
26ee741196d1 Allow complain(NULL, format, ...)
David A. Holland
parents: 114
diff changeset
267 }
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
268 va_start(ap, fmt);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
269 vfprintf(stderr, fmt, ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
270 va_end(ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
271 fprintf(stderr, "\n");
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
272 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
273
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
274 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
275 complain_fail(void)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
276 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
277 overall_failure = true;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
278 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
279
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
280 bool
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
281 complain_failed(void)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
282 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
283 return overall_failure;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
284 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
285
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
286 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
287 // module init and cleanup
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
288
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
289 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
290 place_init(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
291 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
292 placefilearray_init(&placefiles);
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
293 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
294
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
295 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
296 place_cleanup(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
297 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
298 placefilearray_destroyall(&placefiles);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
299 placefilearray_cleanup(&placefiles);
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
300 }