1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

o tidying

This commit is contained in:
Joe Thornber 2001-10-21 10:24:10 +00:00
parent 291ec3b6c0
commit 98af757b00
4 changed files with 60 additions and 96 deletions

View File

@ -169,7 +169,7 @@ static void _destroy(struct dev_filter *f)
struct dev_filter *regex_filter_create(struct config_value *patterns) struct dev_filter *regex_filter_create(struct config_value *patterns)
{ {
struct pool *mem = pool_create(256); struct pool *mem = pool_create(10 * 1024);
struct rfilter *rf; struct rfilter *rf;
struct dev_filter *f; struct dev_filter *f;

View File

@ -340,7 +340,7 @@ int matcher_run(struct matcher *m, const char *b)
if (!(cs = cs->lookup[(int) (unsigned char) *b])) if (!(cs = cs->lookup[(int) (unsigned char) *b]))
break; break;
if (cs->final && (!r || cs->final > r)) if (cs->final && (cs->final > r))
r = cs->final; r = cs->final;
} }

View File

@ -22,7 +22,7 @@ struct parse_sp { /* scratch pad for the parsing process */
}; };
static struct rx_node *_expr(struct parse_sp *ps, struct rx_node *l); static struct rx_node *_or_term(struct parse_sp *ps);
/* /*
@ -172,8 +172,8 @@ static int _get_token(struct parse_sp *ps)
return 1; return 1;
} }
static struct rx_node *_create_node(struct pool *mem, int type, static struct rx_node *_node(struct pool *mem, int type,
struct rx_node *l, struct rx_node *r) struct rx_node *l, struct rx_node *r)
{ {
struct rx_node *n = pool_zalloc(mem, sizeof(*n)); struct rx_node *n = pool_zalloc(mem, sizeof(*n));
@ -197,7 +197,7 @@ static struct rx_node *_term(struct parse_sp *ps)
switch(ps->type) { switch(ps->type) {
case 0: case 0:
if (!(n = _create_node(ps->mem, CHARSET, NULL, NULL))) { if (!(n = _node(ps->mem, CHARSET, NULL, NULL))) {
stack; stack;
return NULL; return NULL;
} }
@ -208,7 +208,7 @@ static struct rx_node *_term(struct parse_sp *ps)
case '(': case '(':
_get_token(ps); /* match '(' */ _get_token(ps); /* match '(' */
n = _expr(ps, 0); n = _or_term(ps);
if(ps->type != ')') { if(ps->type != ')') {
log_debug("missing ')' in regular expression"); log_debug("missing ')' in regular expression");
return 0; return 0;
@ -230,29 +230,33 @@ static struct rx_node *_closure_term(struct parse_sp *ps)
if(!(l = _term(ps))) if(!(l = _term(ps)))
return NULL; return NULL;
switch(ps->type) { for (;;) {
case '*': switch(ps->type) {
n = _create_node(ps->mem, STAR, l, NULL); case '*':
break; n = _node(ps->mem, STAR, l, NULL);
break;
case '+': case '+':
n = _create_node(ps->mem, PLUS, l, NULL); n = _node(ps->mem, PLUS, l, NULL);
break; break;
case '?': case '?':
n = _create_node(ps->mem, QUEST, l, NULL); n = _node(ps->mem, QUEST, l, NULL);
break; break;
default: default:
return l; return l;
}
if (!n) {
stack;
return NULL;
}
_get_token(ps);
l = n;
} }
if (!n) {
stack;
return NULL;
}
_get_token(ps);
return n; return n;
} }
@ -264,95 +268,61 @@ static struct rx_node *_cat_term(struct parse_sp *ps)
return NULL; return NULL;
if (ps->type == '|') if (ps->type == '|')
/* bail out */
return l; return l;
/* catenate */
if (!(r = _cat_term(ps))) if (!(r = _cat_term(ps)))
return l; return l;
if (!(n = _create_node(ps->mem, CAT, l, r))) { if (!(n = _node(ps->mem, CAT, l, r)))
stack; stack;
return n;
}
static struct rx_node *_or_term(struct parse_sp *ps)
{
struct rx_node *l, *r, *n;
if (!(l = _cat_term(ps)))
return NULL;
if (ps->type != '|')
return l;
_get_token(ps); /* match '|' */
if (!(r = _or_term(ps))) {
log_info("badly formed 'or' expression");
return NULL; return NULL;
} }
return n; if (!(n = _node(ps->mem, OR, l, r)))
} stack;
static struct rx_node *_expr(struct parse_sp *ps, struct rx_node *l)
{
struct rx_node *n = 0;
while((ps->type >= 0) && (ps->type != ')')) {
if (!(n = _create_node(ps->mem, CAT, l, NULL))) {
stack;
return NULL;
}
switch(ps->type) {
case 0:
case '(':
/* implicit catenation */
if(!l)
n = _cat_term(ps);
else
n->right = _cat_term(ps);
break;
case '|':
/* 'or' */
if(!l) {
log_debug("badly formed '|' expression");
return 0;
}
n->type = OR;
_get_token(ps); /* match '|' */
n->right = _cat_term(ps);
break;
default:
log_debug("unexpected token");
return 0;
}
if(!n) {
log_err("parse error in regex");
return NULL;
}
if((n->type != CHARSET) && !n->left) {
log_debug("badly formed regex");
ps->type = -1;
ps->cursor = ps->rx_end;
return 0;
}
l = n;
}
return n; return n;
} }
struct rx_node *rx_parse_tok(struct pool *mem, struct rx_node *rx_parse_tok(struct pool *mem,
const char *begin, const char *end) const char *begin, const char *end)
{ {
struct rx_node *r; struct rx_node *r;
struct parse_sp *ps = pool_alloc(mem, sizeof(*ps)); struct parse_sp *ps = pool_zalloc(mem, sizeof(*ps));
if (!ps) { if (!ps) {
stack; stack;
return NULL; return NULL;
} }
memset(ps, 0, sizeof(*ps));
ps->mem = mem; ps->mem = mem;
ps->charset = bitset_create(mem, 256); ps->charset = bitset_create(mem, 256);
ps->cursor = begin; ps->cursor = begin;
ps->rx_end = end; ps->rx_end = end;
_get_token(ps); /* load the first token */ _get_token(ps); /* load the first token */
if (!(r = _expr(ps, NULL)))
if (!(r = _or_term(ps))) {
log_err("parse error in regex");
pool_free(mem, ps); pool_free(mem, ps);
}
return r; return r;
} }

