Added clean-local sections to fix make distcheck
[idzebra-moved-to-github.git] / dfa / dfa.c
index cce45ac..8450d2a 100644 (file)
--- a/dfa/dfa.c
+++ b/dfa/dfa.c
@@ -1,5 +1,5 @@
-/* $Id: dfa.c,v 1.36 2006-06-13 19:43:42 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.
@@ -15,9 +15,9 @@ 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.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
 */
 
 
@@ -32,8 +32,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "dfap.h"
 #include "imalloc.h"
 
-#define DFA_OPEN_RANGE 1
-
 #define CAT     16000
 #define OR      16001
 #define STAR    16002
@@ -357,7 +355,7 @@ static int nextchar_set (struct DFA_parse *parse_info, int *esc)
 
 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);
 
@@ -367,8 +365,13 @@ static int read_charset (struct DFA_parse *parse_info)
         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 == '-')
@@ -380,16 +383,23 @@ static int read_charset (struct DFA_parse *parse_info)
        }
        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);
        }
@@ -398,20 +408,16 @@ static int read_charset (struct DFA_parse *parse_info)
             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];
@@ -421,12 +427,12 @@ static int read_charset (struct DFA_parse *parse_info)
                 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
         {
@@ -1097,6 +1103,11 @@ void dfa_set_cmap (struct DFA *dfa, void *vp,
     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;