]>
jfr.im git - irc/evilnet/x3.git/blob - rx/rxunfa.c
1 /* classes: src_files */
3 /* Copyright (C) 1995, 1996 Tom Lord
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this software; see the file COPYING. If not, write to
17 * the Free Software Foundation, 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
31 unfa_equal (void * va
, void * vb
)
39 return rx_rexp_equal ((struct rexp_node
*)va
, (struct rexp_node
*)vb
);
43 struct rx_hash_rules unfa_rules
= { unfa_equal
, 0, 0, 0, 0 };
47 static struct rx_cached_rexp
*
48 canonical_unfa (struct rx_hash
* table
, struct rexp_node
* rexp
, int cset_size
)
50 static struct rx_cached_rexp
*
51 canonical_unfa (table
, rexp
, cset_size
)
52 struct rx_hash
* table
;
53 struct rexp_node
* rexp
;
57 struct rx_hash_item
* it
;
58 it
= rx_hash_store (table
, rx_rexp_hash (rexp
, 0), rexp
, &unfa_rules
);
62 struct rx_cached_rexp
* cr
;
64 if (it
->data
== (void *)rexp
)
67 cr
= (struct rx_cached_rexp
*)malloc (sizeof (*cr
));
68 rx_bzero ((char *)cr
, sizeof (*cr
));
71 it
->binding
= (void *)cr
;
77 return (struct rx_cached_rexp
*)it
->binding
;
83 rx_unfa_rx (struct rx_cached_rexp
* cr
, struct rexp_node
* exp
, int cset_size
)
86 rx_unfa_rx (cr
, exp
, cset_size
)
87 struct rx_cached_rexp
* cr
;
88 struct rexp_node
* exp
;
97 new_rx
= rx_make_rx (cset_size
);
101 struct rx_nfa_state
* start
;
102 struct rx_nfa_state
* end
;
104 if (!rx_build_nfa (new_rx
, exp
, &start
, &end
))
109 new_rx
->start_nfa_states
= start
;
113 struct rx_nfa_state
* s
;
116 for (s
= new_rx
->nfa_states
; s
; s
= s
->next
)
120 cr
->unfa
.nfa
= new_rx
;
128 struct rx_unfaniverse
*
129 rx_make_unfaniverse (int delay
)
131 struct rx_unfaniverse
*
132 rx_make_unfaniverse (delay
)
136 struct rx_unfaniverse
* it
;
137 it
= (struct rx_unfaniverse
*)malloc (sizeof (*it
));
139 rx_bzero ((char *)it
, sizeof (*it
));
147 rx_free_unfaniverse (struct rx_unfaniverse
* it
)
150 rx_free_unfaniverse (it
)
151 struct rx_unfaniverse
* it
;
162 rx_unfa (struct rx_unfaniverse
* unfaniverse
, struct rexp_node
* exp
, int cset_size
)
165 rx_unfa (unfaniverse
, exp
, cset_size
)
166 struct rx_unfaniverse
* unfaniverse
;
167 struct rexp_node
* exp
;
171 struct rx_cached_rexp
* cr
;
176 cr
= canonical_unfa (&unfaniverse
->table
, exp
, cset_size
);
184 if (unfaniverse
->free_queue
== cr
)
186 unfaniverse
->free_queue
= cr
->next
;
187 if (unfaniverse
->free_queue
== cr
)
188 unfaniverse
->free_queue
= 0;
190 cr
->next
->prev
= cr
->prev
;
191 cr
->prev
->next
= cr
->next
;
194 --unfaniverse
->delayed
;
197 cr
->unfa
.cset_size
= cset_size
;
198 cr
->unfa
.verse
= unfaniverse
;
199 rx_unfa_rx (cr
, exp
, cset_size
);
206 rx_free_unfa (struct rx_unfa
* unfa
)
210 struct rx_unfa
* unfa
;
213 struct rx_cached_rexp
* cr
;
214 cr
= (struct rx_cached_rexp
*)unfa
;
217 if (!--cr
->unfa
.refs
)
219 if (!unfa
->verse
->free_queue
)
221 unfa
->verse
->free_queue
= cr
;
222 cr
->next
= cr
->prev
= cr
;
226 cr
->next
= unfa
->verse
->free_queue
;
227 cr
->prev
= unfa
->verse
->free_queue
->prev
;
232 ++unfa
->verse
->delayed
;
233 while (unfa
->verse
->delayed
> unfa
->verse
->delay
)
235 struct rx_cached_rexp
* it
;
236 it
= unfa
->verse
->free_queue
;
237 unfa
->verse
->free_queue
= it
->next
;
238 if (!--unfa
->verse
->delayed
)
239 unfa
->verse
->free_queue
= 0;
240 it
->prev
->next
= it
->next
;
241 it
->next
->prev
= it
->prev
;
243 it
->unfa
.exp
->cr
= 0;
244 rx_free_rexp ((struct rexp_node
*)it
->hash_item
->data
);
245 rx_hash_free (it
->hash_item
, &unfa_rules
);
246 rx_free_rx (it
->unfa
.nfa
);
247 rx_free_rexp (it
->unfa
.exp
);
260 rx_save_unfa (struct rx_unfa
* unfa
)
264 struct rx_unfa
* unfa
;