View File

@ -8,8 +8,6 @@
#include "pool.h" #include "pool.h"
#include "log.h" #include "log.h"
#include <stdlib.h>
struct node { struct node {
unsigned k; unsigned k;
struct node *l, *m, *r; struct node *l, *m, *r;
@ -44,19 +42,16 @@ void *ttree_lookup(struct ttree *tt, unsigned *key)
{ {
struct node **c = &tt->root; struct node **c = &tt->root;
int count = tt->klen; int count = tt->klen;
unsigned int k;
while (*c && count) { while (*c && count) {
k = *key++; c = _lookup_single(c, *key++);
count--; count--;
c = _lookup_single(c, k);
} }
return *c ? (*c)->data : NULL; return *c ? (*c)->data : NULL;
} }
static struct node *_create_node(struct pool *mem, unsigned int k) static struct node *_node(struct pool *mem, unsigned int k)
{ {
struct node *n = pool_zalloc(mem, sizeof(*n)); struct node *n = pool_zalloc(mem, sizeof(*n));
@ -74,16 +69,15 @@ int ttree_insert(struct ttree *tt, unsigned int *key, void *data)
while (*c && count) { while (*c && count) {
k = *key++; k = *key++;
count--;
c = _lookup_single(c, k); c = _lookup_single(c, k);
count--;
} }
if (!*c) { if (!*c) {
count++; count++;
while (count--) { while (count--) {
if (!(*c = _create_node(tt->mem, k))) { if (!(*c = _node(tt->mem, k))) {
stack; stack;
return 0; return 0;
} }