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