2 * Compiler error handler
4 * (C) 1992 Joseph H. Allen
6 * This file is part of JOE (Joe's Own Editor)
11 __RCSID("$MirOS: contrib/code/jupp/uerror.c,v 1.6 2017/12/02 18:50:03 tg Exp $");
26 typedef struct error ERROR;
29 LINK(ERROR) link; /* Linked list of errors */
30 long line; /* Target line number */
31 long org; /* Original target line number */
32 unsigned char *file; /* Target file name */
33 long src; /* Error-file line number */
34 unsigned char *msg; /* The message */
35 } errors = { { &errors, &errors}, 0, 0, NULL, 0, NULL };
36 ERROR *errptr = &errors; /* Current error row */
38 B *errbuf = NULL; /* Buffer with error messages */
40 /* Insert and delete notices */
42 void inserr(unsigned char *name, long int where, long int n, int bol)
47 for (e = errors.link.next; e != &errors; e = e->link.next) {
48 if (!strcmp(e->file, name)) {
51 else if (e->line == where && bol)
58 void delerr(unsigned char *name, long int where, long int n)
63 for (e = errors.link.next; e != &errors; e = e->link.next) {
64 if (!strcmp(e->file, name)) {
65 if (e->line > where + n)
67 else if (e->line > where)
76 void abrerr(unsigned char *name)
81 for (e = errors.link.next; e != &errors; e = e->link.next)
82 if (!strcmp(e->file, name))
88 void saverr(unsigned char *name)
93 for (e = errors.link.next; e != &errors; e = e->link.next)
94 if (!strcmp(e->file, name))
98 /* Pool of free error nodes */
99 ERROR errnodes = { {&errnodes, &errnodes}, 0, 0, NULL, 0, NULL };
101 /* Free an error node */
103 static void freeerr(ERROR *n)
107 enquef(ERROR, link, &errnodes, n);
110 /* Free all errors */
112 static void freeall(void)
114 while (!qempty(ERROR, link, &errors))
115 freeerr(deque_f(ERROR, link, errors.link.next));
119 /* Parse error messages into database */
121 /* From joe's joe 2.9 */
123 /* First word on line with a '.' in it. This is the file name. The next number after that is the line number. */
125 static int parseit(struct charmap *map,unsigned char *s, long int row)
128 unsigned char *name = NULL;
136 /* Skip to first word */
137 for (x = y; s[x] && !(joe_isalnum_(map,s[x]) || s[x] == '.' || s[x] == '/'); ++x) ;
139 /* Skip to end of first word */
140 for (y = x; joe_isalnum_(map,s[y]) || s[y] == '.' || s[y] == '/'; ++y)
143 } while (!flg && x!=y);
147 name = vsncpy(NULL, 0, s + x, y - x);
149 /* Skip to first number */
150 for (x = y; s[x] && (s[x] < '0' || s[x] > '9'); ++x) ;
152 /* Skip to end of first number */
153 for (y = x; s[y] >= '0' && s[y] <= '9'; ++y) ;
155 /* Save line number */
157 sscanf((char *)(s + x), "%ld", &line);
172 if (line != -1 && flg) {
173 /* We have an error */
174 err = (ERROR *) alitem(&errnodes, sizeof(ERROR));
176 err->org = err->line = line;
178 err->msg = vsncpy(NULL, 0, sc("\\i"));
179 err->msg = vsncpy(sv(err->msg), sv(s));
180 enqueb(ERROR, link, &errors, err);
188 /* Parse the error output contained in a buffer */
190 static long parserr(B *b)
202 s = brvs(q, (int) (p->byte - q->byte));
204 nerrs += parseit(b->o.charmap, s, q->line);
207 } while (pgetc(p) != NO_MORE_DATA);
213 BW *find_a_good_bw(B *b)
217 /* Find lowest window with buffer */
218 if ((w = maint->topwin) != NULL) {
220 if ((w->watom->what&TYPETW) && ((BW *)w->object)->b==b && w->y>=0)
221 bw = (BW *)w->object;
223 } while (w != maint->topwin);
227 /* Otherwise just find lowest window */
228 if ((w = maint->topwin) != NULL) {
230 if ((w->watom->what&TYPETW) && w->y>=0)
231 bw = (BW *)w->object;
233 } while (w != maint->topwin);
245 bw = find_a_good_bw(b);
247 joe_snprintf_1((char *)msgbuf, JOE_MSGBUFSIZE, "%ld messages found", n);
249 joe_snprintf_0((char *)msgbuf, JOE_MSGBUFSIZE, "No messages found");
250 msgnw(bw->parent, msgbuf);
261 joe_snprintf_1((char *)msgbuf, JOE_MSGBUFSIZE, "%ld messages found", n);
263 joe_snprintf_0((char *)msgbuf, JOE_MSGBUFSIZE, "No messages found");
264 msgnw(bw->parent, msgbuf);
272 if (errptr->link.next == &errors) {
273 msgnw(bw->parent, US "No more errors");
276 errptr = errptr->link.next;
277 if (!bw->b->name || strcmp(errptr->file, bw->b->name)) {
278 if (doswitch(bw, vsdup(errptr->file), NULL, NULL))
280 bw = (BW *) maint->curwin->object;
284 pline(bw->cursor, errptr->line);
285 setline(errbuf, errptr->src);
288 bw->cursor->xcol = piscol(bw->cursor);
289 msgnw(bw->parent, errptr->msg);
297 if (errptr->link.prev == &errors) {
298 msgnw(bw->parent, US "No more errors");
301 errptr = errptr->link.prev;
302 if (!bw->b->name || strcmp(errptr->file, bw->b->name)) {
303 if (doswitch(bw, vsdup(errptr->file), NULL, NULL))
305 bw = (BW *) maint->curwin->object;
309 pline(bw->cursor, errptr->line);
310 setline(errbuf, errptr->src);
313 bw->cursor->xcol = piscol(bw->cursor);
314 msgnw(bw->parent, errptr->msg);