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