Since V8 regex routines have been moved to libcompat(), the BSD regex

routines must again be defined as wrappers around them.
This commit is contained in:
jtc 1994-02-01 17:45:53 +00:00
parent d4498ee608
commit ec22bca1e7
1 changed files with 27 additions and 27 deletions

View File

@ -43,51 +43,51 @@
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
/*static char sccsid[] = "from: @(#)regex.c 5.1 (Berkeley) 3/29/92";*/ /*static char sccsid[] = "from: @(#)regex.c 5.1 (Berkeley) 3/29/92";*/
static char rcsid[] = "$Id: regex.c,v 1.3 1993/11/11 01:24:50 jtc Exp $"; static char rcsid[] = "$Id: regex.c,v 1.4 1994/02/01 17:45:53 jtc Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/types.h> #include <sys/types.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <regexp.h>
#include <string.h> #include <string.h>
#include <regex.h> #include <stdlib.h>
static int compiled_regexp = 0; static regexp *re_regexp;
static char errbuf[256]; static int re_goterr;
static regex_t rp; static char *re_errstr;
char * char *
re_comp(s) re_comp(s)
char *s; char *s;
{ {
int eval;
if (s == NULL) if (s == NULL)
return (NULL); return (NULL);
if (re_regexp)
if (compiled_regexp) { free(re_regexp);
regfree(&rp); if (re_errstr)
compiled_regexp = 0; free(re_errstr);
} re_goterr = 0;
re_regexp = regcomp(s);
if ((eval = regcomp(&rp, s, REG_NOSUB)) != 0) { return (re_goterr ? re_errstr : NULL);
regerror (eval, &rp, errbuf, sizeof(errbuf));
return errbuf;
}
compiled_regexp = 1;
return NULL;
} }
int int
re_exec(s) re_exec(s)
char *s; char *s;
{ {
regmatch_t rm[1]; int rc;
int eval;
if ((eval = regexec(&rp, s, 0, rm, 0)) == 0) re_goterr = 0;
return 1; rc = regexec(re_regexp, s);
return (re_goterr ? -1 : rc);
return eval == REG_NOMATCH ? 0 : -1; }
void
regerror(s)
const char *s;
{
re_goterr = 1;
if (re_errstr)
free(re_errstr);
re_errstr = strdup(s);
} }