annotate place.c @ 29:8d915cb578dd

Added tag posted-20101220 for changeset 8a955e3dda2c
author David A. Holland
date Mon, 20 Dec 2010 05:44:08 -0500
parents 8a955e3dda2c
children 76c114899f63
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;
28
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
13 int depth;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
14 bool fromsystemdir;
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
15 };
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
16 DECLARRAY(placefile);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
17 DEFARRAY(placefile, );
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
18
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
19 static struct placefilearray placefiles;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
20 static bool overall_failure;
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 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
23 // seenfiles
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 static
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
26 struct placefile *
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
27 placefile_create(const struct place *from, const char *name,
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
28 bool fromsystemdir)
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
29 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
30 struct placefile *pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
31
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
32 pf = domalloc(sizeof(*pf));
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
33 pf->includedfrom = *from;
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
34 pf->name = dostrdup(name);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
35 pf->fromsystemdir = fromsystemdir;
28
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
36 if (from->file != NULL) {
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
37 pf->depth = from->file->depth + 1;
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
38 } else {
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
39 pf->depth = 1;
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
40 }
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
41 return pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
42 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
43
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
44 static
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
45 void
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
46 placefile_destroy(struct placefile *pf)
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 free(pf->name);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
49 free(pf);
10
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
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
52 DESTROYALL_ARRAY(placefile, );
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
53
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
54 const struct placefile *
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
55 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
56 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
57 struct placefile *pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
58
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
59 pf = placefile_create(place, file, issystem);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
60 placefilearray_add(&placefiles, pf, NULL);
28
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
61 if (pf->depth > 128) {
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
62 complain(place, "Maximum include nesting depth exceeded");
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
63 die();
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
64 }
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
65 return pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
66 }
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
67
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
68 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
69 // places
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
70
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
71 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
72 place_setnowhere(struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
73 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
74 p->type = P_NOWHERE;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
75 p->file = NULL;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
76 p->line = 0;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
77 p->column = 0;
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
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
80 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
81 place_setbuiltin(struct place *p, unsigned num)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
82 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
83 p->type = P_BUILTIN;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
84 p->file = NULL;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
85 p->line = num;
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
86 p->column = 1;
8
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
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
89 void
14
David A. Holland
parents: 13
diff changeset
90 place_setcommandline(struct place *p, unsigned line, unsigned column)
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
91 {
14
David A. Holland
parents: 13
diff changeset
92 p->type = P_COMMANDLINE;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
93 p->file = NULL;
14
David A. Holland
parents: 13
diff changeset
94 p->line = line;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
95 p->column = column;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
96 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
97
14
David A. Holland
parents: 13
diff changeset
98 void
David A. Holland
parents: 13
diff changeset
99 place_setfilestart(struct place *p, const struct placefile *pf)
David A. Holland
parents: 13
diff changeset
100 {
28
8a955e3dda2c two more tests, more fixes
David A. Holland
parents: 14
diff changeset
101 p->type = P_FILE;
14
David A. Holland
parents: 13
diff changeset
102 p->file = pf;
David A. Holland
parents: 13
diff changeset
103 p->line = 1;
David A. Holland
parents: 13
diff changeset
104 p->column = 1;
David A. Holland
parents: 13
diff changeset
105 }
David A. Holland
parents: 13
diff changeset
106
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
107 static
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
108 const char *
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
109 place_getname(const struct place *p)
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
110 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
111 switch (p->type) {
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
112 case P_NOWHERE: return "<nowhere>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
113 case P_BUILTIN: return "<built-in>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
114 case P_COMMANDLINE: return "<command-line>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
115 case P_FILE: return p->file->name;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
116 }
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
117 assert(0);
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
118 return NULL;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
119 }
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 static
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
122 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
123 place_printfrom(const struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
124 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
125 const struct place *from;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
126
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
127 from = &p->file->includedfrom;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
128 if (from->type != P_NOWHERE) {
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
129 place_printfrom(from);
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
130 fprintf(stderr, "In file included from %s:%u:%u:\n",
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
131 place_getname(from), from->line, from->column);
8
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 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
134
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
135 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
136 // complaints
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
137
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
138 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
139 complain(const struct place *p, const char *fmt, ...)
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 va_list ap;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
142
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
143 place_printfrom(p);
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
144 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
145 va_start(ap, fmt);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
146 vfprintf(stderr, fmt, ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
147 va_end(ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
148 fprintf(stderr, "\n");
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
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
151 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
152 complain_fail(void)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
153 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
154 overall_failure = true;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
155 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
156
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
157 bool
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
158 complain_failed(void)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
159 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
160 return overall_failure;
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
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
163 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
164 // module init and cleanup
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
165
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
166 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
167 place_init(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
168 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
169 placefilearray_init(&placefiles);
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
170 }
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 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
173 place_cleanup(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
174 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
175 placefilearray_destroyall(&placefiles);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
176 placefilearray_cleanup(&placefiles);
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
177 }