* re.c - compile regular expressions.
* Copyright (C) 1991, 1992 the Free Software Foundation, Inc.
* This file is part of GAWK, the GNU implementation of the
* AWK Progamming Language.
* GAWK is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* GAWK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with GAWK; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
/* Generate compiled regular expressions */
make_regexp(s
, len
, ignorecase
, dfa
)
/* Handle escaped characters first. */
/* Build a copy of the string (in dest) with the
escaped characters translated, and generate the regex
emalloc(dest
, char *, len
+ 2, "make_regexp");
*dest
++ = *src
++; /* not '\\' */
*dest
= '\0' ; /* Only necessary if we print dest ? */
emalloc(rp
, Regexp
*, sizeof(*rp
), "make_regexp");
memset((char *) rp
, 0, sizeof(*rp
));
emalloc(rp
->pat
.buffer
, char *, 16, "make_regexp");
emalloc(rp
->pat
.fastmap
, char *, 256, "make_regexp");
rp
->pat
.translate
= casetable
;
rp
->pat
.translate
= NULL
;
if ((err
= re_compile_pattern(temp
, (size_t) len
, &(rp
->pat
))) != NULL
)
fatal("%s: /%s/", err
, temp
);
if (dfa
&& !ignorecase
) {
regcompile(temp
, len
, &(rp
->dfareg
), 1);
research(rp
, str
, start
, len
, need_start
)
save2
= str
[start
+len
+1];
ret
= regexecute(&(rp
->dfareg
), str
+start
, str
+start
+len
+1, 1,
str
[start
+len
+1] = save2
;
if (need_start
|| rp
->dfa
== 0)
return re_search(&(rp
->pat
), str
, start
+len
, start
,
if ((t
->re_flags
& CASE
) == IGNORECASE
) {
t1
= force_string(tree_eval(t
->re_exp
));
if (cmp_nodes(t
->re_text
, t1
) == 0) {
t
->re_text
= dupnode(t1
);
t1
= force_string(tree_eval(t
->re_exp
));
t
->re_text
= dupnode(t1
);
t
->re_reg
= make_regexp(t
->re_text
->stptr
, t
->re_text
->stlen
, IGNORECASE
, t
->re_cnt
);
t
->re_flags
|= IGNORECASE
;
(void) re_set_syntax(RE_SYNTAX_AWK
);
regsyntax(RE_SYNTAX_AWK
, 0);