8
#ifndef HAVE_GLIBC_REGEX
9
#include "regexrepl/regex.h"
16
/* OSF/1 doc says that POSIX and XPG4 include regcomp in libc.
17
So we might as well set ourselves up to take advantage of it.
18
This functionality is also available in hpux, and is also provided
19
by the FSF's librx package, so if you can use that if your
20
operating system vendor doesn't supply it.
24
init_regex_version (void)
26
setvar (cintern ("*regex-version*"),
27
cintern ("$Id: regex.c,v 1.12 2003/01/05 20:51:39 yosh Exp $"),
42
get_tc_regex (LISP ptr)
45
(ptr, tc_regex) my_err ("not a regular expression", ptr);
46
return ((struct tc_regex *) ptr->storage_as.string.data);
50
regcomp_l (LISP pattern, LISP flags)
53
char *str, errbuff[1024];
57
iflags = NNULLP (flags) ? get_c_long (flags) : 0;
58
str = get_c_string (pattern);
59
iflag = no_interrupt (1);
60
result = cons (NIL, NIL);
61
h = (struct tc_regex *) must_malloc (sizeof (struct tc_regex));
66
result->type = tc_regex;
67
result->storage_as.string.data = (char *) h;
68
h->r = (regex_t *) must_malloc (sizeof (regex_t));
69
if ((error = regcomp (h->r, str, iflags)))
71
regerror (error, h->r, errbuff, sizeof (errbuff));
72
return (my_err (errbuff, pattern));
75
if (iflags & REG_NOSUB)
80
h->nmatch = h->r->re_nsub + 1;
81
h->m = (regmatch_t *) must_malloc (sizeof (regmatch_t) * h->nmatch);
87
regerror_l (LISP code, LISP ptr)
90
regerror (get_c_long (code), get_tc_regex (ptr)->r, errbuff, sizeof (errbuff));
91
return (strcons (strlen (errbuff), errbuff));
95
regexec_l (LISP ptr, LISP str, LISP eflags)
101
h = get_tc_regex (ptr);
102
if ((error = regexec (h->r,
106
NNULLP (eflags) ? get_c_long (eflags) : 0)))
107
return (flocons (error));
108
for (j = 0, result = NIL; j < h->nmatch; ++j)
109
result = cons (cons (flocons (h->m[j].rm_so),
110
flocons (h->m[j].rm_eo)),
112
return (nreverse (result));
116
regex_gc_free (LISP ptr)
119
if ((h = (struct tc_regex *) ptr->storage_as.string.data))
121
if ((h->compflag) && h->r)
134
ptr->storage_as.string.data = NULL;
139
regex_prin1 (LISP ptr, struct gen_printio *f)
143
p = get_tc_regex (ptr)->r;
144
sprintf (buffer, "#<REGEX %p nsub=%d",
145
p, (int) p->re_nsub);
154
tc_regex = allocate_user_tc ();
155
set_gc_hooks (tc_regex,
161
set_print_hooks (tc_regex, regex_prin1);
162
init_subr_2 ("regcomp", regcomp_l);
163
init_subr_2 ("regerror", regerror_l);
164
init_subr_3 ("regexec", regexec_l);
165
setvar (cintern ("REG_EXTENDED"), flocons (REG_EXTENDED), NIL);
166
setvar (cintern ("REG_ICASE"), flocons (REG_ICASE), NIL);
167
setvar (cintern ("REG_NOSUB"), flocons (REG_NOSUB), NIL);
168
setvar (cintern ("REG_NEWLINE"), flocons (REG_NEWLINE), NIL);
170
setvar (cintern ("REG_NOTBOL"), flocons (REG_NOTBOL), NIL);
171
setvar (cintern ("REG_NOTEOL"), flocons (REG_NOTEOL), NIL);
173
setvar (cintern ("REG_NOMATCH"), flocons (REG_NOMATCH), NIL);
174
setvar (cintern ("REG_BADPAT"), flocons (REG_BADPAT), NIL);
175
setvar (cintern ("REG_ECOLLATE"), flocons (REG_ECOLLATE), NIL);
176
setvar (cintern ("REG_ECTYPE"), flocons (REG_ECTYPE), NIL);
177
setvar (cintern ("REG_EESCAPE"), flocons (REG_EESCAPE), NIL);
178
setvar (cintern ("REG_ESUBREG"), flocons (REG_ESUBREG), NIL);
179
setvar (cintern ("REG_EBRACK"), flocons (REG_EBRACK), NIL);
180
setvar (cintern ("REG_EPAREN"), flocons (REG_EPAREN), NIL);
181
setvar (cintern ("REG_EBRACE"), flocons (REG_EBRACE), NIL);
182
setvar (cintern ("REG_BADBR"), flocons (REG_BADBR), NIL);
183
setvar (cintern ("REG_ERANGE"), flocons (REG_ERANGE), NIL);
184
setvar (cintern ("REG_ESPACE"), flocons (REG_ESPACE), NIL);
185
setvar (cintern ("REG_BADRPT"), flocons (REG_BADRPT), NIL);
187
setvar (cintern ("REG_ECHAR"), flocons (REG_ECHAR), NIL);
189
init_regex_version ();