Annotation of src/usr.bin/error/input.c, Revision 1.4
1.4 ! todd 1: /* $OpenBSD: input.c,v 1.3 2001/07/12 05:17:02 deraadt Exp $ */
1.1 deraadt 2: /* $NetBSD: input.c,v 1.4 1995/09/10 15:55:13 christos Exp $ */
3:
4: /*
5: * Copyright (c) 1980, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
37: #ifndef lint
38: #if 0
39: static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 6/6/93";
40: #endif
1.4 ! todd 41: static char rcsid[] = "$OpenBSD: input.c,v 1.3 2001/07/12 05:17:02 deraadt Exp $";
1.1 deraadt 42: #endif /* not lint */
43:
44: #include <stdio.h>
45: #include <ctype.h>
46: #include <stdlib.h>
47: #include <string.h>
48: #include "error.h"
49:
50: int wordc; /* how long the current error message is */
51: char **wordv; /* the actual error message */
52:
53: int nerrors;
54: int language;
55:
56: Errorclass onelong();
57: Errorclass cpp();
58: Errorclass pccccom(); /* Portable C Compiler C Compiler */
59: Errorclass richieccom(); /* Richie Compiler for 11 */
60: Errorclass lint0();
61: Errorclass lint1();
62: Errorclass lint2();
63: Errorclass lint3();
64: Errorclass make();
65: Errorclass f77();
66: Errorclass pi();
67: Errorclass ri();
68: Errorclass troff();
69: Errorclass mod2();
70: /*
71: * Eat all of the lines in the input file, attempting to categorize
72: * them by their various flavors
73: */
1.3 deraadt 74: void
1.1 deraadt 75: eaterrors(r_errorc, r_errorv)
76: int *r_errorc;
77: Eptr **r_errorv;
78: {
79: Errorclass errorclass = C_SYNC;
80: char *line;
81: char *inbuffer;
82: size_t inbuflen;
83:
84: for (;;){
85: if ((inbuffer = fgetln(errorfile, &inbuflen)) == NULL)
86: break;
87: line = Calloc(inbuflen + 1, sizeof(char));
88: memcpy(line, inbuffer, inbuflen);
89: line[inbuflen] = '\0';
90: wordvbuild(line, &wordc, &wordv);
91: /*
1.4 ! todd 92: * for convenience, convert wordv to be 1 based, instead
1.1 deraadt 93: * of 0 based.
94: */
95: wordv -= 1;
96: if ( wordc > 0 &&
97: ((( errorclass = onelong() ) != C_UNKNOWN)
98: || (( errorclass = cpp() ) != C_UNKNOWN)
99: || (( errorclass = pccccom() ) != C_UNKNOWN)
100: || (( errorclass = richieccom() ) != C_UNKNOWN)
101: || (( errorclass = lint0() ) != C_UNKNOWN)
102: || (( errorclass = lint1() ) != C_UNKNOWN)
103: || (( errorclass = lint2() ) != C_UNKNOWN)
104: || (( errorclass = lint3() ) != C_UNKNOWN)
105: || (( errorclass = make() ) != C_UNKNOWN)
106: || (( errorclass = f77() ) != C_UNKNOWN)
107: || ((errorclass = pi() ) != C_UNKNOWN)
108: || (( errorclass = ri() )!= C_UNKNOWN)
109: || (( errorclass = mod2() )!= C_UNKNOWN)
110: || (( errorclass = troff() )!= C_UNKNOWN))
111: ) ;
112: else
113: errorclass = catchall();
114: if (wordc)
115: erroradd(wordc, wordv+1, errorclass, C_UNKNOWN);
116: }
117: #ifdef FULLDEBUG
118: printf("%d errorentrys\n", nerrors);
119: #endif
120: arrayify(r_errorc, r_errorv, er_head);
121: }
122:
123: /*
124: * create a new error entry, given a zero based array and count
125: */
1.3 deraadt 126: void
1.1 deraadt 127: erroradd(errorlength, errorv, errorclass, errorsubclass)
128: int errorlength;
129: char **errorv;
130: Errorclass errorclass;
131: Errorclass errorsubclass;
132: {
133: reg Eptr newerror;
134: reg char *cp;
135:
136: if (errorclass == C_TRUE){
137: /* check canonicalization of the second argument*/
138: for(cp = errorv[1]; *cp && isdigit(*cp); cp++)
139: continue;
140: errorclass = (*cp == '\0') ? C_TRUE : C_NONSPEC;
141: #ifdef FULLDEBUG
142: if (errorclass != C_TRUE)
143: printf("The 2nd word, \"%s\" is not a number.\n",
144: errorv[1]);
145: #endif
146: }
147: if (errorlength > 0){
148: newerror = (Eptr)Calloc(1, sizeof(Edesc));
149: newerror->error_language = language; /* language is global */
150: newerror->error_text = errorv;
151: newerror->error_lgtext = errorlength;
152: if (errorclass == C_TRUE)
153: newerror->error_line = atoi(errorv[1]);
154: newerror->error_e_class = errorclass;
155: newerror->error_s_class = errorsubclass;
156: switch(newerror->error_e_class = discardit(newerror)){
157: case C_SYNC: nsyncerrors++; break;
158: case C_DISCARD: ndiscard++; break;
159: case C_NULLED: nnulled++; break;
160: case C_NONSPEC: nnonspec++; break;
161: case C_THISFILE: nthisfile++; break;
162: case C_TRUE: ntrue++; break;
163: case C_UNKNOWN: nunknown++; break;
164: case C_IGNORE: nignore++; break;
165: }
166: newerror->error_next = er_head;
167: er_head = newerror;
168: newerror->error_no = nerrors++;
169: } /* length > 0 */
170: }
171:
172: Errorclass onelong()
173: {
174: char **nwordv;
175: if ( (wordc == 1) && (language != INLD) ){
176: /*
177: * We have either:
178: * a) file name from cc
179: * b) Assembler telling world that it is complaining
180: * c) Noise from make ("Stop.")
181: * c) Random noise
182: */
183: wordc = 0;
184: if (strcmp(wordv[1], "Stop.") == 0){
185: language = INMAKE; return(C_SYNC);
186: }
187: if (strcmp(wordv[1], "Assembler:") == 0){
188: /* assembler always alerts us to what happened*/
189: language = INAS; return(C_SYNC);
190: } else
191: if (strcmp(wordv[1], "Undefined:") == 0){
192: /* loader complains about unknown symbols*/
193: language = INLD; return(C_SYNC);
194: }
195: if (lastchar(wordv[1]) == ':'){
196: /* cc tells us what file we are in */
197: currentfilename = wordv[1];
198: (void)substitute(currentfilename, ':', '\0');
199: language = INCC; return(C_SYNC);
200: }
201: } else
202: if ( (wordc == 1) && (language == INLD) ){
203: nwordv = (char **)Calloc(4, sizeof(char *));
204: nwordv[0] = "ld:";
205: nwordv[1] = wordv[1];
206: nwordv[2] = "is";
207: nwordv[3] = "undefined.";
208: wordc = 4;
209: wordv = nwordv - 1;
210: return(C_NONSPEC);
211: } else
212: if (wordc == 1){
213: return(C_SYNC);
214: }
215: return(C_UNKNOWN);
216: } /* end of one long */
217:
218: Errorclass cpp()
219: {
220: /*
221: * Now attempt a cpp error message match
222: * Examples:
223: * ./morse.h: 23: undefined control
224: * morsesend.c: 229: MAGNIBBL: argument mismatch
225: * morsesend.c: 237: MAGNIBBL: argument mismatch
226: * test1.c: 6: undefined control
227: */
228: if ( (language != INLD) /* loader errors have almost same fmt*/
229: && (lastchar(wordv[1]) == ':')
230: && (isdigit(firstchar(wordv[2])))
231: && (lastchar(wordv[2]) == ':') ){
232: language = INCPP;
233: clob_last(wordv[1], '\0');
234: clob_last(wordv[2], '\0');
235: return(C_TRUE);
236: }
237: return(C_UNKNOWN);
238: } /*end of cpp*/
239:
240: Errorclass pccccom()
241: {
242: /*
243: * Now attempt a ccom error message match:
244: * Examples:
245: * "morsesend.c", line 237: operands of & have incompatible types
246: * "test.c", line 7: warning: old-fashioned initialization: use =
247: * "subdir.d/foo2.h", line 1: illegal initialization
248: */
249: if ( (firstchar(wordv[1]) == '"')
250: && (lastchar(wordv[1]) == ',')
251: && (next_lastchar(wordv[1]) == '"')
252: && (strcmp(wordv[2],"line") == 0)
253: && (isdigit(firstchar(wordv[3])))
254: && (lastchar(wordv[3]) == ':') ){
255: clob_last(wordv[1], '\0'); /* drop last , */
256: clob_last(wordv[1], '\0'); /* drop last " */
257: wordv[1]++; /* drop first " */
258: clob_last(wordv[3], '\0'); /* drop : on line number */
259: wordv[2] = wordv[1]; /* overwrite "line" */
260: wordv++; /*compensate*/
261: wordc--;
262: currentfilename = wordv[1];
263: language = INCC;
264: return(C_TRUE);
265: }
266: return(C_UNKNOWN);
267: } /* end of ccom */
268: /*
269: * Do the error message from the Richie C Compiler for the PDP11,
270: * which has this source:
271: *
272: * if (filename[0])
273: * fprintf(stderr, "%s:", filename);
274: * fprintf(stderr, "%d: ", line);
275: *
276: */
277: Errorclass richieccom()
278: {
279: reg char *cp;
280: reg char **nwordv;
281: char *file;
282:
283: if (lastchar(wordv[1]) == ':'){
284: cp = wordv[1] + strlen(wordv[1]) - 1;
285: while (isdigit(*--cp))
286: continue;
287: if (*cp == ':'){
288: clob_last(wordv[1], '\0'); /* last : */
289: *cp = '\0'; /* first : */
290: file = wordv[1];
291: nwordv = wordvsplice(1, wordc, wordv+1);
292: nwordv[0] = file;
293: nwordv[1] = cp + 1;
294: wordc += 1;
295: wordv = nwordv - 1;
296: language = INCC;
297: currentfilename = wordv[1];
298: return(C_TRUE);
299: }
300: }
301: return(C_UNKNOWN);
302: }
303:
304: Errorclass lint0()
305: {
306: reg char **nwordv;
307: char *line, *file;
308: /*
309: * Attempt a match for the new lint style normal compiler
310: * error messages, of the form
311: *
312: * printf("%s(%d): %s\n", filename, linenumber, message);
313: */
314: if (wordc >= 2){
315: if ( (lastchar(wordv[1]) == ':')
316: && (next_lastchar(wordv[1]) == ')')
317: ) {
318: clob_last(wordv[1], '\0'); /* colon */
319: if (persperdexplode(wordv[1], &line, &file)){
320: nwordv = wordvsplice(1, wordc, wordv+1);
321: nwordv[0] = file; /* file name */
322: nwordv[1] = line; /* line number */
323: wordc += 1;
324: wordv = nwordv - 1;
325: language = INLINT;
326: return(C_TRUE);
327: }
328: wordv[1][strlen(wordv[1])] = ':';
329: }
330: }
331: return (C_UNKNOWN);
332: }
333:
334: Errorclass lint1()
335: {
336: char *line1, *line2;
337: char *file1, *file2;
338: char **nwordv1, **nwordv2;
339:
340: /*
341: * Now, attempt a match for the various errors that lint
342: * can complain about.
343: *
344: * Look first for type 1 lint errors
345: */
346: if (wordc > 1 && strcmp(wordv[wordc-1], "::") == 0){
347: /*
348: * %.7s, arg. %d used inconsistently %s(%d) :: %s(%d)
349: * %.7s value used inconsistently %s(%d) :: %s(%d)
350: * %.7s multiply declared %s(%d) :: %s(%d)
351: * %.7s value declared inconsistently %s(%d) :: %s(%d)
352: * %.7s function value type must be declared before use %s(%d) :: %s(%d)
353: */
354: language = INLINT;
355: if (wordc > 2
356: && (persperdexplode(wordv[wordc], &line2, &file2))
357: && (persperdexplode(wordv[wordc-2], &line1, &file1)) ){
358: nwordv1 = wordvsplice(2, wordc, wordv+1);
359: nwordv2 = wordvsplice(2, wordc, wordv+1);
360: nwordv1[0] = file1; nwordv1[1] = line1;
361: erroradd(wordc+2, nwordv1, C_TRUE, C_DUPL); /* takes 0 based*/
362: nwordv2[0] = file2; nwordv2[1] = line2;
363: wordc = wordc + 2;
364: wordv = nwordv2 - 1; /* 1 based */
365: return(C_TRUE);
366: }
367: }
368: return(C_UNKNOWN);
369: } /* end of lint 1*/
370:
371: Errorclass lint2()
372: {
373: char *file;
374: char *line;
375: char **nwordv;
376: /*
377: * Look for type 2 lint errors
378: *
379: * %.7s used( %s(%d) ), but not defined
380: * %.7s defined( %s(%d) ), but never used
381: * %.7s declared( %s(%d) ), but never used or defined
382: *
383: * bufp defined( "./metric.h"(10) ), but never used
384: */
385: if ( (lastchar(wordv[2]) == '(' /* ')' */ )
386: && (strcmp(wordv[4], "),") == 0) ){
387: language = INLINT;
388: if (persperdexplode(wordv[3], &line, &file)){
389: nwordv = wordvsplice(2, wordc, wordv+1);
390: nwordv[0] = file; nwordv[1] = line;
391: wordc = wordc + 2;
392: wordv = nwordv - 1; /* 1 based */
393: return(C_TRUE);
394: }
395: }
396: return(C_UNKNOWN);
397: } /* end of lint 2*/
398:
399: char *Lint31[4] = {"returns", "value", "which", "is"};
400: char *Lint32[6] = {"value", "is", "used,", "but", "none", "returned"};
401: Errorclass lint3()
402: {
403: if ( (wordvcmp(wordv+2, 4, Lint31) == 0)
404: || (wordvcmp(wordv+2, 6, Lint32) == 0) ){
405: language = INLINT;
406: return(C_NONSPEC);
407: }
408: return(C_UNKNOWN);
409: }
410:
411: /*
412: * Special word vectors for use by F77 recognition
413: */
414: char *F77_fatal[3] = {"Compiler", "error", "line"};
415: char *F77_error[3] = {"Error", "on", "line"};
416: char *F77_warning[3] = {"Warning", "on", "line"};
417: char *F77_no_ass[3] = {"Error.","No","assembly."};
1.3 deraadt 418: int
1.1 deraadt 419: f77()
420: {
421: char **nwordv;
422: /*
423: * look for f77 errors:
424: * Error messages from /usr/src/cmd/f77/error.c, with
425: * these printf formats:
426: *
427: * Compiler error line %d of %s: %s
428: * Error on line %d of %s: %s
429: * Warning on line %d of %s: %s
430: * Error. No assembly.
431: */
432: if (wordc == 3 && wordvcmp(wordv+1, 3, F77_no_ass) == 0) {
433: wordc = 0;
434: return(C_SYNC);
435: }
436: if (wordc < 6)
437: return(C_UNKNOWN);
438: if ( (lastchar(wordv[6]) == ':')
439: &&(
440: (wordvcmp(wordv+1, 3, F77_fatal) == 0)
441: || (wordvcmp(wordv+1, 3, F77_error) == 0)
442: || (wordvcmp(wordv+1, 3, F77_warning) == 0) )
443: ){
444: language = INF77;
445: nwordv = wordvsplice(2, wordc, wordv+1);
446: nwordv[0] = wordv[6];
447: clob_last(nwordv[0],'\0');
448: nwordv[1] = wordv[4];
449: wordc += 2;
450: wordv = nwordv - 1; /* 1 based */
451: return(C_TRUE);
452: }
453: return(C_UNKNOWN);
454: } /* end of f77 */
455:
456: char *Make_Croak[3] = {"***", "Error", "code"};
457: char *Make_NotRemade[5] = {"not", "remade", "because", "of", "errors"};
458: Errorclass make()
459: {
460: if (wordvcmp(wordv+1, 3, Make_Croak) == 0){
461: language = INMAKE;
462: return(C_SYNC);
463: }
464: if (wordvcmp(wordv+2, 5, Make_NotRemade) == 0){
465: language = INMAKE;
466: return(C_SYNC);
467: }
468: return(C_UNKNOWN);
469: }
470: Errorclass ri()
471: {
472: /*
473: * Match an error message produced by ri; here is the
474: * procedure yanked from the distributed version of ri
475: * April 24, 1980.
476: *
477: * serror(str, x1, x2, x3)
478: * char str[];
479: * char *x1, *x2, *x3;
480: * {
481: * extern int yylineno;
482: *
483: * putc('"', stdout);
484: * fputs(srcfile, stdout);
485: * putc('"', stdout);
486: * fprintf(stdout, " %d: ", yylineno);
487: * fprintf(stdout, str, x1, x2, x3);
488: * fprintf(stdout, "\n");
489: * synerrs++;
490: * }
491: */
492: if ( (firstchar(wordv[1]) == '"')
493: &&(lastchar(wordv[1]) == '"')
494: &&(lastchar(wordv[2]) == ':')
495: &&(isdigit(firstchar(wordv[2]))) ){
496: clob_last(wordv[1], '\0'); /* drop the last " */
497: wordv[1]++; /* skip over the first " */
498: clob_last(wordv[2], '\0');
499: language = INRI;
500: return(C_TRUE);
501: }
502: return(C_UNKNOWN);
503: }
504:
505: Errorclass catchall()
506: {
507: /*
508: * Catches random things.
509: */
510: language = INUNKNOWN;
511: return(C_NONSPEC);
512: } /* end of catch all*/
513:
514: Errorclass troff()
515: {
516: /*
517: * troff source error message, from eqn, bib, tbl...
518: * Just like pcc ccom, except uses `'
519: */
520: if ( (firstchar(wordv[1]) == '`')
521: && (lastchar(wordv[1]) == ',')
522: && (next_lastchar(wordv[1]) == '\'')
523: && (strcmp(wordv[2],"line") == 0)
524: && (isdigit(firstchar(wordv[3])))
525: && (lastchar(wordv[3]) == ':') ){
526: clob_last(wordv[1], '\0'); /* drop last , */
527: clob_last(wordv[1], '\0'); /* drop last " */
528: wordv[1]++; /* drop first " */
529: clob_last(wordv[3], '\0'); /* drop : on line number */
530: wordv[2] = wordv[1]; /* overwrite "line" */
531: wordv++; /*compensate*/
532: currentfilename = wordv[1];
533: language = INTROFF;
534: return(C_TRUE);
535: }
536: return(C_UNKNOWN);
537: }
538: Errorclass mod2()
539: {
540: /*
541: * for decwrl modula2 compiler (powell)
542: */
543: if ( ( (strcmp(wordv[1], "!!!") == 0) /* early version */
544: ||(strcmp(wordv[1], "File") == 0)) /* later version */
545: && (lastchar(wordv[2]) == ',') /* file name */
546: && (strcmp(wordv[3], "line") == 0)
547: && (isdigit(firstchar(wordv[4]))) /* line number */
548: && (lastchar(wordv[4]) == ':') /* line number */
549: ){
550: clob_last(wordv[2], '\0'); /* drop last , on file name */
551: clob_last(wordv[4], '\0'); /* drop last : on line number */
552: wordv[3] = wordv[2]; /* file name on top of "line" */
553: wordv += 2;
554: wordc -= 2;
555: currentfilename = wordv[1];
556: language = INMOD2;
557: return(C_TRUE);
558: }
559: return(C_UNKNOWN);
560: }