]>
Commit | Line | Data |
---|---|---|
14b0e578 CS |
1 | #ifndef REGINT_H\r |
2 | #define REGINT_H\r | |
3 | /**********************************************************************\r | |
4 | regint.h - Oniguruma (regular expression library)\r | |
5 | **********************************************************************/\r | |
6 | /*-\r | |
b602265d | 7 | * Copyright (c) 2002-2018 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>\r |
14b0e578 CS |
8 | * All rights reserved.\r |
9 | *\r | |
10 | * Redistribution and use in source and binary forms, with or without\r | |
11 | * modification, are permitted provided that the following conditions\r | |
12 | * are met:\r | |
13 | * 1. Redistributions of source code must retain the above copyright\r | |
14 | * notice, this list of conditions and the following disclaimer.\r | |
15 | * 2. Redistributions in binary form must reproduce the above copyright\r | |
16 | * notice, this list of conditions and the following disclaimer in the\r | |
17 | * documentation and/or other materials provided with the distribution.\r | |
18 | *\r | |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r | |
29 | * SUCH DAMAGE.\r | |
30 | */\r | |
31 | \r | |
32 | /* for debug */\r | |
b602265d | 33 | /* #define ONIG_DEBUG_PARSE */\r |
14b0e578 CS |
34 | /* #define ONIG_DEBUG_COMPILE */\r |
35 | /* #define ONIG_DEBUG_SEARCH */\r | |
36 | /* #define ONIG_DEBUG_MATCH */\r | |
37 | /* #define ONIG_DONT_OPTIMIZE */\r | |
38 | \r | |
39 | /* for byte-code statistical data. */\r | |
40 | /* #define ONIG_DEBUG_STATISTICS */\r | |
41 | \r | |
b602265d | 42 | #if defined(ONIG_DEBUG_PARSE) || defined(ONIG_DEBUG_MATCH) || \\r |
14b0e578 CS |
43 | defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) || \\r |
44 | defined(ONIG_DEBUG_STATISTICS)\r | |
45 | #ifndef ONIG_DEBUG\r | |
46 | #define ONIG_DEBUG\r | |
47 | #endif\r | |
48 | #endif\r | |
49 | \r | |
50 | #if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \\r | |
51 | (defined(__ppc__) && defined(__APPLE__)) || \\r | |
52 | defined(__x86_64) || defined(__x86_64__) || \\r | |
53 | defined(__mc68020__)\r | |
54 | #define PLATFORM_UNALIGNED_WORD_ACCESS\r | |
55 | #endif\r | |
56 | \r | |
57 | /* config */\r | |
58 | /* spec. config */\r | |
b602265d DG |
59 | #define USE_CALL\r |
60 | #define USE_CALLOUT\r | |
14b0e578 | 61 | #define USE_BACKREF_WITH_LEVEL /* \k<name+n>, \k<name-n> */\r |
b602265d | 62 | #define USE_INSISTENT_CHECK_CAPTURES_IN_EMPTY_REPEAT /* /(?:()|())*\2/ */\r |
14b0e578 CS |
63 | #define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE /* /\n$/ =~ "\n" */\r |
64 | #define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR\r | |
b602265d DG |
65 | \r |
66 | #define USE_RETRY_LIMIT_IN_MATCH\r | |
14b0e578 CS |
67 | \r |
68 | /* internal config */\r | |
14b0e578 | 69 | #define USE_OP_PUSH_OR_JUMP_EXACT\r |
b602265d | 70 | #define USE_QUANT_PEEK_NEXT\r |
14b0e578 | 71 | #define USE_ST_LIBRARY\r |
14b0e578 | 72 | \r |
b602265d | 73 | #include "regenc.h"\r |
14b0e578 | 74 | \r |
b602265d DG |
75 | #ifdef __cplusplus\r |
76 | # ifndef HAVE_STDARG_PROTOTYPES\r | |
77 | # define HAVE_STDARG_PROTOTYPES 1\r | |
78 | # endif\r | |
79 | #endif\r | |
80 | \r | |
81 | /* escape Mac OS X/Xcode 2.4/gcc 4.0.1 problem */\r | |
82 | #if defined(__APPLE__) && defined(__GNUC__) && __GNUC__ >= 4\r | |
83 | # ifndef HAVE_STDARG_PROTOTYPES\r | |
84 | # define HAVE_STDARG_PROTOTYPES 1\r | |
85 | # endif\r | |
14b0e578 CS |
86 | #endif\r |
87 | \r | |
b602265d DG |
88 | #ifdef HAVE_STDARG_H\r |
89 | # ifndef HAVE_STDARG_PROTOTYPES\r | |
90 | # define HAVE_STDARG_PROTOTYPES 1\r | |
91 | # endif\r | |
92 | #endif\r | |
93 | \r | |
94 | \r | |
95 | #define INIT_MATCH_STACK_SIZE 160\r | |
96 | #define DEFAULT_MATCH_STACK_LIMIT_SIZE 0 /* unlimited */\r | |
97 | #define DEFAULT_RETRY_LIMIT_IN_MATCH 10000000\r | |
98 | #define DEFAULT_PARSE_DEPTH_LIMIT 4096\r | |
99 | \r | |
14b0e578 CS |
100 | /* */\r |
101 | /* escape other system UChar definition */\r | |
14b0e578 CS |
102 | #ifdef ONIG_ESCAPE_UCHAR_COLLISION\r |
103 | #undef ONIG_ESCAPE_UCHAR_COLLISION\r | |
104 | #endif\r | |
105 | \r | |
106 | #define USE_WORD_BEGIN_END /* "\<", "\>" */\r | |
107 | #define USE_CAPTURE_HISTORY\r | |
108 | #define USE_VARIABLE_META_CHARS\r | |
109 | #define USE_POSIX_API_REGION_OPTION\r | |
110 | #define USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE\r | |
b602265d | 111 | \r |
14b0e578 CS |
112 | #define xmalloc malloc\r |
113 | #define xrealloc realloc\r | |
114 | #define xcalloc calloc\r | |
115 | #define xfree free\r | |
116 | \r | |
14b0e578 CS |
117 | #define st_init_table onig_st_init_table\r |
118 | #define st_init_table_with_size onig_st_init_table_with_size\r | |
119 | #define st_init_numtable onig_st_init_numtable\r | |
120 | #define st_init_numtable_with_size onig_st_init_numtable_with_size\r | |
121 | #define st_init_strtable onig_st_init_strtable\r | |
122 | #define st_init_strtable_with_size onig_st_init_strtable_with_size\r | |
123 | #define st_delete onig_st_delete\r | |
124 | #define st_delete_safe onig_st_delete_safe\r | |
125 | #define st_insert onig_st_insert\r | |
126 | #define st_lookup onig_st_lookup\r | |
127 | #define st_foreach onig_st_foreach\r | |
128 | #define st_add_direct onig_st_add_direct\r | |
129 | #define st_free_table onig_st_free_table\r | |
130 | #define st_cleanup_safe onig_st_cleanup_safe\r | |
131 | #define st_copy onig_st_copy\r | |
132 | #define st_nothing_key_clone onig_st_nothing_key_clone\r | |
133 | #define st_nothing_key_free onig_st_nothing_key_free\r | |
134 | /* */\r | |
135 | #define onig_st_is_member st_is_member\r | |
136 | \r | |
14b0e578 CS |
137 | //#define xmemset memset\r |
138 | //#define xmemcpy memcpy\r | |
139 | //#define xmemmove memmove\r | |
140 | \r | |
141 | #if defined(_WIN32) && !defined(__GNUC__)\r | |
142 | #define xalloca _alloca\r | |
b602265d DG |
143 | #define xvsnprintf(buf,size,fmt,args) _vsnprintf_s(buf,size,_TRUNCATE,fmt,args)\r |
144 | #define xsnprintf sprintf_s\r | |
145 | #define xstrcat(dest,src,size) strcat_s(dest,size,src)\r | |
14b0e578 CS |
146 | #else\r |
147 | #define xalloca alloca\r | |
148 | #define xvsnprintf vsnprintf\r | |
b602265d DG |
149 | #define xsnprintf snprintf\r |
150 | #define xstrcat(dest,src,size) strcat(dest,src)\r | |
14b0e578 CS |
151 | #endif\r |
152 | \r | |
153 | \r | |
b602265d | 154 | // #include <stddef.h>\r |
14b0e578 | 155 | \r |
b602265d DG |
156 | #ifdef HAVE_LIMITS_H\r |
157 | #include <limits.h>\r | |
158 | #endif\r | |
14b0e578 CS |
159 | \r |
160 | #if 0\r | |
161 | #ifdef HAVE_STDLIB_H\r | |
162 | #include <stdlib.h>\r | |
163 | #endif\r | |
164 | \r | |
b602265d DG |
165 | #ifdef HAVE_STDINT_H\r |
166 | #include <stdint.h>\r | |
167 | #endif\r | |
168 | \r | |
14b0e578 CS |
169 | #if defined(HAVE_ALLOCA_H) && !defined(__GNUC__)\r |
170 | #include <alloca.h>\r | |
171 | #endif\r | |
172 | \r | |
173 | #ifdef HAVE_STRING_H\r | |
174 | # include <string.h>\r | |
175 | #else\r | |
176 | # include <strings.h>\r | |
177 | #endif\r | |
178 | \r | |
179 | #include <ctype.h>\r | |
180 | #ifdef HAVE_SYS_TYPES_H\r | |
181 | #ifndef __BORLANDC__\r | |
182 | #include <sys/types.h>\r | |
183 | #endif\r | |
184 | #endif\r | |
185 | \r | |
b602265d DG |
186 | #ifdef HAVE_INTTYPES_H\r |
187 | #include <inttypes.h>\r | |
188 | #endif\r | |
189 | \r | |
14b0e578 CS |
190 | #ifdef __BORLANDC__\r |
191 | #include <malloc.h>\r | |
192 | #endif\r | |
193 | \r | |
194 | #ifdef ONIG_DEBUG\r | |
195 | # include <stdio.h>\r | |
196 | #endif\r | |
197 | #endif\r | |
198 | \r | |
b602265d DG |
199 | #ifdef _WIN32\r |
200 | #if defined(_MSC_VER) && (_MSC_VER < 1300)\r | |
201 | typedef int intptr_t;\r | |
202 | typedef unsigned int uintptr_t;\r | |
203 | #endif\r | |
204 | #endif\r | |
205 | \r | |
206 | typedef INTN intptr_t;\r | |
207 | typedef UINTN uintptr_t;\r | |
208 | \r | |
209 | #ifndef offsetof\r | |
210 | #define offsetof OFFSET_OF\r | |
211 | #endif\r | |
14b0e578 CS |
212 | \r |
213 | #ifdef MIN\r | |
214 | #undef MIN\r | |
215 | #endif\r | |
216 | #ifdef MAX\r | |
217 | #undef MAX\r | |
218 | #endif\r | |
b602265d | 219 | \r |
14b0e578 CS |
220 | #define MIN(a,b) (((a)>(b))?(b):(a))\r |
221 | #define MAX(a,b) (((a)<(b))?(b):(a))\r | |
222 | \r | |
223 | #define IS_NULL(p) (((void*)(p)) == (void*)0)\r | |
224 | #define IS_NOT_NULL(p) (((void*)(p)) != (void*)0)\r | |
225 | #define CHECK_NULL_RETURN(p) if (IS_NULL(p)) return NULL\r | |
226 | #define CHECK_NULL_RETURN_MEMERR(p) if (IS_NULL(p)) return ONIGERR_MEMORY\r | |
227 | #define NULL_UCHARP ((UChar* )0)\r | |
228 | \r | |
b602265d DG |
229 | #define INFINITE_LEN ONIG_INFINITE_DISTANCE\r |
230 | \r | |
14b0e578 CS |
231 | #ifdef PLATFORM_UNALIGNED_WORD_ACCESS\r |
232 | \r | |
233 | #define PLATFORM_GET_INC(val,p,type) do{\\r | |
234 | val = *(type* )p;\\r | |
235 | (p) += sizeof(type);\\r | |
236 | } while(0)\r | |
237 | \r | |
238 | #else\r | |
239 | \r | |
240 | #define PLATFORM_GET_INC(val,p,type) do{\\r | |
241 | xmemcpy(&val, (p), sizeof(type));\\r | |
242 | (p) += sizeof(type);\\r | |
243 | } while(0)\r | |
244 | \r | |
245 | /* sizeof(OnigCodePoint) */\r | |
b602265d DG |
246 | #ifdef SIZEOF_SIZE_T\r |
247 | # define WORD_ALIGNMENT_SIZE SIZEOF_SIZE_T\r | |
248 | #else\r | |
249 | # define WORD_ALIGNMENT_SIZE SIZEOF_LONG\r | |
250 | #endif\r | |
14b0e578 CS |
251 | \r |
252 | #define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\\r | |
b602265d | 253 | (pad_size) = WORD_ALIGNMENT_SIZE - ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\\r |
14b0e578 CS |
254 | if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\\r |
255 | } while (0)\r | |
256 | \r | |
257 | #define ALIGNMENT_RIGHT(addr) do {\\r | |
258 | (addr) += (WORD_ALIGNMENT_SIZE - 1);\\r | |
b602265d | 259 | (addr) -= ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\\r |
14b0e578 CS |
260 | } while (0)\r |
261 | \r | |
262 | #endif /* PLATFORM_UNALIGNED_WORD_ACCESS */\r | |
263 | \r | |
b602265d DG |
264 | \r |
265 | #ifdef USE_CALLOUT\r | |
266 | \r | |
267 | typedef struct {\r | |
268 | int flag;\r | |
269 | OnigCalloutOf of;\r | |
270 | int in;\r | |
271 | int name_id;\r | |
272 | const UChar* tag_start;\r | |
273 | const UChar* tag_end;\r | |
274 | OnigCalloutType type;\r | |
275 | OnigCalloutFunc start_func;\r | |
276 | OnigCalloutFunc end_func;\r | |
277 | union {\r | |
278 | struct {\r | |
279 | const UChar* start;\r | |
280 | const UChar* end;\r | |
281 | } content;\r | |
282 | struct {\r | |
283 | int num;\r | |
284 | int passed_num;\r | |
285 | OnigType types[ONIG_CALLOUT_MAX_ARGS_NUM];\r | |
286 | OnigValue vals[ONIG_CALLOUT_MAX_ARGS_NUM];\r | |
287 | } arg;\r | |
288 | } u;\r | |
289 | } CalloutListEntry;\r | |
290 | \r | |
291 | #endif\r | |
292 | \r | |
293 | typedef struct {\r | |
294 | const UChar* pattern;\r | |
295 | const UChar* pattern_end;\r | |
296 | #ifdef USE_CALLOUT\r | |
297 | void* tag_table;\r | |
298 | int callout_num;\r | |
299 | int callout_list_alloc;\r | |
300 | CalloutListEntry* callout_list; /* index: callout num */\r | |
301 | #endif\r | |
302 | } RegexExt;\r | |
303 | \r | |
304 | #define REG_EXTP(reg) ((RegexExt* )((reg)->chain))\r | |
305 | #define REG_EXTPL(reg) ((reg)->chain)\r | |
306 | \r | |
307 | struct re_pattern_buffer {\r | |
308 | /* common members of BBuf(bytes-buffer) */\r | |
309 | unsigned char* p; /* compiled pattern */\r | |
310 | unsigned int used; /* used space for p */\r | |
311 | unsigned int alloc; /* allocated space for p */\r | |
312 | \r | |
313 | int num_mem; /* used memory(...) num counted from 1 */\r | |
314 | int num_repeat; /* OP_REPEAT/OP_REPEAT_NG id-counter */\r | |
315 | int num_null_check; /* OP_EMPTY_CHECK_START/END id counter */\r | |
316 | int num_comb_exp_check; /* no longer used (combination explosion check) */\r | |
317 | int num_call; /* number of subexp call */\r | |
318 | unsigned int capture_history; /* (?@...) flag (1-31) */\r | |
319 | unsigned int bt_mem_start; /* need backtrack flag */\r | |
320 | unsigned int bt_mem_end; /* need backtrack flag */\r | |
321 | int stack_pop_level;\r | |
322 | int repeat_range_alloc;\r | |
323 | OnigRepeatRange* repeat_range;\r | |
324 | \r | |
325 | OnigEncoding enc;\r | |
326 | OnigOptionType options;\r | |
327 | OnigSyntaxType* syntax;\r | |
328 | OnigCaseFoldType case_fold_flag;\r | |
329 | void* name_table;\r | |
330 | \r | |
331 | /* optimization info (string search, char-map and anchors) */\r | |
332 | int optimize; /* optimize flag */\r | |
333 | int threshold_len; /* search str-length for apply optimize */\r | |
334 | int anchor; /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */\r | |
335 | OnigLen anchor_dmin; /* (SEMI_)END_BUF anchor distance */\r | |
336 | OnigLen anchor_dmax; /* (SEMI_)END_BUF anchor distance */\r | |
337 | int sub_anchor; /* start-anchor for exact or map */\r | |
338 | unsigned char *exact;\r | |
339 | unsigned char *exact_end;\r | |
340 | unsigned char map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */\r | |
341 | int *int_map; /* BM skip for exact_len > 255 */\r | |
342 | int *int_map_backward; /* BM skip for backward search */\r | |
343 | OnigLen dmin; /* min-distance of exact or map */\r | |
344 | OnigLen dmax; /* max-distance of exact or map */\r | |
345 | \r | |
346 | /* regex_t link chain */\r | |
347 | struct re_pattern_buffer* chain; /* escape compile-conflict */\r | |
348 | };\r | |
349 | \r | |
350 | \r | |
14b0e578 | 351 | /* stack pop level */\r |
b602265d DG |
352 | enum StackPopLevel {\r |
353 | STACK_POP_LEVEL_FREE = 0,\r | |
354 | STACK_POP_LEVEL_MEM_START = 1,\r | |
355 | STACK_POP_LEVEL_ALL = 2\r | |
356 | };\r | |
14b0e578 CS |
357 | \r |
358 | /* optimize flags */\r | |
b602265d DG |
359 | enum OptimizeType {\r |
360 | OPTIMIZE_NONE = 0,\r | |
361 | OPTIMIZE_EXACT = 1, /* Slow Search */\r | |
362 | OPTIMIZE_EXACT_BM = 2, /* Boyer Moore Search */\r | |
363 | OPTIMIZE_EXACT_BM_NO_REV = 3, /* BM (but not simple match) */\r | |
364 | OPTIMIZE_EXACT_IC = 4, /* Slow Search (ignore case) */\r | |
365 | OPTIMIZE_MAP = 5 /* char map */\r | |
366 | };\r | |
14b0e578 CS |
367 | \r |
368 | /* bit status */\r | |
b602265d DG |
369 | typedef unsigned int MemStatusType;\r |
370 | \r | |
371 | #define MEM_STATUS_BITS_NUM (sizeof(MemStatusType) * 8)\r | |
372 | #define MEM_STATUS_CLEAR(stats) (stats) = 0\r | |
373 | #define MEM_STATUS_ON_ALL(stats) (stats) = ~((MemStatusType )0)\r | |
374 | #define MEM_STATUS_AT(stats,n) \\r | |
375 | ((n) < (int )MEM_STATUS_BITS_NUM ? ((stats) & ((MemStatusType )1 << n)) : ((stats) & 1))\r | |
376 | #define MEM_STATUS_AT0(stats,n) \\r | |
377 | ((n) > 0 && (n) < (int )MEM_STATUS_BITS_NUM ? ((stats) & ((MemStatusType )1 << n)) : ((stats) & 1))\r | |
378 | \r | |
379 | #define MEM_STATUS_ON(stats,n) do {\\r | |
380 | if ((n) < (int )MEM_STATUS_BITS_NUM) {\\r | |
381 | if ((n) != 0)\\r | |
382 | (stats) |= ((MemStatusType )1 << (n));\\r | |
383 | }\\r | |
14b0e578 CS |
384 | else\\r |
385 | (stats) |= 1;\\r | |
386 | } while (0)\r | |
387 | \r | |
b602265d DG |
388 | #define MEM_STATUS_ON_SIMPLE(stats,n) do {\\r |
389 | if ((n) < (int )MEM_STATUS_BITS_NUM)\\r | |
390 | (stats) |= ((MemStatusType )1 << (n));\\r | |
14b0e578 CS |
391 | } while (0)\r |
392 | \r | |
393 | \r | |
394 | #define INT_MAX_LIMIT ((1UL << (SIZEOF_INT * 8 - 1)) - 1)\r | |
395 | \r | |
b602265d DG |
396 | #define IS_CODE_WORD_ASCII(enc,code) \\r |
397 | (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_WORD(enc,code))\r | |
398 | #define IS_CODE_DIGIT_ASCII(enc, code) \\r | |
399 | (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_DIGIT(enc,code))\r | |
400 | #define IS_CODE_XDIGIT_ASCII(enc, code) \\r | |
401 | (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_XDIGIT(enc,code))\r | |
402 | \r | |
14b0e578 CS |
403 | #define DIGITVAL(code) ((code) - '0')\r |
404 | #define ODIGITVAL(code) DIGITVAL(code)\r | |
405 | #define XDIGITVAL(enc,code) \\r | |
b602265d | 406 | (IS_CODE_DIGIT_ASCII(enc,code) ? DIGITVAL(code) \\r |
14b0e578 CS |
407 | : (ONIGENC_IS_CODE_UPPER(enc,code) ? (code) - 'A' + 10 : (code) - 'a' + 10))\r |
408 | \r | |
409 | #define IS_SINGLELINE(option) ((option) & ONIG_OPTION_SINGLELINE)\r | |
410 | #define IS_MULTILINE(option) ((option) & ONIG_OPTION_MULTILINE)\r | |
411 | #define IS_IGNORECASE(option) ((option) & ONIG_OPTION_IGNORECASE)\r | |
412 | #define IS_EXTEND(option) ((option) & ONIG_OPTION_EXTEND)\r | |
413 | #define IS_FIND_LONGEST(option) ((option) & ONIG_OPTION_FIND_LONGEST)\r | |
414 | #define IS_FIND_NOT_EMPTY(option) ((option) & ONIG_OPTION_FIND_NOT_EMPTY)\r | |
415 | #define IS_FIND_CONDITION(option) ((option) & \\r | |
416 | (ONIG_OPTION_FIND_LONGEST | ONIG_OPTION_FIND_NOT_EMPTY))\r | |
417 | #define IS_NOTBOL(option) ((option) & ONIG_OPTION_NOTBOL)\r | |
418 | #define IS_NOTEOL(option) ((option) & ONIG_OPTION_NOTEOL)\r | |
419 | #define IS_POSIX_REGION(option) ((option) & ONIG_OPTION_POSIX_REGION)\r | |
420 | \r | |
b602265d DG |
421 | #define IS_WORD_ASCII(option) \\r |
422 | ((option) & (ONIG_OPTION_WORD_IS_ASCII | ONIG_OPTION_POSIX_IS_ASCII))\r | |
423 | #define IS_DIGIT_ASCII(option) \\r | |
424 | ((option) & (ONIG_OPTION_DIGIT_IS_ASCII | ONIG_OPTION_POSIX_IS_ASCII))\r | |
425 | #define IS_SPACE_ASCII(option) \\r | |
426 | ((option) & (ONIG_OPTION_SPACE_IS_ASCII | ONIG_OPTION_POSIX_IS_ASCII))\r | |
427 | #define IS_POSIX_ASCII(option) ((option) & ONIG_OPTION_POSIX_IS_ASCII)\r | |
428 | \r | |
429 | #define IS_ASCII_MODE_CTYPE_OPTION(ctype, options) \\r | |
430 | ((ctype) >= 0 && \\r | |
431 | (((ctype) < ONIGENC_CTYPE_ASCII && IS_POSIX_ASCII(options)) ||\\r | |
432 | ((ctype) == ONIGENC_CTYPE_WORD && IS_WORD_ASCII(options)) ||\\r | |
433 | ((ctype) == ONIGENC_CTYPE_DIGIT && IS_DIGIT_ASCII(options)) ||\\r | |
434 | ((ctype) == ONIGENC_CTYPE_SPACE && IS_SPACE_ASCII(options))))\r | |
14b0e578 CS |
435 | \r |
436 | #define DISABLE_CASE_FOLD_MULTI_CHAR(case_fold_flag) \\r | |
437 | ((case_fold_flag) & ~INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR)\r | |
438 | \r | |
439 | #define REPEAT_INFINITE -1\r | |
440 | #define IS_REPEAT_INFINITE(n) ((n) == REPEAT_INFINITE)\r | |
441 | \r | |
442 | /* bitset */\r | |
443 | #define BITS_PER_BYTE 8\r | |
444 | #define SINGLE_BYTE_SIZE (1 << BITS_PER_BYTE)\r | |
445 | #define BITS_IN_ROOM (sizeof(Bits) * BITS_PER_BYTE)\r | |
446 | #define BITSET_SIZE (SINGLE_BYTE_SIZE / BITS_IN_ROOM)\r | |
447 | \r | |
448 | #ifdef PLATFORM_UNALIGNED_WORD_ACCESS\r | |
449 | typedef unsigned int Bits;\r | |
450 | #else\r | |
451 | typedef unsigned char Bits;\r | |
452 | #endif\r | |
453 | typedef Bits BitSet[BITSET_SIZE];\r | |
454 | typedef Bits* BitSetRef;\r | |
455 | \r | |
456 | #define SIZE_BITSET sizeof(BitSet)\r | |
457 | \r | |
458 | #define BITSET_CLEAR(bs) do {\\r | |
b602265d DG |
459 | int i;\\r |
460 | for (i = 0; i < (int )BITSET_SIZE; i++) { (bs)[i] = 0; } \\r | |
14b0e578 CS |
461 | } while (0)\r |
462 | \r | |
463 | #define BS_ROOM(bs,pos) (bs)[pos / BITS_IN_ROOM]\r | |
464 | #define BS_BIT(pos) (1 << (pos % BITS_IN_ROOM))\r | |
465 | \r | |
466 | #define BITSET_AT(bs, pos) (BS_ROOM(bs,pos) & BS_BIT(pos))\r | |
467 | #define BITSET_SET_BIT(bs, pos) BS_ROOM(bs,pos) |= BS_BIT(pos)\r | |
468 | #define BITSET_CLEAR_BIT(bs, pos) BS_ROOM(bs,pos) &= ~(BS_BIT(pos))\r | |
469 | #define BITSET_INVERT_BIT(bs, pos) BS_ROOM(bs,pos) ^= BS_BIT(pos)\r | |
470 | \r | |
471 | /* bytes buffer */\r | |
472 | typedef struct _BBuf {\r | |
473 | UChar* p;\r | |
474 | unsigned int used;\r | |
475 | unsigned int alloc;\r | |
476 | } BBuf;\r | |
477 | \r | |
b602265d | 478 | #define BB_INIT(buf,size) onig_bbuf_init((BBuf* )(buf), (size))\r |
14b0e578 | 479 | \r |
b602265d | 480 | #define BB_SIZE_INC(buf,inc) do{\\r |
14b0e578 CS |
481 | (buf)->alloc += (inc);\\r |
482 | (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\\r | |
483 | if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\\r | |
484 | } while (0)\r | |
485 | \r | |
b602265d | 486 | #define BB_EXPAND(buf,low) do{\\r |
14b0e578 CS |
487 | unsigned int OldSize_ = (buf)->alloc * sizeof((buf)->p[0]);\\r |
488 | do { (buf)->alloc *= 2; } while ((buf)->alloc < (unsigned int )low);\\r | |
489 | (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc, OldSize_);\\r | |
490 | if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\\r | |
491 | } while (0)\r | |
492 | \r | |
b602265d | 493 | #define BB_ENSURE_SIZE(buf,size) do{\\r |
14b0e578 CS |
494 | unsigned int new_alloc = (buf)->alloc;\\r |
495 | while (new_alloc < (unsigned int )(size)) { new_alloc *= 2; }\\r | |
496 | if ((buf)->alloc != new_alloc) {\\r | |
497 | (buf)->p = (UChar* )xrealloc((buf)->p, new_alloc, (buf)->alloc);\\r | |
498 | if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\\r | |
499 | (buf)->alloc = new_alloc;\\r | |
500 | }\\r | |
501 | } while (0)\r | |
502 | \r | |
b602265d | 503 | #define BB_WRITE(buf,pos,bytes,n) do{\\r |
14b0e578 | 504 | int used = (pos) + (n);\\r |
b602265d | 505 | if ((buf)->alloc < (unsigned int )used) BB_EXPAND((buf),used);\\r |
14b0e578 CS |
506 | xmemcpy((buf)->p + (pos), (bytes), (n));\\r |
507 | if ((buf)->used < (unsigned int )used) (buf)->used = used;\\r | |
508 | } while (0)\r | |
509 | \r | |
b602265d | 510 | #define BB_WRITE1(buf,pos,byte) do{\\r |
14b0e578 | 511 | int used = (pos) + 1;\\r |
b602265d | 512 | if ((buf)->alloc < (unsigned int )used) BB_EXPAND((buf),used);\\r |
14b0e578 CS |
513 | (buf)->p[(pos)] = (byte);\\r |
514 | if ((buf)->used < (unsigned int )used) (buf)->used = used;\\r | |
515 | } while (0)\r | |
516 | \r | |
b602265d DG |
517 | #define BB_ADD(buf,bytes,n) BB_WRITE((buf),(buf)->used,(bytes),(n))\r |
518 | #define BB_ADD1(buf,byte) BB_WRITE1((buf),(buf)->used,(byte))\r | |
519 | #define BB_GET_ADD_ADDRESS(buf) ((buf)->p + (buf)->used)\r | |
520 | #define BB_GET_OFFSET_POS(buf) ((buf)->used)\r | |
14b0e578 CS |
521 | \r |
522 | /* from < to */\r | |
b602265d DG |
523 | #define BB_MOVE_RIGHT(buf,from,to,n) do {\\r |
524 | if ((unsigned int )((to)+(n)) > (buf)->alloc) BB_EXPAND((buf),(to) + (n));\\r | |
14b0e578 CS |
525 | xmemmove((buf)->p + (to), (buf)->p + (from), (n));\\r |
526 | if ((unsigned int )((to)+(n)) > (buf)->used) (buf)->used = (to) + (n);\\r | |
527 | } while (0)\r | |
528 | \r | |
529 | /* from > to */\r | |
b602265d | 530 | #define BB_MOVE_LEFT(buf,from,to,n) do {\\r |
14b0e578 CS |
531 | xmemmove((buf)->p + (to), (buf)->p + (from), (n));\\r |
532 | } while (0)\r | |
533 | \r | |
534 | /* from > to */\r | |
b602265d | 535 | #define BB_MOVE_LEFT_REDUCE(buf,from,to) do {\\r |
14b0e578 CS |
536 | xmemmove((buf)->p + (to), (buf)->p + (from), (buf)->used - (from));\\r |
537 | (buf)->used -= (from - to);\\r | |
538 | } while (0)\r | |
539 | \r | |
b602265d | 540 | #define BB_INSERT(buf,pos,bytes,n) do {\\r |
14b0e578 | 541 | if (pos >= (buf)->used) {\\r |
b602265d | 542 | BB_WRITE(buf,pos,bytes,n);\\r |
14b0e578 CS |
543 | }\\r |
544 | else {\\r | |
b602265d | 545 | BB_MOVE_RIGHT((buf),(pos),(pos) + (n),((buf)->used - (pos)));\\r |
14b0e578 CS |
546 | xmemcpy((buf)->p + (pos), (bytes), (n));\\r |
547 | }\\r | |
548 | } while (0)\r | |
549 | \r | |
b602265d DG |
550 | #define BB_GET_BYTE(buf, pos) (buf)->p[(pos)]\r |
551 | \r | |
552 | \r | |
553 | /* has body */\r | |
554 | #define ANCHOR_PREC_READ (1<<0)\r | |
555 | #define ANCHOR_PREC_READ_NOT (1<<1)\r | |
556 | #define ANCHOR_LOOK_BEHIND (1<<2)\r | |
557 | #define ANCHOR_LOOK_BEHIND_NOT (1<<3)\r | |
558 | /* no body */\r | |
559 | #define ANCHOR_BEGIN_BUF (1<<4)\r | |
560 | #define ANCHOR_BEGIN_LINE (1<<5)\r | |
561 | #define ANCHOR_BEGIN_POSITION (1<<6)\r | |
562 | #define ANCHOR_END_BUF (1<<7)\r | |
563 | #define ANCHOR_SEMI_END_BUF (1<<8)\r | |
564 | #define ANCHOR_END_LINE (1<<9)\r | |
565 | #define ANCHOR_WORD_BOUNDARY (1<<10)\r | |
566 | #define ANCHOR_NO_WORD_BOUNDARY (1<<11)\r | |
567 | #define ANCHOR_WORD_BEGIN (1<<12)\r | |
568 | #define ANCHOR_WORD_END (1<<13)\r | |
569 | #define ANCHOR_ANYCHAR_INF (1<<14)\r | |
570 | #define ANCHOR_ANYCHAR_INF_ML (1<<15)\r | |
571 | #define ANCHOR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY (1<<16)\r | |
572 | #define ANCHOR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY (1<<17)\r | |
573 | \r | |
574 | \r | |
575 | #define ANCHOR_HAS_BODY(a) ((a)->type < ANCHOR_BEGIN_BUF)\r | |
576 | \r | |
577 | #define IS_WORD_ANCHOR_TYPE(type) \\r | |
578 | ((type) == ANCHOR_WORD_BOUNDARY || (type) == ANCHOR_NO_WORD_BOUNDARY || \\r | |
579 | (type) == ANCHOR_WORD_BEGIN || (type) == ANCHOR_WORD_END)\r | |
14b0e578 CS |
580 | \r |
581 | /* operation code */\r | |
582 | enum OpCode {\r | |
583 | OP_FINISH = 0, /* matching process terminator (no more alternative) */\r | |
584 | OP_END = 1, /* pattern code terminator (success end) */\r | |
585 | \r | |
586 | OP_EXACT1 = 2, /* single byte, N = 1 */\r | |
587 | OP_EXACT2, /* single byte, N = 2 */\r | |
588 | OP_EXACT3, /* single byte, N = 3 */\r | |
589 | OP_EXACT4, /* single byte, N = 4 */\r | |
590 | OP_EXACT5, /* single byte, N = 5 */\r | |
591 | OP_EXACTN, /* single byte */\r | |
592 | OP_EXACTMB2N1, /* mb-length = 2 N = 1 */\r | |
593 | OP_EXACTMB2N2, /* mb-length = 2 N = 2 */\r | |
594 | OP_EXACTMB2N3, /* mb-length = 2 N = 3 */\r | |
595 | OP_EXACTMB2N, /* mb-length = 2 */\r | |
596 | OP_EXACTMB3N, /* mb-length = 3 */\r | |
597 | OP_EXACTMBN, /* other length */\r | |
598 | \r | |
599 | OP_EXACT1_IC, /* single byte, N = 1, ignore case */\r | |
600 | OP_EXACTN_IC, /* single byte, ignore case */\r | |
601 | \r | |
602 | OP_CCLASS,\r | |
603 | OP_CCLASS_MB,\r | |
604 | OP_CCLASS_MIX,\r | |
605 | OP_CCLASS_NOT,\r | |
606 | OP_CCLASS_MB_NOT,\r | |
607 | OP_CCLASS_MIX_NOT,\r | |
b602265d | 608 | #ifdef USE_OP_CCLASS_NODE\r |
14b0e578 | 609 | OP_CCLASS_NODE, /* pointer to CClassNode node */\r |
b602265d | 610 | #endif\r |
14b0e578 CS |
611 | \r |
612 | OP_ANYCHAR, /* "." */\r | |
613 | OP_ANYCHAR_ML, /* "." multi-line */\r | |
614 | OP_ANYCHAR_STAR, /* ".*" */\r | |
615 | OP_ANYCHAR_ML_STAR, /* ".*" multi-line */\r | |
616 | OP_ANYCHAR_STAR_PEEK_NEXT,\r | |
617 | OP_ANYCHAR_ML_STAR_PEEK_NEXT,\r | |
618 | \r | |
619 | OP_WORD,\r | |
b602265d DG |
620 | OP_WORD_ASCII,\r |
621 | OP_NO_WORD,\r | |
622 | OP_NO_WORD_ASCII,\r | |
623 | OP_WORD_BOUNDARY,\r | |
624 | OP_NO_WORD_BOUNDARY,\r | |
14b0e578 CS |
625 | OP_WORD_BEGIN,\r |
626 | OP_WORD_END,\r | |
627 | \r | |
b602265d DG |
628 | OP_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY,\r |
629 | OP_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY,\r | |
630 | \r | |
14b0e578 CS |
631 | OP_BEGIN_BUF,\r |
632 | OP_END_BUF,\r | |
633 | OP_BEGIN_LINE,\r | |
634 | OP_END_LINE,\r | |
635 | OP_SEMI_END_BUF,\r | |
636 | OP_BEGIN_POSITION,\r | |
637 | \r | |
638 | OP_BACKREF1,\r | |
639 | OP_BACKREF2,\r | |
b602265d DG |
640 | OP_BACKREF_N,\r |
641 | OP_BACKREF_N_IC,\r | |
14b0e578 CS |
642 | OP_BACKREF_MULTI,\r |
643 | OP_BACKREF_MULTI_IC,\r | |
b602265d DG |
644 | OP_BACKREF_WITH_LEVEL, /* \k<xxx+n>, \k<xxx-n> */\r |
645 | OP_BACKREF_CHECK, /* (?(n)), (?('name')) */\r | |
646 | OP_BACKREF_CHECK_WITH_LEVEL, /* (?(n-level)), (?('name-level')) */\r | |
14b0e578 CS |
647 | \r |
648 | OP_MEMORY_START,\r | |
649 | OP_MEMORY_START_PUSH, /* push back-tracker to stack */\r | |
650 | OP_MEMORY_END_PUSH, /* push back-tracker to stack */\r | |
651 | OP_MEMORY_END_PUSH_REC, /* push back-tracker to stack */\r | |
652 | OP_MEMORY_END,\r | |
653 | OP_MEMORY_END_REC, /* push marker to stack */\r | |
654 | \r | |
655 | OP_FAIL, /* pop stack and move */\r | |
656 | OP_JUMP,\r | |
657 | OP_PUSH,\r | |
b602265d DG |
658 | OP_PUSH_SUPER,\r |
659 | OP_POP_OUT,\r | |
14b0e578 CS |
660 | OP_PUSH_OR_JUMP_EXACT1, /* if match exact then push, else jump. */\r |
661 | OP_PUSH_IF_PEEK_NEXT, /* if match exact then push, else none. */\r | |
662 | OP_REPEAT, /* {n,m} */\r | |
663 | OP_REPEAT_NG, /* {n,m}? (non greedy) */\r | |
664 | OP_REPEAT_INC,\r | |
665 | OP_REPEAT_INC_NG, /* non greedy */\r | |
666 | OP_REPEAT_INC_SG, /* search and get in stack */\r | |
667 | OP_REPEAT_INC_NG_SG, /* search and get in stack (non greedy) */\r | |
b602265d DG |
668 | OP_EMPTY_CHECK_START, /* null loop checker start */\r |
669 | OP_EMPTY_CHECK_END, /* null loop checker end */\r | |
670 | OP_EMPTY_CHECK_END_MEMST, /* null loop checker end (with capture status) */\r | |
671 | OP_EMPTY_CHECK_END_MEMST_PUSH, /* with capture status and push check-end */\r | |
672 | \r | |
673 | OP_PREC_READ_START, /* (?=...) start */\r | |
674 | OP_PREC_READ_END, /* (?=...) end */\r | |
675 | OP_PREC_READ_NOT_START, /* (?!...) start */\r | |
676 | OP_PREC_READ_NOT_END, /* (?!...) end */\r | |
677 | OP_ATOMIC_START, /* (?>...) start */\r | |
678 | OP_ATOMIC_END, /* (?>...) end */\r | |
679 | OP_LOOK_BEHIND, /* (?<=...) start (no needs end opcode) */\r | |
680 | OP_LOOK_BEHIND_NOT_START, /* (?<!...) start */\r | |
681 | OP_LOOK_BEHIND_NOT_END, /* (?<!...) end */\r | |
682 | \r | |
683 | OP_CALL, /* \g<name> */\r | |
14b0e578 | 684 | OP_RETURN,\r |
b602265d DG |
685 | OP_PUSH_SAVE_VAL,\r |
686 | OP_UPDATE_VAR,\r | |
687 | #ifdef USE_CALLOUT\r | |
688 | OP_CALLOUT_CONTENTS, /* (?{...}) (?{{...}}) */\r | |
689 | OP_CALLOUT_NAME, /* (*name) (*name[tag](args...)) */\r | |
690 | #endif\r | |
691 | };\r | |
14b0e578 | 692 | \r |
b602265d DG |
693 | enum SaveType {\r |
694 | SAVE_KEEP = 0, /* SAVE S */\r | |
695 | SAVE_S = 1,\r | |
696 | SAVE_RIGHT_RANGE = 2,\r | |
697 | };\r | |
14b0e578 | 698 | \r |
b602265d DG |
699 | enum UpdateVarType {\r |
700 | UPDATE_VAR_KEEP_FROM_STACK_LAST = 0,\r | |
701 | UPDATE_VAR_S_FROM_STACK = 1,\r | |
702 | UPDATE_VAR_RIGHT_RANGE_FROM_STACK = 2,\r | |
703 | UPDATE_VAR_RIGHT_RANGE_FROM_S_STACK = 3,\r | |
704 | UPDATE_VAR_RIGHT_RANGE_INIT = 4,\r | |
14b0e578 CS |
705 | };\r |
706 | \r | |
707 | typedef int RelAddrType;\r | |
708 | typedef int AbsAddrType;\r | |
709 | typedef int LengthType;\r | |
710 | typedef int RepeatNumType;\r | |
b602265d | 711 | typedef int MemNumType;\r |
14b0e578 | 712 | typedef void* PointerType;\r |
b602265d DG |
713 | typedef int SaveType;\r |
714 | typedef int UpdateVarType;\r | |
715 | typedef int ModeType;\r | |
14b0e578 CS |
716 | \r |
717 | #define SIZE_OPCODE 1\r | |
718 | #define SIZE_RELADDR sizeof(RelAddrType)\r | |
719 | #define SIZE_ABSADDR sizeof(AbsAddrType)\r | |
720 | #define SIZE_LENGTH sizeof(LengthType)\r | |
721 | #define SIZE_MEMNUM sizeof(MemNumType)\r | |
14b0e578 CS |
722 | #define SIZE_REPEATNUM sizeof(RepeatNumType)\r |
723 | #define SIZE_OPTION sizeof(OnigOptionType)\r | |
724 | #define SIZE_CODE_POINT sizeof(OnigCodePoint)\r | |
725 | #define SIZE_POINTER sizeof(PointerType)\r | |
b602265d DG |
726 | #define SIZE_SAVE_TYPE sizeof(SaveType)\r |
727 | #define SIZE_UPDATE_VAR_TYPE sizeof(UpdateVarType)\r | |
728 | #define SIZE_MODE sizeof(ModeType)\r | |
14b0e578 CS |
729 | \r |
730 | #define GET_RELADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, RelAddrType)\r | |
731 | #define GET_ABSADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, AbsAddrType)\r | |
732 | #define GET_LENGTH_INC(len,p) PLATFORM_GET_INC(len, p, LengthType)\r | |
733 | #define GET_MEMNUM_INC(num,p) PLATFORM_GET_INC(num, p, MemNumType)\r | |
734 | #define GET_REPEATNUM_INC(num,p) PLATFORM_GET_INC(num, p, RepeatNumType)\r | |
735 | #define GET_OPTION_INC(option,p) PLATFORM_GET_INC(option, p, OnigOptionType)\r | |
736 | #define GET_POINTER_INC(ptr,p) PLATFORM_GET_INC(ptr, p, PointerType)\r | |
b602265d DG |
737 | #define GET_SAVE_TYPE_INC(type,p) PLATFORM_GET_INC(type, p, SaveType)\r |
738 | #define GET_UPDATE_VAR_TYPE_INC(type,p) PLATFORM_GET_INC(type, p, UpdateVarType)\r | |
739 | #define GET_MODE_INC(mode,p) PLATFORM_GET_INC(mode, p, ModeType)\r | |
14b0e578 CS |
740 | \r |
741 | /* code point's address must be aligned address. */\r | |
742 | #define GET_CODE_POINT(code,p) code = *((OnigCodePoint* )(p))\r | |
743 | #define GET_BYTE_INC(byte,p) do{\\r | |
744 | byte = *(p);\\r | |
745 | (p)++;\\r | |
746 | } while(0)\r | |
747 | \r | |
748 | \r | |
749 | /* op-code + arg size */\r | |
750 | #define SIZE_OP_ANYCHAR_STAR SIZE_OPCODE\r | |
751 | #define SIZE_OP_ANYCHAR_STAR_PEEK_NEXT (SIZE_OPCODE + 1)\r | |
752 | #define SIZE_OP_JUMP (SIZE_OPCODE + SIZE_RELADDR)\r | |
753 | #define SIZE_OP_PUSH (SIZE_OPCODE + SIZE_RELADDR)\r | |
b602265d DG |
754 | #define SIZE_OP_PUSH_SUPER (SIZE_OPCODE + SIZE_RELADDR)\r |
755 | #define SIZE_OP_POP_OUT SIZE_OPCODE\r | |
14b0e578 CS |
756 | #define SIZE_OP_PUSH_OR_JUMP_EXACT1 (SIZE_OPCODE + SIZE_RELADDR + 1)\r |
757 | #define SIZE_OP_PUSH_IF_PEEK_NEXT (SIZE_OPCODE + SIZE_RELADDR + 1)\r | |
758 | #define SIZE_OP_REPEAT_INC (SIZE_OPCODE + SIZE_MEMNUM)\r | |
759 | #define SIZE_OP_REPEAT_INC_NG (SIZE_OPCODE + SIZE_MEMNUM)\r | |
b602265d DG |
760 | #define SIZE_OP_WORD_BOUNDARY (SIZE_OPCODE + SIZE_MODE)\r |
761 | #define SIZE_OP_PREC_READ_START SIZE_OPCODE\r | |
762 | #define SIZE_OP_PREC_READ_NOT_START (SIZE_OPCODE + SIZE_RELADDR)\r | |
763 | #define SIZE_OP_PREC_READ_END SIZE_OPCODE\r | |
764 | #define SIZE_OP_PREC_READ_NOT_END SIZE_OPCODE\r | |
14b0e578 CS |
765 | #define SIZE_OP_FAIL SIZE_OPCODE\r |
766 | #define SIZE_OP_MEMORY_START (SIZE_OPCODE + SIZE_MEMNUM)\r | |
767 | #define SIZE_OP_MEMORY_START_PUSH (SIZE_OPCODE + SIZE_MEMNUM)\r | |
768 | #define SIZE_OP_MEMORY_END_PUSH (SIZE_OPCODE + SIZE_MEMNUM)\r | |
769 | #define SIZE_OP_MEMORY_END_PUSH_REC (SIZE_OPCODE + SIZE_MEMNUM)\r | |
770 | #define SIZE_OP_MEMORY_END (SIZE_OPCODE + SIZE_MEMNUM)\r | |
771 | #define SIZE_OP_MEMORY_END_REC (SIZE_OPCODE + SIZE_MEMNUM)\r | |
b602265d DG |
772 | #define SIZE_OP_ATOMIC_START SIZE_OPCODE\r |
773 | #define SIZE_OP_ATOMIC_END SIZE_OPCODE\r | |
774 | #define SIZE_OP_EMPTY_CHECK_START (SIZE_OPCODE + SIZE_MEMNUM)\r | |
775 | #define SIZE_OP_EMPTY_CHECK_END (SIZE_OPCODE + SIZE_MEMNUM)\r | |
14b0e578 | 776 | #define SIZE_OP_LOOK_BEHIND (SIZE_OPCODE + SIZE_LENGTH)\r |
b602265d DG |
777 | #define SIZE_OP_LOOK_BEHIND_NOT_START (SIZE_OPCODE + SIZE_RELADDR + SIZE_LENGTH)\r |
778 | #define SIZE_OP_LOOK_BEHIND_NOT_END SIZE_OPCODE\r | |
14b0e578 CS |
779 | #define SIZE_OP_CALL (SIZE_OPCODE + SIZE_ABSADDR)\r |
780 | #define SIZE_OP_RETURN SIZE_OPCODE\r | |
b602265d DG |
781 | #define SIZE_OP_PUSH_SAVE_VAL (SIZE_OPCODE + SIZE_SAVE_TYPE + SIZE_MEMNUM)\r |
782 | #define SIZE_OP_UPDATE_VAR (SIZE_OPCODE + SIZE_UPDATE_VAR_TYPE + SIZE_MEMNUM)\r | |
14b0e578 | 783 | \r |
b602265d DG |
784 | #ifdef USE_CALLOUT\r |
785 | #define SIZE_OP_CALLOUT_CONTENTS (SIZE_OPCODE + SIZE_MEMNUM)\r | |
786 | #define SIZE_OP_CALLOUT_NAME (SIZE_OPCODE + SIZE_MEMNUM + SIZE_MEMNUM)\r | |
14b0e578 CS |
787 | #endif\r |
788 | \r | |
789 | #define MC_ESC(syn) (syn)->meta_char_table.esc\r | |
790 | #define MC_ANYCHAR(syn) (syn)->meta_char_table.anychar\r | |
791 | #define MC_ANYTIME(syn) (syn)->meta_char_table.anytime\r | |
792 | #define MC_ZERO_OR_ONE_TIME(syn) (syn)->meta_char_table.zero_or_one_time\r | |
793 | #define MC_ONE_OR_MORE_TIME(syn) (syn)->meta_char_table.one_or_more_time\r | |
794 | #define MC_ANYCHAR_ANYTIME(syn) (syn)->meta_char_table.anychar_anytime\r | |
795 | \r | |
796 | #define IS_MC_ESC_CODE(code, syn) \\r | |
797 | ((code) == MC_ESC(syn) && \\r | |
798 | !IS_SYNTAX_OP2((syn), ONIG_SYN_OP2_INEFFECTIVE_ESCAPE))\r | |
799 | \r | |
800 | \r | |
801 | #define SYN_POSIX_COMMON_OP \\r | |
802 | ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_POSIX_BRACKET | \\r | |
803 | ONIG_SYN_OP_DECIMAL_BACKREF | \\r | |
804 | ONIG_SYN_OP_BRACKET_CC | ONIG_SYN_OP_ASTERISK_ZERO_INF | \\r | |
805 | ONIG_SYN_OP_LINE_ANCHOR | \\r | |
806 | ONIG_SYN_OP_ESC_CONTROL_CHARS )\r | |
807 | \r | |
808 | #define SYN_GNU_REGEX_OP \\r | |
809 | ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC | \\r | |
810 | ONIG_SYN_OP_POSIX_BRACKET | ONIG_SYN_OP_DECIMAL_BACKREF | \\r | |
811 | ONIG_SYN_OP_BRACE_INTERVAL | ONIG_SYN_OP_LPAREN_SUBEXP | \\r | |
812 | ONIG_SYN_OP_VBAR_ALT | \\r | |
813 | ONIG_SYN_OP_ASTERISK_ZERO_INF | ONIG_SYN_OP_PLUS_ONE_INF | \\r | |
814 | ONIG_SYN_OP_QMARK_ZERO_ONE | \\r | |
815 | ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR | ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR | \\r | |
816 | ONIG_SYN_OP_ESC_W_WORD | \\r | |
817 | ONIG_SYN_OP_ESC_B_WORD_BOUND | ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END | \\r | |
818 | ONIG_SYN_OP_ESC_S_WHITE_SPACE | ONIG_SYN_OP_ESC_D_DIGIT | \\r | |
819 | ONIG_SYN_OP_LINE_ANCHOR )\r | |
820 | \r | |
821 | #define SYN_GNU_REGEX_BV \\r | |
822 | ( ONIG_SYN_CONTEXT_INDEP_ANCHORS | ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS | \\r | |
823 | ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS | ONIG_SYN_ALLOW_INVALID_INTERVAL | \\r | |
824 | ONIG_SYN_BACKSLASH_ESCAPE_IN_CC | ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC )\r | |
825 | \r | |
826 | \r | |
827 | #define NCCLASS_FLAGS(cc) ((cc)->flags)\r | |
828 | #define NCCLASS_FLAG_SET(cc,flag) (NCCLASS_FLAGS(cc) |= (flag))\r | |
829 | #define NCCLASS_FLAG_CLEAR(cc,flag) (NCCLASS_FLAGS(cc) &= ~(flag))\r | |
830 | #define IS_NCCLASS_FLAG_ON(cc,flag) ((NCCLASS_FLAGS(cc) & (flag)) != 0)\r | |
831 | \r | |
832 | /* cclass node */\r | |
833 | #define FLAG_NCCLASS_NOT (1<<0)\r | |
834 | #define FLAG_NCCLASS_SHARE (1<<1)\r | |
835 | \r | |
836 | #define NCCLASS_SET_NOT(nd) NCCLASS_FLAG_SET(nd, FLAG_NCCLASS_NOT)\r | |
14b0e578 CS |
837 | #define NCCLASS_CLEAR_NOT(nd) NCCLASS_FLAG_CLEAR(nd, FLAG_NCCLASS_NOT)\r |
838 | #define IS_NCCLASS_NOT(nd) IS_NCCLASS_FLAG_ON(nd, FLAG_NCCLASS_NOT)\r | |
14b0e578 | 839 | \r |
b602265d | 840 | extern void onig_add_end_call(void (*func)(void));\r |
14b0e578 | 841 | \r |
14b0e578 | 842 | \r |
b602265d | 843 | #ifdef ONIG_DEBUG\r |
14b0e578 | 844 | \r |
b602265d DG |
845 | #ifdef ONIG_DEBUG_COMPILE\r |
846 | extern void onig_print_compiled_byte_code_list(FILE* f, regex_t* reg);\r | |
14b0e578 | 847 | #endif\r |
14b0e578 | 848 | \r |
b602265d DG |
849 | #ifdef ONIG_DEBUG_STATISTICS\r |
850 | extern void onig_statistics_init P_((void));\r | |
851 | extern int onig_print_statistics P_((FILE* f));\r | |
14b0e578 | 852 | #endif\r |
14b0e578 | 853 | #endif\r |
14b0e578 | 854 | \r |
b602265d DG |
855 | extern void onig_warning(const char* s);\r |
856 | extern UChar* onig_error_code_to_format P_((int code));\r | |
857 | extern void EFIAPI onig_snprintf_with_pattern PV_((UChar buf[], int bufsize, OnigEncoding enc, UChar* pat, UChar* pat_end, const UChar *fmt, ...));\r | |
858 | extern int onig_bbuf_init P_((BBuf* buf, int size));\r | |
859 | extern int onig_compile P_((regex_t* reg, const UChar* pattern, const UChar* pattern_end, OnigErrorInfo* einfo));\r | |
860 | extern void onig_transfer P_((regex_t* to, regex_t* from));\r | |
861 | extern int onig_is_code_in_cc_len P_((int enclen, OnigCodePoint code, void* /* CClassNode* */ cc));\r | |
862 | extern RegexExt* onig_get_regex_ext(regex_t* reg);\r | |
863 | extern int onig_ext_set_pattern(regex_t* reg, const UChar* pattern, const UChar* pattern_end);\r | |
864 | \r | |
865 | #ifdef USE_CALLOUT\r | |
866 | \r | |
867 | extern OnigCalloutType onig_get_callout_type_by_name_id(int name_id);\r | |
868 | extern OnigCalloutFunc onig_get_callout_start_func_by_name_id(int id);\r | |
869 | extern OnigCalloutFunc onig_get_callout_end_func_by_name_id(int id);\r | |
870 | extern int onig_callout_tag_table_free(void* table);\r | |
871 | extern void onig_free_reg_callout_list(int n, CalloutListEntry* list);\r | |
872 | extern CalloutListEntry* onig_reg_callout_list_at(regex_t* reg, int num);\r | |
873 | extern OnigCalloutFunc onig_get_callout_start_func(regex_t* reg, int callout_num);\r | |
874 | \r | |
875 | /* for definition of builtin callout */\r | |
876 | #define BC0_P(name, func) do {\\r | |
877 | int len = onigenc_str_bytelen_null(enc, (UChar* )name);\\r | |
878 | id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\\r | |
879 | (UChar* )(name), (UChar* )((name) + len),\\r | |
880 | ONIG_CALLOUT_IN_PROGRESS,\\r | |
881 | onig_builtin_ ## func, 0, 0, 0, 0, 0);\\r | |
882 | if (id < 0) return id;\\r | |
883 | } while(0)\r | |
14b0e578 | 884 | \r |
b602265d DG |
885 | #define BC0_R(name, func) do {\\r |
886 | int len = onigenc_str_bytelen_null(enc, (UChar* )name);\\r | |
887 | id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\\r | |
888 | (UChar* )(name), (UChar* )((name) + len),\\r | |
889 | ONIG_CALLOUT_IN_RETRACTION,\\r | |
890 | onig_builtin_ ## func, 0, 0, 0, 0, 0);\\r | |
891 | if (id < 0) return id;\\r | |
892 | } while(0)\r | |
14b0e578 | 893 | \r |
b602265d DG |
894 | #define BC0_B(name, func) do {\\r |
895 | int len = onigenc_str_bytelen_null(enc, (UChar* )name);\\r | |
896 | id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\\r | |
897 | (UChar* )(name), (UChar* )((name) + len),\\r | |
898 | ONIG_CALLOUT_IN_BOTH,\\r | |
899 | onig_builtin_ ## func, 0, 0, 0, 0, 0);\\r | |
900 | if (id < 0) return id;\\r | |
901 | } while(0)\r | |
14b0e578 | 902 | \r |
b602265d DG |
903 | #define BC_P(name, func, na, ts) do {\\r |
904 | int len = onigenc_str_bytelen_null(enc, (UChar* )name);\\r | |
905 | id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\\r | |
906 | (UChar* )(name), (UChar* )((name) + len),\\r | |
907 | ONIG_CALLOUT_IN_PROGRESS,\\r | |
908 | onig_builtin_ ## func, 0, (na), (ts), 0, 0); \\r | |
909 | if (id < 0) return id;\\r | |
910 | } while(0)\r | |
14b0e578 | 911 | \r |
b602265d DG |
912 | #define BC_P_O(name, func, nts, ts, nopts, opts) do {\\r |
913 | int len = onigenc_str_bytelen_null(enc, (UChar* )name);\\r | |
914 | id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\\r | |
915 | (UChar* )(name), (UChar* )((name) + len),\\r | |
916 | ONIG_CALLOUT_IN_PROGRESS,\\r | |
917 | onig_builtin_ ## func, 0, (nts), (ts), (nopts), (opts));\\r | |
918 | if (id < 0) return id;\\r | |
919 | } while(0)\r | |
14b0e578 | 920 | \r |
b602265d DG |
921 | #define BC_B(name, func, na, ts) do {\\r |
922 | int len = onigenc_str_bytelen_null(enc, (UChar* )name);\\r | |
923 | id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\\r | |
924 | (UChar* )(name), (UChar* )((name) + len),\\r | |
925 | ONIG_CALLOUT_IN_BOTH,\\r | |
926 | onig_builtin_ ## func, 0, (na), (ts), 0, 0);\\r | |
927 | if (id < 0) return id;\\r | |
928 | } while(0)\r | |
14b0e578 | 929 | \r |
b602265d DG |
930 | #define BC_B_O(name, func, nts, ts, nopts, opts) do {\\r |
931 | int len = onigenc_str_bytelen_null(enc, (UChar* )name);\\r | |
932 | id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\\r | |
933 | (UChar* )(name), (UChar* )((name) + len),\\r | |
934 | ONIG_CALLOUT_IN_BOTH,\\r | |
935 | onig_builtin_ ## func, 0, (nts), (ts), (nopts), (opts));\\r | |
936 | if (id < 0) return id;\\r | |
937 | } while(0)\r | |
14b0e578 | 938 | \r |
b602265d | 939 | #endif /* USE_CALLOUT */\r |
14b0e578 CS |
940 | \r |
941 | \r | |
b602265d DG |
942 | /* strend hash */\r |
943 | typedef void hash_table_type;\r | |
14b0e578 | 944 | \r |
b602265d DG |
945 | #ifdef _WIN32\r |
946 | # include <windows.h>\r | |
947 | typedef ULONG_PTR hash_data_type;\r | |
948 | #else\r | |
949 | //typedef unsigned long hash_data_type;\r | |
14b0e578 CS |
950 | #endif\r |
951 | \r | |
b602265d | 952 | typedef UINTN hash_data_type;\r |
14b0e578 CS |
953 | \r |
954 | extern hash_table_type* onig_st_init_strend_table_with_size P_((int size));\r | |
955 | extern int onig_st_lookup_strend P_((hash_table_type* table, const UChar* str_key, const UChar* end_key, hash_data_type *value));\r | |
956 | extern int onig_st_insert_strend P_((hash_table_type* table, const UChar* str_key, const UChar* end_key, hash_data_type value));\r | |
957 | \r | |
14b0e578 CS |
958 | typedef int (*ONIGENC_INIT_PROPERTY_LIST_FUNC_TYPE)(void);\r |
959 | \r | |
14b0e578 | 960 | #endif /* REGINT_H */\r |
b602265d DG |
961 | #include <ProcessorBind.h>\r |
962 | #define INT_MAX MAX_INTN\r | |
963 | #define LONG_MAX MAX_UINTN\r |