annotate place.c @ 27:01c3a2088ab4

fix some more bugs
author David A. Holland
date Mon, 20 Dec 2010 05:01:18 -0500
parents 5045b9678bb0
children 8a955e3dda2c
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
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
10 struct placefile {
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
11 struct place includedfrom;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
12 char *name;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
13 bool fromsystemdir;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
14 };
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
15 DECLARRAY(placefile);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
16 DEFARRAY(placefile, );
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
17
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
18 static struct placefilearray placefiles;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
19 static bool overall_failure;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
20
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
21 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
22 // seenfiles
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
23
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
24 static
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
25 struct placefile *
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
26 placefile_create(const struct place *from, const char *name,
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
27 bool fromsystemdir)
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
28 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
29 struct placefile *pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
30
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
31 pf = domalloc(sizeof(*pf));
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
32 pf->includedfrom = *from;
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
33 pf->name = dostrdup(name);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
34 pf->fromsystemdir = fromsystemdir;
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
35 return pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
36 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
37
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
38 static
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
39 void
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
40 placefile_destroy(struct placefile *pf)
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
41 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
42 free(pf->name);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
43 free(pf);
10
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
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
46 DESTROYALL_ARRAY(placefile, );
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
47
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
48 const struct placefile *
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
49 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
50 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
51 struct placefile *pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
52
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
53 pf = placefile_create(place, file, issystem);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
54 placefilearray_add(&placefiles, pf, NULL);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
55 return pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
56 }
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 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
59 // places
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
60
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
61 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
62 place_setnowhere(struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
63 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
64 p->type = P_NOWHERE;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
65 p->file = NULL;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
66 p->line = 0;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
67 p->column = 0;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
68 }
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 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
71 place_setbuiltin(struct place *p, unsigned num)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
72 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
73 p->type = P_BUILTIN;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
74 p->file = NULL;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
75 p->line = num;
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
76 p->column = 1;
8
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
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
79 void
14
David A. Holland
parents: 13
diff changeset
80 place_setcommandline(struct place *p, unsigned line, unsigned column)
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
81 {
14
David A. Holland
parents: 13
diff changeset
82 p->type = P_COMMANDLINE;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
83 p->file = NULL;
14
David A. Holland
parents: 13
diff changeset
84 p->line = line;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
85 p->column = column;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
86 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
87
14
David A. Holland
parents: 13
diff changeset
88 void
David A. Holland
parents: 13
diff changeset
89 place_setfilestart(struct place *p, const struct placefile *pf)
David A. Holland
parents: 13
diff changeset
90 {
David A. Holland
parents: 13
diff changeset
91 p->type = P_COMMANDLINE;
David A. Holland
parents: 13
diff changeset
92 p->file = pf;
David A. Holland
parents: 13
diff changeset
93 p->line = 1;
David A. Holland
parents: 13
diff changeset
94 p->column = 1;
David A. Holland
parents: 13
diff changeset
95 }
David A. Holland
parents: 13
diff changeset
96
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
97 static
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
98 const char *
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
99 place_getname(const struct place *p)
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
100 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
101 switch (p->type) {
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
102 case P_NOWHERE: return "<nowhere>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
103 case P_BUILTIN: return "<built-in>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
104 case P_COMMANDLINE: return "<command-line>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
105 case P_FILE: return p->file->name;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
106 }
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
107 assert(0);
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
108 return NULL;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
109 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
110
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
111 static
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
112 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
113 place_printfrom(const struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
114 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
115 const struct place *from;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
116
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
117 from = &p->file->includedfrom;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
118 if (from->type != P_NOWHERE) {
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
119 place_printfrom(from);
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
120 fprintf(stderr, "In file included from %s:%u:%u:\n",
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
121 place_getname(from), from->line, from->column);
8
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 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
124
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
125 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
126 // complaints
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
127
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
128 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
129 complain(const struct place *p, const char *fmt, ...)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
130 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
131 va_list ap;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
132
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
133 place_printfrom(p);
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
134 fprintf(stderr, "%s:%u:%u: ", place_getname(p), p->line, p->column);
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
135 va_start(ap, fmt);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
136 vfprintf(stderr, fmt, ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
137 va_end(ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
138 fprintf(stderr, "\n");
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
139 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
140
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_fail(void)
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 overall_failure = true;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
145 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
146
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
147 bool
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
148 complain_failed(void)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
149 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
150 return overall_failure;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
151 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
152
10
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 // module init and cleanup
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
155
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
156 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
157 place_init(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
158 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
159 placefilearray_init(&placefiles);
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
160 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
161
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
162 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
163 place_cleanup(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
164 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
165 placefilearray_destroyall(&placefiles);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
166 placefilearray_cleanup(&placefiles);
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
167 }