2 /********************************************
4 copyright 1991, Michael D. Brennan
6 This is a source file for mawk, an implementation of
7 the AWK programming language.
9 Mawk is distributed without warranty under the terms of
10 the GNU General Public License, version 2, 1991.
11 ********************************************/
14 * Revision 1.2 1993/07/23 13:21:35 mike
17 * Revision 1.1.1.1 1993/07/03 18:58:27 mike
20 * Revision 3.6 1992/01/21 17:31:45 brennan
21 * moved ison() macro out of rexp[23].c
23 * Revision 3.5 91/10/29 10:53:55 brennan
26 * Revision 3.4 91/08/13 09:10:02 brennan
29 * Revision 3.3 91/06/15 09:40:25 brennan
30 * gcc defines __STDC__ but might not have stdlib.h
32 * Revision 3.2 91/06/10 16:18:19 brennan
35 * Revision 3.1 91/06/07 10:33:18 brennan
38 * Revision 1.3 91/06/05 08:57:57 brennan
39 * removed RE_xmalloc()
41 * Revision 1.2 91/06/03 07:23:26 brennan
42 * changed type of RE_error_trap
44 * Revision 1.1 91/06/03 07:05:41 brennan
56 PTR PROTO( RE_malloc, (unsigned) ) ;
57 PTR PROTO( RE_realloc, (void *,unsigned) ) ;
60 /* finite machine state types */
76 #define END_ON (2*U_ON)
79 typedef unsigned char BV[32] ; /* bit vector */
83 unsigned char len ; /* used for M_STR */
86 char *str ; /* string */
92 #define STATESZ (sizeof(STATE))
95 { STATE *start, *stop ; } MACHINE ;
99 #define T_OR 1 /* | */
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 */
115 /* precedences and error codes */
127 #define MEMORY_FAILURE 5
129 #define ison(b,x) ((b)[((unsigned char)(x))>>3] & (1<<((x)&7)))
131 /* struct for the run time stack */
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 */
141 void PROTO(RE_error_trap, (int) ) ;
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) ) ;
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) ) ;