annotate place.c @ 12:6c15ca895585

improve places more
author David A. Holland
date Sun, 19 Dec 2010 19:39:26 -0500
parents b9d50e786322
children 120629a5d6bf
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 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
65 place_setnowhere(struct place *p)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
66 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
67 p->type = P_NOWHERE;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
68 p->file = NULL;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
69 p->line = 0;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
70 p->column = 0;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
71 }
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 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
74 place_setbuiltin(struct place *p, unsigned num)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
75 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
76 p->type = P_BUILTIN;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
77 p->file = NULL;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
78 p->line = num;
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
79 p->column = 1;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
80 }
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 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
83 place_setcommandline(struct place *p, unsigned column)
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 p->file = NULL;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
86 p->line = COMMANDLINE_LINE;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
87 p->column = column;
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
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
90 static
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
91 const char *
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
92 place_getname(const struct place *p)
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
93 {
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
94 switch (p->type) {
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
95 case P_NOWHERE: return "<nowhere>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
96 case P_BUILTIN: return "<built-in>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
97 case P_COMMANDLINE: return "<command-line>";
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
98 case P_FILE: return p->file->name;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
99 }
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
100 assert(0);
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
101 return NULL;
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
102 }
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 static
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
105 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
106 place_printfrom(const struct place *p)
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 const struct place *from;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
109
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
110 from = &p->file->includedfrom;
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
111 if (from->type != P_NOWHERE) {
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
112 place_printfrom(from);
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
113 fprintf(stderr, "In file included from %s:%u:%u:\n",
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
114 place_getname(from), from->line, from->column);
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
115 }
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
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
118 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
119 // complaints
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
120
8
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
121 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
122 complain(const struct place *p, const char *fmt, ...)
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 va_list ap;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
125
12
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
126 place_printfrom(p);
6c15ca895585 improve places more
David A. Holland
parents: 11
diff changeset
127 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
128 va_start(ap, fmt);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
129 vfprintf(stderr, fmt, ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
130 va_end(ap);
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
131 fprintf(stderr, "\n");
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 void
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
135 complain_fail(void)
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 overall_failure = true;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
138 }
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 bool
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
141 complain_failed(void)
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
142 {
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
143 return overall_failure;
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
144 }
97243badae69 split place stuff to its own file
David A. Holland
parents:
diff changeset
145
10
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
146 ////////////////////////////////////////////////////////////
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
147 // module init and cleanup
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
148
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
149 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
150 place_init(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
151 {
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
152 seenfilearray_init(&seenfiles);
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 void
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
156 place_cleanup(void)
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
157 {
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
158 seenfilearray_destroyall(&seenfiles);
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
159 seenfilearray_cleanup(&seenfiles);
800f3a560a3b move seenfiles to place.c too
David A. Holland
parents: 8
diff changeset
160 }