Bump year. Change Aps->ApS
[idzebra-moved-to-github.git] / dfa / dfa.c
index da10335..310bd58 100644 (file)
--- a/dfa/dfa.c
+++ b/dfa/dfa.c
@@ -1,85 +1,26 @@
-/*
- * Copyright (C) 1994-1998, Index Data
- * All rights reserved.
- * Sebastian Hammer, Adam Dickmeiss
- *
- * $Log: dfa.c,v $
- * Revision 1.23  1998-09-02 14:15:28  adam
- * Zebra uses GNU Configure.
- *
- * Revision 1.22  1998/06/24 12:16:10  adam
- * Support for relations on text operands. Open range support in
- * DFA module (i.e. [-j], [g-]).
- *
- * Revision 1.21  1998/06/22 11:33:39  adam
- * Added two type casts.
- *
- * Revision 1.20  1998/06/08 14:40:44  adam
- * Fixed problem with signed character(s) in regular expressions.
- *
- * Revision 1.19  1998/01/12 14:39:39  adam
- * Fixed bug in term_Tnode.
- *
- * Revision 1.18  1997/09/29 09:05:17  adam
- * Thread safe DFA module. We simply had to put a few static vars to
- * the DFA_parse structure.
- *
- * Revision 1.17  1997/09/18 08:59:17  adam
- * Extra generic handle for the character mapping routines.
- *
- * Revision 1.16  1997/09/05 15:29:57  adam
- * Changed prototype for chr_map_input - added const.
- * Added support for C++, headers uses extern "C" for public definitions.
- *
- * Revision 1.15  1997/02/10 10:19:20  adam
- * Added facility for open character sets, eg [a-].
- *
- * Revision 1.14  1996/10/29 13:57:22  adam
- * Include of zebrautl.h instead of alexutil.h.
- *
- * Revision 1.13  1996/06/17 14:24:08  adam
- * Bug fix: read_charset didn't handle character mapping.
- *
- * Revision 1.12  1996/06/04 10:20:02  adam
- * Added support for character mapping.
- *
- * Revision 1.11  1996/01/08  19:15:24  adam
- * Allow single $ in expressions.
- *
- * Revision 1.10  1996/01/08  09:09:17  adam
- * Function dfa_parse got 'const' string argument.
- * New functions to define char mappings made public.
- *
- * Revision 1.9  1995/12/06  12:24:58  adam
- * Removed verbatim mode code.
- *
- * Revision 1.8  1995/12/06  09:09:58  adam
- * Work on left and right anchors.
- *
- * Revision 1.7  1995/11/27  09:23:02  adam
- * New berbatim hook in regular expressions. "[]n ..".
- *
- * Revision 1.6  1995/10/16  09:31:25  adam
- * Bug fix.
- *
- * Revision 1.5  1995/10/02  15:17:58  adam
- * Bug fix in dfa_delete.
- *
- * Revision 1.4  1995/09/28  09:18:52  adam
- * Removed various preprocessor defines.
- *
- * Revision 1.3  1995/09/04  12:33:26  adam
- * Various cleanup. YAZ util used instead.
- *
- * Revision 1.2  1995/01/25  11:30:50  adam
- * Simple error reporting when parsing regular expressions.
- * Memory usage reduced.
- *
- * Revision 1.1  1995/01/24  16:02:52  adam
- * New private header file in dfa module (dfap.h).
- * Module no longer uses yacc to parse regular expressions.
- *
- */
+/* $Id: dfa.c,v 1.32 2005-01-15 19:38:18 adam Exp $
+   Copyright (C) 1995-2005
+   Index Data ApS
+
+This file is part of the Zebra server.
+
+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 Zebra; see the file LICENSE.zebra.  If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+*/
+
+
 #include <stdio.h>
 #include <assert.h>
 
@@ -518,7 +459,7 @@ static int map_l_char (struct DFA_parse *parse_info)
     
     parse_info->expr_ptr = (const unsigned char *) cp0;
     parse_info->look_ch = ((unsigned char **) mapto)[i][0];
