Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison place.c @ 12:6c15ca895585
improve places more
author | David A. Holland |
---|---|
date | Sun, 19 Dec 2010 19:39:26 -0500 |
parents | b9d50e786322 |
children | 120629a5d6bf |
comparison
equal
deleted
inserted
replaced
11:b9d50e786322 | 12:6c15ca895585 |
---|---|
59 } | 59 } |
60 | 60 |
61 //////////////////////////////////////////////////////////// | 61 //////////////////////////////////////////////////////////// |
62 // places | 62 // places |
63 | 63 |
64 static | |
65 bool | |
66 place_isnowhere(const struct place *p) | |
67 { | |
68 return p->file == NULL && p->line == NOWHERE_LINE; | |
69 } | |
70 | |
71 static | |
72 bool | |
73 place_isbuiltin(const struct place *p) | |
74 { | |
75 return p->file == NULL && p->line == BUILTIN_LINE; | |
76 } | |
77 | |
78 static | |
79 bool | |
80 place_iscommandline(const struct place *p) | |
81 { | |
82 return p->file == NULL && p->line == COMMANDLINE_LINE; | |
83 } | |
84 | |
85 void | 64 void |
86 place_setnowhere(struct place *p) | 65 place_setnowhere(struct place *p) |
87 { | 66 { |
67 p->type = P_NOWHERE; | |
88 p->file = NULL; | 68 p->file = NULL; |
89 p->line = NOWHERE_LINE; | 69 p->line = 0; |
90 p->column = 0; | 70 p->column = 0; |
91 } | 71 } |
92 | 72 |
93 void | 73 void |
94 place_setbuiltin(struct place *p, unsigned num) | 74 place_setbuiltin(struct place *p, unsigned num) |
95 { | 75 { |
76 p->type = P_BUILTIN; | |
96 p->file = NULL; | 77 p->file = NULL; |
97 p->line = BUILTIN_LINE; | 78 p->line = num; |
98 p->column = num; | 79 p->column = 1; |
99 } | 80 } |
100 | 81 |
101 void | 82 void |
102 place_setcommandline(struct place *p, unsigned column) | 83 place_setcommandline(struct place *p, unsigned column) |
103 { | 84 { |
105 p->line = COMMANDLINE_LINE; | 86 p->line = COMMANDLINE_LINE; |
106 p->column = column; | 87 p->column = column; |
107 } | 88 } |
108 | 89 |
109 static | 90 static |
110 void | 91 const char * |
111 place_print(const struct place *p) | 92 place_getname(const struct place *p) |
112 { | 93 { |
113 if (place_iscommandline(p)) { | 94 switch (p->type) { |
114 fprintf(stderr, "<command-line>:1:%u", p->column); | 95 case P_NOWHERE: return "<nowhere>"; |
115 } else if (place_isbuiltin(p)) { | 96 case P_BUILTIN: return "<built-in>"; |
116 fprintf(stderr, "<built-in>:%u:1", p->column); | 97 case P_COMMANDLINE: return "<command-line>"; |
117 } else { | 98 case P_FILE: return p->file->name; |
118 fprintf(stderr, "%s:%u:%u", p->file->name, | |
119 p->line, p->column); | |
120 } | 99 } |
100 assert(0); | |
101 return NULL; | |
121 } | 102 } |
122 | 103 |
123 static | 104 static |
124 void | 105 void |
125 place_printfrom(const struct place *p) | 106 place_printfrom(const struct place *p) |
126 { | 107 { |
127 const struct place *from; | 108 const struct place *from; |
128 | 109 |
129 from = &p->file->includedfrom; | 110 from = &p->file->includedfrom; |
130 if (!place_isnowhere(from)) { | 111 if (from->type != P_NOWHERE) { |
131 place_printfrom(from); | 112 place_printfrom(from); |
113 fprintf(stderr, "In file included from %s:%u:%u:\n", | |
114 place_getname(from), from->line, from->column); | |
132 } | 115 } |
133 fprintf(stderr, "In file included from "); | |
134 place_print(p); | |
135 fprintf(stderr, ":\n"); | |
136 } | 116 } |
137 | 117 |
138 //////////////////////////////////////////////////////////// | 118 //////////////////////////////////////////////////////////// |
139 // complaints | 119 // complaints |
140 | 120 |
141 void | 121 void |
142 complain(const struct place *p, const char *fmt, ...) | 122 complain(const struct place *p, const char *fmt, ...) |
143 { | 123 { |
144 va_list ap; | 124 va_list ap; |
145 const struct place *from; | |
146 | 125 |
147 from = &p->file->includedfrom; | 126 place_printfrom(p); |
148 if (!place_isnowhere(from)) { | 127 fprintf(stderr, "%s:%u:%u: ", place_getname(p), p->line, p->column); |
149 place_printfrom(from); | |
150 } | |
151 place_print(p); | |
152 fprintf(stderr, ": "); | |
153 va_start(ap, fmt); | 128 va_start(ap, fmt); |
154 vfprintf(stderr, fmt, ap); | 129 vfprintf(stderr, fmt, ap); |
155 va_end(ap); | 130 va_end(ap); |
156 fprintf(stderr, "\n"); | 131 fprintf(stderr, "\n"); |
157 } | 132 } |