-/* $Id: dfa.c,v 1.35 2006-05-10 08:13:18 adam Exp $
- Copyright (C) 1995-2005
+/* $Id: dfa.c,v 1.40 2007-01-15 15:10:15 adam Exp $
+ Copyright (C) 1995-2007
Index Data ApS
This file is part of the Zebra server.
for more details.
You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
*/
#include "dfap.h"
#include "imalloc.h"
-#define DFA_OPEN_RANGE 1
-
#define CAT 16000
#define OR 16001
#define STAR 16002
static int read_charset (struct DFA_parse *parse_info)
{
- int i, ch0, ch1, esc0, esc1, cc = 0;
+ int i, ch0, esc0, cc = 0;
parse_info->look_chars = mk_BSet (&parse_info->charset);
res_BSet (parse_info->charset, parse_info->look_chars);
cc = 1;
ch0 = nextchar_set (parse_info, &esc0);
}
+ /**
+ ch0 is last met character
+ ch1 is "next" char
+ */
while (ch0 != 0)
{
+ int ch1, esc1;
if (!esc0 && ch0 == ']')
break;
if (!esc0 && ch0 == '-')
}
else
{
- if (parse_info->cmap)
- {
- const char **mapto;
- char mapfrom[2];
- const char *mcp = mapfrom;
- mapfrom[0] = ch0;
- mapto = (*parse_info->cmap)(parse_info->cmap_data, &mcp, 1);
- assert (mapto);
- ch0 = mapto[0][0];
- }
+ if (ch0 == 1)
+ {
+ ch0 = nextchar(parse_info, &esc0);
+ }
+ else
+ {
+ if (parse_info->cmap)
+ {
+ const char **mapto;
+ char mapfrom[2];
+ const char *mcp = mapfrom;
+ mapfrom[0] = ch0;
+ mapto = parse_info->cmap(parse_info->cmap_data, &mcp, 1);
+ assert (mapto);
+ ch0 = mapto[0][0];
+ }
+ }
add_BSet (parse_info->charset, parse_info->look_chars, ch0);
ch1 = nextchar_set (parse_info, &esc1);
}
int open_range = 0;
if ((ch1 = nextchar_set (parse_info, &esc1)) == 0)
break;
-#if DFA_OPEN_RANGE
if (!esc1 && ch1 == ']')
{
ch1 = 255;
open_range = 1;
}
-#else
- if (!esc1 && ch1 == ']')
+ else if (ch1 == 1)
{
- add_BSet (parse_info->charset, parse_info->look_chars, '-');
- break;
+ ch1 = nextchar(parse_info, &esc1);
}
-#endif
- if (!open_range && parse_info->cmap)
+ else if (parse_info->cmap)
{
const char **mapto;
char mapfrom[2];
assert (mapto);
ch1 = mapto[0][0];
}
- for (i=ch0; ++i<=ch1;)
+ for (i = ch0; ++i <= ch1;)
add_BSet (parse_info->charset, parse_info->look_chars, i);
- if (!open_range)
- ch0 = nextchar_set (parse_info, &esc0);
- else
+
+ if (open_range)
break;
+ ch0 = nextchar_set (parse_info, &esc0);
}
else
{
{
long i, j;
int k;
- printf ("%d/%d tree nodes used, %d bytes each\n",
- parse_info->use_Tnode, parse_info->max_Tnode, sizeof (struct Tnode));
+ printf ("%d/%d tree nodes used, %ld bytes each\n",
+ parse_info->use_Tnode, parse_info->max_Tnode, (long) sizeof (struct Tnode));
k = inf_BSetHandle (parse_info->charset, &i, &j);
- printf ("%ld/%ld character sets, %d bytes each\n",
- i/k, j/k, k*sizeof(BSetWord));
+ printf ("%ld/%ld character sets, %ld bytes each\n",
+ i/k, j/k, (long) k*sizeof(BSetWord));
k = inf_DFASetType (parse_info->poset, &i, &j);
printf ("%ld/%ld poset items, %d bytes each\n", i, j, k);
printf ("%d DFA states\n", dfas->no);
dfa->parse_info->cmap_data = vp;
}
+int dfa_get_last_rule (struct DFA *dfa)
+{
+ return dfa->parse_info->rule;
+}
+
int dfa_parse (struct DFA *dfa, const char **pattern)
{
struct Tnode *top;