X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=dfa%2Fbset.c;h=6ca49e43ce5a8da48e596db2e8a945c380207638;hp=db028324cfa80b3af25ec9f3f36630809f19f45b;hb=aeea139423b8eaf28a4de53b3d7b2ad1f22284e7;hpb=ead74d0c3b9d76204494553c61854812eb69bbc7 diff --git a/dfa/bset.c b/dfa/bset.c index db02832..6ca49e4 100644 --- a/dfa/bset.c +++ b/dfa/bset.c @@ -1,36 +1,48 @@ -/* - * Copyright (C) 1994, Index Data I/S - * All rights reserved. - * Sebastian Hammer, Adam Dickmeiss - * - * $Log: bset.c,v $ - * Revision 1.1 1994-09-26 10:16:53 adam - * First version of dfa module in alex. This version uses yacc to parse - * regular expressions. This should be hand-made instead. - * - */ +/* This file is part of the Zebra server. + Copyright (C) 1994-2011 Index Data + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#if HAVE_CONFIG_H +#include +#endif #include #include #include #include -#include +#include #include #include "imalloc.h" -#define GET_BIT(s,m) (s[(m)/(sizeof(BSetWord)*8)]&(1<<(m&(sizeof(BSetWord)*8-1)))) +#define GET_BIT(s,m) (s[(m)/(sizeof(BSetWord)*8)]&(1<<(m&(sizeof(BSetWord)*8-1)))) #define SET_BIT(s,m) (s[(m)/(sizeof(BSetWord)*8)]|=(1<<(m&(sizeof(BSetWord)*8-1)))) BSetHandle *mk_BSetHandle (int size, int chunk) { - int wsize = 1+size/(sizeof(BSetWord)*8); + int wsize = 1+size/(sizeof(BSetWord)*8); BSetHandle *sh; - if( chunk <= 1 ) + if (chunk <= 1) chunk = 32; - sh = (BSetHandle *) imalloc( sizeof(BSetHandle) + - chunk*sizeof(BSetWord)*wsize ); + sh = (BSetHandle *) imalloc (sizeof(BSetHandle) + + chunk*sizeof(BSetWord)*wsize); sh->size = size; sh->wsize = wsize; @@ -44,13 +56,13 @@ void rm_BSetHandle (BSetHandle **shp) { BSetHandle *sh, *sh1; - assert( shp ); + assert (shp); sh = *shp; - assert( sh ); - while( sh ) + assert (sh); + while (sh) { sh1 = sh->setchain; - ifree( sh ); + ifree (sh); sh = sh1; } } @@ -59,7 +71,7 @@ int inf_BSetHandle (BSetHandle *sh, long *used, long *allocated) { int wsize; - assert( sh ); + assert (sh); *used = 0; *allocated = 0; wsize = sh->wsize; @@ -67,7 +79,7 @@ int inf_BSetHandle (BSetHandle *sh, long *used, long *allocated) { *used += sh->offset; *allocated += sh->chunk; - } while( (sh = sh->setchain) ); + } while ((sh = sh->setchain)); return wsize; } @@ -75,15 +87,15 @@ BSet mk_BSet (BSetHandle **shp) { BSetHandle *sh, *sh1; unsigned off; - assert( shp ); + assert (shp); sh = *shp; - assert( sh ); + assert (sh); off = sh->offset; - if( (off + sh->wsize) > sh->chunk ) + if ((off + sh->wsize) > sh->chunk) { - sh1 = (BSetHandle *) imalloc( sizeof(BSetHandle ) + - sh->chunk*sizeof(BSetWord) ); + sh1 = (BSetHandle *) imalloc (sizeof(BSetHandle) + + sh->chunk*sizeof(BSetWord)); sh1->size = sh->size; sh1->wsize = sh->wsize; sh1->chunk = sh->chunk; @@ -97,42 +109,42 @@ BSet mk_BSet (BSetHandle **shp) void add_BSet (BSetHandle *sh, BSet dst, unsigned member) { - assert( dst ); - assert( sh ); - assert( member <= sh->size ); + assert (dst); + assert (sh); + assert (member <= sh->size); SET_BIT(dst, member); } unsigned test_BSet (BSetHandle *sh, BSet src, unsigned member) { - assert( src ); - assert( sh ); - assert( member <= sh->size ); - return GET_BIT( src , member) != 0; + assert (src); + assert (sh); + assert (member <= sh->size); + return GET_BIT (src , member) != 0; } BSet cp_BSet (BSetHandle *sh, BSet dst, BSet src) { - assert( sh ); - assert( dst ); - assert( src ); - memcpy( dst, src, sh->wsize * sizeof(BSetWord)); + assert (sh); + assert (dst); + assert (src); + memcpy (dst, src, sh->wsize * sizeof(BSetWord)); return dst; } void res_BSet (BSetHandle *sh, BSet dst) { - assert( dst ); - memset( dst, 0, sh->wsize * sizeof(BSetWord)); + assert (dst); + memset (dst, 0, sh->wsize * sizeof(BSetWord)); } void union_BSet (BSetHandle *sh, BSet dst, BSet src) { int i; - assert( sh ); - assert( dst ); - assert( src ); - for( i=sh->wsize; --i >= 0; ) + assert (sh); + assert (dst); + assert (src); + for (i=sh->wsize; --i >= 0;) *dst++ |= *src++; } @@ -140,9 +152,9 @@ unsigned hash_BSet (BSetHandle *sh, BSet src) { int i; unsigned s = 0; - assert( sh ); - assert( src ); - for( i=sh->wsize; --i >= 0; ) + assert (sh); + assert (src); + for (i=sh->wsize; --i >= 0;) s += *src++; return s; } @@ -150,20 +162,20 @@ unsigned hash_BSet (BSetHandle *sh, BSet src) void com_BSet (BSetHandle *sh, BSet dst) { int i; - assert( sh ); - assert( dst ); - for( i=sh->wsize; --i >= 0; dst++ ) + assert (sh); + assert (dst); + for (i=sh->wsize; --i >= 0; dst++) *dst = ~*dst; } int eq_BSet (BSetHandle *sh, BSet dst, BSet src) { int i; - assert( sh ); - assert( dst ); - assert( src ); - for( i=sh->wsize; --i >= 0; ) - if( *dst++ != *src++ ) + assert (sh); + assert (dst); + assert (src); + for (i=sh->wsize; --i >= 0;) + if (*dst++ != *src++) return 0; return 1; } @@ -174,19 +186,19 @@ int trav_BSet (BSetHandle *sh, BSet src, unsigned member) BSetWord *sw = src+member/(sizeof(BSetWord)*8); unsigned b = member & (sizeof(BSetWord)*8-1); while(i >= 0) - if( b == 0 && *sw == 0 ) + if (b == 0 && *sw == 0) { member += sizeof(BSetWord)*8; ++sw; i -= sizeof(BSetWord)*8; } - else if( *sw & (1<= 0) - if( b == 0 && *sw == (BSetWord) ~ 0 ) + if (b == 0 && *sw == (BSetWord) ~ 0) { member += sizeof(BSetWord)*8; ++sw; i -= sizeof(BSetWord)*8; } - else if( (*sw & (1<