00001 #ifndef ONIGURUMA_REGINT_H
00002 #define ONIGURUMA_REGINT_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #if defined(ONIG_DEBUG_PARSE_TREE) || defined(ONIG_DEBUG_MATCH) || \
00043 defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) || \
00044 defined(ONIG_DEBUG_STATISTICS)
00045 #ifndef ONIG_DEBUG
00046 #define ONIG_DEBUG
00047 #endif
00048 #endif
00049
00050 #if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
00051 (defined(__ppc__) && defined(__APPLE__)) || \
00052 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD86) || \
00053 defined(__mc68020__)
00054 #define PLATFORM_UNALIGNED_WORD_ACCESS
00055 #endif
00056
00057
00058
00059 #define USE_NAMED_GROUP
00060 #define USE_SUBEXP_CALL
00061 #define USE_BACKREF_WITH_LEVEL
00062 #define USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT
00063 #define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE
00064 #define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
00065
00066
00067
00068
00069 #define USE_PARSE_TREE_NODE_RECYCLE
00070 #define USE_OP_PUSH_OR_JUMP_EXACT
00071 #define USE_QTFR_PEEK_NEXT
00072 #define USE_ST_LIBRARY
00073 #define USE_SHARED_CCLASS_TABLE
00074
00075 #define INIT_MATCH_STACK_SIZE 160
00076 #define DEFAULT_MATCH_STACK_LIMIT_SIZE 0
00077
00078 #if defined(__GNUC__)
00079 # define ARG_UNUSED __attribute__ ((unused))
00080 #else
00081 # define ARG_UNUSED
00082 #endif
00083
00084
00085
00086 #ifndef RUBY_DEFINES_H
00087 #include "ruby/ruby.h"
00088 #undef xmalloc
00089 #undef xrealloc
00090 #undef xcalloc
00091 #undef xfree
00092 #endif
00093 #ifdef ONIG_ESCAPE_UCHAR_COLLISION
00094 #undef ONIG_ESCAPE_UCHAR_COLLISION
00095 #endif
00096 #undef USE_MATCH_RANGE_IS_COMPLETE_RANGE
00097 #undef USE_CAPTURE_HISTORY
00098 #define USE_VARIABLE_META_CHARS
00099 #define USE_WORD_BEGIN_END
00100 #define USE_POSIX_REGION_OPTION
00101 #define USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
00102
00103
00104 #define THREAD_SYSTEM_INIT
00105 #define THREAD_SYSTEM_END
00106 #define THREAD_ATOMIC_START
00107 #define THREAD_ATOMIC_END
00108 #define THREAD_PASS
00109 #ifndef xmalloc
00110 #define xmalloc malloc
00111 #define xrealloc realloc
00112 #define xcalloc calloc
00113 #define xfree free
00114 #endif
00115
00116 #ifdef RUBY
00117
00118 #define CHECK_INTERRUPT_IN_MATCH_AT rb_thread_check_ints()
00119 #define onig_st_init_table st_init_table
00120 #define onig_st_init_table_with_size st_init_table_with_size
00121 #define onig_st_init_numtable st_init_numtable
00122 #define onig_st_init_numtable_with_size st_init_numtable_with_size
00123 #define onig_st_init_strtable st_init_strtable
00124 #define onig_st_init_strtable_with_size st_init_strtable_with_size
00125 #define onig_st_delete st_delete
00126 #define onig_st_delete_safe st_delete_safe
00127 #define onig_st_insert st_insert
00128 #define onig_st_lookup st_lookup
00129 #define onig_st_foreach st_foreach
00130 #define onig_st_add_direct st_add_direct
00131 #define onig_st_free_table st_free_table
00132 #define onig_st_cleanup_safe st_cleanup_safe
00133 #define onig_st_copy st_copy
00134 #define onig_st_nothing_key_clone st_nothing_key_clone
00135 #define onig_st_nothing_key_free st_nothing_key_free
00136 #define onig_st_is_member st_is_member
00137
00138 #define USE_UPPER_CASE_TABLE
00139 #else
00140
00141 #define st_init_table onig_st_init_table
00142 #define st_init_table_with_size onig_st_init_table_with_size
00143 #define st_init_numtable onig_st_init_numtable
00144 #define st_init_numtable_with_size onig_st_init_numtable_with_size
00145 #define st_init_strtable onig_st_init_strtable
00146 #define st_init_strtable_with_size onig_st_init_strtable_with_size
00147 #define st_delete onig_st_delete
00148 #define st_delete_safe onig_st_delete_safe
00149 #define st_insert onig_st_insert
00150 #define st_lookup onig_st_lookup
00151 #define st_foreach onig_st_foreach
00152 #define st_add_direct onig_st_add_direct
00153 #define st_free_table onig_st_free_table
00154 #define st_cleanup_safe onig_st_cleanup_safe
00155 #define st_copy onig_st_copy
00156 #define st_nothing_key_clone onig_st_nothing_key_clone
00157 #define st_nothing_key_free onig_st_nothing_key_free
00158
00159 #define onig_st_is_member st_is_member
00160
00161 #define CHECK_INTERRUPT_IN_MATCH_AT
00162
00163 #endif
00164
00165 #define STATE_CHECK_STRING_THRESHOLD_LEN 7
00166 #define STATE_CHECK_BUFF_MAX_SIZE 0x4000
00167
00168 #define THREAD_PASS_LIMIT_COUNT 8
00169 #define xmemset memset
00170 #define xmemcpy memcpy
00171 #define xmemmove memmove
00172
00173 #if defined(_WIN32) && !defined(__GNUC__)
00174 #define xalloca _alloca
00175 #define xvsnprintf _vsnprintf
00176 #else
00177 #define xalloca alloca
00178 #define xvsnprintf vsnprintf
00179 #endif
00180
00181
00182 #if defined(USE_RECOMPILE_API) && defined(USE_MULTI_THREAD_SYSTEM)
00183 #define ONIG_STATE_INC(reg) (reg)->state++
00184 #define ONIG_STATE_DEC(reg) (reg)->state--
00185
00186 #define ONIG_STATE_INC_THREAD(reg) do {\
00187 THREAD_ATOMIC_START;\
00188 (reg)->state++;\
00189 THREAD_ATOMIC_END;\
00190 } while(0)
00191 #define ONIG_STATE_DEC_THREAD(reg) do {\
00192 THREAD_ATOMIC_START;\
00193 (reg)->state--;\
00194 THREAD_ATOMIC_END;\
00195 } while(0)
00196 #else
00197 #define ONIG_STATE_INC(reg)
00198 #define ONIG_STATE_DEC(reg)
00199 #define ONIG_STATE_INC_THREAD(reg)
00200 #define ONIG_STATE_DEC_THREAD(reg)
00201 #endif
00202
00203 #ifdef HAVE_STDLIB_H
00204 #include <stdlib.h>
00205 #endif
00206
00207 #if defined(HAVE_ALLOCA_H) && (defined(_AIX) || !defined(__GNUC__))
00208 #include <alloca.h>
00209 #endif
00210
00211 #ifdef HAVE_STRING_H
00212 # include <string.h>
00213 #else
00214 # include <strings.h>
00215 #endif
00216
00217 #include <ctype.h>
00218 #ifdef HAVE_SYS_TYPES_H
00219 #include <sys/types.h>
00220 #endif
00221
00222 #ifdef ONIG_DEBUG
00223 # include <stdio.h>
00224 #endif
00225
00226 #include "regenc.h"
00227
00228 #ifdef MIN
00229 #undef MIN
00230 #endif
00231 #ifdef MAX
00232 #undef MAX
00233 #endif
00234 #define MIN(a,b) (((a)>(b))?(b):(a))
00235 #define MAX(a,b) (((a)<(b))?(b):(a))
00236
00237 #define IS_NULL(p) (((void*)(p)) == (void*)0)
00238 #define IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
00239 #define CHECK_NULL_RETURN(p) if (IS_NULL(p)) return NULL
00240 #define CHECK_NULL_RETURN_MEMERR(p) if (IS_NULL(p)) return ONIGERR_MEMORY
00241 #define NULL_UCHARP ((UChar* )0)
00242
00243 #ifdef PLATFORM_UNALIGNED_WORD_ACCESS
00244
00245 #define PLATFORM_GET_INC(val,p,type) do{\
00246 val = *(type* )p;\
00247 (p) += sizeof(type);\
00248 } while(0)
00249
00250 #else
00251
00252 #define PLATFORM_GET_INC(val,p,type) do{\
00253 xmemcpy(&val, (p), sizeof(type));\
00254 (p) += sizeof(type);\
00255 } while(0)
00256
00257
00258 #define WORD_ALIGNMENT_SIZE SIZEOF_LONG
00259
00260 #define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\
00261 (pad_size) = WORD_ALIGNMENT_SIZE \
00262 - ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
00263 if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\
00264 } while (0)
00265
00266 #define ALIGNMENT_RIGHT(addr) do {\
00267 (addr) += (WORD_ALIGNMENT_SIZE - 1);\
00268 (addr) -= ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
00269 } while (0)
00270
00271 #endif
00272
00273
00274 #define STACK_POP_LEVEL_FREE 0
00275 #define STACK_POP_LEVEL_MEM_START 1
00276 #define STACK_POP_LEVEL_ALL 2
00277
00278
00279 #define ONIG_OPTIMIZE_NONE 0
00280 #define ONIG_OPTIMIZE_EXACT 1
00281 #define ONIG_OPTIMIZE_EXACT_BM 2
00282 #define ONIG_OPTIMIZE_EXACT_BM_NOT_REV 3
00283 #define ONIG_OPTIMIZE_EXACT_IC 4
00284 #define ONIG_OPTIMIZE_MAP 5
00285
00286
00287 typedef unsigned int BitStatusType;
00288
00289 #define BIT_STATUS_BITS_NUM (sizeof(BitStatusType) * 8)
00290 #define BIT_STATUS_CLEAR(stats) (stats) = 0
00291 #define BIT_STATUS_ON_ALL(stats) (stats) = ~((BitStatusType )0)
00292 #define BIT_STATUS_AT(stats,n) \
00293 ((n) < (int )BIT_STATUS_BITS_NUM ? ((stats) & (1 << n)) : ((stats) & 1))
00294
00295 #define BIT_STATUS_ON_AT(stats,n) do {\
00296 if ((n) < (int )BIT_STATUS_BITS_NUM) \
00297 (stats) |= (1 << (n));\
00298 else\
00299 (stats) |= 1;\
00300 } while (0)
00301
00302 #define BIT_STATUS_ON_AT_SIMPLE(stats,n) do {\
00303 if ((n) < (int )BIT_STATUS_BITS_NUM)\
00304 (stats) |= (1 << (n));\
00305 } while (0)
00306
00307
00308 #define INT_MAX_LIMIT ((1UL << (SIZEOF_INT * 8 - 1)) - 1)
00309
00310 #define DIGITVAL(code) ((code) - '0')
00311 #define ODIGITVAL(code) DIGITVAL(code)
00312 #define XDIGITVAL(enc,code) \
00313 (ONIGENC_IS_CODE_DIGIT(enc,code) ? DIGITVAL(code) \
00314 : (ONIGENC_IS_CODE_UPPER(enc,code) ? (code) - 'A' + 10 : (code) - 'a' + 10))
00315
00316 #define IS_SINGLELINE(option) ((option) & ONIG_OPTION_SINGLELINE)
00317 #define IS_MULTILINE(option) ((option) & ONIG_OPTION_MULTILINE)
00318 #define IS_IGNORECASE(option) ((option) & ONIG_OPTION_IGNORECASE)
00319 #define IS_EXTEND(option) ((option) & ONIG_OPTION_EXTEND)
00320 #define IS_FIND_LONGEST(option) ((option) & ONIG_OPTION_FIND_LONGEST)
00321 #define IS_FIND_NOT_EMPTY(option) ((option) & ONIG_OPTION_FIND_NOT_EMPTY)
00322 #define IS_FIND_CONDITION(option) ((option) & \
00323 (ONIG_OPTION_FIND_LONGEST | ONIG_OPTION_FIND_NOT_EMPTY))
00324 #define IS_NOTBOL(option) ((option) & ONIG_OPTION_NOTBOL)
00325 #define IS_NOTEOL(option) ((option) & ONIG_OPTION_NOTEOL)
00326 #define IS_POSIX_REGION(option) ((option) & ONIG_OPTION_POSIX_REGION)
00327
00328
00329
00330
00331
00332
00333 #define IS_DYNAMIC_OPTION(option) 0
00334
00335 #define DISABLE_CASE_FOLD_MULTI_CHAR(case_fold_flag) \
00336 ((case_fold_flag) & ~INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR)
00337
00338 #define REPEAT_INFINITE -1
00339 #define IS_REPEAT_INFINITE(n) ((n) == REPEAT_INFINITE)
00340
00341
00342 #define BITS_PER_BYTE 8
00343 #define SINGLE_BYTE_SIZE (1 << BITS_PER_BYTE)
00344 #define BITS_IN_ROOM (sizeof(Bits) * BITS_PER_BYTE)
00345 #define BITSET_SIZE (SINGLE_BYTE_SIZE / BITS_IN_ROOM)
00346
00347 #ifdef PLATFORM_UNALIGNED_WORD_ACCESS
00348 typedef unsigned int Bits;
00349 #else
00350 typedef unsigned char Bits;
00351 #endif
00352 typedef Bits BitSet[BITSET_SIZE];
00353 typedef Bits* BitSetRef;
00354
00355 #define SIZE_BITSET (int)sizeof(BitSet)
00356
00357 #define BITSET_CLEAR(bs) do {\
00358 int i;\
00359 for (i = 0; i < (int )BITSET_SIZE; i++) { (bs)[i] = 0; } \
00360 } while (0)
00361
00362 #define BS_ROOM(bs,pos) (bs)[pos / BITS_IN_ROOM]
00363 #define BS_BIT(pos) (1 << (pos % BITS_IN_ROOM))
00364
00365 #define BITSET_AT(bs, pos) (BS_ROOM(bs,pos) & BS_BIT(pos))
00366 #define BITSET_SET_BIT(bs, pos) BS_ROOM(bs,pos) |= BS_BIT(pos)
00367 #define BITSET_CLEAR_BIT(bs, pos) BS_ROOM(bs,pos) &= ~(BS_BIT(pos))
00368 #define BITSET_INVERT_BIT(bs, pos) BS_ROOM(bs,pos) ^= BS_BIT(pos)
00369
00370
00371 typedef struct _BBuf {
00372 UChar* p;
00373 unsigned int used;
00374 unsigned int alloc;
00375 } BBuf;
00376
00377 #define BBUF_INIT(buf,size) onig_bbuf_init((BBuf* )(buf), (size))
00378
00379 #define BBUF_SIZE_INC(buf,inc) do{\
00380 (buf)->alloc += (inc);\
00381 (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
00382 if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
00383 } while (0)
00384
00385 #define BBUF_EXPAND(buf,low) do{\
00386 do { (buf)->alloc *= 2; } while ((buf)->alloc < (unsigned int )low);\
00387 (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
00388 if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
00389 } while (0)
00390
00391 #define BBUF_ENSURE_SIZE(buf,size) do{\
00392 unsigned int new_alloc = (buf)->alloc;\
00393 while (new_alloc < (unsigned int )(size)) { new_alloc *= 2; }\
00394 if ((buf)->alloc != new_alloc) {\
00395 (buf)->p = (UChar* )xrealloc((buf)->p, new_alloc);\
00396 if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
00397 (buf)->alloc = new_alloc;\
00398 }\
00399 } while (0)
00400
00401 #define BBUF_WRITE(buf,pos,bytes,n) do{\
00402 int used = (pos) + (n);\
00403 if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
00404 xmemcpy((buf)->p + (pos), (bytes), (n));\
00405 if ((buf)->used < (unsigned int )used) (buf)->used = used;\
00406 } while (0)
00407
00408 #define BBUF_WRITE1(buf,pos,byte) do{\
00409 int used = (pos) + 1;\
00410 if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
00411 (buf)->p[(pos)] = (byte);\
00412 if ((buf)->used < (unsigned int )used) (buf)->used = used;\
00413 } while (0)
00414
00415 #define BBUF_ADD(buf,bytes,n) BBUF_WRITE((buf),(buf)->used,(bytes),(n))
00416 #define BBUF_ADD1(buf,byte) BBUF_WRITE1((buf),(buf)->used,(byte))
00417 #define BBUF_GET_ADD_ADDRESS(buf) ((buf)->p + (buf)->used)
00418 #define BBUF_GET_OFFSET_POS(buf) ((buf)->used)
00419
00420
00421 #define BBUF_MOVE_RIGHT(buf,from,to,n) do {\
00422 if ((unsigned int )((to)+(n)) > (buf)->alloc) BBUF_EXPAND((buf),(to) + (n));\
00423 xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
00424 if ((unsigned int )((to)+(n)) > (buf)->used) (buf)->used = (to) + (n);\
00425 } while (0)
00426
00427
00428 #define BBUF_MOVE_LEFT(buf,from,to,n) do {\
00429 xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
00430 } while (0)
00431
00432
00433 #define BBUF_MOVE_LEFT_REDUCE(buf,from,to) do {\
00434 xmemmove((buf)->p + (to), (buf)->p + (from), (buf)->used - (from));\
00435 (buf)->used -= (from - to);\
00436 } while (0)
00437
00438 #define BBUF_INSERT(buf,pos,bytes,n) do {\
00439 if (pos >= (buf)->used) {\
00440 BBUF_WRITE(buf,pos,bytes,n);\
00441 }\
00442 else {\
00443 BBUF_MOVE_RIGHT((buf),(pos),(pos) + (n),((buf)->used - (pos)));\
00444 xmemcpy((buf)->p + (pos), (bytes), (n));\
00445 }\
00446 } while (0)
00447
00448 #define BBUF_GET_BYTE(buf, pos) (buf)->p[(pos)]
00449
00450
00451 #define ANCHOR_BEGIN_BUF (1<<0)
00452 #define ANCHOR_BEGIN_LINE (1<<1)
00453 #define ANCHOR_BEGIN_POSITION (1<<2)
00454 #define ANCHOR_END_BUF (1<<3)
00455 #define ANCHOR_SEMI_END_BUF (1<<4)
00456 #define ANCHOR_END_LINE (1<<5)
00457
00458 #define ANCHOR_WORD_BOUND (1<<6)
00459 #define ANCHOR_NOT_WORD_BOUND (1<<7)
00460 #define ANCHOR_WORD_BEGIN (1<<8)
00461 #define ANCHOR_WORD_END (1<<9)
00462 #define ANCHOR_PREC_READ (1<<10)
00463 #define ANCHOR_PREC_READ_NOT (1<<11)
00464 #define ANCHOR_LOOK_BEHIND (1<<12)
00465 #define ANCHOR_LOOK_BEHIND_NOT (1<<13)
00466
00467 #define ANCHOR_ANYCHAR_STAR (1<<14)
00468 #define ANCHOR_ANYCHAR_STAR_ML (1<<15)
00469
00470
00471 enum OpCode {
00472 OP_FINISH = 0,
00473 OP_END = 1,
00474
00475 OP_EXACT1 = 2,
00476 OP_EXACT2,
00477 OP_EXACT3,
00478 OP_EXACT4,
00479 OP_EXACT5,
00480 OP_EXACTN,
00481 OP_EXACTMB2N1,
00482 OP_EXACTMB2N2,
00483 OP_EXACTMB2N3,
00484 OP_EXACTMB2N,
00485 OP_EXACTMB3N,
00486 OP_EXACTMBN,
00487
00488 OP_EXACT1_IC,
00489 OP_EXACTN_IC,
00490
00491 OP_CCLASS,
00492 OP_CCLASS_MB,
00493 OP_CCLASS_MIX,
00494 OP_CCLASS_NOT,
00495 OP_CCLASS_MB_NOT,
00496 OP_CCLASS_MIX_NOT,
00497 OP_CCLASS_NODE,
00498
00499 OP_ANYCHAR,
00500 OP_ANYCHAR_ML,
00501 OP_ANYCHAR_STAR,
00502 OP_ANYCHAR_ML_STAR,
00503 OP_ANYCHAR_STAR_PEEK_NEXT,
00504 OP_ANYCHAR_ML_STAR_PEEK_NEXT,
00505
00506 OP_WORD,
00507 OP_NOT_WORD,
00508 OP_WORD_BOUND,
00509 OP_NOT_WORD_BOUND,
00510 OP_WORD_BEGIN,
00511 OP_WORD_END,
00512
00513 OP_BEGIN_BUF,
00514 OP_END_BUF,
00515 OP_BEGIN_LINE,
00516 OP_END_LINE,
00517 OP_SEMI_END_BUF,
00518 OP_BEGIN_POSITION,
00519
00520 OP_BACKREF1,
00521 OP_BACKREF2,
00522 OP_BACKREFN,
00523 OP_BACKREFN_IC,
00524 OP_BACKREF_MULTI,
00525 OP_BACKREF_MULTI_IC,
00526 OP_BACKREF_WITH_LEVEL,
00527
00528 OP_MEMORY_START,
00529 OP_MEMORY_START_PUSH,
00530 OP_MEMORY_END_PUSH,
00531 OP_MEMORY_END_PUSH_REC,
00532 OP_MEMORY_END,
00533 OP_MEMORY_END_REC,
00534
00535 OP_FAIL,
00536 OP_JUMP,
00537 OP_PUSH,
00538 OP_POP,
00539 OP_PUSH_OR_JUMP_EXACT1,
00540 OP_PUSH_IF_PEEK_NEXT,
00541 OP_REPEAT,
00542 OP_REPEAT_NG,
00543 OP_REPEAT_INC,
00544 OP_REPEAT_INC_NG,
00545 OP_REPEAT_INC_SG,
00546 OP_REPEAT_INC_NG_SG,
00547 OP_NULL_CHECK_START,
00548 OP_NULL_CHECK_END,
00549 OP_NULL_CHECK_END_MEMST,
00550 OP_NULL_CHECK_END_MEMST_PUSH,
00551
00552 OP_PUSH_POS,
00553 OP_POP_POS,
00554 OP_PUSH_POS_NOT,
00555 OP_FAIL_POS,
00556 OP_PUSH_STOP_BT,
00557 OP_POP_STOP_BT,
00558 OP_LOOK_BEHIND,
00559 OP_PUSH_LOOK_BEHIND_NOT,
00560 OP_FAIL_LOOK_BEHIND_NOT,
00561
00562 OP_CALL,
00563 OP_RETURN,
00564
00565 OP_STATE_CHECK_PUSH,
00566 OP_STATE_CHECK_PUSH_OR_JUMP,
00567 OP_STATE_CHECK,
00568 OP_STATE_CHECK_ANYCHAR_STAR,
00569 OP_STATE_CHECK_ANYCHAR_ML_STAR,
00570
00571
00572 OP_SET_OPTION_PUSH,
00573 OP_SET_OPTION
00574 };
00575
00576 typedef int RelAddrType;
00577 typedef int AbsAddrType;
00578 typedef int LengthType;
00579 typedef int RepeatNumType;
00580 typedef short int MemNumType;
00581 typedef short int StateCheckNumType;
00582 typedef void* PointerType;
00583
00584 #define SIZE_OPCODE 1
00585 #define SIZE_RELADDR (int)sizeof(RelAddrType)
00586 #define SIZE_ABSADDR (int)sizeof(AbsAddrType)
00587 #define SIZE_LENGTH (int)sizeof(LengthType)
00588 #define SIZE_MEMNUM (int)sizeof(MemNumType)
00589 #define SIZE_STATE_CHECK_NUM (int)sizeof(StateCheckNumType)
00590 #define SIZE_REPEATNUM (int)sizeof(RepeatNumType)
00591 #define SIZE_OPTION (int)sizeof(OnigOptionType)
00592 #define SIZE_CODE_POINT (int)sizeof(OnigCodePoint)
00593 #define SIZE_POINTER (int)sizeof(PointerType)
00594
00595
00596 #define GET_RELADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, RelAddrType)
00597 #define GET_ABSADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, AbsAddrType)
00598 #define GET_LENGTH_INC(len,p) PLATFORM_GET_INC(len, p, LengthType)
00599 #define GET_MEMNUM_INC(num,p) PLATFORM_GET_INC(num, p, MemNumType)
00600 #define GET_REPEATNUM_INC(num,p) PLATFORM_GET_INC(num, p, RepeatNumType)
00601 #define GET_OPTION_INC(option,p) PLATFORM_GET_INC(option, p, OnigOptionType)
00602 #define GET_POINTER_INC(ptr,p) PLATFORM_GET_INC(ptr, p, PointerType)
00603 #define GET_STATE_CHECK_NUM_INC(num,p) PLATFORM_GET_INC(num, p, StateCheckNumType)
00604
00605
00606 #define GET_CODE_POINT(code,p) code = *((OnigCodePoint* )(p))
00607 #define GET_BYTE_INC(byte,p) do{\
00608 byte = *(p);\
00609 (p)++;\
00610 } while(0)
00611
00612
00613
00614 #define SIZE_OP_ANYCHAR_STAR SIZE_OPCODE
00615 #define SIZE_OP_ANYCHAR_STAR_PEEK_NEXT (SIZE_OPCODE + 1)
00616 #define SIZE_OP_JUMP (SIZE_OPCODE + SIZE_RELADDR)
00617 #define SIZE_OP_PUSH (SIZE_OPCODE + SIZE_RELADDR)
00618 #define SIZE_OP_POP SIZE_OPCODE
00619 #define SIZE_OP_PUSH_OR_JUMP_EXACT1 (SIZE_OPCODE + SIZE_RELADDR + 1)
00620 #define SIZE_OP_PUSH_IF_PEEK_NEXT (SIZE_OPCODE + SIZE_RELADDR + 1)
00621 #define SIZE_OP_REPEAT_INC (SIZE_OPCODE + SIZE_MEMNUM)
00622 #define SIZE_OP_REPEAT_INC_NG (SIZE_OPCODE + SIZE_MEMNUM)
00623 #define SIZE_OP_PUSH_POS SIZE_OPCODE
00624 #define SIZE_OP_PUSH_POS_NOT (SIZE_OPCODE + SIZE_RELADDR)
00625 #define SIZE_OP_POP_POS SIZE_OPCODE
00626 #define SIZE_OP_FAIL_POS SIZE_OPCODE
00627 #define SIZE_OP_SET_OPTION (SIZE_OPCODE + SIZE_OPTION)
00628 #define SIZE_OP_SET_OPTION_PUSH (SIZE_OPCODE + SIZE_OPTION)
00629 #define SIZE_OP_FAIL SIZE_OPCODE
00630 #define SIZE_OP_MEMORY_START (SIZE_OPCODE + SIZE_MEMNUM)
00631 #define SIZE_OP_MEMORY_START_PUSH (SIZE_OPCODE + SIZE_MEMNUM)
00632 #define SIZE_OP_MEMORY_END_PUSH (SIZE_OPCODE + SIZE_MEMNUM)
00633 #define SIZE_OP_MEMORY_END_PUSH_REC (SIZE_OPCODE + SIZE_MEMNUM)
00634 #define SIZE_OP_MEMORY_END (SIZE_OPCODE + SIZE_MEMNUM)
00635 #define SIZE_OP_MEMORY_END_REC (SIZE_OPCODE + SIZE_MEMNUM)
00636 #define SIZE_OP_PUSH_STOP_BT SIZE_OPCODE
00637 #define SIZE_OP_POP_STOP_BT SIZE_OPCODE
00638 #define SIZE_OP_NULL_CHECK_START (SIZE_OPCODE + SIZE_MEMNUM)
00639 #define SIZE_OP_NULL_CHECK_END (SIZE_OPCODE + SIZE_MEMNUM)
00640 #define SIZE_OP_LOOK_BEHIND (SIZE_OPCODE + SIZE_LENGTH)
00641 #define SIZE_OP_PUSH_LOOK_BEHIND_NOT (SIZE_OPCODE + SIZE_RELADDR + SIZE_LENGTH)
00642 #define SIZE_OP_FAIL_LOOK_BEHIND_NOT SIZE_OPCODE
00643 #define SIZE_OP_CALL (SIZE_OPCODE + SIZE_ABSADDR)
00644 #define SIZE_OP_RETURN SIZE_OPCODE
00645
00646 #ifdef USE_COMBINATION_EXPLOSION_CHECK
00647 #define SIZE_OP_STATE_CHECK (SIZE_OPCODE + SIZE_STATE_CHECK_NUM)
00648 #define SIZE_OP_STATE_CHECK_PUSH (SIZE_OPCODE + SIZE_STATE_CHECK_NUM + SIZE_RELADDR)
00649 #define SIZE_OP_STATE_CHECK_PUSH_OR_JUMP (SIZE_OPCODE + SIZE_STATE_CHECK_NUM + SIZE_RELADDR)
00650 #define SIZE_OP_STATE_CHECK_ANYCHAR_STAR (SIZE_OPCODE + SIZE_STATE_CHECK_NUM)
00651 #endif
00652
00653 #define MC_ESC(syn) (syn)->meta_char_table.esc
00654 #define MC_ANYCHAR(syn) (syn)->meta_char_table.anychar
00655 #define MC_ANYTIME(syn) (syn)->meta_char_table.anytime
00656 #define MC_ZERO_OR_ONE_TIME(syn) (syn)->meta_char_table.zero_or_one_time
00657 #define MC_ONE_OR_MORE_TIME(syn) (syn)->meta_char_table.one_or_more_time
00658 #define MC_ANYCHAR_ANYTIME(syn) (syn)->meta_char_table.anychar_anytime
00659
00660 #define IS_MC_ESC_CODE(code, syn) \
00661 ((code) == MC_ESC(syn) && \
00662 !IS_SYNTAX_OP2((syn), ONIG_SYN_OP2_INEFFECTIVE_ESCAPE))
00663
00664
00665 #define SYN_POSIX_COMMON_OP \
00666 ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_POSIX_BRACKET | \
00667 ONIG_SYN_OP_DECIMAL_BACKREF | \
00668 ONIG_SYN_OP_BRACKET_CC | ONIG_SYN_OP_ASTERISK_ZERO_INF | \
00669 ONIG_SYN_OP_LINE_ANCHOR | \
00670 ONIG_SYN_OP_ESC_CONTROL_CHARS )
00671
00672 #define SYN_GNU_REGEX_OP \
00673 ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC | \
00674 ONIG_SYN_OP_POSIX_BRACKET | ONIG_SYN_OP_DECIMAL_BACKREF | \
00675 ONIG_SYN_OP_BRACE_INTERVAL | ONIG_SYN_OP_LPAREN_SUBEXP | \
00676 ONIG_SYN_OP_VBAR_ALT | \
00677 ONIG_SYN_OP_ASTERISK_ZERO_INF | ONIG_SYN_OP_PLUS_ONE_INF | \
00678 ONIG_SYN_OP_QMARK_ZERO_ONE | \
00679 ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR | ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR | \
00680 ONIG_SYN_OP_ESC_W_WORD | \
00681 ONIG_SYN_OP_ESC_B_WORD_BOUND | ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END | \
00682 ONIG_SYN_OP_ESC_S_WHITE_SPACE | ONIG_SYN_OP_ESC_D_DIGIT | \
00683 ONIG_SYN_OP_LINE_ANCHOR )
00684
00685 #define SYN_GNU_REGEX_BV \
00686 ( ONIG_SYN_CONTEXT_INDEP_ANCHORS | ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS | \
00687 ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS | ONIG_SYN_ALLOW_INVALID_INTERVAL | \
00688 ONIG_SYN_BACKSLASH_ESCAPE_IN_CC | ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC )
00689
00690
00691 #define NCCLASS_FLAGS(cc) ((cc)->flags)
00692 #define NCCLASS_FLAG_SET(cc,flag) (NCCLASS_FLAGS(cc) |= (flag))
00693 #define NCCLASS_FLAG_CLEAR(cc,flag) (NCCLASS_FLAGS(cc) &= ~(flag))
00694 #define IS_NCCLASS_FLAG_ON(cc,flag) ((NCCLASS_FLAGS(cc) & (flag)) != 0)
00695
00696
00697 #define FLAG_NCCLASS_NOT (1<<0)
00698 #define FLAG_NCCLASS_SHARE (1<<1)
00699
00700 #define NCCLASS_SET_NOT(nd) NCCLASS_FLAG_SET(nd, FLAG_NCCLASS_NOT)
00701 #define NCCLASS_SET_SHARE(nd) NCCLASS_FLAG_SET(nd, FLAG_NCCLASS_SHARE)
00702 #define NCCLASS_CLEAR_NOT(nd) NCCLASS_FLAG_CLEAR(nd, FLAG_NCCLASS_NOT)
00703 #define IS_NCCLASS_NOT(nd) IS_NCCLASS_FLAG_ON(nd, FLAG_NCCLASS_NOT)
00704 #define IS_NCCLASS_SHARE(nd) IS_NCCLASS_FLAG_ON(nd, FLAG_NCCLASS_SHARE)
00705
00706 typedef struct {
00707 int type;
00708
00709
00710 } NodeBase;
00711
00712 typedef struct {
00713 NodeBase base;
00714 unsigned int flags;
00715 BitSet bs;
00716 BBuf* mbuf;
00717 } CClassNode;
00718
00719 typedef intptr_t OnigStackIndex;
00720
00721 typedef struct _OnigStackType {
00722 unsigned int type;
00723 union {
00724 struct {
00725 UChar *pcode;
00726 UChar *pstr;
00727 UChar *pstr_prev;
00728 #ifdef USE_COMBINATION_EXPLOSION_CHECK
00729 unsigned int state_check;
00730 #endif
00731 } state;
00732 struct {
00733 int count;
00734 UChar *pcode;
00735 int num;
00736 } repeat;
00737 struct {
00738 OnigStackIndex si;
00739 } repeat_inc;
00740 struct {
00741 int num;
00742 UChar *pstr;
00743
00744 OnigStackIndex start;
00745 OnigStackIndex end;
00746 } mem;
00747 struct {
00748 int num;
00749 UChar *pstr;
00750 } null_check;
00751 #ifdef USE_SUBEXP_CALL
00752 struct {
00753 UChar *ret_addr;
00754 int num;
00755 UChar *pstr;
00756 } call_frame;
00757 #endif
00758 } u;
00759 } OnigStackType;
00760
00761 typedef struct {
00762 void* stack_p;
00763 size_t stack_n;
00764 OnigOptionType options;
00765 OnigRegion* region;
00766 const UChar* start;
00767 #ifdef USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
00768 int best_len;
00769 UChar* best_s;
00770 #endif
00771 #ifdef USE_COMBINATION_EXPLOSION_CHECK
00772 void* state_check_buff;
00773 int state_check_buff_size;
00774 #endif
00775 } OnigMatchArg;
00776
00777
00778 #define IS_CODE_SB_WORD(enc,code) \
00779 (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_WORD(enc,code))
00780
00781 #ifdef ONIG_DEBUG
00782
00783 typedef struct {
00784 short int opcode;
00785 char* name;
00786 short int arg_type;
00787 } OnigOpInfoType;
00788
00789 extern OnigOpInfoType OnigOpInfo[];
00790
00791
00792
00793 #ifdef ONIG_DEBUG_STATISTICS
00794 extern void onig_statistics_init P_((void));
00795 extern void onig_print_statistics P_((FILE* f));
00796 #endif
00797 #endif
00798
00799 extern UChar* onig_error_code_to_format P_((int code));
00800 extern void onig_snprintf_with_pattern PV_((UChar buf[], int bufsize, OnigEncoding enc, UChar* pat, UChar* pat_end, const UChar *fmt, ...));
00801 extern int onig_bbuf_init P_((BBuf* buf, int size));
00802 extern int onig_compile P_((regex_t* reg, const UChar* pattern, const UChar* pattern_end, OnigErrorInfo* einfo, const char *sourcefile, int sourceline));
00803 extern void onig_chain_reduce P_((regex_t* reg));
00804 extern void onig_chain_link_add P_((regex_t* to, regex_t* add));
00805 extern void onig_transfer P_((regex_t* to, regex_t* from));
00806 extern int onig_is_code_in_cc P_((OnigEncoding enc, OnigCodePoint code, CClassNode* cc));
00807 extern int onig_is_code_in_cc_len P_((int enclen, OnigCodePoint code, CClassNode* cc));
00808
00809
00810 typedef void hash_table_type;
00811 #ifdef RUBY
00812 #include "ruby/st.h"
00813 typedef st_data_t hash_data_type;
00814 #else
00815 typedef unsigned long hash_data_type;
00816 #endif
00817
00818 extern hash_table_type* onig_st_init_strend_table_with_size P_((st_index_t size));
00819 extern int onig_st_lookup_strend P_((hash_table_type* table, const UChar* str_key, const UChar* end_key, hash_data_type *value));
00820 extern int onig_st_insert_strend P_((hash_table_type* table, const UChar* str_key, const UChar* end_key, hash_data_type value));
00821
00822
00823 #define PROPERTY_LIST_ADD_PROP(Name, CR) \
00824 r = onigenc_property_list_add_property((UChar* )Name, CR,\
00825 &PropertyNameTable, &PropertyList, &PropertyListNum,\
00826 &PropertyListSize);\
00827 if (r != 0) goto end
00828
00829 #define PROPERTY_LIST_INIT_CHECK \
00830 if (PropertyInited == 0) {\
00831 int r = onigenc_property_list_init(init_property_list);\
00832 if (r != 0) return r;\
00833 }
00834
00835 extern int onigenc_property_list_add_property P_((UChar* name, const OnigCodePoint* prop, hash_table_type **table, const OnigCodePoint*** plist, int *pnum, int *psize));
00836
00837 typedef int (*ONIGENC_INIT_PROPERTY_LIST_FUNC_TYPE)(void);
00838
00839 extern int onigenc_property_list_init P_((ONIGENC_INIT_PROPERTY_LIST_FUNC_TYPE));
00840
00841 #endif
00842