Home | History | Annotate | Line # | Download | only in lint2
main2.c revision 1.2
      1  1.2  cgd /*	$NetBSD: main2.c,v 1.2 1995/07/03 21:24:53 cgd 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.1  cgd #ifndef lint
     35  1.2  cgd static char rcsid[] = "$NetBSD: main2.c,v 1.2 1995/07/03 21:24:53 cgd Exp $";
     36  1.1  cgd #endif
     37  1.1  cgd 
     38  1.1  cgd #include <stdio.h>
     39  1.1  cgd #include <stdlib.h>
     40  1.1  cgd #include <string.h>
     41  1.1  cgd #include <unistd.h>
     42  1.1  cgd 
     43  1.1  cgd #include "lint2.h"
     44  1.1  cgd 
     45  1.1  cgd /* warnings for symbols which are declared but not defined or used */
     46  1.1  cgd int	xflag;
     47  1.1  cgd 
     48  1.1  cgd /*
     49  1.1  cgd  * warnings for symbols which are used and not defined or defined
     50  1.1  cgd  * and not used
     51  1.1  cgd  */
     52  1.1  cgd int	uflag = 1;
     53  1.1  cgd 
     54  1.1  cgd /* Create a lint library in the current directory with name libname. */
     55  1.1  cgd int	Cflag;
     56  1.1  cgd const	char *libname;
     57  1.1  cgd 
     58  1.1  cgd int	pflag;
     59  1.1  cgd 
     60  1.1  cgd /*
     61  1.1  cgd  * warnings for (tentative) definitions of the same name in more then
     62  1.1  cgd  * one translation unit
     63  1.1  cgd  */
     64  1.1  cgd int	sflag;
     65  1.1  cgd 
     66  1.1  cgd int	tflag;
     67  1.1  cgd 
     68  1.1  cgd /*
     69  1.1  cgd  * If a complaint stems from a included file, print the name of the included
     70  1.1  cgd  * file instead of the name spezified at the command line followed by '?'
     71  1.1  cgd  */
     72  1.1  cgd int	Hflag;
     73  1.1  cgd 
     74  1.1  cgd int	hflag;
     75  1.1  cgd 
     76  1.1  cgd /* Print full path names, not only the last component */
     77  1.1  cgd int	Fflag;
     78  1.1  cgd 
     79  1.1  cgd /*
     80  1.1  cgd  * List of libraries (from -l flag). These libraries are read after all
     81  1.1  cgd  * other input files has been read and, for Cflag, after the new lint library
     82  1.1  cgd  * has been written.
     83  1.1  cgd  */
     84  1.1  cgd const	char	**libs;
     85  1.1  cgd 
     86  1.1  cgd static	void	usage __P((void));
     87  1.1  cgd 
     88  1.1  cgd 
     89  1.1  cgd int
     90  1.1  cgd main(argc, argv)
     91  1.1  cgd 	int	argc;
     92  1.1  cgd 	char	*argv[];
     93  1.1  cgd {
     94  1.1  cgd 	int	c, i;
     95  1.1  cgd 	size_t	len;
     96  1.1  cgd 	char	*lname;
     97  1.1  cgd 
     98  1.1  cgd 	libs = xcalloc(1, sizeof (char *));
     99  1.1  cgd 
    100  1.1  cgd 	opterr = 0;
    101  1.1  cgd 	while ((c = getopt(argc, argv, "hpstxuC:HFl:")) != -1) {
    102  1.1  cgd 		switch (c) {
    103  1.1  cgd 		case 's':
    104  1.1  cgd 			sflag = 1;
    105  1.1  cgd 			break;
    106  1.1  cgd 		case 't':
    107  1.1  cgd 			tflag = 1;
    108  1.1  cgd 			break;
    109  1.1  cgd 		case 'u':
    110  1.1  cgd 			uflag = 0;
    111  1.1  cgd 			break;
    112  1.1  cgd 		case 'x':
    113  1.1  cgd 			xflag = 1;
    114  1.1  cgd 			break;
    115  1.1  cgd 		case 'p':
    116  1.1  cgd 			pflag = 1;
    117  1.1  cgd 			break;
    118  1.1  cgd 		case 'C':
    119  1.1  cgd 			len = strlen(optarg);
    120  1.1  cgd 			lname = xmalloc(len + 10);
    121  1.1  cgd 			(void)sprintf(lname, "llib-l%s.ln", optarg);
    122  1.1  cgd 			libname = lname;
    123  1.1  cgd 			Cflag = 1;
    124  1.1  cgd 			uflag = 0;
    125  1.1  cgd 			break;
    126  1.1  cgd 		case 'H':
    127  1.1  cgd 			Hflag = 1;
    128  1.1  cgd 			break;
    129  1.1  cgd 		case 'h':
    130  1.1  cgd 			hflag = 1;
    131  1.1  cgd 			break;
    132  1.1  cgd 		case 'F':
    133  1.1  cgd 			Fflag = 1;
    134  1.1  cgd 			break;
    135  1.1  cgd 		case 'l':
    136  1.1  cgd 			for (i = 0; libs[i] != NULL; i++) ;
    137  1.1  cgd 			libs = xrealloc(libs, (i + 2) * sizeof (char *));
    138  1.1  cgd 			libs[i] = xstrdup(optarg);
    139  1.1  cgd 			libs[i + 1] = NULL;
    140  1.1  cgd 			break;
    141  1.1  cgd 		case '?':
    142  1.1  cgd 			usage();
    143  1.1  cgd 		}
    144  1.1  cgd 	}
    145  1.1  cgd 
    146  1.1  cgd 	argc -= optind;
    147  1.1  cgd 	argv += optind;
    148  1.1  cgd 
    149  1.1  cgd 	if (argc == 0)
    150  1.1  cgd 		usage();
    151  1.1  cgd 
    152  1.1  cgd 	initmem();
    153  1.1  cgd 
    154  1.1  cgd 	/* initialize hash table */
    155  1.1  cgd 	inithash();
    156  1.1  cgd 
    157  1.1  cgd 	inittyp();
    158  1.1  cgd 
    159  1.1  cgd 	for (i = 0; i < argc; i++)
    160  1.1  cgd 		readfile(argv[i]);
    161  1.1  cgd 
    162  1.1  cgd 	/* write the lint library */
    163  1.1  cgd 	if (Cflag) {
    164  1.1  cgd 		forall(mkstatic);
    165  1.1  cgd 		outlib(libname);
    166  1.1  cgd 	}
    167  1.1  cgd 
    168  1.1  cgd 	/* read additional libraries */
    169  1.1  cgd 	for (i = 0; libs[i] != NULL; i++)
    170  1.1  cgd 		readfile(libs[i]);
    171  1.1  cgd 
    172  1.1  cgd 	forall(mkstatic);
    173  1.1  cgd 
    174  1.1  cgd 	mainused();
    175  1.1  cgd 
    176  1.1  cgd 	/* perform all tests */
    177  1.1  cgd 	forall(chkname);
    178  1.1  cgd 
    179  1.1  cgd 	exit(0);
    180  1.1  cgd 	/* NOTREACHED */
    181  1.1  cgd }
    182  1.1  cgd 
    183  1.1  cgd static void
    184  1.1  cgd usage()
    185  1.1  cgd {
    186  1.1  cgd 	(void)fprintf(stderr,
    187  1.1  cgd 		      "usage: lint2 -hpstxuHF -Clib -l lib ... src1 ...\n");
    188  1.1  cgd 	exit(1);
    189  1.1  cgd }
    190  1.1  cgd 
    191