Ejemplo n.º 1
0
BOOL
search(void)
{
	char	*volatile egreperror = NULL;	/* egrep error message */
	FINDINIT volatile rc = NOERROR;		/* findinit return code */
	SIGTYPE	(*volatile savesig)() = SIG_DFL; /* old value of signal */
	FP	f;			/* searching function */
	char	*s;
	int	c;

	/* note: the pattern may have been a cscope argument */
	if (caseless == YES) {
		for (s = pattern; *s != '\0'; ++s) {
			*s = tolower(*s);
		}
	}
	/* open the references found file for writing */
	if (writerefsfound() == NO) {
		return (NO);
	}
	/* find the pattern - stop on an interrupt */
	if (linemode == NO) {
		putmsg("Searching");
	}
	initprogress();
	if (setjmp(env) == 0) {
		savesig = signal(SIGINT, jumpback);
		f = fields[field].findfcn;
		if (fields[field].patterntype == EGREP) {
			egreperror = (*f)(pattern);
		} else {
			if ((nonglobalrefs = fopen(temp2, "w")) == NULL) {
				cannotopen(temp2);
				return (NO);
			}
			if ((rc = findinit()) == NOERROR) {
				(void) dbseek(0L); /* goto the first block */
				(*f)();
				findcleanup();

				/* append the non-global references */
				(void) freopen(temp2, "r", nonglobalrefs);
				while ((c = getc(nonglobalrefs)) != EOF) {
					(void) putc(c, refsfound);
				}
			}
			(void) fclose(nonglobalrefs);
		}
	}
	(void) signal(SIGINT, savesig);
	/* reopen the references found file for reading */
	(void) freopen(temp1, "r", refsfound);
	nextline = 1;
	totallines = 0;

	/* see if it is empty */
	if ((c = getc(refsfound)) == EOF) {
		if (egreperror != NULL) {
			(void) sprintf(lastmsg, "Egrep %s in this pattern: %s",
			    egreperror, pattern);
		} else if (rc == NOTSYMBOL) {
			(void) sprintf(lastmsg, "This is not a C symbol: %s",
			    pattern);
		} else if (rc == REGCMPERROR) {
			(void) sprintf(lastmsg,
			    "Error in this regcmp(3X) regular expression: %s",
			    pattern);
		} else {
			(void) sprintf(lastmsg, "Could not find the %s: %s",
			    fields[field].text2, pattern);
		}
		return (NO);
	}
	/* put back the character read */
	(void) ungetc(c, refsfound);

	countrefs();
	return (YES);
}
Ejemplo n.º 2
0
BOOL
search(void)
{
	char	*findresult = NULL;	/* find function output */
	BOOL	funcexist = YES;		/* find "function" error */
	FINDINIT rc = NOERROR;		/* findinit return code */
	sighandler_t savesig;		/* old value of signal */
	FP	f;			/* searching function */
	int	c;
	
	/* open the references found file for writing */
	if (writerefsfound() == NO) {
		return(NO);
	}
	/* find the pattern - stop on an interrupt */
	if (linemode == NO) {
		postmsg("Searching");
	}
	searchcount = 0;
	savesig = signal(SIGINT, jumpback);
	if (sigsetjmp(env, 1) == 0) {
		f = fields[field].findfcn;
		if (f == findregexp || f == findstring) {
			findresult = (*f)(Pattern);
		} else {
			if ((nonglobalrefs = myfopen(temp2, "wb")) == NULL) {
				cannotopen(temp2);
				return(NO);
			}
			if ((rc = findinit(Pattern)) == NOERROR) {
				(void) dbseek(0L); /* read the first block */
				findresult = (*f)(Pattern);
				if (f == findcalledby) 
					funcexist = (*findresult == 'y');
				findcleanup();

				/* append the non-global references */
				(void) fclose(nonglobalrefs);
				if ((nonglobalrefs = myfopen(temp2, "rb"))
				     == NULL) {
					cannotopen(temp2);
					return(NO);
				}
				while ((c = getc(nonglobalrefs)) != EOF) {
					(void) putc(c, refsfound);
				}
			}
			(void) fclose(nonglobalrefs);
		}
	}
	signal(SIGINT, savesig);

	/* rewind the cross-reference file */
	(void) lseek(symrefs, (long) 0, 0);
	
	/* reopen the references found file for reading */
	(void) fclose(refsfound);
	if ((refsfound = myfopen(temp1, "rb")) == NULL) {
		cannotopen(temp1);
		return(NO);
	}
	nextline = 1;
	totallines = 0;
	disprefs = 0;
	
	/* see if it is empty */
	if ((c = getc(refsfound)) == EOF) {
		if (findresult != NULL) {
			(void) snprintf(lastmsg, sizeof(lastmsg), "Egrep %s in this pattern: %s", 
				       findresult, Pattern);
		} else if (rc == NOTSYMBOL) {
			(void) snprintf(lastmsg, sizeof(lastmsg), "This is not a C symbol: %s", 
				       Pattern);
		} else if (rc == REGCMPERROR) {
			(void) snprintf(lastmsg, sizeof(lastmsg), "Error in this regcomp(3) regular expression: %s", 
				       Pattern);
			
		} else if (funcexist == NO) {
			(void) snprintf(lastmsg, sizeof(lastmsg), "Function definition does not exist: %s", 
				       Pattern);
		} else {
			(void) snprintf(lastmsg, sizeof(lastmsg), "Could not find the %s: %s", 
				       fields[field].text2, Pattern);
		}
		return(NO);
	}
	/* put back the character read */
	(void) ungetc(c, refsfound);

	/* HBB 20041027: this used to hold a copy of the code of 
	 * countrefs(), but with the crucial display width adjustments
	 * missing.  Just call the real thing instead! */
	countrefs();
	return(YES);
}