Home | History | Annotate | Line # | Download | only in lint1
main1.c revision 1.11
      1 /*	$NetBSD: main1.c,v 1.11 2002/01/29 02:43:38 tv Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994, 1995 Jochen Pohl
      5  * All Rights Reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     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. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Jochen Pohl for
     18  *	The NetBSD Project.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 #ifndef lint
     36 __RCSID("$NetBSD: main1.c,v 1.11 2002/01/29 02:43:38 tv Exp $");
     37 #endif
     38 
     39 #include <sys/types.h>
     40 #include <stdio.h>
     41 #include <string.h>
     42 #include <stdlib.h>
     43 #include <unistd.h>
     44 #include <errno.h>
     45 #include <limits.h>
     46 
     47 #include "lint1.h"
     48 
     49 /* set yydebug to 1*/
     50 int	yflag;
     51 
     52 /*
     53  * Print warnings if an assignment of an integertype to another integertype
     54  * causes an implizit narrowing conversion. If aflag is 1, these warnings
     55  * are printed only if the source type is at least as wide as long. If aflag
     56  * is greater than 1, they are always printed.
     57  */
     58 int	aflag;
     59 
     60 /* Print a warning if a break statement cannot be reached. */
     61 int	bflag;
     62 
     63 /* Print warnings for pointer casts. */
     64 int	cflag;
     65 
     66 /* Print various debug information. */
     67 int	dflag;
     68 
     69 /* Perform stricter checking of enum types and operations on enum types. */
     70 int	eflag;
     71 
     72 /* Print complete pathnames, not only the basename. */
     73 int	Fflag;
     74 
     75 /* Enable some extensions of gcc */
     76 int	gflag;
     77 
     78 /* Treat warnings as errors */
     79 int	wflag;
     80 
     81 /*
     82  * Apply a number of heuristic tests to attempt to intuit bugs, improve
     83  * style, and reduce waste.
     84  */
     85 int	hflag;
     86 
     87 /* Attempt to check portability to other dialects of C. */
     88 int	pflag;
     89 
     90 /*
     91  * In case of redeclarations/redefinitions print the location of the
     92  * previous declaration/definition.
     93  */
     94 int	rflag;
     95 
     96 /* Strict ANSI C mode. */
     97 int	sflag;
     98 
     99 /* Traditional C mode. */
    100 int	tflag;
    101 
    102 /*
    103  * Complain about functions and external variables used and not defined,
    104  * or defined and not used.
    105  */
    106 int	uflag = 1;
    107 
    108 /* Complain about unused function arguments. */
    109 int	vflag = 1;
    110 
    111 /* Complain about structures which are never defined. */
    112 int	zflag = 1;
    113 
    114 err_set	msgset;
    115 
    116 static	void	usage(void);
    117 
    118 int main(int, char *[]);
    119 
    120 int
    121 main(int argc, char *argv[])
    122 {
    123 	int	c;
    124 	char	*ptr;
    125 
    126 	ERR_ZERO(&msgset);
    127 	while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFX:")) != -1) {
    128 		switch (c) {
    129 		case 'a':	aflag++;	break;
    130 		case 'b':	bflag = 1;	break;
    131 		case 'c':	cflag = 1;	break;
    132 		case 'd':	dflag = 1;	break;
    133 		case 'e':	eflag = 1;	break;
    134 		case 'F':	Fflag = 1;	break;
    135 		case 'g':	gflag = 1;	break;
    136 		case 'h':	hflag = 1;	break;
    137 		case 'p':	pflag = 1;	break;
    138 		case 'r':	rflag = 1;	break;
    139 		case 's':	sflag = 1;	break;
    140 		case 't':	tflag = 1;	break;
    141 		case 'u':	uflag = 0;	break;
    142 		case 'w':	wflag = 1;	break;
    143 		case 'v':	vflag = 0;	break;
    144 		case 'y':	yflag = 1;	break;
    145 		case 'z':	zflag = 0;	break;
    146 
    147 		case 'm':
    148 			msglist();
    149 			return(0);
    150 
    151 		case 'X':
    152 			for (ptr = strtok(optarg, ","); ptr;
    153 			    ptr = strtok(NULL, ",")) {
    154 				char *eptr;
    155 				long msg = strtol(ptr, &eptr, 0);
    156 				if ((msg == LONG_MIN || msg == LONG_MAX) &&
    157 				    errno == ERANGE)
    158 				    err(1, "invalid error message id '%s'",
    159 					ptr);
    160 				if (*eptr || ptr == eptr || msg < 0 ||
    161 				    msg >= ERR_SETSIZE)
    162 					errx(1, "invalid error message id '%s'",
    163 					    ptr);
    164 				ERR_SET(msg, &msgset);
    165 			}
    166 			break;
    167 		case '?':
    168 		default:
    169 			usage();
    170 			break;
    171 		}
    172 	}
    173 	argc -= optind;
    174 	argv += optind;
    175 
    176 	if (argc != 2)
    177 		usage();
    178 
    179 	/* open the input file */
    180 	if ((yyin = fopen(argv[0], "r")) == NULL)
    181 		err(1, "cannot open '%s'", argv[0]);
    182 
    183 	/* initialize output */
    184 	outopen(argv[1]);
    185 
    186 	if (yflag)
    187 		yydebug = 1;
    188 
    189 	initmem();
    190 	initdecl();
    191 	initscan();
    192 	initmtab();
    193 
    194 	yyparse();
    195 
    196 	/* Following warnings cannot be suppressed by LINTED */
    197 	nowarn = 0;
    198 
    199 	chkglsyms();
    200 
    201 	outclose();
    202 
    203 	return (nerr != 0);
    204 }
    205 
    206 static void
    207 usage(void)
    208 {
    209 
    210 	(void)fprintf(stderr,
    211 	    "Usage: %s [-abcdeghmprstuvwyzF] [-X <id>[,<id>]... src dest\n",
    212 	    getprogname());
    213 	exit(1);
    214 }
    215 
    216 void
    217 norecover(void)
    218 {
    219 
    220 	/* cannot recover from previous errors */
    221 	error(224);
    222 	exit(1);
    223 }
    224