-    logf (LOG_DEBUG, "map from %c to %d", parse_info->expr_ptr[-1], parse_info->look_ch);
+    yaz_log (YLOG_DEBUG, "map from %c to %d", parse_info->expr_ptr[-1], parse_info->look_ch);
     return L_CHAR;
 }
 
@@ -540,7 +481,7 @@ static int lex_sub(struct DFA_parse *parse_info)
         {
             const int *cc;
             for (cc = parse_info->charMap; *cc; cc += 2)
-                if (*cc == parse_info->look_ch)
+                if (*cc == (int) (parse_info->look_ch))
                 {
                     if (!cc[1])
                         --parse_info->expr_ptr;
@@ -982,7 +923,8 @@ void dfa_parse_cmap_clean (struct DFA *d)
     if (!dfa->charMap)
     {
         dfa->charMapSize = 7;
-        dfa->charMap = imalloc (dfa->charMapSize * sizeof(*dfa->charMap));
+        dfa->charMap = (int *)
+           imalloc (dfa->charMapSize * sizeof(*dfa->charMap));
     }
     dfa->charMap[0] = 0;
 }
@@ -1002,7 +944,7 @@ void dfa_parse_cmap_new (struct DFA *d, const int *cmap)
         if (dfa->charMap)
             ifree (dfa->charMap);
         dfa->charMapSize = size;
-        dfa->charMap = imalloc (size * sizeof(*dfa->charMap));
+        dfa->charMap = (int *) imalloc (size * sizeof(*dfa->charMap));
     }
     memcpy (dfa->charMap, cmap, size * sizeof(*dfa->charMap));
 }
@@ -1042,7 +984,7 @@ void dfa_parse_cmap_add (struct DFA *d, int from, int to)
     size = dfa->charMapSize;
     if (indx >= size)
     {
-        int *cn = imalloc ((size+16) * sizeof(*dfa->charMap));
+        int *cn = (int *) imalloc ((size+16) * sizeof(*dfa->charMap));
         memcpy (cn, dfa->charMap, indx*sizeof(*dfa->charMap));
         ifree (dfa->charMap);
         dfa->charMap = cn;
@@ -1086,7 +1028,6 @@ static struct DFA_parse *dfa_parse_init (void)
 
     parse_info->anyset = mk_BSet (&parse_info->charset);
     res_BSet (parse_info->charset, parse_info->anyset);
-    add_BSet (parse_info->charset, parse_info->anyset, '\n');
     com_BSet (parse_info->charset, parse_info->anyset);
     parse_info->use_Tnode = parse_info->max_Tnode = 0;
     parse_info->start = parse_info->end = NULL;
@@ -1123,10 +1064,12 @@ static struct DFA_states *mk_dfas (struct DFA_parse *dfap, int poset_chunk)
 
     if (debug_dfa_followpos)
         pr_followpos(parse_info);
-    init_DFA_states (&dfas, parse_info->poset, STATE_HASH);
+    init_DFA_states (&dfas, parse_info->poset, (int) (STATE_HASH));
     mk_dfa_tran (parse_info, dfas);
     if (debug_dfa_tran)
+    {
         pr_tran (parse_info, dfas);
+    }
     if (dfa_verbose)
         pr_verbose (parse_info, dfas);
     del_pos(parse_info);
@@ -1139,7 +1082,7 @@ struct DFA *dfa_init (void)
 {
     struct DFA *dfa;
 
-    dfa = imalloc (sizeof(*dfa));
+    dfa = (struct DFA *) imalloc (sizeof(*dfa));
     dfa->parse_info = dfa_parse_init ();
     dfa->state_info = NULL;
     dfa->states = NULL;
@@ -1162,6 +1105,13 @@ int dfa_parse (struct DFA *dfa, const char **pattern)
     assert (dfa);
     assert (dfa->parse_info);
     parse_info = dfa->parse_info;
+
+    if (!parse_info->cmap)
+    {
+       res_BSet (parse_info->charset, parse_info->anyset);
+       add_BSet (parse_info->charset, parse_info->anyset, '\n');
+       com_BSet (parse_info->charset, parse_info->anyset);
+    }
     do_parse (parse_info, pattern, &top);
     if (parse_info->err_code)
         return parse_info->err_code;