xref: /onnv-gate/usr/src/tools/cscope-fast/dir.c (revision 871:f917b2ed7d21)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
230Sstevel@tonic-gate /*	  All Rights Reserved  	*/
240Sstevel@tonic-gate 
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
27*871Scasper  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28*871Scasper  * Use is subject to license terms.
290Sstevel@tonic-gate  */
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
320Sstevel@tonic-gate 
330Sstevel@tonic-gate /*
340Sstevel@tonic-gate  *	cscope - interactive C symbol cross-reference
350Sstevel@tonic-gate  *
360Sstevel@tonic-gate  *	directory searching functions
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include <sys/types.h>	/* needed by stat.h */
400Sstevel@tonic-gate #include <sys/stat.h>	/* stat */
410Sstevel@tonic-gate #include "global.h"
420Sstevel@tonic-gate #include "dirent.h"
430Sstevel@tonic-gate #include "vp.h"		/* vpdirs and vpndirs */
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #define	DIRSEPS	" ,:"	/* directory list separators */
460Sstevel@tonic-gate #define	DIRINC	10	/* directory list size increment */
470Sstevel@tonic-gate #define	HASHMOD	2003	/* must be a prime number */
480Sstevel@tonic-gate #define	SRCINC	HASHMOD	/* source file list size increment */
490Sstevel@tonic-gate 			/* largest known database had 22049 files */
500Sstevel@tonic-gate 
510Sstevel@tonic-gate char	**incdirs;		/* #include directories */
520Sstevel@tonic-gate char	**srcdirs;		/* source directories */
530Sstevel@tonic-gate char	**srcfiles;		/* source files */
540Sstevel@tonic-gate int	nincdirs;		/* number of #include directories */
550Sstevel@tonic-gate int	mincdirs = DIRINC;	/* maximum number of #include directories */
560Sstevel@tonic-gate int	nsrcdirs;		/* number of source directories */
570Sstevel@tonic-gate int	msrcdirs = DIRINC;	/* maximum number of source directories */
580Sstevel@tonic-gate int	nsrcfiles;		/* number of source files */
590Sstevel@tonic-gate int	msrcfiles = SRCINC;	/* maximum number of source files */
600Sstevel@tonic-gate 
610Sstevel@tonic-gate static	struct	listitem {	/* source file table entry */
620Sstevel@tonic-gate 	char	*file;
630Sstevel@tonic-gate 	struct	listitem *next;
640Sstevel@tonic-gate } *srcfiletable[HASHMOD];
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 
670Sstevel@tonic-gate static void getsrcfiles(char *vpdir, char *dir);
680Sstevel@tonic-gate static BOOL issrcfile(char *file);
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /* add a source directory to the list for each view path source directory */
710Sstevel@tonic-gate 
720Sstevel@tonic-gate void
sourcedir(char * dirlist)730Sstevel@tonic-gate sourcedir(char *dirlist)
740Sstevel@tonic-gate {
750Sstevel@tonic-gate 	struct	stat	statstruct;
760Sstevel@tonic-gate 	char	*dir;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	/* don't change environment variable text */
790Sstevel@tonic-gate 	dirlist = stralloc(dirlist);
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	/* parse the directory list */
820Sstevel@tonic-gate 	dir = strtok(dirlist, DIRSEPS);
830Sstevel@tonic-gate 	while (dir != NULL) {
840Sstevel@tonic-gate 		/*
850Sstevel@tonic-gate 		 * make sure it is a directory (must exist in current
860Sstevel@tonic-gate 		 * view path node)
870Sstevel@tonic-gate 		 */
880Sstevel@tonic-gate 		if (stat(compath(dir), &statstruct) == 0 &&
89*871Scasper 		    S_ISDIR(statstruct.st_mode)) {
900Sstevel@tonic-gate 			if (srcdirs == NULL) {
910Sstevel@tonic-gate 				srcdirs = mymalloc(msrcdirs * sizeof (char *));
920Sstevel@tonic-gate 			} else if (nsrcdirs == msrcdirs) {
930Sstevel@tonic-gate 				msrcdirs += DIRINC;
940Sstevel@tonic-gate 				srcdirs = myrealloc(srcdirs,
950Sstevel@tonic-gate 				    msrcdirs * sizeof (char *));
960Sstevel@tonic-gate 			}
970Sstevel@tonic-gate 			srcdirs[nsrcdirs++] = stralloc(dir);
980Sstevel@tonic-gate 		}
990Sstevel@tonic-gate 		dir = strtok((char *)NULL, DIRSEPS);
1000Sstevel@tonic-gate 	}
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate /* add a #include directory to the list for each view path source directory */
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate void
includedir(char * dirlist)1060Sstevel@tonic-gate includedir(char *dirlist)
1070Sstevel@tonic-gate {
1080Sstevel@tonic-gate 	struct	stat	statstruct;
1090Sstevel@tonic-gate 	char	*dir;
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	/* don't change environment variable text */
1120Sstevel@tonic-gate 	dirlist = stralloc(dirlist);
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	/* parse the directory list */
1150Sstevel@tonic-gate 	dir = strtok(dirlist, DIRSEPS);
1160Sstevel@tonic-gate 	while (dir != NULL) {
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 		/*
1190Sstevel@tonic-gate 		 * make sure it is a directory (must exist in current
1200Sstevel@tonic-gate 		 * view path node)
1210Sstevel@tonic-gate 		 */
1220Sstevel@tonic-gate 		if (stat(compath(dir), &statstruct) == 0 &&
123*871Scasper 		    S_ISDIR(statstruct.st_mode)) {
1240Sstevel@tonic-gate 			if (incdirs == NULL) {
1250Sstevel@tonic-gate 				incdirs = mymalloc(mincdirs * sizeof (char *));
1260Sstevel@tonic-gate 			} else if (nincdirs == mincdirs) {
1270Sstevel@tonic-gate 				mincdirs += DIRINC;
1280Sstevel@tonic-gate 				incdirs = myrealloc(incdirs,
1290Sstevel@tonic-gate 				    mincdirs * sizeof (char *));
1300Sstevel@tonic-gate 			}
1310Sstevel@tonic-gate 			incdirs[nincdirs++] = stralloc(dir);
1320Sstevel@tonic-gate 		}
1330Sstevel@tonic-gate 		dir = strtok((char *)NULL, DIRSEPS);
1340Sstevel@tonic-gate 	}
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate /* make the source file list */
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate void
makefilelist(void)1400Sstevel@tonic-gate makefilelist(void)
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate 	static	BOOL	firstbuild = YES;	/* first time through */
1430Sstevel@tonic-gate 	FILE	*names;			/* name file pointer */
1440Sstevel@tonic-gate 	char	dir[PATHLEN + 1];
1450Sstevel@tonic-gate 	char	path[PATHLEN + 1];
1460Sstevel@tonic-gate 	struct	stat	statstruct;
1470Sstevel@tonic-gate 	char	*file;
1480Sstevel@tonic-gate 	char	*s;
1490Sstevel@tonic-gate 	int	i, j;
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	/* if there are source file arguments */
1520Sstevel@tonic-gate 	if (fileargc > 0) {
1530Sstevel@tonic-gate 		/* put them in a list that can be expanded */
1540Sstevel@tonic-gate 		for (i = 0; i < fileargc; ++i) {
1550Sstevel@tonic-gate 			file = fileargv[i];
1560Sstevel@tonic-gate 			if (infilelist(file) == NO) {
1570Sstevel@tonic-gate 				if (vpaccess(file, READ) == 0) {
1580Sstevel@tonic-gate 					addsrcfile(file);
1590Sstevel@tonic-gate 				} else {
1600Sstevel@tonic-gate 					(void) fprintf(stderr,
1610Sstevel@tonic-gate 					    "cscope: cannot find file %s\n",
1620Sstevel@tonic-gate 					    file);
1630Sstevel@tonic-gate 					errorsfound = YES;
1640Sstevel@tonic-gate 				}
1650Sstevel@tonic-gate 			}
1660Sstevel@tonic-gate 		}
1670Sstevel@tonic-gate 		return;
1680Sstevel@tonic-gate 	}
1690Sstevel@tonic-gate 	/* see if a file name file exists */
1700Sstevel@tonic-gate 	if (namefile == NULL && vpaccess(NAMEFILE, READ) == 0) {
1710Sstevel@tonic-gate 		namefile = NAMEFILE;
1720Sstevel@tonic-gate 	}
1730Sstevel@tonic-gate 	/* if there is a file of source file names */
1740Sstevel@tonic-gate 	if (namefile != NULL) {
1750Sstevel@tonic-gate 		if ((names = vpfopen(namefile, "r")) == NULL) {
1760Sstevel@tonic-gate 			cannotopen(namefile);
1770Sstevel@tonic-gate 			myexit(1);
1780Sstevel@tonic-gate 		}
1790Sstevel@tonic-gate 		/* get the names in the file */
1800Sstevel@tonic-gate 		while (fscanf(names, "%s", path) == 1) {
1810Sstevel@tonic-gate 			if (*path == '-') {	/* if an option */
1820Sstevel@tonic-gate 				i = path[1];
1830Sstevel@tonic-gate 				switch (i) {
1840Sstevel@tonic-gate 				case 'q':	/* quick search */
1850Sstevel@tonic-gate 					invertedindex = YES;
1860Sstevel@tonic-gate 					break;
1870Sstevel@tonic-gate 				case 'T':
1880Sstevel@tonic-gate 					/* truncate symbols to 8 characters */
1890Sstevel@tonic-gate 					truncatesyms = YES;
1900Sstevel@tonic-gate 					break;
1910Sstevel@tonic-gate 				case 'I':	/* #include file directory */
1920Sstevel@tonic-gate 				case 'p':	/* file path components to */
1930Sstevel@tonic-gate 						/* display */
1940Sstevel@tonic-gate 					s = path + 2;	  /* for "-Ipath" */
1950Sstevel@tonic-gate 					if (*s == '\0') { /* if "-I path" */
1960Sstevel@tonic-gate 						(void) fscanf(names,
1970Sstevel@tonic-gate 						    "%s", path);
1980Sstevel@tonic-gate 						s = path;
1990Sstevel@tonic-gate 					}
2000Sstevel@tonic-gate 					switch (i) {
2010Sstevel@tonic-gate 					case 'I': /* #include file directory */
2020Sstevel@tonic-gate 						if (firstbuild == YES) {
2030Sstevel@tonic-gate 							/* expand $ and ~ */
2040Sstevel@tonic-gate 							shellpath(dir,
2050Sstevel@tonic-gate 							    sizeof (dir), s);
2060Sstevel@tonic-gate 							includedir(dir);
2070Sstevel@tonic-gate 						}
2080Sstevel@tonic-gate 						break;
2090Sstevel@tonic-gate 					case 'p':
2100Sstevel@tonic-gate 						/* file path components */
2110Sstevel@tonic-gate 						/* to display */
2120Sstevel@tonic-gate 						if (*s < '0' || *s > '9') {
2130Sstevel@tonic-gate 							(void) fprintf(stderr,
2140Sstevel@tonic-gate 							    "cscope: -p option "
2150Sstevel@tonic-gate 							    "in file %s: "
2160Sstevel@tonic-gate 							    "missing or "
2170Sstevel@tonic-gate 							    "invalid numeric "
2180Sstevel@tonic-gate 							    "value\n",
2190Sstevel@tonic-gate 							    namefile);
2200Sstevel@tonic-gate 						}
2210Sstevel@tonic-gate 						dispcomponents = atoi(s);
2220Sstevel@tonic-gate 						break;
2230Sstevel@tonic-gate 					}
2240Sstevel@tonic-gate 					break;
2250Sstevel@tonic-gate 				default:
2260Sstevel@tonic-gate 					(void) fprintf(stderr,
2270Sstevel@tonic-gate 					    "cscope: only -I, -p, and -T "
2280Sstevel@tonic-gate 					    "options can be in file %s\n",
2290Sstevel@tonic-gate 					    namefile);
2300Sstevel@tonic-gate 				}
2310Sstevel@tonic-gate 			} else if (vpaccess(path, READ) == 0) {
2320Sstevel@tonic-gate 				addsrcfile(path);
2330Sstevel@tonic-gate 			} else {
2340Sstevel@tonic-gate 				(void) fprintf(stderr,
2350Sstevel@tonic-gate 				    "cscope: cannot find file %s\n",
2360Sstevel@tonic-gate 				    path);
2370Sstevel@tonic-gate 				errorsfound = YES;
2380Sstevel@tonic-gate 			}
2390Sstevel@tonic-gate 		}
2400Sstevel@tonic-gate 		(void) fclose(names);
2410Sstevel@tonic-gate 		firstbuild = NO;
2420Sstevel@tonic-gate 		return;
2430Sstevel@tonic-gate 	}
2440Sstevel@tonic-gate 	/* make a list of all the source files in the directories */
2450Sstevel@tonic-gate 	for (i = 0; i < nsrcdirs; ++i) {
2460Sstevel@tonic-gate 		s = srcdirs[i];
2470Sstevel@tonic-gate 		getsrcfiles(s, s);
2480Sstevel@tonic-gate 		if (*s != '/') {	/* if it isn't a full path name */
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate 			/* compute its path from any higher view path nodes */
2510Sstevel@tonic-gate 			for (j = 1; j < vpndirs; ++j) {
2520Sstevel@tonic-gate 				(void) sprintf(dir, "%s/%s", vpdirs[j], s);
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate 				/* make sure it is a directory */
2550Sstevel@tonic-gate 				if (stat(compath(dir), &statstruct) == 0 &&
256*871Scasper 				    S_ISDIR(statstruct.st_mode)) {
2570Sstevel@tonic-gate 					getsrcfiles(dir, s);
2580Sstevel@tonic-gate 				}
2590Sstevel@tonic-gate 			}
2600Sstevel@tonic-gate 		}
2610Sstevel@tonic-gate 	}
2620Sstevel@tonic-gate }
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate /* get the source file names in this directory */
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate static void
getsrcfiles(char * vpdir,char * dir)2670Sstevel@tonic-gate getsrcfiles(char *vpdir, char *dir)
2680Sstevel@tonic-gate {
2690Sstevel@tonic-gate 	DIR	*dirfile;	/* directory file descriptor */
2700Sstevel@tonic-gate 	struct	dirent	*entry;	/* directory entry pointer */
2710Sstevel@tonic-gate 	char	path[PATHLEN + 1];
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 	/* attempt to open the directory */
2740Sstevel@tonic-gate 	if ((dirfile = opendir(vpdir)) != NULL) {
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate 		/* read each entry in the directory */
2770Sstevel@tonic-gate 		while ((entry = readdir(dirfile)) != NULL) {
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate 			/* if it is a source file not already found */
2800Sstevel@tonic-gate 			(void) sprintf(path, "%s/%s", dir, entry->d_name);
2810Sstevel@tonic-gate 			if (entry->d_ino != 0 &&
2820Sstevel@tonic-gate 			    issrcfile(path) && infilelist(path) == NO) {
2830Sstevel@tonic-gate 				addsrcfile(path);	/* add it to the list */
2840Sstevel@tonic-gate 			}
2850Sstevel@tonic-gate 		}
2860Sstevel@tonic-gate 		closedir(dirfile);
2870Sstevel@tonic-gate 	}
2880Sstevel@tonic-gate }
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate /* see if this is a source file */
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate static BOOL
issrcfile(char * file)2930Sstevel@tonic-gate issrcfile(char *file)
2940Sstevel@tonic-gate {
2950Sstevel@tonic-gate 	struct	stat	statstruct;
2960Sstevel@tonic-gate 	char	*s;
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate 	/* if there is a file suffix */
2990Sstevel@tonic-gate 	if ((s = strrchr(file, '.')) != NULL && *++s != '\0') {
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 		/* if an SCCS or versioned file */
3020Sstevel@tonic-gate 		if (file[1] == '.' && file + 2 != s) { /* 1 character prefix */
3030Sstevel@tonic-gate 			switch (*file) {
3040Sstevel@tonic-gate 			case 's':
3050Sstevel@tonic-gate 			case 'S':
3060Sstevel@tonic-gate 				return (NO);
3070Sstevel@tonic-gate 			}
3080Sstevel@tonic-gate 		}
3090Sstevel@tonic-gate 		if (s[1] == '\0') {	/* 1 character suffix */
3100Sstevel@tonic-gate 			switch (*s) {
3110Sstevel@tonic-gate 			case 'c':
3120Sstevel@tonic-gate 			case 'h':
3130Sstevel@tonic-gate 			case 'l':
3140Sstevel@tonic-gate 			case 'y':
3150Sstevel@tonic-gate 			case 'C':
3160Sstevel@tonic-gate 			case 'G':
3170Sstevel@tonic-gate 			case 'H':
3180Sstevel@tonic-gate 			case 'L':
3190Sstevel@tonic-gate 				return (YES);
3200Sstevel@tonic-gate 			}
3210Sstevel@tonic-gate 		} else if (s[2] == '\0') {	/* 2 character suffix */
3220Sstevel@tonic-gate 			if (*s == 'b' && s[1] == 'p' ||	/* breakpoint listing */
3230Sstevel@tonic-gate 			    *s == 'q' &&
3240Sstevel@tonic-gate 				(s[1] == 'c' || s[1] == 'h') || /* Ingres */
3250Sstevel@tonic-gate 			    *s == 'p' && s[1] == 'r' ||	/* SDL */
3260Sstevel@tonic-gate 			    *s == 's' && s[1] == 'd') {	/* SDL */
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 				/*
3290Sstevel@tonic-gate 				 * some directories have 2 character
3300Sstevel@tonic-gate 				 * suffixes so make sure it is a file
3310Sstevel@tonic-gate 				 */
3320Sstevel@tonic-gate 				if (vpstat(file, &statstruct) == 0 &&
333*871Scasper 				    S_ISREG(statstruct.st_mode)) {
3340Sstevel@tonic-gate 					return (YES);
3350Sstevel@tonic-gate 				}
3360Sstevel@tonic-gate 			}
3370Sstevel@tonic-gate 		}
3380Sstevel@tonic-gate 	}
3390Sstevel@tonic-gate 	return (NO);
3400Sstevel@tonic-gate }
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate /* add an include file to the source file list */
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate void
incfile(char * file,int type)3450Sstevel@tonic-gate incfile(char *file, int type)
3460Sstevel@tonic-gate {
3470Sstevel@tonic-gate 	char	path[PATHLEN + 1];
3480Sstevel@tonic-gate 	int	i;
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate 	/* see if the file is already in the source file list */
3510Sstevel@tonic-gate 	if (infilelist(file) == YES) {
3520Sstevel@tonic-gate 		return;
3530Sstevel@tonic-gate 	}
3540Sstevel@tonic-gate 	/* look in current directory if it was #include "file" */
3550Sstevel@tonic-gate 	if (type == '"' && vpaccess(file, READ) == 0) {
3560Sstevel@tonic-gate 		addsrcfile(file);
3570Sstevel@tonic-gate 	} else {
3580Sstevel@tonic-gate 		/* search for the file in the #include directory list */
3590Sstevel@tonic-gate 		for (i = 0; i < nincdirs; ++i) {
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate 			/* don't include the file from two directories */
3620Sstevel@tonic-gate 			(void) sprintf(path, "%s/%s", incdirs[i], file);
3630Sstevel@tonic-gate 			if (infilelist(path) == YES) {
3640Sstevel@tonic-gate 				break;
3650Sstevel@tonic-gate 			}
3660Sstevel@tonic-gate 			/* make sure it exists and is readable */
3670Sstevel@tonic-gate 			if (vpaccess(compath(path), READ) == 0) {
3680Sstevel@tonic-gate 				addsrcfile(path);
3690Sstevel@tonic-gate 				break;
3700Sstevel@tonic-gate 			}
3710Sstevel@tonic-gate 		}
3720Sstevel@tonic-gate 	}
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate /* see if the file is already in the list */
3760Sstevel@tonic-gate 
3770Sstevel@tonic-gate BOOL
infilelist(char * file)3780Sstevel@tonic-gate infilelist(char *file)
3790Sstevel@tonic-gate {
3800Sstevel@tonic-gate 	struct	listitem *p;
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate 	for (p = srcfiletable[hash(compath(file)) % HASHMOD];
3830Sstevel@tonic-gate 	    p != NULL; p = p->next) {
3840Sstevel@tonic-gate 		if (strequal(file, p->file)) {
3850Sstevel@tonic-gate 			return (YES);
3860Sstevel@tonic-gate 		}
3870Sstevel@tonic-gate 	}
3880Sstevel@tonic-gate 	return (NO);
3890Sstevel@tonic-gate }
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate /* add a source file to the list */
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate void
addsrcfile(char * path)3940Sstevel@tonic-gate addsrcfile(char *path)
3950Sstevel@tonic-gate {
3960Sstevel@tonic-gate 	struct	listitem *p;
3970Sstevel@tonic-gate 	int	i;
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate 	/* make sure there is room for the file */
4000Sstevel@tonic-gate 	if (nsrcfiles == msrcfiles) {
4010Sstevel@tonic-gate 		msrcfiles += SRCINC;
4020Sstevel@tonic-gate 		srcfiles = myrealloc(srcfiles, msrcfiles * sizeof (char *));
4030Sstevel@tonic-gate 	}
4040Sstevel@tonic-gate 	/* add the file to the list */
4050Sstevel@tonic-gate 	p = (struct listitem *)mymalloc(sizeof (struct listitem));
4060Sstevel@tonic-gate 	p->file = stralloc(compath(path));
4070Sstevel@tonic-gate 	i = hash(p->file) % HASHMOD;
4080Sstevel@tonic-gate 	p->next = srcfiletable[i];
4090Sstevel@tonic-gate 	srcfiletable[i] = p;
4100Sstevel@tonic-gate 	srcfiles[nsrcfiles++] = p->file;
4110Sstevel@tonic-gate }
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate /* free the memory allocated for the source file list */
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate void
freefilelist(void)4160Sstevel@tonic-gate freefilelist(void)
4170Sstevel@tonic-gate {
4180Sstevel@tonic-gate 	struct	listitem *p, *nextp;
4190Sstevel@tonic-gate 	int	i;
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate 	while (nsrcfiles > 0) {
4220Sstevel@tonic-gate 		free(srcfiles[--nsrcfiles]);
4230Sstevel@tonic-gate 	}
4240Sstevel@tonic-gate 	for (i = 0; i < HASHMOD; ++i) {
4250Sstevel@tonic-gate 		for (p = srcfiletable[i]; p != NULL; p = nextp) {
4260Sstevel@tonic-gate 			nextp = p->next;
4270Sstevel@tonic-gate 			free(p);
4280Sstevel@tonic-gate 		}
4290Sstevel@tonic-gate 		srcfiletable[i] = NULL;
4300Sstevel@tonic-gate 	}
4310Sstevel@tonic-gate }
432