Changed prototype for chr_map_input - added const.
[idzebra-moved-to-github.git] / include / dfa.h
1 /*
2  * Copyright (C) 1994-1997, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: dfa.h,v $
7  * Revision 1.7  1997-09-05 15:29:59  adam
8  * Changed prototype for chr_map_input - added const.
9  * Added support for C++, headers uses extern "C" for public definitions.
10  *
11  * Revision 1.6  1996/06/04 10:20:10  adam
12  * Added support for character mapping.
13  *
14  * Revision 1.5  1996/01/08  09:09:48  adam
15  * Function dfa_parse got 'const' string argument.
16  *
17  * Revision 1.4  1995/01/25  11:31:04  adam
18  * Simple error reporting when parsing regular expressions.
19  *
20  * Revision 1.3  1995/01/24  16:01:30  adam
21  * Added -ansi to CFLAGS.
22  * New functions and change of data structures.
23  *
24  * Revision 1.2  1994/09/26  16:31:23  adam
25  * Minor changes. xmalloc declares xcalloc now.
26  *
27  * Revision 1.1  1994/09/26  10:17:43  adam
28  * Dfa-module header files.
29  *
30  */
31
32 #ifndef DFA_H
33 #define DFA_H
34
35 #include <bset.h>
36 #include <set.h>
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 struct DFA_tran {
43     unsigned char ch[2];      /* transition on ch[0] <= c <= ch[1] to */
44     unsigned short to;        /* this state */
45 };
46
47 struct DFA_trans {
48     struct DFA_trans *next;   /* next DFA transition block */
49     struct DFA_tran *tran_block; /* pointer to transitions */
50     int  ptr;                 /* index of next transition in tran_block */
51     int  size;                /* allocated size of tran_block */
52 };
53
54 struct DFA_state {
55     struct DFA_state *next;   /* next entry in free/unmarked/marked list */
56     struct DFA_state *link;   /* link to next entry in hash chain */
57     struct DFA_tran *trans;   /* transition list */
58     Set set;                  /* set of positions (important nfa states) */
59     short no;                 /* no of this state */
60     short tran_no;            /* no of transitions to other states */
61     short rule_no;            /* if non-zero, this holds accept rule no */
62     short rule_nno;           /* accept rule no - except start rules */
63 };
64
65 struct DFA {
66     int no_states;
67     struct DFA_state  **states;
68     struct DFA_states *state_info;
69     struct DFA_parse  *parse_info;
70 };
71
72 struct DFA *dfa_init (void);
73 void dfa_set_cmap (struct DFA *dfa,
74                    const char **(*cmap)(const char **from, int len));
75 int dfa_parse (struct DFA *, const char **);
76 void dfa_mkstate (struct DFA *);
77 void dfa_delete (struct DFA **);
78
79 void dfa_parse_cmap_clean (struct DFA *d);
80 void dfa_parse_cmap_new (struct DFA *d, const int *cmap);
81 void dfa_parse_cmap_del (struct DFA *d, int from);
82 void dfa_parse_cmap_add (struct DFA *d, int from, int to);
83
84 extern int  debug_dfa_trav;
85 extern int  debug_dfa_tran;
86 extern int  debug_dfa_followpos;
87 extern int  dfa_verbose;
88
89 extern unsigned short
90         dfa_thompson_chars[],
91         dfa_ccl_chars[];
92
93 #define L_LP 1
94 #define L_RP 2
95 #define L_CHAR 3
96 #define L_CHARS 4
97 #define L_ANY 5
98 #define L_ALT 6
99 #define L_ANYZ 7
100 #define L_WILD 8
101 #define L_QUEST 9
102 #define L_CLOS1 10
103 #define L_CLOS0 11
104 #define L_END 12
105 #define L_START 13
106
107 #define DFA_ERR_SYNTAX 1
108 #define DFA_ERR_LP     2
109 #define DFA_ERR_RP     3
110
111 #ifdef __cplusplus
112 }
113 #endif
114
115 #endif