1 | /* Copyright (C) 1995, 1996 Tom Lord |
---|
2 | * |
---|
3 | * This program is free software; you can redistribute it and/or modify |
---|
4 | * it under the terms of the GNU Library General Public License as published by |
---|
5 | * the Free Software Foundation; either version 2, or (at your option) |
---|
6 | * any later version. |
---|
7 | * |
---|
8 | * This program is distributed in the hope that it will be useful, |
---|
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | * GNU Library General Public License for more details. |
---|
12 | * |
---|
13 | * You should have received a copy of the GNU Library General Public License |
---|
14 | * along with this software; see the file COPYING. If not, write to |
---|
15 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
---|
16 | * Boston, MA 02111-1307, USA. |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | #include "rxall.h" |
---|
22 | #include "rxbasic.h" |
---|
23 | #include "rxstr.h" |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | int rx_basic_unfaniverse_delay = RX_DEFAULT_NFA_DELAY; |
---|
29 | static struct rx_unfaniverse * rx_basic_uv = 0; |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | static int |
---|
34 | init_basic_once () |
---|
35 | { |
---|
36 | if (rx_basic_uv) |
---|
37 | return 0; |
---|
38 | rx_basic_uv = rx_make_unfaniverse (rx_basic_unfaniverse_delay); |
---|
39 | return (rx_basic_uv ? 0 : -1); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | #ifdef __STDC__ |
---|
44 | struct rx_unfaniverse * |
---|
45 | rx_basic_unfaniverse (void) |
---|
46 | #else |
---|
47 | struct rx_unfaniverse * |
---|
48 | rx_basic_unfaniverse () |
---|
49 | #endif |
---|
50 | { |
---|
51 | if (init_basic_once ()) |
---|
52 | return 0; |
---|
53 | return rx_basic_uv; |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | static char * silly_hack = 0; |
---|
58 | |
---|
59 | #ifdef __STDC__ |
---|
60 | struct rx_solutions * |
---|
61 | rx_basic_make_solutions (struct rx_registers * regs, struct rexp_node * expression, struct rexp_node ** subexps, int start, int end, struct rx_context_rules * rules, const unsigned char * str) |
---|
62 | #else |
---|
63 | struct rx_solutions * |
---|
64 | rx_basic_make_solutions (regs, expression, subexps, start, end, rules, str) |
---|
65 | struct rx_registers * regs; |
---|
66 | struct rexp_node * expression; |
---|
67 | struct rexp_node ** subexps; |
---|
68 | int start; |
---|
69 | int end; |
---|
70 | struct rx_context_rules * rules; |
---|
71 | const unsigned char * str; |
---|
72 | #endif |
---|
73 | { |
---|
74 | struct rx_str_closure * closure; |
---|
75 | if (init_basic_once ()) |
---|
76 | return 0; /* bogus but rare */ |
---|
77 | if ( expression |
---|
78 | && (expression->len >= 0) |
---|
79 | && (expression->len != (end - start))) |
---|
80 | return &rx_no_solutions; |
---|
81 | if (silly_hack) |
---|
82 | { |
---|
83 | closure = (struct rx_str_closure *)silly_hack; |
---|
84 | silly_hack = 0; |
---|
85 | } |
---|
86 | else |
---|
87 | closure = (struct rx_str_closure *)malloc (sizeof (*closure)); |
---|
88 | if (!closure) |
---|
89 | return 0; |
---|
90 | closure->str = str; |
---|
91 | closure->len = end; |
---|
92 | closure->rules = *rules; |
---|
93 | return rx_make_solutions (regs, rx_basic_uv, expression, subexps, 256, |
---|
94 | start, end, rx_str_vmfn, rx_str_contextfn, |
---|
95 | (void *)closure); |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | #ifdef __STDC__ |
---|
101 | void |
---|
102 | rx_basic_free_solutions (struct rx_solutions * solns) |
---|
103 | #else |
---|
104 | void |
---|
105 | rx_basic_free_solutions (solns) |
---|
106 | struct rx_solutions * solns; |
---|
107 | #endif |
---|
108 | { |
---|
109 | if (solns == &rx_no_solutions) |
---|
110 | return; |
---|
111 | |
---|
112 | if (!silly_hack) |
---|
113 | silly_hack = (char *)solns->closure; |
---|
114 | else |
---|
115 | free (solns->closure); |
---|
116 | solns->closure = 0; |
---|
117 | rx_free_solutions (solns); |
---|
118 | } |
---|