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