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

📄 find.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 or text cross-reference * *	searching functions */#include "global.h"#include "build.h"#include "scanner.h"		/* for token definitions */#if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)#include <ncurses.h>#else#include <curses.h>#endif#include <regex.h>static char const rcsid[] = "$Id: find.c,v 1.15 2002/06/20 16:26:29 broeker Exp $";/* most of these functions have been optimized so their innermost loops have * only one test for the desired character by putting the char and  * an end-of-block marker (\0) at the end of the disk block buffer. * When the inner loop exits on the char, an outer loop will see if * the char is followed by a \0.  If so, it will read the next block * and restart the inner loop. */char	*blockp;			/* pointer to current char in block */char	block[BUFSIZ + 2];		/* leave room for end-of-block mark */int	blocklen;			/* length of disk block read */char	blockmark;			/* mark character to be searched for */long	blocknumber;			/* block number */static	char	global[] = "<global>";	/* dummy global function name */static	char	cpattern[PATLEN + 1];	/* compressed pattern */static	long	lastfcnoffset;		/* last function name offset */static	POSTING	*postingp;		/* retrieved posting set pointer */static	long	postingsfound;		/* retrieved number of postings */static	regex_t regexp;			/* regular expression */static	BOOL	isregexp_valid = NO;	/* regular expression status */static	BOOL	match(void);static	BOOL	matchrest(void);static	POSTING	*getposting(void);static	char	*lcasify(char *s);static	void	findcalledbysub(char *file, BOOL macro);static	void	findterm(char *pattern);static	void	putline(FILE *output);static	void	putpostingref(POSTING *p, char *pat);static	void	putref(int seemore, char *file, char *func);static	void	putsource(int seemore, FILE *output);/* find the symbol in the cross-reference */char *findsymbol(char *pattern){	char	file[PATHLEN + 1];	/* source file name */	char	function[PATLEN + 1];	/* function name */	char	macro[PATLEN + 1];	/* macro name */	char	symbol[PATLEN + 1];	/* symbol name */	char	*cp;	char	*s;	char firstchar;		/* first character of a potential symbol */	BOOL fcndef = NO;	if (invertedindex == YES) {		long	lastline = 0;		POSTING *p;		findterm(pattern);		while ((p = getposting()) != NULL) {			if (p->type != INCLUDE && p->lineoffset != lastline) {				putpostingref(p, 0);				lastline = p->lineoffset;			}		}		return NULL;	}	(void) scanpast('\t');			/* find the end of the header */	skiprefchar();			/* skip the file marker */	putstring(file);		/* save the file name */	(void) strcpy(function, global);/* set the dummy global function name */	(void) strcpy(macro, global);/* set the dummy global macro name */		/* find the next symbol */	/* note: this code was expanded in-line for speed */	/* other macros were replaced by code using cp instead of blockp */	cp = blockp;	for (;;) {		setmark('\n');		do {	/* innermost loop optimized to only one test */			while (*cp != '\n') {				++cp;			}		} while (*(cp + 1) == '\0' && (cp = readblock()) != NULL);		/* skip the found character */		if (cp != NULL && *(++cp + 1) == '\0') {			cp = readblock();		}		if (cp == NULL) {			break;		}		/* look for a source file, function, or macro name */		if (*cp == '\t') {			blockp = cp;			switch (getrefchar()) {			case NEWFILE:		/* file name */				/* save the name */				skiprefchar();				putstring(file);							/* check for the end of the symbols */				if (*file == '\0') {					return NULL;				}				progress("Search", searchcount, nsrcfiles);				/* FALLTHROUGH */							case FCNEND:		/* function end */				(void) strcpy(function, global);				goto notmatched;	/* don't match name */							case FCNDEF:		/* function name */				fcndef = YES;				s = function;				break;			case DEFINE:		/* macro name */				if (fileversion >= 10) {					s = macro;				}				else {						s = symbol;				}				break;			case DEFINEEND:		/* macro end */				(void) strcpy(macro, global);				goto notmatched;			case INCLUDE:			/* #include file */				goto notmatched;	/* don't match name */						default:		/* other symbol */				s = symbol;			}			/* save the name */			skiprefchar();			putstring(s);			/* see if this is a regular expression pattern */			if (isregexp_valid == YES) { 				if (caseless == YES) {					s = lcasify(s);				}				if (*s != '\0' && regexec (&regexp, s, (size_t)0, NULL, 0) == 0) { 					goto matched;				}			}			/* match the symbol to the text pattern */			else if (strequal(pattern, s)) {				goto matched;			}			goto notmatched;		}		/* if this is a regular expression pattern */		if (isregexp_valid == YES) {						/* if this is a symbol */						/**************************************************			 * The first character may be a digraph'ed char, so			 * unpack it into firstchar, and then test that.			 *			 * Assume that all digraphed chars have the 8th bit			 * set (0200).			 **************************************************/			if (*cp & 0200) {	/* digraph char? */				firstchar = dichar1[(*cp & 0177) / 8];			}			else {				firstchar = *cp;			}						if (isalpha((unsigned char)firstchar) || firstchar == '_') {				blockp = cp;				putstring(symbol);				if (caseless == YES) {					s = lcasify(symbol);	/* point to lower case version */				}				else {					s = symbol;				}								/* match the symbol to the regular expression */				if (*s != '\0' && regexec (&regexp, s, (size_t)0, NULL, 0) == 0) {					goto matched;				}				goto notmatched;			}		}		/* match the character to the text pattern */		else if (*cp == cpattern[0]) {			blockp = cp;			/* match the rest of the symbol to the text pattern */			if (matchrest()) {				s = NULL;		matched:				/* output the file, function or macro, and source line */				if (strcmp(macro, global) && s != macro) {					putref(0, file, macro);				}				else if (fcndef == YES || s != function) {					fcndef = NO;					putref(0, file, function);				}				else {					putref(0, file, global);				}				if (blockp == NULL) {					return NULL;				}			}		notmatched:			cp = blockp;		}	}	blockp = cp;	return NULL;}/* find the function definition or #define */char *finddef(char *pattern){	char	file[PATHLEN + 1];	/* source file name */	if (invertedindex == YES) {		POSTING *p;		findterm(pattern);		while ((p = getposting()) != NULL) {			switch (p->type) {			case DEFINE:/* could be a macro */			case FCNDEF:			case CLASSDEF:			case ENUMDEF:			case MEMBERDEF:			case STRUCTDEF:			case TYPEDEF:			case UNIONDEF:			case GLOBALDEF:/* other global definition */				putpostingref(p, pattern);			}		}		return NULL;	}	/* find the next file name or definition */	while (scanpast('\t') != NULL) {		switch (*blockp) {					case NEWFILE:			skiprefchar();	/* save file name */			putstring(file);			if (*file == '\0') {	/* if end of symbols */				return NULL;			}			progress("Search", searchcount, nsrcfiles);			break;		case DEFINE:		/* could be a macro */		case FCNDEF:		case CLASSDEF:		case ENUMDEF:		case MEMBERDEF:		case STRUCTDEF:		case TYPEDEF:		case UNIONDEF:		case GLOBALDEF:		/* other global definition */			skiprefchar();	/* match name to pattern */			if (match()) {						/* output the file, function and source line */				putref(0, file, pattern);			}			break;		}	}		return NULL;}/* find all function definitions (used by samuel only) */char *findallfcns(char *dummy){	char	file[PATHLEN + 1];	/* source file name */	char	function[PATLEN + 1];	/* function name */	(void) dummy;		/* unused argument */	/* find the next file name or definition */	while (scanpast('\t') != NULL) {		switch (*blockp) {					case NEWFILE:			skiprefchar();	/* save file name */			putstring(file);			if (*file == '\0') {	/* if end of symbols */				return NULL;			}			progress("Search", searchcount, nsrcfiles);			/* FALLTHROUGH */					case FCNEND:		/* function end */			(void) strcpy(function, global);			break;		case FCNDEF:		case CLASSDEF:			skiprefchar();	/* save function name */			putstring(function);			/* output the file, function and source line */			putref(0, file, function);			break;		}	}	return NULL;}/* find the functions calling this function */char *findcalling(char *pattern){	char	file[PATHLEN + 1];	/* source file name */	char	function[PATLEN + 1];	/* function name */	char	tmpfunc[10][PATLEN + 1];/* 10 temporary function names */	char	macro[PATLEN + 1];	/* macro name */	char	*tmpblockp;	int	morefuns, i;	if (invertedindex == YES) {		POSTING	*p;				findterm(pattern);		while ((p = getposting()) != NULL) {			if (p->type == FCNCALL) {				putpostingref(p, 0);			}		}		return NULL;	}	/* find the next file name or function definition */	*macro = '\0';	/* a macro can be inside a function, but not vice versa */	tmpblockp = 0;	morefuns = 0;	/* one function definition is normal case */	for (i = 0; i < 10; i++) *(tmpfunc[i]) = '\0';	while (scanpast('\t') != NULL) {		switch (*blockp) {					case NEWFILE:		/* save file name */			skiprefchar();			putstring(file);			if (*file == '\0') {	/* if end of symbols */				return NULL;			}			progress("Search", searchcount, nsrcfiles);			(void) strcpy(function, global);			break;					case DEFINE:		/* could be a macro */			if (fileversion >= 10) {				skiprefchar();				putstring(macro);			}			break;		case DEFINEEND:			*macro = '\0';			break;		case FCNDEF:		/* save calling function name */			skiprefchar();			putstring(function);			for (i = 0; i < morefuns; i++)				if ( !strcmp(tmpfunc[i], function) )					break;			if (i == morefuns) {				(void) strcpy(tmpfunc[morefuns], function);				if (++morefuns >= 10) morefuns = 9;			}			break;					case FCNEND:			for (i = 0; i < morefuns; i++)				*(tmpfunc[i]) = '\0';			morefuns = 0;			break;		case FCNCALL:		/* match function called to pattern */			skiprefchar();			if (match()) {								/* output the file, calling function or macro, and source */				if (*macro != '\0') {					putref(1, file, macro);				}				else {					tmpblockp = blockp;					for (i = 0; i < morefuns; i++) {						blockp = tmpblockp;						putref(1, file, tmpfunc[i]);					}				}			}		}	}	morefuns = 0;		return NULL;}/* find the text in the source files */char *findstring(char *pattern){	char	egreppat[2 * PATLEN];	char	*cp, *pp;	/* translate special characters in the regular expression */	cp = egreppat;	for (pp = pattern; *pp != '\0'; ++pp) {		if (strchr(".*[\\^$+?|()", *pp) != NULL) {			*cp++ = '\\';		}		*cp++ = *pp;	}	*cp = '\0';		/* search the source files */	return(findregexp(egreppat));}/* find this regular expression in the source files */char *findregexp(char *egreppat){	int	i;	char	*egreperror;	/* compile the pattern */	if ((egreperror = egrepinit(egreppat)) == NULL) {		/* search the files */		for (i = 0; i < nsrcfiles; ++i) {			char *file = filepath(srcfiles[i]);			progress("Search", searchcount, nsrcfiles);			if (egrep(file, refsfound, "%s <unknown> %ld ") < 0) {				posterr ("Cannot open file %s", file);			}		}	}	return(egreperror);}/* find matching file names */char *findfile(char *dummy){	int	i;		(void) dummy;		/* unused argument */	for (i = 0; i < nsrcfiles; ++i) {		char *s;		if (caseless == YES) {			s = lcasify(srcfiles[i]);		}		else {			s = srcfiles[i];		}		if (regexec (&regexp, s, (size_t)0, NULL, 0) == 0) {			(void) fprintf(refsfound, "%s <unknown> 1 <unknown>\n", 				srcfiles[i]);		}	}	return NULL;}/* find files #including this file */char *findinclude(char *pattern){	char	file[PATHLEN + 1];	/* source file name */	if (invertedindex == YES) {		POSTING *p;		findterm(pattern);		while ((p = getposting()) != NULL) {			if (p->type == INCLUDE) {				putpostingref(p, 0);                        }                }                return NULL;        }	/* find the next file name or function definition */	while (scanpast('\t') != NULL) {		switch (*blockp) {					case NEWFILE:		/* save file name */			skiprefchar();			putstring(file);			if (*file == '\0') {	/* if end of symbols */				return NULL;			}			progress("Search", searchcount, nsrcfiles);			break;					case INCLUDE:		/* match function called to pattern */			skiprefchar();			skiprefchar();	/* skip global or local #include marker */			if (match()) {								/* output the file and source line */				putref(0, file, global);			}		}	}		return NULL;}/* initialize */FINDINITfindinit(char *pattern){	char	buf[PATLEN + 3];	BOOL	isregexp = NO;	int	i;	char	*s;	unsigned char c;	/* HBB 20010427: changed uint to uchar */	/* HBB: be nice: free regexp before allocating a new one */	if(isregexp_valid == YES)		regfree(&regexp);	isregexp_valid = NO;	/* remove trailing white space */	for (s = pattern + strlen(pattern) - 1; 	     isspace((unsigned char)*s);	     --s) {		*s = '\0';	}

⌨️ 快捷键说明

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