191586Smarkm/* $NetBSD: main2.c,v 1.5 2001/11/21 19:14:26 wiz 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 3491586Smarkm#include <sys/cdefs.h> 3591586Smarkm#if defined(__RCSID) && !defined(lint) 3691586Smarkm__RCSID("$NetBSD: main2.c,v 1.5 2001/11/21 19:14:26 wiz Exp $"); 3712099Sjoerg#endif 38108532Sschweikh__FBSDID("$FreeBSD$"); 3912099Sjoerg 4012099Sjoerg#include <stdio.h> 4112099Sjoerg#include <stdlib.h> 4212099Sjoerg#include <string.h> 4312099Sjoerg#include <unistd.h> 4412099Sjoerg 4512099Sjoerg#include "lint2.h" 4612099Sjoerg 4712099Sjoerg/* warnings for symbols which are declared but not defined or used */ 4812099Sjoergint xflag; 4912099Sjoerg 5012099Sjoerg/* 5112099Sjoerg * warnings for symbols which are used and not defined or defined 5212099Sjoerg * and not used 5312099Sjoerg */ 5412099Sjoergint uflag = 1; 5512099Sjoerg 5612099Sjoerg/* Create a lint library in the current directory with name libname. */ 5712099Sjoergint Cflag; 5812099Sjoergconst char *libname; 5912099Sjoerg 6012099Sjoergint pflag; 6112099Sjoerg 6212099Sjoerg/* 6391586Smarkm * warnings for (tentative) definitions of the same name in more than 6412099Sjoerg * one translation unit 6512099Sjoerg */ 6612099Sjoergint sflag; 6712099Sjoerg 6812099Sjoergint tflag; 6912099Sjoerg 7012099Sjoerg/* 71108532Sschweikh * If a complaint stems from an included file, print the name of the included 7212099Sjoerg * file instead of the name spezified at the command line followed by '?' 7312099Sjoerg */ 7412099Sjoergint Hflag; 7512099Sjoerg 7612099Sjoergint hflag; 7712099Sjoerg 7812099Sjoerg/* Print full path names, not only the last component */ 7912099Sjoergint Fflag; 8012099Sjoerg 8112099Sjoerg/* 8212099Sjoerg * List of libraries (from -l flag). These libraries are read after all 8312099Sjoerg * other input files has been read and, for Cflag, after the new lint library 8412099Sjoerg * has been written. 8512099Sjoerg */ 8612099Sjoergconst char **libs; 8712099Sjoerg 8891586Smarkmstatic void usage(void); 8912099Sjoerg 9091586Smarkmint main(int, char *[]); 9112099Sjoerg 9212099Sjoergint 9391586Smarkmmain(int argc, char *argv[]) 9412099Sjoerg{ 9512099Sjoerg int c, i; 9612099Sjoerg size_t len; 9712099Sjoerg char *lname; 9812099Sjoerg 9912099Sjoerg libs = xcalloc(1, sizeof (char *)); 10012099Sjoerg 10112099Sjoerg opterr = 0; 10212099Sjoerg while ((c = getopt(argc, argv, "hpstxuC:HFl:")) != -1) { 10312099Sjoerg switch (c) { 10412099Sjoerg case 's': 10512099Sjoerg sflag = 1; 10612099Sjoerg break; 10712099Sjoerg case 't': 10812099Sjoerg tflag = 1; 10912099Sjoerg break; 11012099Sjoerg case 'u': 11112099Sjoerg uflag = 0; 11212099Sjoerg break; 11312099Sjoerg case 'x': 11412099Sjoerg xflag = 1; 11512099Sjoerg break; 11612099Sjoerg case 'p': 11712099Sjoerg pflag = 1; 11812099Sjoerg break; 11912099Sjoerg case 'C': 12012099Sjoerg len = strlen(optarg); 12112099Sjoerg lname = xmalloc(len + 10); 12212099Sjoerg (void)sprintf(lname, "llib-l%s.ln", optarg); 12312099Sjoerg libname = lname; 12412099Sjoerg Cflag = 1; 12512099Sjoerg uflag = 0; 12612099Sjoerg break; 12712099Sjoerg case 'H': 12812099Sjoerg Hflag = 1; 12912099Sjoerg break; 13012099Sjoerg case 'h': 13112099Sjoerg hflag = 1; 13212099Sjoerg break; 13312099Sjoerg case 'F': 13412099Sjoerg Fflag = 1; 13512099Sjoerg break; 13612099Sjoerg case 'l': 13791586Smarkm for (i = 0; libs[i] != NULL; i++) 13891586Smarkm continue; 13991586Smarkm libs = xrealloc(libs, (i + 2) * sizeof (char *)); 14012099Sjoerg libs[i] = xstrdup(optarg); 14112099Sjoerg libs[i + 1] = NULL; 14212099Sjoerg break; 14312099Sjoerg case '?': 14412099Sjoerg usage(); 14512099Sjoerg } 14612099Sjoerg } 14791586Smarkm 14812099Sjoerg argc -= optind; 14912099Sjoerg argv += optind; 15012099Sjoerg 15112099Sjoerg if (argc == 0) 15212099Sjoerg usage(); 15312099Sjoerg 15412099Sjoerg initmem(); 15512099Sjoerg 15612099Sjoerg /* initialize hash table */ 15712099Sjoerg inithash(); 15812099Sjoerg 15912099Sjoerg inittyp(); 16012099Sjoerg 16112099Sjoerg for (i = 0; i < argc; i++) 16212099Sjoerg readfile(argv[i]); 16312099Sjoerg 16412099Sjoerg /* write the lint library */ 16512099Sjoerg if (Cflag) { 16612099Sjoerg forall(mkstatic); 16712099Sjoerg outlib(libname); 16812099Sjoerg } 16912099Sjoerg 17012099Sjoerg /* read additional libraries */ 17112099Sjoerg for (i = 0; libs[i] != NULL; i++) 17212099Sjoerg readfile(libs[i]); 17312099Sjoerg 17412099Sjoerg forall(mkstatic); 17512099Sjoerg 17612099Sjoerg mainused(); 17712099Sjoerg 17812099Sjoerg /* perform all tests */ 17912099Sjoerg forall(chkname); 18012099Sjoerg 18112099Sjoerg exit(0); 18212099Sjoerg /* NOTREACHED */ 18312099Sjoerg} 18412099Sjoerg 18512099Sjoergstatic void 18691586Smarkmusage(void) 18712099Sjoerg{ 18812099Sjoerg (void)fprintf(stderr, 18912099Sjoerg "usage: lint2 -hpstxuHF -Clib -l lib ... src1 ...\n"); 19012099Sjoerg exit(1); 19112099Sjoerg} 192