1 /* $MirOS: contrib/code/jupp/uerror.c,v 1.3 2008/05/13 13:08:27 tg Exp $ */
3 * Compiler error handler
5 * (C) 1992 Joseph H. Allen
7 * This file is part of JOE (Joe's Own Editor)
27 typedef struct error ERROR;
30 LINK(ERROR) link; /* Linked list of errors */
31 long line; /* Target line number */
32 long org; /* Original target line number */
33 unsigned char *file; /* Target file name */
34 long src; /* Error-file line number */
35 unsigned char *msg; /* The message */
36 } errors = { { &errors, &errors} };
37 ERROR *errptr = &errors; /* Current error row */
39 B *errbuf = NULL; /* Buffer with error messages */
41 /* Insert and delete notices */
43 void inserr(unsigned char *name, long int where, long int n, int bol)
48 for (e = errors.link.next; e != &errors; e = e->link.next) {
49 if (!strcmp(e->file, name)) {
52 else if (e->line == where && bol)
59 void delerr(unsigned char *name, long int where, long int n)
64 for (e = errors.link.next; e != &errors; e = e->link.next) {
65 if (!strcmp(e->file, name)) {
66 if (e->line > where + n)
68 else if (e->line > where)
77 void abrerr(unsigned char *name)
82 for (e = errors.link.next; e != &errors; e = e->link.next)
83 if (!strcmp(e->file, name))
89 void saverr(unsigned char *name)
94 for (e = errors.link.next; e != &errors; e = e->link.next)
95 if (!strcmp(e->file, name))
99 /* Pool of free error nodes */
100 ERROR errnodes = { {&errnodes, &errnodes} };
102 /* Free an error node */
104 static void freeerr(ERROR *n)
108 enquef(ERROR, link, &errnodes, n);
111 /* Free all errors */
113 static void freeall(void)
115 while (!qempty(ERROR, link, &errors))
116 freeerr(deque_f(ERROR, link, errors.link.next));
120 /* Parse error messages into database */
122 /* From joe's joe 2.9 */
124 /* First word on line with a '.' in it. This is the file name. The next number after that is the line number. */
126 static int parseit(struct charmap *map,unsigned char *s, long int row)
129 unsigned char *name = NULL;
137 /* Skip to first word */
138 for (x = y; s[x] && !(joe_isalnum_(map,s[x]) || s[x] == '.' || s[x] == '/'); ++x) ;
140 /* Skip to end of first word */
141 for (y = x; joe_isalnum_(map,s[y]) || s[y] == '.' || s[y] == '/'; ++y)
144 } while (!flg && x!=y);
148 name = vsncpy(NULL, 0, s + x, y - x);
150 /* Skip to first number */
151 for (x = y; s[x] && (s[x] < '0' || s[x] > '9'); ++x) ;
153 /* Skip to end of first number */
154 for (y = x; s[y] >= '0' && s[y] <= '9'; ++y) ;
156 /* Save line number */
158 sscanf((char *)(s + x), "%ld", &line);
173 if (line != -1 && flg) {
174 /* We have an error */
175 err = (ERROR *) alitem(&errnodes, sizeof(ERROR));
177 err->org = err->line = line;
179 err->msg = vsncpy(NULL, 0, sc("\\i"));
180 err->msg = vsncpy(sv(err->msg), sv(s));
181 enqueb(ERROR, link, &errors, err);
189 /* Parse the error output contained in a buffer */
191 static long parserr(B *b)
203 s = brvs(q, (int) (p->byte - q->byte));
205 nerrs += parseit(b->o.charmap, s, q->line);
208 } while (pgetc(p) != NO_MORE_DATA);
214 BW *find_a_good_bw(B *b)
218 /* Find lowest window with buffer */
219 if ((w = maint->topwin) != NULL) {
221 if ((w->watom->what&TYPETW) && ((BW *)w->object)->b==b && w->y>=0)
222 bw = (BW *)w->object;
224 } while (w != maint->topwin);
228 /* Otherwise just find lowest window */
229 if ((w = maint->topwin) != NULL) {
231 if ((w->watom->what&TYPETW) && w->y>=0)
232 bw = (BW *)w->object;
234 } while (w != maint->topwin);
246 bw = find_a_good_bw(b);
248 joe_snprintf_1((char *)msgbuf, JOE_MSGBUFSIZE, "%ld messages found", n);
250 joe_snprintf_0((char *)msgbuf, JOE_MSGBUFSIZE, "No messages found");
251 msgnw(bw->parent, msgbuf);
262 joe_snprintf_1((char *)msgbuf, JOE_MSGBUFSIZE, "%ld messages found", n);
264 joe_snprintf_0((char *)msgbuf, JOE_MSGBUFSIZE, "No messages found");
265 msgnw(bw->parent, msgbuf);
273 if (errptr->link.next == &errors) {
274 msgnw(bw->parent, US "No more errors");
277 errptr = errptr->link.next;
278 if (!bw->b->name || strcmp(errptr->file, bw->b->name)) {
279 if (doedit(bw, vsdup(errptr->file), NULL, NULL))
281 bw = (BW *) maint->curwin->object;
285 pline(bw->cursor, errptr->line);
286 setline(errbuf, errptr->src);
289 bw->cursor->xcol = piscol(bw->cursor);
290 msgnw(bw->parent, errptr->msg);
298 if (errptr->link.prev == &errors) {
299 msgnw(bw->parent, US "No more errors");
302 errptr = errptr->link.prev;
303 if (!bw->b->name || strcmp(errptr->file, bw->b->name)) {
304 if (doedit(bw, vsdup(errptr->file), NULL, NULL))
306 bw = (BW *) maint->curwin->object;
310 pline(bw->cursor, errptr->line);
311 setline(errbuf, errptr->src);
314 bw->cursor->xcol = piscol(bw->cursor);
315 msgnw(bw->parent, errptr->msg);