1 /* $NetBSD: input.c,v 1.15 2009/08/13 05:53:58 dholland Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)input.c 8.1 (Berkeley) 6/6/93";
37 __RCSID("$NetBSD: input.c,v 1.15 2009/08/13 05:53:58 dholland Exp $");
46 int cur_wordc
; /* how long the current error message is */
47 char **cur_wordv
; /* the actual error message */
49 static Errorclass
catchall(void);
50 static Errorclass
cpp(void);
51 static Errorclass
f77(void);
52 static Errorclass
lint0(void);
53 static Errorclass
lint1(void);
54 static Errorclass
lint2(void);
55 static Errorclass
lint3(void);
56 static Errorclass
make(void);
57 static Errorclass
mod2(void);
58 static Errorclass
onelong(void);
59 static Errorclass
pccccom(void); /* Portable C Compiler C Compiler */
60 static Errorclass
ri(void);
61 static Errorclass
richieccom(void); /* Richie Compiler for 11 */
62 static Errorclass
troff(void);
65 * Eat all of the lines in the input file, attempting to categorize
66 * them by their various flavors
69 eaterrors(int *r_errorc
, Eptr
**r_errorv
)
71 Errorclass errorclass
= C_SYNC
;
77 if ((inbuffer
= fgetln(errorfile
, &inbuflen
)) == NULL
)
79 line
= Calloc(inbuflen
+ 1, sizeof(char));
80 memcpy(line
, inbuffer
, inbuflen
);
81 line
[inbuflen
] = '\0';
82 wordvbuild(line
, &cur_wordc
, &cur_wordv
);
85 * for convenience, convert cur_wordv to be 1 based, instead
90 ((( errorclass
= onelong() ) != C_UNKNOWN
)
91 || (( errorclass
= cpp() ) != C_UNKNOWN
)
92 || (( errorclass
= pccccom() ) != C_UNKNOWN
)
93 || (( errorclass
= richieccom() ) != C_UNKNOWN
)
94 || (( errorclass
= lint0() ) != C_UNKNOWN
)
95 || (( errorclass
= lint1() ) != C_UNKNOWN
)
96 || (( errorclass
= lint2() ) != C_UNKNOWN
)
97 || (( errorclass
= lint3() ) != C_UNKNOWN
)
98 || (( errorclass
= make() ) != C_UNKNOWN
)
99 || (( errorclass
= f77() ) != C_UNKNOWN
)
100 || ((errorclass
= pi() ) != C_UNKNOWN
)
101 || (( errorclass
= ri() )!= C_UNKNOWN
)
102 || (( errorclass
= mod2() )!= C_UNKNOWN
)
103 || (( errorclass
= troff() )!= C_UNKNOWN
))
106 errorclass
= catchall();
108 erroradd(cur_wordc
, cur_wordv
+1, errorclass
, C_UNKNOWN
);
111 printf("%d errorentrys\n", nerrors
);
113 arrayify(r_errorc
, r_errorv
, er_head
);
117 * create a new error entry, given a zero based array and count
120 erroradd(int errorlength
, char **errorv
, Errorclass errorclass
,
121 Errorclass errorsubclass
)
126 if (errorclass
== C_TRUE
) {
127 /* check canonicalization of the second argument*/
128 for (cp
= errorv
[1]; *cp
&& isdigit((unsigned char)*cp
); cp
++)
130 errorclass
= (*cp
== '\0') ? C_TRUE
: C_NONSPEC
;
132 if (errorclass
!= C_TRUE
)
133 printf("The 2nd word, \"%s\" is not a number.\n",
137 if (errorlength
> 0) {
138 newerror
= Calloc(1, sizeof(Edesc
));
139 newerror
->error_language
= language
; /* language is global */
140 newerror
->error_text
= errorv
;
141 newerror
->error_lgtext
= errorlength
;
142 if (errorclass
== C_TRUE
)
143 newerror
->error_line
= atoi(errorv
[1]);
144 newerror
->error_e_class
= errorclass
;
145 newerror
->error_s_class
= errorsubclass
;
146 switch (newerror
->error_e_class
= discardit(newerror
)) {
147 case C_SYNC
: nsyncerrors
++; break;
148 case C_DISCARD
: ndiscard
++; break;
149 case C_NULLED
: nnulled
++; break;
150 case C_NONSPEC
: nnonspec
++; break;
151 case C_THISFILE
: nthisfile
++; break;
152 case C_TRUE
: ntrue
++; break;
153 case C_UNKNOWN
: nunknown
++; break;
154 case C_IGNORE
: nignore
++; break;
156 newerror
->error_next
= er_head
;
158 newerror
->error_no
= nerrors
++;
167 if (cur_wordc
== 1 && language
!= INLD
) {
170 * a) file name from cc
171 * b) Assembler telling world that it is complaining
172 * c) Noise from make ("Stop.")
176 if (strcmp(cur_wordv
[1], "Stop.") == 0) {
180 if (strcmp(cur_wordv
[1], "Assembler:") == 0) {
181 /* assembler always alerts us to what happened*/
185 if (strcmp(cur_wordv
[1], "Undefined:") == 0) {
186 /* loader complains about unknown symbols*/
190 if (lastchar(cur_wordv
[1]) == ':') {
191 /* cc tells us what file we are in */
192 currentfilename
= cur_wordv
[1];
193 (void)substitute(currentfilename
, ':', '\0');
198 if (cur_wordc
== 1 && language
== INLD
) {
199 nwordv
= Calloc(4, sizeof(char *));
200 nwordv
[0] = Strdup("ld:"); /* XXX leaked */
201 nwordv
[1] = cur_wordv
[1];
202 nwordv
[2] = Strdup("is"); /* XXX leaked */
203 nwordv
[3] = Strdup("undefined.");/* XXX leaked */
205 cur_wordv
= nwordv
- 1;
208 if (cur_wordc
== 1) {
212 } /* end of one long */
218 * Now attempt a cpp error message match
220 * ./morse.h: 23: undefined control
221 * morsesend.c: 229: MAGNIBBL: argument mismatch
222 * morsesend.c: 237: MAGNIBBL: argument mismatch
223 * test1.c: 6: undefined control
227 if (language
!= INLD
/* loader errors have almost same fmt */
228 && lastchar(cur_wordv
[1]) == ':'
229 && isdigit((unsigned char)firstchar(cur_wordv
[2]))
230 && lastchar(cur_wordv
[2]) == ':') {
232 clob_last(cur_wordv
[1], '\0');
233 clob_last(cur_wordv
[2], '\0');
243 * Now attempt a ccom error message match:
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
251 if (firstchar(cur_wordv
[1]) == '"'
252 && lastchar(cur_wordv
[1]) == ','
253 && next_lastchar(cur_wordv
[1]) == '"'
254 && strcmp(cur_wordv
[2], "line") == 0
255 && isdigit((unsigned char)firstchar(cur_wordv
[3]))
256 && lastchar(cur_wordv
[3]) == ':') {
257 clob_last(cur_wordv
[1], '\0'); /* drop last , */
258 clob_last(cur_wordv
[1], '\0'); /* drop last " */
259 cur_wordv
[1]++; /* drop first " */
260 clob_last(cur_wordv
[3], '\0'); /* drop : on line number */
261 cur_wordv
[2] = cur_wordv
[1]; /* overwrite "line" */
262 cur_wordv
++; /*compensate*/
264 currentfilename
= cur_wordv
[1];
272 * Do the error message from the Richie C Compiler for the PDP11,
273 * which has this source:
276 * fprintf(stderr, "%s:", filename);
277 * fprintf(stderr, "%d: ", line);
291 if (lastchar(cur_wordv
[1]) == ':') {
292 cp
= cur_wordv
[1] + strlen(cur_wordv
[1]) - 1;
293 while (isdigit((unsigned char)*--cp
))
296 clob_last(cur_wordv
[1], '\0'); /* last : */
297 *cp
= '\0'; /* first : */
299 nwordv
= wordvsplice(1, cur_wordc
, cur_wordv
+1);
303 cur_wordv
= nwordv
- 1;
305 currentfilename
= cur_wordv
[1];
319 * Attempt a match for the new lint style normal compiler
320 * error messages, of the form
322 * printf("%s(%d): %s\n", filename, linenumber, message);
327 if (lastchar(cur_wordv
[1]) == ':'
328 && next_lastchar(cur_wordv
[1]) == ')') {
329 clob_last(cur_wordv
[1], '\0'); /* colon */
330 if (persperdexplode(cur_wordv
[1], &line
, &file
)) {
331 nwordv
= wordvsplice(1, cur_wordc
, cur_wordv
+1);
332 nwordv
[0] = file
; /* file name */
333 nwordv
[1] = line
; /* line number */
335 cur_wordv
= nwordv
- 1;
339 cur_wordv
[1][strlen(cur_wordv
[1])] = ':';
347 char *line1
= NULL
, *line2
= NULL
;
348 char *file1
= NULL
, *file2
= NULL
;
349 char **nwordv1
, **nwordv2
;
352 * Now, attempt a match for the various errors that lint
353 * can complain about.
355 * Look first for type 1 lint errors
357 if (cur_wordc
> 1 && strcmp(cur_wordv
[cur_wordc
-1], "::") == 0) {
359 * %.7s, arg. %d used inconsistently %s(%d) :: %s(%d)
360 * %.7s value used inconsistently %s(%d) :: %s(%d)
361 * %.7s multiply declared %s(%d) :: %s(%d)
362 * %.7s value declared inconsistently %s(%d) :: %s(%d)
363 * %.7s function value type must be declared before use %s(%d) :: %s(%d)
367 && persperdexplode(cur_wordv
[cur_wordc
], &line2
, &file2
)
368 && persperdexplode(cur_wordv
[cur_wordc
-2], &line1
, &file1
)) {
369 nwordv1
= wordvsplice(2, cur_wordc
, cur_wordv
+1);
370 nwordv2
= wordvsplice(2, cur_wordc
, cur_wordv
+1);
373 erroradd(cur_wordc
+2, nwordv1
, C_TRUE
, C_DUPL
); /* takes 0 based*/
376 cur_wordc
= cur_wordc
+ 2;
377 cur_wordv
= nwordv2
- 1; /* 1 based */
400 * Look for type 2 lint errors
402 * %.7s used( %s(%d) ), but not defined
403 * %.7s defined( %s(%d) ), but never used
404 * %.7s declared( %s(%d) ), but never used or defined
406 * bufp defined( "./metric.h"(10) ), but never used
411 if (lastchar(cur_wordv
[2]) == '(' /* ')' */
412 && strcmp(cur_wordv
[4], "),") == 0) {
414 if (persperdexplode(cur_wordv
[3], &line
, &file
)) {
415 nwordv
= wordvsplice(2, cur_wordc
, cur_wordv
+1);
418 cur_wordc
= cur_wordc
+ 2;
419 cur_wordv
= nwordv
- 1; /* 1 based */
426 #if 0 /* not const-correct */
427 static char *Lint31
[4] = {"returns", "value", "which", "is"};
428 static char *Lint32
[6] = {"value", "is", "used,", "but", "none", "returned"};
430 DECL_STRINGS_4(static, Lint31
,
431 "returns", "value", "which", "is");
432 DECL_STRINGS_6(static, Lint32
,
433 "value", "is", "used,", "but", "none", "returned");
441 if (wordvcmp(cur_wordv
+2, 4, Lint31
) == 0
442 || wordvcmp(cur_wordv
+2, 6, Lint32
) == 0) {
450 * Special word vectors for use by F77 recognition
452 #if 0 /* not const-correct */
453 static char *F77_fatal
[3] = {"Compiler", "error", "line"};
454 static char *F77_error
[3] = {"Error", "on", "line"};
455 static char *F77_warning
[3] = {"Warning", "on", "line"};
456 static char *F77_no_ass
[3] = {"Error.","No","assembly."};
458 DECL_STRINGS_3(static, F77_fatal
, "Compiler", "error", "line");
459 DECL_STRINGS_3(static, F77_error
, "Error", "on", "line");
460 DECL_STRINGS_3(static, F77_warning
, "Warning", "on", "line");
461 DECL_STRINGS_3(static, F77_no_ass
, "Error.", "No", "assembly.");
470 * look for f77 errors:
471 * Error messages from /usr/src/cmd/f77/error.c, with
472 * these printf formats:
474 * Compiler error line %d of %s: %s
475 * Error on line %d of %s: %s
476 * Warning on line %d of %s: %s
477 * Error. No assembly.
479 if (cur_wordc
== 3 && wordvcmp(cur_wordv
+1, 3, F77_no_ass
) == 0) {
485 if (lastchar(cur_wordv
[6]) == ':'
487 wordvcmp(cur_wordv
+1, 3, F77_fatal
) == 0
488 || wordvcmp(cur_wordv
+1, 3, F77_error
) == 0
489 || wordvcmp(cur_wordv
+1, 3, F77_warning
) == 0
493 nwordv
= wordvsplice(2, cur_wordc
, cur_wordv
+1);
494 nwordv
[0] = cur_wordv
[6];
495 clob_last(nwordv
[0],'\0');
496 nwordv
[1] = cur_wordv
[4];
498 cur_wordv
= nwordv
- 1; /* 1 based */
504 #if 0 /* not const-correct */
505 static char *Make_Croak
[3] = {"***", "Error", "code"};
506 static char *Make_NotRemade
[5] = {"not", "remade", "because", "of", "errors"};
508 DECL_STRINGS_3(static, Make_Croak
, "***", "Error", "code");
509 DECL_STRINGS_5(static, Make_NotRemade
,
510 "not", "remade", "because", "of", "errors");
516 if (wordvcmp(cur_wordv
+1, 3, Make_Croak
) == 0) {
520 if (wordvcmp(cur_wordv
+2, 5, Make_NotRemade
) == 0) {
531 * Match an error message produced by ri; here is the
532 * procedure yanked from the distributed version of ri
535 * serror(str, x1, x2, x3)
537 * char *x1, *x2, *x3;
539 * extern int yylineno;
542 * fputs(srcfile, stdout);
544 * fprintf(stdout, " %d: ", yylineno);
545 * fprintf(stdout, str, x1, x2, x3);
546 * fprintf(stdout, "\n");
552 if (firstchar(cur_wordv
[1]) == '"'
553 && lastchar(cur_wordv
[1]) == '"'
554 && lastchar(cur_wordv
[2]) == ':'
555 && isdigit((unsigned char)firstchar(cur_wordv
[2]))) {
556 clob_last(cur_wordv
[1], '\0'); /* drop the last " */
557 cur_wordv
[1]++; /* skip over the first " */
558 clob_last(cur_wordv
[2], '\0');
569 * Catches random things.
571 language
= INUNKNOWN
;
573 } /* end of catch all*/
579 * troff source error message, from eqn, bib, tbl...
580 * Just like pcc ccom, except uses `'
585 if (firstchar(cur_wordv
[1]) == '`'
586 && lastchar(cur_wordv
[1]) == ','
587 && next_lastchar(cur_wordv
[1]) == '\''
588 && strcmp(cur_wordv
[2], "line") == 0
589 && isdigit((unsigned char)firstchar(cur_wordv
[3]))
590 && lastchar(cur_wordv
[3]) == ':') {
591 clob_last(cur_wordv
[1], '\0'); /* drop last , */
592 clob_last(cur_wordv
[1], '\0'); /* drop last " */
593 cur_wordv
[1]++; /* drop first " */
594 clob_last(cur_wordv
[3], '\0'); /* drop : on line number */
595 cur_wordv
[2] = cur_wordv
[1]; /* overwrite "line" */
596 cur_wordv
++; /*compensate*/
597 currentfilename
= cur_wordv
[1];
608 * for decwrl modula2 compiler (powell)
612 if ((strcmp(cur_wordv
[1], "!!!") == 0 /* early version */
613 || strcmp(cur_wordv
[1], "File") == 0) /* later version */
614 && lastchar(cur_wordv
[2]) == ',' /* file name */
615 && strcmp(cur_wordv
[3], "line") == 0
616 && isdigit((unsigned char)firstchar(cur_wordv
[4])) /* line number */
617 && lastchar(cur_wordv
[4]) == ':' /* line number */
619 clob_last(cur_wordv
[2], '\0'); /* drop last , on file name */
620 clob_last(cur_wordv
[4], '\0'); /* drop last : on line number */
621 cur_wordv
[3] = cur_wordv
[2]; /* file name on top of "line" */
624 currentfilename
= cur_wordv
[1];