2
* re.c - compile regular expressions.
6
* Copyright (C) 1991 the Free Software Foundation, Inc.
8
* This file is part of GAWK, the GNU implementation of the
9
* AWK Progamming Language.
11
* GAWK is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 1, or (at your option)
16
* GAWK is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with GAWK; see the file COPYING. If not, write to
23
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28
/* Generate compiled regular expressions */
30
make_regexp(s, ignorecase, dfa)
38
emalloc(rp, Regexp *, sizeof(*rp), "make_regexp");
39
memset((char *) rp, 0, sizeof(*rp));
40
emalloc(rp->pat.buffer, char *, 16, "make_regexp");
41
rp->pat.allocated = 16;
42
emalloc(rp->pat.fastmap, char *, 256, "make_regexp");
45
rp->pat.translate = casetable;
47
rp->pat.translate = NULL;
48
if ((err = re_compile_pattern(s->stptr, (size_t) s->stlen, &(rp->pat))) != NULL)
49
fatal("%s: /%s/", err, s->stptr);
50
if (dfa && !ignorecase) {
51
regcompile(s->stptr, s->stlen, &(rp->dfareg), 1);
60
research(rp, str, len, need_start)
76
ret = regexecute(&(rp->dfareg), str, str+len+1, 0, &count,
82
if (need_start || rp->dfa == 0)
83
return re_search(&(rp->pat), str, len, 0, len, &(rp->regs));
95
free(rp->pat.fastmap);
97
regfree(&(rp->dfareg));
115
if ((t->re_flags & CASE) == IGNORECASE) {
116
if (t->re_flags & CONST)
118
t1 = force_string(tree_eval(t->re_exp));
120
if (cmp_nodes(t->re_text, t1) == 0) {
126
t->re_text = dupnode(t1);
136
t1 = force_string(tree_eval(t->re_exp));
137
t->re_text = dupnode(t1);
140
t->re_reg = make_regexp(t->re_text, IGNORECASE, t->re_cnt);
141
t->re_flags &= ~CASE;
142
t->re_flags |= IGNORECASE;