main2.c revision 12099
112099Sjoerg/*	$NetBSD: main2.c,v 1.2 1995/07/03 21:24:53 cgd Exp $	*/
212099Sjoerg
312099Sjoerg/*
412099Sjoerg * Copyright (c) 1994, 1995 Jochen Pohl
512099Sjoerg * All Rights Reserved.
612099Sjoerg *
712099Sjoerg * Redistribution and use in source and binary forms, with or without
812099Sjoerg * modification, are permitted provided that the following conditions
912099Sjoerg * are met:
1012099Sjoerg * 1. Redistributions of source code must retain the above copyright
1112099Sjoerg *    notice, this list of conditions and the following disclaimer.
1212099Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
1312099Sjoerg *    notice, this list of conditions and the following disclaimer in the
1412099Sjoerg *    documentation and/or other materials provided with the distribution.
1512099Sjoerg * 3. All advertising materials mentioning features or use of this software
1612099Sjoerg *    must display the following acknowledgement:
1712099Sjoerg *      This product includes software developed by Jochen Pohl for
1812099Sjoerg *	The NetBSD Project.
1912099Sjoerg * 4. The name of the author may not be used to endorse or promote products
2012099Sjoerg *    derived from this software without specific prior written permission.
2112099Sjoerg *
2212099Sjoerg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2312099Sjoerg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2412099Sjoerg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2512099Sjoerg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2612099Sjoerg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2712099Sjoerg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2812099Sjoerg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2912099Sjoerg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3012099Sjoerg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3112099Sjoerg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3212099Sjoerg */
3312099Sjoerg
3412099Sjoerg#ifndef lint
3512099Sjoergstatic char rcsid[] = "$NetBSD: main2.c,v 1.2 1995/07/03 21:24:53 cgd Exp $";
3612099Sjoerg#endif
3712099Sjoerg
3812099Sjoerg#include <stdio.h>
3912099Sjoerg#include <stdlib.h>
4012099Sjoerg#include <string.h>
4112099Sjoerg#include <unistd.h>
4212099Sjoerg
4312099Sjoerg#include "lint2.h"
4412099Sjoerg
4512099Sjoerg/* warnings for symbols which are declared but not defined or used */
4612099Sjoergint	xflag;
4712099Sjoerg
4812099Sjoerg/*
4912099Sjoerg * warnings for symbols which are used and not defined or defined
5012099Sjoerg * and not used
5112099Sjoerg */
5212099Sjoergint	uflag = 1;
5312099Sjoerg
5412099Sjoerg/* Create a lint library in the current directory with name libname. */
5512099Sjoergint	Cflag;
5612099Sjoergconst	char *libname;
5712099Sjoerg
5812099Sjoergint	pflag;
5912099Sjoerg
6012099Sjoerg/*
6112099Sjoerg * warnings for (tentative) definitions of the same name in more then
6212099Sjoerg * one translation unit
6312099Sjoerg */
6412099Sjoergint	sflag;
6512099Sjoerg
6612099Sjoergint	tflag;
6712099Sjoerg
6812099Sjoerg/*
6912099Sjoerg * If a complaint stems from a included file, print the name of the included
7012099Sjoerg * file instead of the name spezified at the command line followed by '?'
7112099Sjoerg */
7212099Sjoergint	Hflag;
7312099Sjoerg
7412099Sjoergint	hflag;
7512099Sjoerg
7612099Sjoerg/* Print full path names, not only the last component */
7712099Sjoergint	Fflag;
7812099Sjoerg
7912099Sjoerg/*
8012099Sjoerg * List of libraries (from -l flag). These libraries are read after all
8112099Sjoerg * other input files has been read and, for Cflag, after the new lint library
8212099Sjoerg * has been written.
8312099Sjoerg */
8412099Sjoergconst	char	**libs;
8512099Sjoerg
8612099Sjoergstatic	void	usage __P((void));
8712099Sjoerg
8812099Sjoerg
8912099Sjoergint
9012099Sjoergmain(argc, argv)
9112099Sjoerg	int	argc;
9212099Sjoerg	char	*argv[];
9312099Sjoerg{
9412099Sjoerg	int	c, i;
9512099Sjoerg	size_t	len;
9612099Sjoerg	char	*lname;
9712099Sjoerg
9812099Sjoerg	libs = xcalloc(1, sizeof (char *));
9912099Sjoerg
10012099Sjoerg	opterr = 0;
10112099Sjoerg	while ((c = getopt(argc, argv, "hpstxuC:HFl:")) != -1) {
10212099Sjoerg		switch (c) {
10312099Sjoerg		case 's':
10412099Sjoerg			sflag = 1;
10512099Sjoerg			break;
10612099Sjoerg		case 't':
10712099Sjoerg			tflag = 1;
10812099Sjoerg			break;
10912099Sjoerg		case 'u':
11012099Sjoerg			uflag = 0;
11112099Sjoerg			break;
11212099Sjoerg		case 'x':
11312099Sjoerg			xflag = 1;
11412099Sjoerg			break;
11512099Sjoerg		case 'p':
11612099Sjoerg			pflag = 1;
11712099Sjoerg			break;
11812099Sjoerg		case 'C':
11912099Sjoerg			len = strlen(optarg);
12012099Sjoerg			lname = xmalloc(len + 10);
12112099Sjoerg			(void)sprintf(lname, "llib-l%s.ln", optarg);
12212099Sjoerg			libname = lname;
12312099Sjoerg			Cflag = 1;
12412099Sjoerg			uflag = 0;
12512099Sjoerg			break;
12612099Sjoerg		case 'H':
12712099Sjoerg			Hflag = 1;
12812099Sjoerg			break;
12912099Sjoerg		case 'h':
13012099Sjoerg			hflag = 1;
13112099Sjoerg			break;
13212099Sjoerg		case 'F':
13312099Sjoerg			Fflag = 1;
13412099Sjoerg			break;
13512099Sjoerg		case 'l':
13612099Sjoerg			for (i = 0; libs[i] != NULL; i++) ;
13712099Sjoerg			libs = xrealloc(libs, (i + 2) * sizeof (char *));
13812099Sjoerg			libs[i] = xstrdup(optarg);
13912099Sjoerg			libs[i + 1] = NULL;
14012099Sjoerg			break;
14112099Sjoerg		case '?':
14212099Sjoerg			usage();
14312099Sjoerg		}
14412099Sjoerg	}
14512099Sjoerg
14612099Sjoerg	argc -= optind;
14712099Sjoerg	argv += optind;
14812099Sjoerg
14912099Sjoerg	if (argc == 0)
15012099Sjoerg		usage();
15112099Sjoerg
15212099Sjoerg	initmem();
15312099Sjoerg
15412099Sjoerg	/* initialize hash table */
15512099Sjoerg	inithash();
15612099Sjoerg
15712099Sjoerg	inittyp();
15812099Sjoerg
15912099Sjoerg	for (i = 0; i < argc; i++)
16012099Sjoerg		readfile(argv[i]);
16112099Sjoerg
16212099Sjoerg	/* write the lint library */
16312099Sjoerg	if (Cflag) {
16412099Sjoerg		forall(mkstatic);
16512099Sjoerg		outlib(libname);
16612099Sjoerg	}
16712099Sjoerg
16812099Sjoerg	/* read additional libraries */
16912099Sjoerg	for (i = 0; libs[i] != NULL; i++)
17012099Sjoerg		readfile(libs[i]);
17112099Sjoerg
17212099Sjoerg	forall(mkstatic);
17312099Sjoerg
17412099Sjoerg	mainused();
17512099Sjoerg
17612099Sjoerg	/* perform all tests */
17712099Sjoerg	forall(chkname);
17812099Sjoerg
17912099Sjoerg	exit(0);
18012099Sjoerg	/* NOTREACHED */
18112099Sjoerg}
18212099Sjoerg
18312099Sjoergstatic void
18412099Sjoergusage()
18512099Sjoerg{
18612099Sjoerg	(void)fprintf(stderr,
18712099Sjoerg		      "usage: lint2 -hpstxuHF -Clib -l lib ... src1 ...\n");
18812099Sjoerg	exit(1);
18912099Sjoerg}
19012099Sjoerg
191