1
/* Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal. All Rights Reserved. */
1
2
/* this file contains various utility functions for accessing
2
3
and manipulating regular expression syntax trees. */
7
9
/************************************************************************/
19
node = (Stack) new_node(node);
20
if (s == NULL || node == NULL) return NULL; /* can't allocate */
23
if (*s == NULL) node->size = 1;
24
else node->size = (*s)->size + 1;
21
new_node(Stack, node, node);
22
if (s == NULL || node == NULL) return NULL; /* can't allocate */
25
if (*s == NULL) node->size = 1;
26
else node->size = (*s)->size + 1;
35
if (s == NULL || *s == NULL) return NULL;
37
if (s == NULL || *s == NULL) return NULL;
48
if (s == NULL) return NULL;
50
if (s == NULL) return NULL;
55
if (s == NULL) return 0;
57
if (s == NULL) return 0;
59
61
/************************************************************************/
70
if (n == p->posnum) return 1;
72
if (n == p->posnum) return 1;
75
77
/* pset_union() takes two position-sets and returns their union. */
77
Pset pset_union(s1, s2)
79
Pset pset_union(s1, s2, dontreplicate)
83
hd = NULL; curr = NULL;
85
if (!occurs_in(s1->posnum, s2)) {
86
new = (Pset) new_node(new);
87
if (new == NULL) return NULL;
88
new->posnum = s1->posnum;
89
if (hd == NULL) hd = new;
90
else curr->nextpos = new;
95
if (hd == NULL) hd = s2;
96
else curr->nextpos = s2;
83
Pset hd, curr, new = NULL;
84
Pset replicas2 = NULL, temps2 = s2; /* code added: 26/Aug/96 */
86
/* Code added on 26/Aug/96 */
87
if (dontreplicate) replicas2 = s2;
88
else while (temps2 != NULL) {
89
new_node(Pset, new, new);
90
if (new == NULL) return NULL;
91
new->posnum = temps2->posnum;
92
if (replicas2 == NULL) replicas2 = new;
93
else curr->nextpos = new;
95
temps2 = temps2->nextpos;
101
if (!occurs_in(s1->posnum, s2)) {
102
new_node(Pset, new, new);
103
if (new == NULL) return NULL;
104
new->posnum = s1->posnum;
105
if (hd == NULL) hd = new;
106
else curr->nextpos = new;
111
if (hd == NULL) hd = replicas2; /* changed from s2: 26/Aug/96 */
112
else curr->nextpos = replicas2; /* changed from s2: 26/Aug/96 */
100
116
/* create_pos() creates a position node with the position value given,
103
119
Pset create_pos(n)
108
x = (Pset) new_node(x);
109
if (x == NULL) return NULL;
124
new_node(Pset, x, x);
125
if (x == NULL) return NULL;
115
131
/* eq_pset() takes two position sets and checks to see if they are
116
132
equal. It returns 1 if the sets are equal, 0 if they are not. */
118
134
subset_pset(s1, s2)
123
while (s1 != NULL && subs != 0) {
125
while (s2 != NULL && subs != 1)
126
if (s1->posnum == s2->posnum) subs = 1;
127
else s2 = s2->nextpos;
139
while (s1 != NULL && subs != 0) {
141
while (s2 != NULL && subs != 1)
142
if (s1->posnum == s2->posnum) subs = 1;
143
else s2 = s2->nextpos;
133
149
int eq_pset(s1, s2)
136
return subset_pset(s1, s2) && subset_pset(s2, s1);
152
return subset_pset(s1, s2) && subset_pset(s2, s1);
156
word_exists(word, wordlen, line, linelen)
157
unsigned char *word, *line;
158
int wordlen, linelen;
160
unsigned char oldchar, *lineend = line+linelen;
164
while(line<lineend) {
165
if (!isalnum(line[i])) {
168
if (!strncmp(line, word, wordlen)) {