Tizen 2.0 Release
[external/mawk.git] / rexp / rexp.h
1
2 /********************************************
3 rexp.h
4 copyright 1991, Michael D. Brennan
5
6 This is a source file for mawk, an implementation of
7 the AWK programming language.
8
9 Mawk is distributed without warranty under the terms of
10 the GNU General Public License, version 2, 1991.
11 ********************************************/
12
13 /*$Log: rexp.h,v $
14  * Revision 1.2  1993/07/23  13:21:35  mike
15  * cleanup rexp code
16  *
17  * Revision 1.1.1.1  1993/07/03  18:58:27  mike
18  * move source to cvs
19  *
20  * Revision 3.6  1992/01/21  17:31:45  brennan
21  * moved ison() macro out of rexp[23].c
22  *
23  * Revision 3.5  91/10/29  10:53:55  brennan
24  * SIZE_T
25  * 
26  * Revision 3.4  91/08/13  09:10:02  brennan
27  * VERSION .9994
28  * 
29  * Revision 3.3  91/06/15  09:40:25  brennan
30  * gcc defines __STDC__ but might not have stdlib.h
31  * 
32  * Revision 3.2  91/06/10  16:18:19  brennan
33  * changes for V7
34  * 
35  * Revision 3.1  91/06/07  10:33:18  brennan
36  * VERSION 0.995
37  * 
38  * Revision 1.3  91/06/05  08:57:57  brennan
39  * removed RE_xmalloc()
40  * 
41  * Revision 1.2  91/06/03  07:23:26  brennan
42  * changed type of RE_error_trap
43  * 
44  * Revision 1.1  91/06/03  07:05:41  brennan
45  * Initial revision
46  * 
47 */
48
49 #ifndef  REXP_H
50 #define  REXP_H
51
52 #include "nstd.h"
53 #include <stdio.h>
54 #include  <setjmp.h>
55
56 PTR  PROTO( RE_malloc, (unsigned) ) ;
57 PTR  PROTO( RE_realloc, (void *,unsigned) ) ;
58
59
60 /*  finite machine  state types  */
61
62 #define  M_STR          0
63 #define  M_CLASS        1
64 #define  M_ANY          2
65 #define  M_START        3
66 #define  M_END          4
67 #define  M_U            5
68 #define  M_1J           6
69 #define  M_2JA          7
70 #define  M_2JB          8
71 #define  M_ACCEPT       9
72 #define  U_ON           10
73
74 #define  U_OFF     0
75 #define  END_OFF   0
76 #define  END_ON    (2*U_ON)
77
78
79 typedef  unsigned char BV[32] ;  /* bit vector */
80
81 typedef  struct
82 { char type ;
83   unsigned char  len ;  /* used for M_STR  */
84   union
85    { 
86      char *str  ;  /* string */
87      BV   *bvp ;   /*  class  */
88      int   jump ;
89    }  data ;
90 }     STATE  ;
91
92 #define  STATESZ  (sizeof(STATE))
93
94 typedef  struct
95 { STATE  *start, *stop ; }   MACHINE ;
96
97
98 /*  tokens   */
99 #define  T_OR   1       /* | */
100 #define  T_CAT  2       
101 #define  T_STAR 3       /* * */
102 #define  T_PLUS 4       /* + */
103 #define  T_Q    5       /* ? */
104 #define  T_LP   6       /* ( */
105 #define  T_RP   7       /* ) */
106 #define  T_START 8      /* ^ */
107 #define  T_END  9       /* $ */
108 #define  T_ANY  10      /* . */
109 #define  T_CLASS 11     /* starts with [ */
110 #define  T_SLASH 12     /*  \  */
111 #define  T_CHAR  13     /* all the rest */
112 #define  T_STR   14
113 #define  T_U     15
114
115 /*  precedences and error codes  */
116 #define  L   0
117 #define  EQ  1
118 #define  G   2
119 #define  E1  (-1)
120 #define  E2  (-2)
121 #define  E3  (-3)
122 #define  E4  (-4)
123 #define  E5  (-5)
124 #define  E6  (-6)
125 #define  E7  (-7)
126
127 #define  MEMORY_FAILURE      5
128
129 #define  ison(b,x)  ((b)[((unsigned char)(x))>>3] & (1<<((x)&7)))
130
131 /* struct for the run time stack */
132 typedef struct {
133 STATE *m ;   /*   save the machine ptr */
134 int    u ;   /*   save the u_flag */
135 char  *s ;   /*   save the active string ptr */
136 char  *ss ;  /*   save the match start -- only used by REmatch */
137 } RT_STATE ;   /* run time state */
138
139 /*  error  trap   */
140 extern int REerrno ;
141 void   PROTO(RE_error_trap, (int) ) ;
142
143
144 MACHINE   PROTO( RE_u, (void) ) ;
145 MACHINE   PROTO( RE_start, (void) ) ;
146 MACHINE   PROTO( RE_end, (void) ) ;
147 MACHINE   PROTO( RE_any, (void) ) ;
148 MACHINE   PROTO( RE_str, (char *, unsigned) ) ;
149 MACHINE   PROTO( RE_class, (BV *) ) ;
150 void      PROTO( RE_cat, (MACHINE *, MACHINE *) ) ;
151 void      PROTO( RE_or, (MACHINE *, MACHINE *) ) ;
152 void      PROTO( RE_close, (MACHINE *) ) ;
153 void      PROTO( RE_poscl, (MACHINE *) ) ;
154 void      PROTO( RE_01, (MACHINE *) ) ;
155 void      PROTO( RE_panic, (char *) ) __attribute__((noreturn)) ;
156 char     *PROTO( str_str, (char *, char *, unsigned) ) ;
157
158 void      PROTO( RE_lex_init , (char *) ) ;
159 int       PROTO( RE_lex , (MACHINE *) ) ;
160 void      PROTO( RE_run_stack_init, (void) ) ;
161 RT_STATE *PROTO( RE_new_run_stack, (void) ) ;
162
163 #endif   /* REXP_H  */