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