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