summaryrefslogtreecommitdiffstats
path: root/lib/regex/matcher.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/regex/matcher.c')
-rw-r--r--lib/regex/matcher.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/lib/regex/matcher.c b/lib/regex/matcher.c
index 95f7765f..8a607463 100644
--- a/lib/regex/matcher.c
+++ b/lib/regex/matcher.c
@@ -25,7 +25,7 @@ struct state_queue {
struct state_queue *next;
};
-struct matcher { /* Instance variables for the lexer */
+struct matcher { /* Instance variables for the lexer */
struct dfa_state *start;
int num_nodes, nodes_entered;
struct rx_node **nodes;
@@ -38,10 +38,10 @@ static int _count_nodes(struct rx_node *rx)
{
int r = 1;
- if(rx->left)
+ if (rx->left)
r += _count_nodes(rx->left);
- if(rx->right)
+ if (rx->right)
r += _count_nodes(rx->right);
return r;
@@ -51,10 +51,10 @@ static void _fill_table(struct matcher *m, struct rx_node *rx)
{
assert((rx->type != OR) || (rx->left && rx->right));
- if(rx->left)
+ if (rx->left)
_fill_table(m, rx->left);
- if(rx->right)
+ if (rx->right)
_fill_table(m, rx->right);
m->nodes[m->nodes_entered++] = rx;
@@ -64,7 +64,7 @@ static void _create_bitsets(struct matcher *m)
{
int i;
- for(i = 0; i < m->num_nodes; i++) {
+ for (i = 0; i < m->num_nodes; i++) {
struct rx_node *n = m->nodes[i];
n->firstpos = bitset_create(m->scratch, m->num_nodes);
n->lastpos = bitset_create(m->scratch, m->num_nodes);
@@ -77,23 +77,23 @@ static void _calc_functions(struct matcher *m)
int i, j, final = 1;
struct rx_node *rx, *c1, *c2;
- for(i = 0; i < m->num_nodes; i++) {
+ for (i = 0; i < m->num_nodes; i++) {
rx = m->nodes[i];
c1 = rx->left;
c2 = rx->right;
- if(bit(rx->charset, TARGET_TRANS))
+ if (bit(rx->charset, TARGET_TRANS))
rx->final = final++;
- switch(rx->type) {
+ switch (rx->type) {
case CAT:
- if(c1->nullable)
+ if (c1->nullable)
bit_union(rx->firstpos,
c1->firstpos, c2->firstpos);
else
bit_copy(rx->firstpos, c1->firstpos);
- if(c2->nullable)
+ if (c2->nullable)
bit_union(rx->lastpos,
c1->lastpos, c2->lastpos);
else
@@ -136,10 +136,10 @@ static void _calc_functions(struct matcher *m)
* because PLUS and STAR do the
* same thing.
*/
- switch(rx->type) {
+ switch (rx->type) {
case CAT:
- for(j = 0; j < m->num_nodes; j++) {
- if(bit(c1->lastpos, j)) {
+ for (j = 0; j < m->num_nodes; j++) {
+ if (bit(c1->lastpos, j)) {
struct rx_node *n = m->nodes[j];
bit_union(n->followpos,
n->followpos, c2->firstpos);
@@ -149,8 +149,8 @@ static void _calc_functions(struct matcher *m)
case PLUS:
case STAR:
- for(j = 0; j < m->num_nodes; j++) {
- if(bit(rx->lastpos, j)) {
+ for (j = 0; j < m->num_nodes; j++) {
+ if (bit(rx->lastpos, j)) {
struct rx_node *n = m->nodes[j];
bit_union(n->followpos,
n->followpos, rx->firstpos);
@@ -178,7 +178,7 @@ static struct state_queue *_create_state_queue(struct pool *mem,
}
r->s = dfa;
- r->bits = bitset_create(mem, bits[0]); /* first element is the size */
+ r->bits = bitset_create(mem, bits[0]); /* first element is the size */
bit_copy(r->bits, bits);
r->next = 0;
return r;
@@ -218,28 +218,30 @@ static int _calc_states(struct matcher *m, struct rx_node *rx)
/* iterate through all the inputs for this state */
bit_clear_all(bs);
- for(a = 0; a < 256; a++) {
+ for (a = 0; a < 256; a++) {
/* iterate through all the states in firstpos */
- for(i = bit_get_first(dfa_bits);
- i >=0;
- i = bit_get_next(dfa_bits, i)) {
- if(bit(m->nodes[i]->charset, a)) {
- if(a == TARGET_TRANS)
+ for (i = bit_get_first(dfa_bits);
+ i >= 0; i = bit_get_next(dfa_bits, i)) {
+ if (bit(m->nodes[i]->charset, a)) {
+ if (a == TARGET_TRANS)
dfa->final = m->nodes[i]->final;
- bit_union(bs, bs, m->nodes[i]->followpos);
+ bit_union(bs, bs,
+ m->nodes[i]->followpos);
set_bits = 1;
}
}
- if(set_bits) {
+ if (set_bits) {
ldfa = ttree_lookup(tt, bs + 1);
- if(!ldfa) {
+ if (!ldfa) {
/* push */
ldfa = _create_dfa_state(m->mem);
ttree_insert(tt, bs + 1, ldfa);
- tmp = _create_state_queue(m->scratch, ldfa, bs);
- if(!h)
+ tmp =
+ _create_state_queue(m->scratch,
+ ldfa, bs);
+ if (!h)
h = t = tmp;
else {
t->next = tmp;
@@ -260,8 +262,7 @@ static int _calc_states(struct matcher *m, struct rx_node *rx)
return 1;
}
-struct matcher *matcher_create(struct pool *mem,
- const char **patterns, int num)
+struct matcher *matcher_create(struct pool *mem, const char **patterns, int num)
{
char *all, *ptr;
int i, len = 0;
@@ -282,7 +283,7 @@ struct matcher *matcher_create(struct pool *mem,
memset(m, 0, sizeof(*m));
/* join the regexps together, delimiting with zero */
- for(i = 0; i < num; i++)
+ for (i = 0; i < num; i++)
len += strlen(patterns[i]) + 8;
ptr = all = pool_alloc(scratch, len + 1);
@@ -292,15 +293,14 @@ struct matcher *matcher_create(struct pool *mem,
goto bad;
}
- for(i = 0; i < num; i++) {
- ptr += sprintf(ptr, "(.*(%s)%c)", patterns[i],
- TARGET_TRANS);
- if(i < (num - 1))
+ for (i = 0; i < num; i++) {
+ ptr += sprintf(ptr, "(.*(%s)%c)", patterns[i], TARGET_TRANS);
+ if (i < (num - 1))
*ptr++ = '|';
}
/* parse this expression */
- if(!(rx = rx_parse_tok(scratch, all, ptr))) {
+ if (!(rx = rx_parse_tok(scratch, all, ptr))) {
log_error("Couldn't parse regex");
goto bad;
}
@@ -324,7 +324,7 @@ struct matcher *matcher_create(struct pool *mem,
return m;
- bad:
+ bad:
pool_destroy(scratch);
pool_destroy(mem);
return NULL;