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 pool *mem = pool_create(256);
struct pool *mem = pool_create(10 * 1024);
struct rfilter *rf;
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]))
break;
if (cs->final && (!r || cs->final > r))
if (cs->final && (cs->final > r))
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,7 +172,7 @@ static int _get_token(struct parse_sp *ps)
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 *n = pool_zalloc(mem, sizeof(*n));
@ -197,7 +197,7 @@ static struct rx_node *_term(struct parse_sp *ps)
switch(ps->type) {
case 0:
if (!(n = _create_node(ps->mem, CHARSET, NULL, NULL))) {
if (!(n = _node(ps->mem, CHARSET, NULL, NULL))) {
stack;
return NULL;
}
@ -208,7 +208,7 @@ static struct rx_node *_term(struct parse_sp *ps)
case '(':
_get_token(ps); /* match '(' */
n = _expr(ps, 0);
n = _or_term(ps);
if(ps->type != ')') {
log_debug("missing ')' in regular expression");
return 0;
@ -230,17 +230,18 @@ static struct rx_node *_closure_term(struct parse_sp *ps)
if(!(l = _term(ps)))
return NULL;
for (;;) {
switch(ps->type) {
case '*':
n = _create_node(ps->mem, STAR, l, NULL);
n = _node(ps->mem, STAR, l, NULL);
break;
case '+':
n = _create_node(ps->mem, PLUS, l, NULL);
n = _node(ps->mem, PLUS, l, NULL);
break;
case '?':
n = _create_node(ps->mem, QUEST, l, NULL);
n = _node(ps->mem, QUEST, l, NULL);
break;
default:
@ -253,6 +254,9 @@ static struct rx_node *_closure_term(struct parse_sp *ps)
}
_get_token(ps);
l = n;
}
return n;
}
@ -264,72 +268,36 @@ static struct rx_node *_cat_term(struct parse_sp *ps)
return NULL;
if (ps->type == '|')
/* bail out */
return l;
/* catenate */
if (!(r = _cat_term(ps)))
return l;
if (!(n = _create_node(ps->mem, CAT, l, r))) {
if (!(n = _node(ps->mem, CAT, l, r)))
stack;
return NULL;
}
return n;
}
static struct rx_node *_expr(struct parse_sp *ps, struct rx_node *l)
static struct rx_node *_or_term(struct parse_sp *ps)
{
struct rx_node *n = 0;
while((ps->type >= 0) && (ps->type != ')')) {
struct rx_node *l, *r, *n;
if (!(n = _create_node(ps->mem, CAT, l, NULL))) {
stack;
if (!(l = _cat_term(ps)))
return NULL;
}
switch(ps->type) {
case 0:
case '(':
/* implicit catenation */
if(!l)
n = _cat_term(ps);
else
n->right = _cat_term(ps);
if (ps->type != '|')
return l;
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");
if (!(r = _or_term(ps))) {
log_info("badly formed 'or' expression");
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;
}
if (!(n = _node(ps->mem, OR, l, r)))
stack;
return n;
}
@ -338,21 +306,23 @@ struct rx_node *rx_parse_tok(struct pool *mem,
const char *begin, const char *end)
{
struct rx_node *r;
struct parse_sp *ps = pool_alloc(mem, sizeof(*ps));
struct parse_sp *ps = pool_zalloc(mem, sizeof(*ps));
if (!ps) {
stack;
return NULL;
}
memset(ps, 0, sizeof(*ps));
ps->mem = mem;
ps->charset = bitset_create(mem, 256);
ps->cursor = begin;
ps->rx_end = end;
_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);
}
return r;
}

View File

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