Commit | Line | Data |
---|---|---|
a7e60862 WJ |
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 3.6 92/01/21 17:31:45 brennan | |
15 | * moved ison() macro out of rexp[23].c | |
16 | * | |
17 | * Revision 3.5 91/10/29 10:53:55 brennan | |
18 | * SIZE_T | |
19 | * | |
20 | * Revision 3.4 91/08/13 09:10:02 brennan | |
21 | * VERSION .9994 | |
22 | * | |
23 | * Revision 3.3 91/06/15 09:40:25 brennan | |
24 | * gcc defines __STDC__ but might not have stdlib.h | |
25 | * | |
26 | * Revision 3.2 91/06/10 16:18:19 brennan | |
27 | * changes for V7 | |
28 | * | |
29 | * Revision 3.1 91/06/07 10:33:18 brennan | |
30 | * VERSION 0.995 | |
31 | * | |
32 | * Revision 1.3 91/06/05 08:57:57 brennan | |
33 | * removed RE_xmalloc() | |
34 | * | |
35 | * Revision 1.2 91/06/03 07:23:26 brennan | |
36 | * changed type of RE_error_trap | |
37 | * | |
38 | * Revision 1.1 91/06/03 07:05:41 brennan | |
39 | * Initial revision | |
40 | * | |
41 | */ | |
42 | ||
43 | #ifndef REXP_H | |
44 | #define REXP_H | |
45 | ||
46 | #ifdef THINK_C | |
47 | #define MAWK /* THINK C doesn't allow compile-time definitions */ | |
48 | #define SIZE_T(x) (size_t)(x) | |
49 | #endif | |
50 | ||
51 | #ifndef SIZE_T | |
52 | #define SIZE_T(x) (x) | |
53 | #endif | |
54 | ||
55 | #include <stdio.h> | |
56 | #include <setjmp.h> | |
57 | ||
58 | char *strchr() ; | |
59 | ||
60 | #ifndef PROTO | |
61 | #ifdef __STDC__ | |
62 | #define PROTO(name, args) name args | |
63 | #else | |
64 | #define PROTO(name, args) name() | |
65 | #endif | |
66 | #endif | |
67 | ||
68 | #ifdef __STDC__ | |
69 | #define VOID void | |
70 | #else | |
71 | #define VOID char | |
72 | #endif | |
73 | ||
74 | VOID *malloc(), *realloc() ; | |
75 | void free() ; | |
76 | ||
77 | ||
78 | VOID *PROTO( RE_malloc, (unsigned) ) ; | |
79 | VOID *PROTO( RE_realloc, (void *,unsigned) ) ; | |
80 | ||
81 | ||
82 | /* finite machine state types */ | |
83 | ||
84 | #define M_STR 0 | |
85 | #define M_CLASS 1 | |
86 | #define M_ANY 2 | |
87 | #define M_START 3 | |
88 | #define M_END 4 | |
89 | #define M_U 5 | |
90 | #define M_1J 6 | |
91 | #define M_2JA 7 | |
92 | #define M_2JB 8 | |
93 | #define M_ACCEPT 9 | |
94 | #define U_ON 10 | |
95 | ||
96 | #define U_OFF 0 | |
97 | #define END_OFF 0 | |
98 | #define END_ON (2*U_ON) | |
99 | ||
100 | ||
101 | typedef unsigned char BV[32] ; /* bit vector */ | |
102 | ||
103 | typedef struct | |
104 | { char type ; | |
105 | unsigned char len ; /* used for M_STR */ | |
106 | union | |
107 | { | |
108 | char *str ; /* string */ | |
109 | BV *bvp ; /* class */ | |
110 | int jump ; | |
111 | } data ; | |
112 | } STATE ; | |
113 | ||
114 | #define STATESZ (sizeof(STATE)) | |
115 | ||
116 | typedef struct | |
117 | { STATE *start, *stop ; } MACHINE ; | |
118 | ||
119 | ||
120 | /* tokens */ | |
121 | #define T_OR 1 /* | */ | |
122 | #define T_CAT 2 | |
123 | #define T_STAR 3 /* * */ | |
124 | #define T_PLUS 4 /* + */ | |
125 | #define T_Q 5 /* ? */ | |
126 | #define T_LP 6 /* ( */ | |
127 | #define T_RP 7 /* ) */ | |
128 | #define T_START 8 /* ^ */ | |
129 | #define T_END 9 /* $ */ | |
130 | #define T_ANY 10 /* . */ | |
131 | #define T_CLASS 11 /* starts with [ */ | |
132 | #define T_SLASH 12 /* \ */ | |
133 | #define T_CHAR 13 /* all the rest */ | |
134 | #define T_STR 14 | |
135 | #define T_U 15 | |
136 | ||
137 | /* precedences and error codes */ | |
138 | #define L 0 | |
139 | #define EQ 1 | |
140 | #define G 2 | |
141 | #define E1 (-1) | |
142 | #define E2 (-2) | |
143 | #define E3 (-3) | |
144 | #define E4 (-4) | |
145 | #define E5 (-5) | |
146 | #define E6 (-6) | |
147 | #define E7 (-7) | |
148 | ||
149 | #define MEMORY_FAILURE 5 | |
150 | ||
151 | #define ison(b,x) ((b)[((unsigned char)(x))>>3] & (1<<((x)&7))) | |
152 | ||
153 | /* struct for the run time stack */ | |
154 | typedef struct { | |
155 | STATE *m ; /* save the machine ptr */ | |
156 | int u ; /* save the u_flag */ | |
157 | char *s ; /* save the active string ptr */ | |
158 | char *ss ; /* save the match start -- only used by REmatch */ | |
159 | } RT_STATE ; /* run time state */ | |
160 | ||
161 | /* error trap */ | |
162 | extern int REerrno ; | |
163 | void PROTO(RE_error_trap, (int) ) ; | |
164 | ||
165 | ||
166 | MACHINE PROTO( RE_u, (void) ) ; | |
167 | MACHINE PROTO( RE_start, (void) ) ; | |
168 | MACHINE PROTO( RE_end, (void) ) ; | |
169 | MACHINE PROTO( RE_any, (void) ) ; | |
170 | MACHINE PROTO( RE_str, (char *, unsigned) ) ; | |
171 | MACHINE PROTO( RE_class, (BV *) ) ; | |
172 | void PROTO( RE_cat, (MACHINE *, MACHINE *) ) ; | |
173 | void PROTO( RE_or, (MACHINE *, MACHINE *) ) ; | |
174 | void PROTO( RE_close, (MACHINE *) ) ; | |
175 | void PROTO( RE_poscl, (MACHINE *) ) ; | |
176 | void PROTO( RE_01, (MACHINE *) ) ; | |
177 | void PROTO( RE_panic, (char *) ) ; | |
178 | char *PROTO( str_str, (char *, char *, unsigned) ) ; | |
179 | ||
180 | void PROTO( RE_lex_init , (char *) ) ; | |
181 | int PROTO( RE_lex , (MACHINE *) ) ; | |
182 | void PROTO( RE_run_stack_init, (void) ) ; | |
183 | RT_STATE *PROTO( RE_new_run_stack, (void) ) ; | |
184 | ||
185 | #endif /* REXP_H */ |