*BSD News Article 22684


Return to BSD News archive

Newsgroups: comp.os.386bsd.bugs
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!pacbell.com!amdahl!amd!netcomsv!netcom.com!alm
From: alm@netcom.com (Andrew Moore)
Subject: 2nd try - bug fix (was Re: elvis tag bug in FreeBSD-1.0E)
Message-ID: <almCF8r5J.FBw@netcom.com>
Keywords: elvis tags
Organization: Netcom Online Communications Services (408-241-9760 login: guest)
References: <517@irbs.UUCP>
Date: Thu, 21 Oct 1993 09:46:31 GMT
Lines: 79

In article <517@irbs.UUCP> jc@irbs.UUCP (John Capo) writes:
>
>If elvis is compiled with -DREGEX, as in the stock source distribution,
>he can not find a tag with a * in the function return value or in the
>arguments. Remove -DREGEX from the Makefile and all is well again.
>
>Is this a known bug or do I have another problem?

With REGEX, the magic and ignorecase flags weren't being heeded.
This should fix it:

*** regexp.c~	Thu Oct 21 00:19:55 1993
--- regexp.c	Thu Oct 21 01:22:14 1993
***************
*** 49,54 ****
--- 49,56 ----
  optpat(s)
  	char *s;
  {
+ 	char *neuter();
+ 
  	int n;
  	if (*s == '\0') {
  		if (!previous) regerr("RE error: no previous pattern");
***************
*** 60,72 ****
  		return previous;
  	}
  	patlock = 0;
! 	if (n = regcomp(previous, s, 0)) {
  		regerr("RE error: %d", n);
  		free(previous);
  		return previous = NULL;
  	}
  	return previous;
  }
  #else
  static char	*previous;	/* the previous regexp, used when null regexp is given */
  
--- 62,100 ----
  		return previous;
  	}
  	patlock = 0;
! 	if (n = regcomp(previous, *o_magic ? s : neuter(s), 
! 	    *o_ignorecase ? REG_ICASE : 0)) {
  		regerr("RE error: %d", n);
  		free(previous);
  		return previous = NULL;
  	}
  	return previous;
  }
+ 
+ /* escape BRE meta-characters in a string */
+ char *
+ neuter(s)
+ 	char *s;
+ {
+ 	static char *hd = NULL;
+ 
+ 	char *t;
+ 	int n = strlen(s);
+ 
+ 	free(hd);
+ 	if ((hd = t = (char *) malloc(n + n + 1)) == NULL)
+ 		return NULL;
+ 	if (*s == '^')
+ 		*t++ = *s++;
+ 	while (*s) {
+ 		if (*s == '.' || *s == '\\' || *s == '[' || *s == '*')
+ 			*t++ = '\\';
+ 		*t++ = *s++;
+ 	}
+ 	*t = '\0';
+ 	return hd;
+ }
+ 
  #else
  static char	*previous;	/* the previous regexp, used when null regexp is given */