annotate place.c @ 13:120629a5d6bf

seenfile -> placefile (clearer)
author David A. Holland
date Sun, 19 Dec 2010 19:49:43 -0500
parents 6c15ca895585
children 5045b9678bb0
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
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
14 struct placefile {
10
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 };
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
19 DECLARRAY(placefile);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
20 DEFARRAY(placefile, );
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
21
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
22 static struct placefilearray placefiles;
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
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
29 struct placefile *
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
30 placefile_create(const struct place *from, const char *name,
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
31 bool fromsystemdir)
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
32 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
33 struct placefile *pf;
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
34
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
35 pf = domalloc(sizeof(*pf));
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
36 pf->includedfrom = *from;
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
37 pf->name = dostrdup(name);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
38 pf->fromsystemdir = fromsystemdir;
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
39 return pf;
10
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
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
42 static
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
43 void
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
44 placefile_destroy(struct placefile *pf)
10
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 free(pf->name);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
47 free(pf);
10
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
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
50 DESTROYALL_ARRAY(placefile, );
10
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 const struct placefile *
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
53 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
54 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
55 struct placefile *pf;
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 pf = placefile_create(place, file, issystem);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
58 placefilearray_add(&placefiles, pf, NULL);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
59 return pf;
10
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 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
63 // places
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
64
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
65 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
66 place_setnowhere(struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
67 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
68 p->type = P_NOWHERE;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
69 p->file = NULL;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
70 p->line = 0;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
71 p->column = 0;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
72 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
73
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
74 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
75 place_setbuiltin(struct place *p, unsigned num)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
76 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
77 p->type = P_BUILTIN;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
78 p->file = NULL;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
79 p->line = num;
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
80 p->column = 1;
8
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
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
83 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
84 place_setcommandline(struct place *p, unsigned column)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
85 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
86 p->file = NULL;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
87 p->line = COMMANDLINE_LINE;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
88 p->column = column;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
89 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
90
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
91 static
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
92 const char *
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
93 place_getname(const struct place *p)
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
94 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
95 switch (p->type) {
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
96 case P_NOWHERE: return "<nowhere>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
97 case P_BUILTIN: return "<built-in>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
98 case P_COMMANDLINE: return "<command-line>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
99 case P_FILE: return p->file->name;
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 assert(0);
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
102 return NULL;
8
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
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
105 static
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
106 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
107 place_printfrom(const struct place *p)
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 const struct place *from;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
110
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
111 from = &p->file->includedfrom;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
112 if (from->type != P_NOWHERE) {
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
113 place_printfrom(from);
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
114 fprintf(stderr, "In file included from %s:%u:%u:\n",
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
115 place_getname(from), from->line, from->column);
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
116 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
117 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
118
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
119 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
120 // complaints
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
121
8
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 complain(const struct place *p, const char *fmt, ...)
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 va_list ap;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
126
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
127 place_printfrom(p);
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
128 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
129 va_start(ap, fmt);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
130 vfprintf(stderr, fmt, ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
131 va_end(ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
132 fprintf(stderr, "\n");
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
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
135 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
136 complain_fail(void)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
137 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
138 overall_failure = true;
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 bool
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
142 complain_failed(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 return overall_failure;
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
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
147 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
148 // module init and cleanup
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
149
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
150 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
151 place_init(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
152 {
13
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
153 placefilearray_init(&placefiles);
10
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
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_cleanup(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_destroyall(&placefiles);
120629a5d6bf seenfile -> placefile (clearer)
David A. Holland
parents: 12
diff changeset
160 placefilearray_cleanup(&placefiles);
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
161 }