2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 6/6/93";
44 int wordc; /* how long the current error message is */
45 char **wordv; /* the actual error message */
52 Errorclass pccccom(); /* Portable C Compiler C Compiler */
53 Errorclass richieccom(); /* Richie Compiler for 11 */
65 * Eat all of the lines in the input file, attempting to categorize
66 * them by their various flavors
68 static char inbuffer[BUFSIZ];
70 eaterrors(r_errorc, r_errorv)
74 extern boolean piflag;
75 Errorclass errorclass = C_SYNC;
78 if (fgets(inbuffer, BUFSIZ, errorfile) == NULL)
80 wordvbuild(inbuffer, &wordc, &wordv);
82 * for convience, convert wordv to be 1 based, instead
87 ((( errorclass = onelong() ) != C_UNKNOWN)
88 || (( errorclass = cpp() ) != C_UNKNOWN)
89 || (( errorclass = pccccom() ) != C_UNKNOWN)
90 || (( errorclass = richieccom() ) != C_UNKNOWN)
91 || (( errorclass = lint0() ) != C_UNKNOWN)
92 || (( errorclass = lint1() ) != C_UNKNOWN)
93 || (( errorclass = lint2() ) != C_UNKNOWN)
94 || (( errorclass = lint3() ) != C_UNKNOWN)
95 || (( errorclass = make() ) != C_UNKNOWN)
96 || (( errorclass = f77() ) != C_UNKNOWN)
97 || ((errorclass = pi() ) != C_UNKNOWN)
98 || (( errorclass = ri() )!= C_UNKNOWN)
99 || (( errorclass = mod2() )!= C_UNKNOWN)
100 || (( errorclass = troff() )!= C_UNKNOWN))
103 errorclass = catchall();
105 erroradd(wordc, wordv+1, errorclass, C_UNKNOWN);
108 printf("%d errorentrys\n", nerrors);
110 arrayify(r_errorc, r_errorv, er_head);
114 * create a new error entry, given a zero based array and count
116 erroradd(errorlength, errorv, errorclass, errorsubclass)
119 Errorclass errorclass;
120 Errorclass errorsubclass;
125 if (errorclass == C_TRUE){
126 /* check canonicalization of the second argument*/
127 for(cp = errorv[1]; *cp && isdigit(*cp); cp++)
129 errorclass = (*cp == '\0') ? C_TRUE : C_NONSPEC;
131 if (errorclass != C_TRUE)
132 printf("The 2nd word, \"%s\" is not a number.\n",
136 if (errorlength > 0){
137 newerror = (Eptr)Calloc(1, sizeof(Edesc));
138 newerror->error_language = language; /* language is global */
139 newerror->error_text = errorv;
140 newerror->error_lgtext = errorlength;
141 if (errorclass == C_TRUE)
142 newerror->error_line = atoi(errorv[1]);
143 newerror->error_e_class = errorclass;
144 newerror->error_s_class = errorsubclass;
145 switch(newerror->error_e_class = discardit(newerror)){
146 case C_SYNC: nsyncerrors++; break;
147 case C_DISCARD: ndiscard++; break;
148 case C_NULLED: nnulled++; break;
149 case C_NONSPEC: nnonspec++; break;
150 case C_THISFILE: nthisfile++; break;
151 case C_TRUE: ntrue++; break;
152 case C_UNKNOWN: nunknown++; break;
153 case C_IGNORE: nignore++; break;
155 newerror->error_next = er_head;
157 newerror->error_no = nerrors++;
164 if ( (wordc == 1) && (language != INLD) ){
167 * a) file name from cc
168 * b) Assembler telling world that it is complaining
169 * c) Noise from make ("Stop.")
173 if (strcmp(wordv[1], "Stop.") == 0){
174 language = INMAKE; return(C_SYNC);
176 if (strcmp(wordv[1], "Assembler:") == 0){
177 /* assembler always alerts us to what happened*/
178 language = INAS; return(C_SYNC);
180 if (strcmp(wordv[1], "Undefined:") == 0){
181 /* loader complains about unknown symbols*/
182 language = INLD; return(C_SYNC);
184 if (lastchar(wordv[1]) == ':'){
185 /* cc tells us what file we are in */
186 currentfilename = wordv[1];
187 (void)substitute(currentfilename, ':', '\0');
188 language = INCC; return(C_SYNC);
191 if ( (wordc == 1) && (language == INLD) ){
192 nwordv = (char **)Calloc(4, sizeof(char *));
194 nwordv[1] = wordv[1];
196 nwordv[3] = "undefined.";
205 } /* end of one long */
210 * Now attempt a cpp error message match
212 * ./morse.h: 23: undefined control
213 * morsesend.c: 229: MAGNIBBL: argument mismatch
214 * morsesend.c: 237: MAGNIBBL: argument mismatch
215 * test1.c: 6: undefined control
217 if ( (language != INLD) /* loader errors have almost same fmt*/
218 && (lastchar(wordv[1]) == ':')
219 && (isdigit(firstchar(wordv[2])))
220 && (lastchar(wordv[2]) == ':') ){
222 clob_last(wordv[1], '\0');
223 clob_last(wordv[2], '\0');
232 * Now attempt a ccom error message match:
234 * "morsesend.c", line 237: operands of & have incompatible types
235 * "test.c", line 7: warning: old-fashioned initialization: use =
236 * "subdir.d/foo2.h", line 1: illegal initialization
238 if ( (firstchar(wordv[1]) == '"')
239 && (lastchar(wordv[1]) == ',')
240 && (next_lastchar(wordv[1]) == '"')
241 && (strcmp(wordv[2],"line") == 0)
242 && (isdigit(firstchar(wordv[3])))
243 && (lastchar(wordv[3]) == ':') ){
244 clob_last(wordv[1], '\0'); /* drop last , */
245 clob_last(wordv[1], '\0'); /* drop last " */
246 wordv[1]++; /* drop first " */
247 clob_last(wordv[3], '\0'); /* drop : on line number */
248 wordv[2] = wordv[1]; /* overwrite "line" */
249 wordv++; /*compensate*/
251 currentfilename = wordv[1];
258 * Do the error message from the Richie C Compiler for the PDP11,
259 * which has this source:
262 * fprintf(stderr, "%s:", filename);
263 * fprintf(stderr, "%d: ", line);
266 Errorclass richieccom()
272 if (lastchar(wordv[1]) == ':'){
273 cp = wordv[1] + strlen(wordv[1]) - 1;
274 while (isdigit(*--cp))
277 clob_last(wordv[1], '\0'); /* last : */
278 *cp = '\0'; /* first : */
280 nwordv = wordvsplice(1, wordc, wordv+1);
286 currentfilename = wordv[1];
298 * Attempt a match for the new lint style normal compiler
299 * error messages, of the form
301 * printf("%s(%d): %s\n", filename, linenumber, message);
304 if ( (lastchar(wordv[1]) == ':')
305 && (next_lastchar(wordv[1]) == ')')
307 clob_last(wordv[1], '\0'); /* colon */
308 if (persperdexplode(wordv[1], &line, &file)){
309 nwordv = wordvsplice(1, wordc, wordv+1);
310 nwordv[0] = file; /* file name */
311 nwordv[1] = line; /* line number */
317 wordv[1][strlen(wordv[1])] = ':';
327 char **nwordv1, **nwordv2;
330 * Now, attempt a match for the various errors that lint
331 * can complain about.
333 * Look first for type 1 lint errors
335 if (wordc > 1 && strcmp(wordv[wordc-1], "::") == 0){
337 * %.7s, arg. %d used inconsistently %s(%d) :: %s(%d)
338 * %.7s value used inconsistently %s(%d) :: %s(%d)
339 * %.7s multiply declared %s(%d) :: %s(%d)
340 * %.7s value declared inconsistently %s(%d) :: %s(%d)
341 * %.7s function value type must be declared before use %s(%d) :: %s(%d)
345 && (persperdexplode(wordv[wordc], &line2, &file2))
346 && (persperdexplode(wordv[wordc-2], &line1, &file1)) ){
347 nwordv1 = wordvsplice(2, wordc, wordv+1);
348 nwordv2 = wordvsplice(2, wordc, wordv+1);
349 nwordv1[0] = file1; nwordv1[1] = line1;
350 erroradd(wordc+2, nwordv1, C_TRUE, C_DUPL); /* takes 0 based*/
351 nwordv2[0] = file2; nwordv2[1] = line2;
353 wordv = nwordv2 - 1; /* 1 based */
366 * Look for type 2 lint errors
368 * %.7s used( %s(%d) ), but not defined
369 * %.7s defined( %s(%d) ), but never used
370 * %.7s declared( %s(%d) ), but never used or defined
372 * bufp defined( "./metric.h"(10) ), but never used
374 if ( (lastchar(wordv[2]) == '(' /* ')' */ )
375 && (strcmp(wordv[4], "),") == 0) ){
377 if (persperdexplode(wordv[3], &line, &file)){
378 nwordv = wordvsplice(2, wordc, wordv+1);
379 nwordv[0] = file; nwordv[1] = line;
381 wordv = nwordv - 1; /* 1 based */
388 char *Lint31[4] = {"returns", "value", "which", "is"};
389 char *Lint32[6] = {"value", "is", "used,", "but", "none", "returned"};
392 if ( (wordvcmp(wordv+2, 4, Lint31) == 0)
393 || (wordvcmp(wordv+2, 6, Lint32) == 0) ){
401 * Special word vectors for use by F77 recognition
403 char *F77_fatal[3] = {"Compiler", "error", "line"};
404 char *F77_error[3] = {"Error", "on", "line"};
405 char *F77_warning[3] = {"Warning", "on", "line"};
406 char *F77_no_ass[3] = {"Error.","No","assembly."};
411 * look for f77 errors:
412 * Error messages from /usr/src/cmd/f77/error.c, with
413 * these printf formats:
415 * Compiler error line %d of %s: %s
416 * Error on line %d of %s: %s
417 * Warning on line %d of %s: %s
418 * Error. No assembly.
420 if (wordc == 3 && wordvcmp(wordv+1, 3, F77_no_ass) == 0) {
426 if ( (lastchar(wordv[6]) == ':')
428 (wordvcmp(wordv+1, 3, F77_fatal) == 0)
429 || (wordvcmp(wordv+1, 3, F77_error) == 0)
430 || (wordvcmp(wordv+1, 3, F77_warning) == 0) )
433 nwordv = wordvsplice(2, wordc, wordv+1);
434 nwordv[0] = wordv[6];
435 clob_last(nwordv[0],'\0');
436 nwordv[1] = wordv[4];
438 wordv = nwordv - 1; /* 1 based */
444 char *Make_Croak[3] = {"***", "Error", "code"};
445 char *Make_NotRemade[5] = {"not", "remade", "because", "of", "errors"};
448 if (wordvcmp(wordv+1, 3, Make_Croak) == 0){
452 if (wordvcmp(wordv+2, 5, Make_NotRemade) == 0){
461 * Match an error message produced by ri; here is the
462 * procedure yanked from the distributed version of ri
465 * serror(str, x1, x2, x3)
467 * char *x1, *x2, *x3;
469 * extern int yylineno;
472 * fputs(srcfile, stdout);
474 * fprintf(stdout, " %d: ", yylineno);
475 * fprintf(stdout, str, x1, x2, x3);
476 * fprintf(stdout, "\n");
480 if ( (firstchar(wordv[1]) == '"')
481 &&(lastchar(wordv[1]) == '"')
482 &&(lastchar(wordv[2]) == ':')
483 &&(isdigit(firstchar(wordv[2]))) ){
484 clob_last(wordv[1], '\0'); /* drop the last " */
485 wordv[1]++; /* skip over the first " */
486 clob_last(wordv[2], '\0');
493 Errorclass catchall()
496 * Catches random things.
498 language = INUNKNOWN;
500 } /* end of catch all*/
505 * troff source error message, from eqn, bib, tbl...
506 * Just like pcc ccom, except uses `'
508 if ( (firstchar(wordv[1]) == '`')
509 && (lastchar(wordv[1]) == ',')
510 && (next_lastchar(wordv[1]) == '\'')
511 && (strcmp(wordv[2],"line") == 0)
512 && (isdigit(firstchar(wordv[3])))
513 && (lastchar(wordv[3]) == ':') ){
514 clob_last(wordv[1], '\0'); /* drop last , */
515 clob_last(wordv[1], '\0'); /* drop last " */
516 wordv[1]++; /* drop first " */
517 clob_last(wordv[3], '\0'); /* drop : on line number */
518 wordv[2] = wordv[1]; /* overwrite "line" */
519 wordv++; /*compensate*/
520 currentfilename = wordv[1];
529 * for decwrl modula2 compiler (powell)
531 if ( ( (strcmp(wordv[1], "!!!") == 0) /* early version */
532 ||(strcmp(wordv[1], "File") == 0)) /* later version */
533 && (lastchar(wordv[2]) == ',') /* file name */
534 && (strcmp(wordv[3], "line") == 0)
535 && (isdigit(firstchar(wordv[4]))) /* line number */
536 && (lastchar(wordv[4]) == ':') /* line number */
538 clob_last(wordv[2], '\0'); /* drop last , on file name */
539 clob_last(wordv[4], '\0'); /* drop last : on line number */
540 wordv[3] = wordv[2]; /* file name on top of "line" */
543 currentfilename = wordv[1];