fix possible crash on user deletion
[srvx.git] / rx / rxnode.h
1 /* classes: h_files */
2
3 #ifndef RXNODEH
4 #define RXNODEH
5 /*      Copyright (C) 1995, 1996 Tom Lord
6  * 
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Library General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Library General Public License for more details.
16  * 
17  * You should have received a copy of the GNU Library General Public License
18  * along with this software; see the file COPYING.  If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330, 
20  * Boston, MA 02111-1307, USA. 
21  */
22
23
24 \f
25 /*
26  * Tom Lord (lord@cygnus.com, lord@gnu.ai.mit.edu)
27  */
28
29 \f
30 #include "rxbitset.h"
31 #include "rxcset.h"
32
33 \f
34
35 enum rexp_node_type
36 {
37   r_cset = 0,                   /* Match from a character set. `a' or `[a-z]'*/
38   r_concat = 1,                 /* Concat two subexpressions.   `ab' */
39   r_alternate = 2,              /* Choose one of two subexpressions. `a\|b' */
40   r_opt = 3,                    /* Optional subexpression. `a?' */
41   r_star = 4,                   /* Repeated subexpression. `a*' */
42   r_plus = 5,                   /* Nontrivially repeated subexpression. `a+' */
43   r_string = 6,                 /* Shorthand for a concatenation of characters */
44   r_cut = 7,                    /* Generates a tagged, final nfa state. */
45
46   /* see RX_regular_node_type */
47
48   r_interval = 8,               /* Counted subexpression.  `a{4, 1000}' */
49   r_parens = 9,                 /* Parenthesized subexpression */
50   r_context = 10                /* Context-sensative operator such as "^" */
51 };
52
53 #define RX_regular_node_type(T)  ((T) <= r_interval)
54
55
56
57 struct rx_string
58 {
59   unsigned long len;
60   unsigned long reallen;
61   unsigned char *contents;
62 };
63
64 struct rexp_node
65 {
66   int refs;
67   enum rexp_node_type type;
68   struct
69   {
70     int cset_size;
71     rx_Bitset cset;
72     int intval;
73     int intval2;
74     struct
75       {
76         struct rexp_node *left;
77         struct rexp_node *right;
78       } pair;
79     struct rx_string cstr;
80   } params;
81   int id;
82   int len;
83   int observed;
84   struct rexp_node * simplified;
85   struct rx_cached_rexp * cr;
86 };
87
88
89 \f
90 #ifdef __STDC__
91 extern int rx_adjoin_string (struct rx_string *str, char c);
92 extern struct rexp_node * rexp_node (int type);
93 extern struct rexp_node * rx_mk_r_cset (int type, int size, rx_Bitset b);
94 extern struct rexp_node * rx_mk_r_int (int type, int intval);
95 extern struct rexp_node * rx_mk_r_str (int type, char c);
96 extern struct rexp_node * rx_mk_r_binop (int type, struct rexp_node * a, struct rexp_node * b);
97 extern struct rexp_node * rx_mk_r_monop (int type, struct rexp_node * a);
98 extern void rx_free_rexp (struct rexp_node * node);
99 extern void rx_save_rexp (struct rexp_node * node);
100 extern struct rexp_node * rx_copy_rexp (int cset_size, struct rexp_node *node);
101 extern struct rexp_node * rx_shallow_copy_rexp (int cset_size, struct rexp_node *node);
102 extern int rx_rexp_equal (struct rexp_node * a, struct rexp_node * b);
103 extern unsigned long rx_rexp_hash (struct rexp_node * node, unsigned long seed);
104
105 #else /* STDC */
106 extern int rx_adjoin_string ();
107 extern struct rexp_node * rexp_node ();
108 extern struct rexp_node * rx_mk_r_cset ();
109 extern struct rexp_node * rx_mk_r_int ();
110 extern struct rexp_node * rx_mk_r_str ();
111 extern struct rexp_node * rx_mk_r_binop ();
112 extern struct rexp_node * rx_mk_r_monop ();
113 extern void rx_free_rexp ();
114 extern void rx_save_rexp ();
115 extern struct rexp_node * rx_copy_rexp ();
116 extern struct rexp_node * rx_shallow_copy_rexp ();
117 extern int rx_rexp_equal ();
118 extern unsigned long rx_rexp_hash ();
119
120 #endif /* STDC */
121
122
123
124
125 #endif  /* RXNODEH */