10
RS_isRegis(const char *str)
12
unsigned char *ptr = (unsigned char *) str;
15
if (isalpha(*ptr) || *ptr == '[' || *ptr == ']' || *ptr == '^')
23
#define RS_IN_ONEOF_IN 2
24
#define RS_IN_NONEOF 3
28
newRegisNode(RegisNode * prev, int len)
32
ptr = (RegisNode *) malloc(RNHDRSZ + len + 1);
34
ts_error(ERROR, "No memory");
35
memset(ptr, 0, RNHDRSZ + len + 1);
42
RS_compile(Regis * r, int issuffix, const char *str)
46
int state = RS_IN_WAIT;
47
RegisNode *ptr = NULL;
49
memset(r, 0, sizeof(Regis));
50
r->issuffix = (issuffix) ? 1 : 0;
52
for (i = 0; i < len; i++)
54
unsigned char c = *(((unsigned char *) str) + i);
56
if (state == RS_IN_WAIT)
61
ptr = newRegisNode(ptr, len);
63
ptr = r->node = newRegisNode(NULL, len);
65
ptr->type = RSF_ONEOF;
71
ptr = newRegisNode(ptr, len);
73
ptr = r->node = newRegisNode(NULL, len);
74
ptr->type = RSF_ONEOF;
78
ts_error(ERROR, "Error in regis: %s at pos %d\n", str, i + 1);
80
else if (state == RS_IN_ONEOF)
84
ptr->type = RSF_NONEOF;
91
state = RS_IN_ONEOF_IN;
94
ts_error(ERROR, "Error in regis: %s at pos %d\n", str, i + 1);
96
else if (state == RS_IN_ONEOF_IN || state == RS_IN_NONEOF)
100
ptr->data[ptr->len] = c;
106
ts_error(ERROR, "Error in regis: %s at pos %d\n", str, i + 1);
109
ts_error(ERROR, "Internal error in RS_compile: %d\n", state);
125
RegisNode *ptr = r->node,
139
RS_execute(Regis * r, const char *str, int len)
141
RegisNode *ptr = r->node;
151
c = ((unsigned char *) str) + len - r->nchar;
153
c = (unsigned char *) str;
162
if (*c != *(ptr->data))
165
else if (strchr((char *) ptr->data, *c) == NULL)
171
if (*c == *(ptr->data))
174
else if (strchr((char *) ptr->data, *c) != NULL)
178
ts_error(ERROR, "RS_execute: Unknown type node: %d\n", ptr->type);