1 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
4 static char rcsid
[] = "$Header$";
18 * Interface to regular expression routines.
19 * Also: simple minded patterns without meta-characters.
23 static char *pattern
; /* Pointer to compiled pattern */
24 char *regcmp(), *regex();
27 static struct regexp
*pattern
;
28 static char *rc_error
;
29 struct regexp
*regcomp();
32 # if USG_REGEX || V8_REGEX
34 * Compile a new pattern, but first free previous result.
42 * user wants previous pattern
48 * there was a compiled pattern
54 return (pattern
= regcmp(s
, (char *) 0)) ?
60 if (pattern
) return (char *) 0;
61 if (rc_error
) return rc_error
;
62 return "Error in pattern";
68 regerror(str
) char *str
; {
74 * Search for compiled pattern in string "s". Return 0 if not found.
80 return !(regex(pattern
,s
) == 0);
84 return regexec(pattern
,s
,1);
86 return regexec(pattern
,s
);
93 * In this case, simple minded pattern search without meta-characters
101 * re_comp : Just remember pattern.
105 re_comp(s
) char *s
; {
109 * User wants previous pattern
112 return "No previous regular expression";
122 pattern
= alloc((unsigned) (strlen(s
) + 1), 0);
123 (VOID
) strcpy(pattern
,s
);
128 * re-exec : Simple minded pattern matcher
131 re_exec(s
) register char *s
; {
133 register char *ppat
, *pstr
;
137 * As long as there are characters ...
139 ppat
= pattern
; /* Try the pattern again */
141 while (*ppat
== *pstr
) {
142 if (*++ppat
== '\0') {
144 * The pattern matched! Report success
148 if (*++pstr
== '\0') {
150 * Not enough characters left in the string.
157 return 0; /* Failure */
159 # endif not BSD_REGEX