⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dir.c

📁 tvapp用于播放tv程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*=========================================================================== Copyright (c) 1998-2000, The Santa Cruz Operation  All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. *Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. *Neither name of The Santa Cruz Operation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  =========================================================================*//*	cscope - interactive C symbol cross-reference * *	directory searching functions */#include <stdlib.h>#include <sys/types.h>	/* needed by stat.h and dirent.h */#include <dirent.h>#include <sys/stat.h>	/* stat */#include "global.h"#include "vp.h"		/* vpdirs and vpndirs */static char const rcsid[] = "$Id: dir.c,v 1.19 2003/06/02 10:42:59 broeker Exp $";#define	DIRSEPS	" ,:"	/* directory list separators */#define	DIRINC	10	/* directory list size increment */#define HASHMOD	2003	/* must be a prime number */#define	SRCINC	HASHMOD	/* source file list size increment */			/* largest known database had 22049 files */char	currentdir[PATHLEN + 1];/* current directory */char	**incdirs;		/* #include directories */char	**srcdirs;		/* source directories */char	**srcfiles;		/* source files */int	nincdirs;		/* number of #include directories */int	nsrcdirs;		/* number of source directories */int	nsrcfiles;		/* number of source files */int	msrcfiles = SRCINC;	/* maximum number of source files */static	char	**incnames;	/* #include directory names without view pathing */static	int	mincdirs = DIRINC; /* maximum number of #include directories */static	int	msrcdirs;	/* maximum number of source directories */static	int	nvpsrcdirs;	/* number of view path source directories */static	struct	listitem {	/* source file names without view pathing */	char	*text;	struct	listitem *next;} *srcnames[HASHMOD];/* Internal prototypes: */static	BOOL	issrcfile(char *file);static	void	addsrcdir(char *dir);static	void	addincdir(char *name, char *path);static	void	scan_dir(const char *dirfile, BOOL recurse);static	void	makevpsrcdirs(void);/* make the view source directory list */static voidmakevpsrcdirs(void){	int	i;	/* return if this function has already been called */	if (nsrcdirs > 0) {		return;	}	/* get the current directory name */	if (getcwd(currentdir, PATHLEN) == NULL) {		(void) fprintf(stderr, "cscope: warning: cannot get current directory name\n");		(void) strcpy(currentdir, "<unknown>");	}	/* see if there is a view path and this directory is in it */	vpinit(currentdir);	if (vpndirs > 1) {		nsrcdirs = vpndirs;	}	else {		nsrcdirs = 1;	}	/* create the source directory list */	msrcdirs = nsrcdirs + DIRINC;	srcdirs = mymalloc(msrcdirs * sizeof(char *));	*srcdirs = ".";	/* first source dir is always current dir */	for (i = 1; i < vpndirs; ++i) {		srcdirs[i] = vpdirs[i];	}	/* save the number of original source directories in the view path */	nvpsrcdirs = nsrcdirs;}/* add a source directory to the list for each view path source directory */voidsourcedir(char *dirlist){	char	path[PATHLEN + 1];	char	*dir;	int	i;	makevpsrcdirs();		/* make the view source directory list */	dirlist = stralloc(dirlist);	/* don't change environment variable text */		/* parse the directory list */	dir = strtok(dirlist, DIRSEPS);	while (dir != NULL) {		int dir_len = strlen(dir);		addsrcdir(dir);		/* if it isn't a full path name and there is a 		   multi-directory view path */		if (*dirlist != '/' && vpndirs > 1) {						/* compute its path from higher view path source dirs */			for (i = 1; i < nvpsrcdirs; ++i) {				(void) sprintf(path, "%.*s/%s",					       PATHLEN - 2 - dir_len,					       srcdirs[i], dir);				addsrcdir(path);			}		}		dir = strtok(NULL, DIRSEPS);	}	free(dirlist);		/* HBB 20000421: avoid memory leaks */}/* add a source directory to the list */static voidaddsrcdir(char *dir){	struct	stat	statstruct;	/* make sure it is a directory */	if (lstat(compath(dir), &statstruct) == 0 && 	    S_ISDIR(statstruct.st_mode)) {		/* note: there already is a source directory list */		if (nsrcdirs == msrcdirs) {			msrcdirs += DIRINC;			srcdirs = myrealloc(srcdirs, msrcdirs * sizeof(char *));		}		srcdirs[nsrcdirs++] = stralloc(dir);	}}/* HBB 20000421: new function, for avoiding leaks *//* free list of src directories */voidfreesrclist(){	if (!srcdirs)		return;	while(nsrcdirs>1)		free(srcdirs[--nsrcdirs]);	free(srcdirs);}/* add a #include directory to the list for each view path source directory */voidincludedir(char *dirlist){	char	path[PATHLEN + 1];	char	*dir;	int	i;	makevpsrcdirs();		/* make the view source directory list */	dirlist = stralloc(dirlist);	/* don't change environment variable text */		/* parse the directory list */	dir = strtok(dirlist, DIRSEPS);	while (dir != NULL) {		int dir_len = strlen(dir);		addincdir(dir, dir);		/* if it isn't a full path name and there is a 		   multi-directory view path */		if (*dirlist != '/' && vpndirs > 1) {						/* compute its path from higher view path source dirs */			for (i = 1; i < nvpsrcdirs; ++i) {				(void) sprintf(path, "%.*s/%s", 					       PATHLEN - 2 - dir_len,					       srcdirs[i], dir);				addincdir(dir, path);			}		}		dir = strtok(NULL, DIRSEPS);	}	free(dirlist);			/* HBB 20000421: avoid leaks */}/* add a #include directory to the list */static voidaddincdir(char *name, char *path){	struct	stat	statstruct;	/* make sure it is a directory */	if (lstat(compath(path), &statstruct) == 0 && 	    S_ISDIR(statstruct.st_mode)) {		if (incdirs == NULL) {			incdirs = mymalloc(mincdirs * sizeof(char *));			incnames = mymalloc(mincdirs * sizeof(char *));		}		else if (nincdirs == mincdirs) {			mincdirs += DIRINC;			incdirs = myrealloc(incdirs, 				mincdirs * sizeof(char *));			incnames = myrealloc(incnames, 				mincdirs * sizeof(char *));		}		incdirs[nincdirs] = stralloc(path);		incnames[nincdirs++] = stralloc(name);	}}/* HBB 2000421: new function, for avoiding memory leaks *//* free the list of include files, if wanted */voidfreeinclist(){	if (!incdirs)			return;	while(nincdirs>0) {		free(incdirs[--nincdirs]);		free(incnames[nincdirs]);	}	free(incdirs);	free(incnames);}/* make the source file list */voidmakefilelist(void){	static	BOOL	firstbuild = YES;	/* first time through */	FILE	*names;			/* name file pointer */	char	dir[PATHLEN + 1];	char	path[PATHLEN + 1];	char    line[PATHLEN * 10];	char	*file;	char	*s;	int	i;	makevpsrcdirs();	/* make the view source directory list */	/* if -i was NOT given and there are source file arguments */	if (namefile == NULL && fileargc > 0) {				/* put them in a list that can be expanded */		for (i = 0; i < fileargc; ++i) {			file = fileargv[i];			if (infilelist(file) == NO) {				if ((s = inviewpath(file)) != NULL) {					addsrcfile(s);				}				else {					(void) fprintf(stderr, "cscope: cannot find file %s\n",					    file);					errorsfound = YES;				}			}		}		return;	}	/* see if a file name file exists */	if (namefile == NULL && vpaccess(NAMEFILE, READ) == 0) {		namefile = NAMEFILE;	}	/* if there is a file of source file names */	if (namefile != NULL) {		if (strcmp(namefile, "-") == 0)		    names = stdin;		else if ((names = vpfopen(namefile, "r")) == NULL) {			cannotopen(namefile);			myexit(1);		}		/* get the names in the file */		while (fgets(line, 10*PATHLEN, names) != NULL) {			char *point_in_line = line + (strlen(line) - 1);			size_t length_of_name = 0;			int unfinished_option = 0;			BOOL done = NO;			/* Kill away \n left at end of fgets()'d string: */			if (*point_in_line == '\n')				*point_in_line = '\0';						/* Parse whitespace-terminated strings in line: */			point_in_line = line;			while (sscanf(point_in_line, "%s", path) == 1) {				/* Have to store this length --- inviewpath() will				 * modify path, later! */				length_of_name = strlen(path);			  				if (*path == '-') {	/* if an option */					if (unfinished_option) {						/* Can't have another option directly after an						 * -I or -p option with no name after it! */						(void) fprintf(stderr, "\cscope: Syntax error in namelist file %s: unfinished -I or -p option\n", 									   namefile);						unfinished_option = 0;					}											i = path[1];					switch (i) {					case 'c':	/* ASCII characters only in crossref */						compress = NO;						break;					case 'k':	/* ignore DFLT_INCDIR */						kernelmode = YES;						break;					case 'q':	/* quick search */						invertedindex = YES;						break;					case 'T':	/* truncate symbols to 8 characters */						trun_syms = YES;						break;					case 'I':	/* #include file directory */					case 'p':	/* file path components to display */						s = path + 2;		/* for "-Ipath" */						if (*s == '\0') {	/* if "-I path" */							unfinished_option = i;							break; 						} 						/* this code block used several times in here						 * --> make it a macro to avoid unnecessary						 * duplication */#define HANDLE_OPTION_ARGUMENT(i, s)																			   \						switch (i) {																			   \

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -