Ruby  2.0.0p247(2013-06-27revision41674)
regint.h
Go to the documentation of this file.
00001 #ifndef ONIGURUMA_REGINT_H
00002 #define ONIGURUMA_REGINT_H
00003 /**********************************************************************
00004   regint.h -  Onigmo (Oniguruma-mod) (regular expression library)
00005 **********************************************************************/
00006 /*-
00007  * Copyright (c) 2002-2008  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp>
00008  * Copyright (c) 2011-2012  K.Takata  <kentkt AT csc DOT jp>
00009  * All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in the
00018  *    documentation and/or other materials provided with the distribution.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00024  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00025  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00026  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00027  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00028  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00029  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00030  * SUCH DAMAGE.
00031  */
00032 
00033 /* for debug */
00034 /* #define ONIG_DEBUG_PARSE_TREE */
00035 /* #define ONIG_DEBUG_COMPILE */
00036 /* #define ONIG_DEBUG_SEARCH */
00037 /* #define ONIG_DEBUG_MATCH */
00038 /* #define ONIG_DONT_OPTIMIZE */
00039 
00040 /* for byte-code statistical data. */
00041 /* #define ONIG_DEBUG_STATISTICS */
00042 
00043 #if defined(ONIG_DEBUG_PARSE_TREE) || defined(ONIG_DEBUG_MATCH) || \
00044     defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) || \
00045     defined(ONIG_DEBUG_STATISTICS)
00046 #ifndef ONIG_DEBUG
00047 #define ONIG_DEBUG
00048 #endif
00049 #endif
00050 
00051 #if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
00052     defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD86) || \
00053     defined(__mc68020__)
00054 #define PLATFORM_UNALIGNED_WORD_ACCESS
00055 #endif
00056 
00057 /* config */
00058 /* spec. config */
00059 #define USE_NAMED_GROUP
00060 #define USE_SUBEXP_CALL
00061 #define USE_PERL_SUBEXP_CALL
00062 #define USE_CAPITAL_P_NAMED_GROUP
00063 #define USE_BACKREF_WITH_LEVEL        /* \k<name+n>, \k<name-n> */
00064 #define USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT  /* /(?:()|())*\2/ */
00065 #define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE     /* /\n$/ =~ "\n" */
00066 #define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
00067 /* #define USE_RECOMPILE_API */
00068 /* !!! moved to regenc.h. */ /* #define USE_CRNL_AS_LINE_TERMINATOR */
00069 #define USE_NO_INVALID_QUANTIFIER
00070 
00071 /* internal config */
00072 #define USE_PARSE_TREE_NODE_RECYCLE
00073 #define USE_OP_PUSH_OR_JUMP_EXACT
00074 #define USE_QTFR_PEEK_NEXT
00075 #define USE_ST_LIBRARY
00076 #define USE_SHARED_CCLASS_TABLE
00077 #define USE_SUNDAY_QUICK_SEARCH
00078 
00079 #define INIT_MATCH_STACK_SIZE                     160
00080 #define DEFAULT_MATCH_STACK_LIMIT_SIZE              0 /* unlimited */
00081 
00082 /* check config */
00083 #if defined(USE_PERL_SUBEXP_CALL) || defined(USE_CAPITAL_P_NAMED_GROUP)
00084 #if !defined(USE_NAMED_GROUP) || !defined(USE_SUBEXP_CALL)
00085 #error USE_NAMED_GROUP and USE_SUBEXP_CALL must be defined.
00086 #endif
00087 #endif
00088 
00089 #if defined(__GNUC__)
00090 #  define ARG_UNUSED  __attribute__ ((unused))
00091 #else
00092 #  define ARG_UNUSED
00093 #endif
00094 
00095 /* */
00096 /* escape other system UChar definition */
00097 #ifndef RUBY_DEFINES_H
00098 #include "ruby/ruby.h"
00099 #undef xmalloc
00100 #undef xrealloc
00101 #undef xcalloc
00102 #undef xfree
00103 #endif
00104 #ifdef ONIG_ESCAPE_UCHAR_COLLISION
00105 #undef ONIG_ESCAPE_UCHAR_COLLISION
00106 #endif
00107 #define USE_WORD_BEGIN_END          /* "<": word-begin, ">": word-end */
00108 #undef USE_MATCH_RANGE_IS_COMPLETE_RANGE
00109 #undef USE_CAPTURE_HISTORY
00110 #define USE_VARIABLE_META_CHARS
00111 #define USE_POSIX_API_REGION_OPTION     /* needed for POSIX API support */
00112 #define USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
00113 /* #define USE_COMBINATION_EXPLOSION_CHECK */     /* (X*)* */
00114 
00115 /* #define USE_MULTI_THREAD_SYSTEM */
00116 #define THREAD_SYSTEM_INIT      /* depend on thread system */
00117 #define THREAD_SYSTEM_END       /* depend on thread system */
00118 #define THREAD_ATOMIC_START     /* depend on thread system */
00119 #define THREAD_ATOMIC_END       /* depend on thread system */
00120 #define THREAD_PASS             /* depend on thread system */
00121 #ifndef xmalloc
00122 #define xmalloc     malloc
00123 #define xrealloc    realloc
00124 #define xcalloc     calloc
00125 #define xfree       free
00126 #endif
00127 
00128 #ifdef RUBY
00129 
00130 #define CHECK_INTERRUPT_IN_MATCH_AT rb_thread_check_ints()
00131 #define onig_st_init_table                  st_init_table
00132 #define onig_st_init_table_with_size        st_init_table_with_size
00133 #define onig_st_init_numtable               st_init_numtable
00134 #define onig_st_init_numtable_with_size     st_init_numtable_with_size
00135 #define onig_st_init_strtable               st_init_strtable
00136 #define onig_st_init_strtable_with_size     st_init_strtable_with_size
00137 #define onig_st_delete                      st_delete
00138 #define onig_st_delete_safe                 st_delete_safe
00139 #define onig_st_insert                      st_insert
00140 #define onig_st_lookup                      st_lookup
00141 #define onig_st_foreach                     st_foreach
00142 #define onig_st_add_direct                  st_add_direct
00143 #define onig_st_free_table                  st_free_table
00144 #define onig_st_cleanup_safe                st_cleanup_safe
00145 #define onig_st_copy                        st_copy
00146 #define onig_st_nothing_key_clone           st_nothing_key_clone
00147 #define onig_st_nothing_key_free            st_nothing_key_free
00148 #define onig_st_is_member                   st_is_member
00149 
00150 #define USE_UPPER_CASE_TABLE
00151 #else
00152 
00153 #define st_init_table                  onig_st_init_table
00154 #define st_init_table_with_size        onig_st_init_table_with_size
00155 #define st_init_numtable               onig_st_init_numtable
00156 #define st_init_numtable_with_size     onig_st_init_numtable_with_size
00157 #define st_init_strtable               onig_st_init_strtable
00158 #define st_init_strtable_with_size     onig_st_init_strtable_with_size
00159 #define st_delete                      onig_st_delete
00160 #define st_delete_safe                 onig_st_delete_safe
00161 #define st_insert                      onig_st_insert
00162 #define st_lookup                      onig_st_lookup
00163 #define st_foreach                     onig_st_foreach
00164 #define st_add_direct                  onig_st_add_direct
00165 #define st_free_table                  onig_st_free_table
00166 #define st_cleanup_safe                onig_st_cleanup_safe
00167 #define st_copy                        onig_st_copy
00168 #define st_nothing_key_clone           onig_st_nothing_key_clone
00169 #define st_nothing_key_free            onig_st_nothing_key_free
00170 /* */
00171 #define onig_st_is_member              st_is_member
00172 
00173 #define CHECK_INTERRUPT_IN_MATCH_AT
00174 
00175 #endif
00176 
00177 #define STATE_CHECK_STRING_THRESHOLD_LEN             7
00178 #define STATE_CHECK_BUFF_MAX_SIZE               0x4000
00179 
00180 #define THREAD_PASS_LIMIT_COUNT     8
00181 #define xmemset     memset
00182 #define xmemcpy     memcpy
00183 #define xmemmove    memmove
00184 
00185 #if defined(_WIN32) && !defined(__GNUC__)
00186 #define xalloca     _alloca
00187 #define xvsnprintf  _vsnprintf
00188 #else
00189 #define xalloca     alloca
00190 #define xvsnprintf  vsnprintf
00191 #endif
00192 
00193 
00194 #if defined(USE_RECOMPILE_API) && defined(USE_MULTI_THREAD_SYSTEM)
00195 #define ONIG_STATE_INC(reg) (reg)->state++
00196 #define ONIG_STATE_DEC(reg) (reg)->state--
00197 
00198 #define ONIG_STATE_INC_THREAD(reg) do {\
00199   THREAD_ATOMIC_START;\
00200   (reg)->state++;\
00201   THREAD_ATOMIC_END;\
00202 } while(0)
00203 #define ONIG_STATE_DEC_THREAD(reg) do {\
00204   THREAD_ATOMIC_START;\
00205   (reg)->state--;\
00206   THREAD_ATOMIC_END;\
00207 } while(0)
00208 #else
00209 #define ONIG_STATE_INC(reg)         /* Nothing */
00210 #define ONIG_STATE_DEC(reg)         /* Nothing */
00211 #define ONIG_STATE_INC_THREAD(reg)  /* Nothing */
00212 #define ONIG_STATE_DEC_THREAD(reg)  /* Nothing */
00213 #endif /* USE_RECOMPILE_API && USE_MULTI_THREAD_SYSTEM */
00214 
00215 #ifdef HAVE_STDLIB_H
00216 #include <stdlib.h>
00217 #endif
00218 
00219 #if defined(HAVE_ALLOCA_H) && (defined(_AIX) || !defined(__GNUC__))
00220 #include <alloca.h>
00221 #endif
00222 
00223 #ifdef HAVE_STRING_H
00224 # include <string.h>
00225 #else
00226 # include <strings.h>
00227 #endif
00228 
00229 #include <ctype.h>
00230 #ifdef HAVE_SYS_TYPES_H
00231 #include <sys/types.h>
00232 #endif
00233 
00234 #ifdef HAVE_STDINT_H
00235 # include <stdint.h>
00236 #endif
00237 
00238 #ifdef STDC_HEADERS
00239 # include <stddef.h>
00240 #endif
00241 
00242 #ifdef __BORLANDC__
00243 #include <malloc.h>
00244 #endif
00245 
00246 #ifdef ONIG_DEBUG
00247 # include <stdio.h>
00248 #endif
00249 
00250 #ifdef _WIN32
00251 #if defined(_MSC_VER) && (_MSC_VER < 1300)
00252 #ifndef _INTPTR_T_DEFINED
00253 #define _INTPTR_T_DEFINED
00254 typedef int intptr_t;
00255 #endif
00256 #ifndef _UINTPTR_T_DEFINED
00257 #define _UINTPTR_T_DEFINED
00258 typedef unsigned int uintptr_t;
00259 #endif
00260 #endif
00261 #endif /* _WIN32 */
00262 
00263 #include "regenc.h"
00264 
00265 #if defined __GNUC__ && __GNUC__ >= 4
00266 #pragma GCC visibility push(default)
00267 #endif
00268 
00269 #ifdef MIN
00270 #undef MIN
00271 #endif
00272 #ifdef MAX
00273 #undef MAX
00274 #endif
00275 #define MIN(a,b) (((a)>(b))?(b):(a))
00276 #define MAX(a,b) (((a)<(b))?(b):(a))
00277 
00278 #define IS_NULL(p)                    (((void*)(p)) == (void*)0)
00279 #define IS_NOT_NULL(p)                (((void*)(p)) != (void*)0)
00280 #define CHECK_NULL_RETURN(p)          if (IS_NULL(p)) return NULL
00281 #define CHECK_NULL_RETURN_MEMERR(p)   if (IS_NULL(p)) return ONIGERR_MEMORY
00282 #define NULL_UCHARP                   ((UChar* )0)
00283 
00284 #define ONIG_LAST_CODE_POINT    (~((OnigCodePoint )0))
00285 
00286 #ifdef PLATFORM_UNALIGNED_WORD_ACCESS
00287 
00288 #define PLATFORM_GET_INC(val,p,type) do{\
00289   val  = *(type* )p;\
00290   (p) += sizeof(type);\
00291 } while(0)
00292 
00293 #else
00294 
00295 #define PLATFORM_GET_INC(val,p,type) do{\
00296   xmemcpy(&val, (p), sizeof(type));\
00297   (p) += sizeof(type);\
00298 } while(0)
00299 
00300 /* sizeof(OnigCodePoint) */
00301 #define WORD_ALIGNMENT_SIZE     SIZEOF_LONG
00302 
00303 #define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\
00304   (pad_size) = WORD_ALIGNMENT_SIZE \
00305                - ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
00306   if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\
00307 } while (0)
00308 
00309 #define ALIGNMENT_RIGHT(addr) do {\
00310   (addr) += (WORD_ALIGNMENT_SIZE - 1);\
00311   (addr) -= ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
00312 } while (0)
00313 
00314 #endif /* PLATFORM_UNALIGNED_WORD_ACCESS */
00315 
00316 /* stack pop level */
00317 #define STACK_POP_LEVEL_FREE        0
00318 #define STACK_POP_LEVEL_MEM_START   1
00319 #define STACK_POP_LEVEL_ALL         2
00320 
00321 /* optimize flags */
00322 #define ONIG_OPTIMIZE_NONE              0
00323 #define ONIG_OPTIMIZE_EXACT             1   /* Slow Search */
00324 #define ONIG_OPTIMIZE_EXACT_BM          2   /* Boyer Moore Search */
00325 #define ONIG_OPTIMIZE_EXACT_BM_NOT_REV  3   /* BM (applied to a multibyte string) */
00326 #define ONIG_OPTIMIZE_EXACT_IC          4   /* Slow Search (ignore case) */
00327 #define ONIG_OPTIMIZE_MAP               5   /* char map */
00328 #define ONIG_OPTIMIZE_EXACT_BM_IC         6 /* BM (ignore case) */
00329 #define ONIG_OPTIMIZE_EXACT_BM_NOT_REV_IC 7 /* BM (applied to a multibyte string) (ignore case) */
00330 
00331 /* bit status */
00332 typedef unsigned int  BitStatusType;
00333 
00334 #define BIT_STATUS_BITS_NUM          (sizeof(BitStatusType) * 8)
00335 #define BIT_STATUS_CLEAR(stats)      (stats) = 0
00336 #define BIT_STATUS_ON_ALL(stats)     (stats) = ~((BitStatusType )0)
00337 #define BIT_STATUS_AT(stats,n) \
00338   ((n) < (int )BIT_STATUS_BITS_NUM  ?  ((stats) & (1 << n)) : ((stats) & 1))
00339 
00340 #define BIT_STATUS_ON_AT(stats,n) do {\
00341     if ((n) < (int )BIT_STATUS_BITS_NUM)        \
00342     (stats) |= (1 << (n));\
00343   else\
00344     (stats) |= 1;\
00345 } while (0)
00346 
00347 #define BIT_STATUS_ON_AT_SIMPLE(stats,n) do {\
00348     if ((n) < (int )BIT_STATUS_BITS_NUM)\
00349     (stats) |= (1 << (n));\
00350 } while (0)
00351 
00352 
00353 #define INT_MAX_LIMIT           ((1UL << (SIZEOF_INT * 8 - 1)) - 1)
00354 
00355 #define DIGITVAL(code)    ((code) - '0')
00356 #define ODIGITVAL(code)   DIGITVAL(code)
00357 #define XDIGITVAL(enc,code) \
00358   (ONIGENC_IS_CODE_DIGIT(enc,code) ? DIGITVAL(code) \
00359    : (ONIGENC_IS_CODE_UPPER(enc,code) ? (code) - 'A' + 10 : (code) - 'a' + 10))
00360 
00361 #define IS_SINGLELINE(option)     ((option) & ONIG_OPTION_SINGLELINE)
00362 #define IS_MULTILINE(option)      ((option) & ONIG_OPTION_MULTILINE)
00363 #define IS_IGNORECASE(option)     ((option) & ONIG_OPTION_IGNORECASE)
00364 #define IS_EXTEND(option)         ((option) & ONIG_OPTION_EXTEND)
00365 #define IS_FIND_LONGEST(option)   ((option) & ONIG_OPTION_FIND_LONGEST)
00366 #define IS_FIND_NOT_EMPTY(option) ((option) & ONIG_OPTION_FIND_NOT_EMPTY)
00367 #define IS_FIND_CONDITION(option) ((option) & \
00368           (ONIG_OPTION_FIND_LONGEST | ONIG_OPTION_FIND_NOT_EMPTY))
00369 #define IS_NOTBOL(option)         ((option) & ONIG_OPTION_NOTBOL)
00370 #define IS_NOTEOL(option)         ((option) & ONIG_OPTION_NOTEOL)
00371 #define IS_POSIX_REGION(option)   ((option) & ONIG_OPTION_POSIX_REGION)
00372 #define IS_ASCII_RANGE(option)    ((option) & ONIG_OPTION_ASCII_RANGE)
00373 #define IS_POSIX_BRACKET_ALL_RANGE(option)  ((option) & ONIG_OPTION_POSIX_BRACKET_ALL_RANGE)
00374 #define IS_WORD_BOUND_ALL_RANGE(option)     ((option) & ONIG_OPTION_WORD_BOUND_ALL_RANGE)
00375 #define IS_NEWLINE_CRLF(option)   ((option) & ONIG_OPTION_NEWLINE_CRLF)
00376 
00377 /* OP_SET_OPTION is required for these options.
00378 #define IS_DYNAMIC_OPTION(option) \
00379   (((option) & (ONIG_OPTION_MULTILINE | ONIG_OPTION_IGNORECASE)) != 0)
00380 */
00381 /* ignore-case and multibyte status are included in compiled code. */
00382 #define IS_DYNAMIC_OPTION(option)  0
00383 
00384 #define DISABLE_CASE_FOLD_MULTI_CHAR(case_fold_flag) \
00385   ((case_fold_flag) & ~INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR)
00386 
00387 #define REPEAT_INFINITE         -1
00388 #define IS_REPEAT_INFINITE(n)   ((n) == REPEAT_INFINITE)
00389 
00390 /* bitset */
00391 #define BITS_PER_BYTE      8
00392 #define SINGLE_BYTE_SIZE   (1 << BITS_PER_BYTE)
00393 #define BITS_IN_ROOM       ((int )sizeof(Bits) * BITS_PER_BYTE)
00394 #define BITSET_SIZE        (SINGLE_BYTE_SIZE / BITS_IN_ROOM)
00395 
00396 #ifdef PLATFORM_UNALIGNED_WORD_ACCESS
00397 typedef unsigned int   Bits;
00398 #else
00399 typedef unsigned char  Bits;
00400 #endif
00401 typedef Bits           BitSet[BITSET_SIZE];
00402 typedef Bits*          BitSetRef;
00403 
00404 #define SIZE_BITSET        (int )sizeof(BitSet)
00405 
00406 #define BITSET_CLEAR(bs) do {\
00407   int i;\
00408   for (i = 0; i < BITSET_SIZE; i++) { (bs)[i] = 0; }    \
00409 } while (0)
00410 
00411 #define BS_ROOM(bs,pos)            (bs)[(int )(pos) / BITS_IN_ROOM]
00412 #define BS_BIT(pos)                (1 << ((int )(pos) % BITS_IN_ROOM))
00413 
00414 #define BITSET_AT(bs, pos)         (BS_ROOM(bs,pos) & BS_BIT(pos))
00415 #define BITSET_SET_BIT(bs, pos)     BS_ROOM(bs,pos) |= BS_BIT(pos)
00416 #define BITSET_CLEAR_BIT(bs, pos)   BS_ROOM(bs,pos) &= ~(BS_BIT(pos))
00417 #define BITSET_INVERT_BIT(bs, pos)  BS_ROOM(bs,pos) ^= BS_BIT(pos)
00418 
00419 /* bytes buffer */
00420 typedef struct _BBuf {
00421   UChar* p;
00422   unsigned int used;
00423   unsigned int alloc;
00424 } BBuf;
00425 
00426 #define BBUF_INIT(buf,size)    onig_bbuf_init((BBuf* )(buf), (size))
00427 
00428 #define BBUF_SIZE_INC(buf,inc) do{\
00429   (buf)->alloc += (inc);\
00430   (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
00431   if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
00432 } while (0)
00433 
00434 #define BBUF_EXPAND(buf,low) do{\
00435   do { (buf)->alloc *= 2; } while ((buf)->alloc < (unsigned int )low);\
00436   (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
00437   if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
00438 } while (0)
00439 
00440 #define BBUF_ENSURE_SIZE(buf,size) do{\
00441   unsigned int new_alloc = (buf)->alloc;\
00442   while (new_alloc < (unsigned int )(size)) { new_alloc *= 2; }\
00443   if ((buf)->alloc != new_alloc) {\
00444     (buf)->p = (UChar* )xrealloc((buf)->p, new_alloc);\
00445     if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
00446     (buf)->alloc = new_alloc;\
00447   }\
00448 } while (0)
00449 
00450 #define BBUF_WRITE(buf,pos,bytes,n) do{\
00451   int used = (pos) + (int )(n);\
00452   if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
00453   xmemcpy((buf)->p + (pos), (bytes), (n));\
00454   if ((buf)->used < (unsigned int )used) (buf)->used = used;\
00455 } while (0)
00456 
00457 #define BBUF_WRITE1(buf,pos,byte) do{\
00458   int used = (pos) + 1;\
00459   if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
00460   (buf)->p[(pos)] = (UChar )(byte);\
00461   if ((buf)->used < (unsigned int )used) (buf)->used = used;\
00462 } while (0)
00463 
00464 #define BBUF_ADD(buf,bytes,n)       BBUF_WRITE((buf),(buf)->used,(bytes),(n))
00465 #define BBUF_ADD1(buf,byte)         BBUF_WRITE1((buf),(buf)->used,(byte))
00466 #define BBUF_GET_ADD_ADDRESS(buf)   ((buf)->p + (buf)->used)
00467 #define BBUF_GET_OFFSET_POS(buf)    ((buf)->used)
00468 
00469 /* from < to */
00470 #define BBUF_MOVE_RIGHT(buf,from,to,n) do {\
00471   if ((unsigned int )((to)+(n)) > (buf)->alloc) BBUF_EXPAND((buf),(to) + (n));\
00472   xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
00473   if ((unsigned int )((to)+(n)) > (buf)->used) (buf)->used = (to) + (n);\
00474 } while (0)
00475 
00476 /* from > to */
00477 #define BBUF_MOVE_LEFT(buf,from,to,n) do {\
00478   xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
00479 } while (0)
00480 
00481 /* from > to */
00482 #define BBUF_MOVE_LEFT_REDUCE(buf,from,to) do {\
00483   xmemmove((buf)->p + (to), (buf)->p + (from), (buf)->used - (from));\
00484   (buf)->used -= (from - to);\
00485 } while (0)
00486 
00487 #define BBUF_INSERT(buf,pos,bytes,n) do {\
00488   if (pos >= (buf)->used) {\
00489     BBUF_WRITE(buf,pos,bytes,n);\
00490   }\
00491   else {\
00492     BBUF_MOVE_RIGHT((buf),(pos),(pos) + (n),((buf)->used - (pos)));\
00493     xmemcpy((buf)->p + (pos), (bytes), (n));\
00494   }\
00495 } while (0)
00496 
00497 #define BBUF_GET_BYTE(buf, pos) (buf)->p[(pos)]
00498 
00499 
00500 #define ANCHOR_BEGIN_BUF        (1<<0)
00501 #define ANCHOR_BEGIN_LINE       (1<<1)
00502 #define ANCHOR_BEGIN_POSITION   (1<<2)
00503 #define ANCHOR_END_BUF          (1<<3)
00504 #define ANCHOR_SEMI_END_BUF     (1<<4)
00505 #define ANCHOR_END_LINE         (1<<5)
00506 
00507 #define ANCHOR_WORD_BOUND       (1<<6)
00508 #define ANCHOR_NOT_WORD_BOUND   (1<<7)
00509 #define ANCHOR_WORD_BEGIN       (1<<8)
00510 #define ANCHOR_WORD_END         (1<<9)
00511 #define ANCHOR_PREC_READ        (1<<10)
00512 #define ANCHOR_PREC_READ_NOT    (1<<11)
00513 #define ANCHOR_LOOK_BEHIND      (1<<12)
00514 #define ANCHOR_LOOK_BEHIND_NOT  (1<<13)
00515 
00516 #define ANCHOR_ANYCHAR_STAR     (1<<14)   /* ".*" optimize info */
00517 #define ANCHOR_ANYCHAR_STAR_ML  (1<<15)   /* ".*" optimize info (multi-line) */
00518 
00519 #define ANCHOR_KEEP             (1<<16)
00520 
00521 /* operation code */
00522 enum OpCode {
00523   OP_FINISH = 0,        /* matching process terminator (no more alternative) */
00524   OP_END    = 1,        /* pattern code terminator (success end) */
00525 
00526   OP_EXACT1 = 2,        /* single byte, N = 1 */
00527   OP_EXACT2,            /* single byte, N = 2 */
00528   OP_EXACT3,            /* single byte, N = 3 */
00529   OP_EXACT4,            /* single byte, N = 4 */
00530   OP_EXACT5,            /* single byte, N = 5 */
00531   OP_EXACTN,            /* single byte */
00532   OP_EXACTMB2N1,        /* mb-length = 2 N = 1 */
00533   OP_EXACTMB2N2,        /* mb-length = 2 N = 2 */
00534   OP_EXACTMB2N3,        /* mb-length = 2 N = 3 */
00535   OP_EXACTMB2N,         /* mb-length = 2 */
00536   OP_EXACTMB3N,         /* mb-length = 3 */
00537   OP_EXACTMBN,          /* other length */
00538 
00539   OP_EXACT1_IC,         /* single byte, N = 1, ignore case */
00540   OP_EXACTN_IC,         /* single byte,        ignore case */
00541 
00542   OP_CCLASS,
00543   OP_CCLASS_MB,
00544   OP_CCLASS_MIX,
00545   OP_CCLASS_NOT,
00546   OP_CCLASS_MB_NOT,
00547   OP_CCLASS_MIX_NOT,
00548   OP_CCLASS_NODE,       /* pointer to CClassNode node */
00549 
00550   OP_ANYCHAR,                 /* "."  */
00551   OP_ANYCHAR_ML,              /* "."  multi-line */
00552   OP_ANYCHAR_STAR,            /* ".*" */
00553   OP_ANYCHAR_ML_STAR,         /* ".*" multi-line */
00554   OP_ANYCHAR_STAR_PEEK_NEXT,
00555   OP_ANYCHAR_ML_STAR_PEEK_NEXT,
00556 
00557   OP_WORD,
00558   OP_NOT_WORD,
00559   OP_WORD_BOUND,
00560   OP_NOT_WORD_BOUND,
00561   OP_WORD_BEGIN,
00562   OP_WORD_END,
00563 
00564   OP_ASCII_WORD,
00565   OP_NOT_ASCII_WORD,
00566   OP_ASCII_WORD_BOUND,
00567   OP_NOT_ASCII_WORD_BOUND,
00568   OP_ASCII_WORD_BEGIN,
00569   OP_ASCII_WORD_END,
00570 
00571   OP_BEGIN_BUF,
00572   OP_END_BUF,
00573   OP_BEGIN_LINE,
00574   OP_END_LINE,
00575   OP_SEMI_END_BUF,
00576   OP_BEGIN_POSITION,
00577   OP_BEGIN_POS_OR_LINE,   /* used for implicit anchor optimization */
00578 
00579   OP_BACKREF1,
00580   OP_BACKREF2,
00581   OP_BACKREFN,
00582   OP_BACKREFN_IC,
00583   OP_BACKREF_MULTI,
00584   OP_BACKREF_MULTI_IC,
00585   OP_BACKREF_WITH_LEVEL,    /* \k<xxx+n>, \k<xxx-n> */
00586 
00587   OP_MEMORY_START,
00588   OP_MEMORY_START_PUSH,   /* push back-tracker to stack */
00589   OP_MEMORY_END_PUSH,     /* push back-tracker to stack */
00590   OP_MEMORY_END_PUSH_REC, /* push back-tracker to stack */
00591   OP_MEMORY_END,
00592   OP_MEMORY_END_REC,      /* push marker to stack */
00593 
00594   OP_KEEP,
00595 
00596   OP_FAIL,               /* pop stack and move */
00597   OP_JUMP,
00598   OP_PUSH,
00599   OP_POP,
00600   OP_PUSH_OR_JUMP_EXACT1,  /* if match exact then push, else jump. */
00601   OP_PUSH_IF_PEEK_NEXT,    /* if match exact then push, else none. */
00602   OP_REPEAT,               /* {n,m} */
00603   OP_REPEAT_NG,            /* {n,m}? (non greedy) */
00604   OP_REPEAT_INC,
00605   OP_REPEAT_INC_NG,        /* non greedy */
00606   OP_REPEAT_INC_SG,        /* search and get in stack */
00607   OP_REPEAT_INC_NG_SG,     /* search and get in stack (non greedy) */
00608   OP_NULL_CHECK_START,     /* null loop checker start */
00609   OP_NULL_CHECK_END,       /* null loop checker end   */
00610   OP_NULL_CHECK_END_MEMST, /* null loop checker end (with capture status) */
00611   OP_NULL_CHECK_END_MEMST_PUSH, /* with capture status and push check-end */
00612 
00613   OP_PUSH_POS,             /* (?=...)  start */
00614   OP_POP_POS,              /* (?=...)  end   */
00615   OP_PUSH_POS_NOT,         /* (?!...)  start */
00616   OP_FAIL_POS,             /* (?!...)  end   */
00617   OP_PUSH_STOP_BT,         /* (?>...)  start */
00618   OP_POP_STOP_BT,          /* (?>...)  end   */
00619   OP_LOOK_BEHIND,          /* (?<=...) start (no needs end opcode) */
00620   OP_PUSH_LOOK_BEHIND_NOT, /* (?<!...) start */
00621   OP_FAIL_LOOK_BEHIND_NOT, /* (?<!...) end   */
00622 
00623   OP_CALL,                 /* \g<name> */
00624   OP_RETURN,
00625 
00626   OP_CONDITION,
00627 
00628   OP_STATE_CHECK_PUSH,         /* combination explosion check and push */
00629   OP_STATE_CHECK_PUSH_OR_JUMP, /* check ok -> push, else jump  */
00630   OP_STATE_CHECK,              /* check only */
00631   OP_STATE_CHECK_ANYCHAR_STAR,
00632   OP_STATE_CHECK_ANYCHAR_ML_STAR,
00633 
00634   /* no need: IS_DYNAMIC_OPTION() == 0 */
00635   OP_SET_OPTION_PUSH,    /* set option and push recover option */
00636   OP_SET_OPTION          /* set option */
00637 };
00638 
00639 typedef int RelAddrType;
00640 typedef int AbsAddrType;
00641 typedef int LengthType;
00642 typedef int RepeatNumType;
00643 typedef short int MemNumType;
00644 typedef short int StateCheckNumType;
00645 typedef void* PointerType;
00646 
00647 #define SIZE_OPCODE           1
00648 #define SIZE_RELADDR          (int )sizeof(RelAddrType)
00649 #define SIZE_ABSADDR          (int )sizeof(AbsAddrType)
00650 #define SIZE_LENGTH           (int )sizeof(LengthType)
00651 #define SIZE_MEMNUM           (int )sizeof(MemNumType)
00652 #define SIZE_STATE_CHECK_NUM  (int )sizeof(StateCheckNumType)
00653 #define SIZE_REPEATNUM        (int )sizeof(RepeatNumType)
00654 #define SIZE_OPTION           (int )sizeof(OnigOptionType)
00655 #define SIZE_CODE_POINT       (int )sizeof(OnigCodePoint)
00656 #define SIZE_POINTER          (int )sizeof(PointerType)
00657 
00658 
00659 #define GET_RELADDR_INC(addr,p)    PLATFORM_GET_INC(addr,   p, RelAddrType)
00660 #define GET_ABSADDR_INC(addr,p)    PLATFORM_GET_INC(addr,   p, AbsAddrType)
00661 #define GET_LENGTH_INC(len,p)      PLATFORM_GET_INC(len,    p, LengthType)
00662 #define GET_MEMNUM_INC(num,p)      PLATFORM_GET_INC(num,    p, MemNumType)
00663 #define GET_REPEATNUM_INC(num,p)   PLATFORM_GET_INC(num,    p, RepeatNumType)
00664 #define GET_OPTION_INC(option,p)   PLATFORM_GET_INC(option, p, OnigOptionType)
00665 #define GET_POINTER_INC(ptr,p)     PLATFORM_GET_INC(ptr,    p, PointerType)
00666 #define GET_STATE_CHECK_NUM_INC(num,p)  PLATFORM_GET_INC(num, p, StateCheckNumType)
00667 
00668 /* code point's address must be aligned address. */
00669 #define GET_CODE_POINT(code,p)   code = *((OnigCodePoint* )(p))
00670 #define GET_BYTE_INC(byte,p) do{\
00671   byte = *(p);\
00672   (p)++;\
00673 } while(0)
00674 
00675 
00676 /* op-code + arg size */
00677 #define SIZE_OP_ANYCHAR_STAR            SIZE_OPCODE
00678 #define SIZE_OP_ANYCHAR_STAR_PEEK_NEXT (SIZE_OPCODE + 1)
00679 #define SIZE_OP_JUMP                   (SIZE_OPCODE + SIZE_RELADDR)
00680 #define SIZE_OP_PUSH                   (SIZE_OPCODE + SIZE_RELADDR)
00681 #define SIZE_OP_POP                     SIZE_OPCODE
00682 #define SIZE_OP_PUSH_OR_JUMP_EXACT1    (SIZE_OPCODE + SIZE_RELADDR + 1)
00683 #define SIZE_OP_PUSH_IF_PEEK_NEXT      (SIZE_OPCODE + SIZE_RELADDR + 1)
00684 #define SIZE_OP_REPEAT_INC             (SIZE_OPCODE + SIZE_MEMNUM)
00685 #define SIZE_OP_REPEAT_INC_NG          (SIZE_OPCODE + SIZE_MEMNUM)
00686 #define SIZE_OP_PUSH_POS                SIZE_OPCODE
00687 #define SIZE_OP_PUSH_POS_NOT           (SIZE_OPCODE + SIZE_RELADDR)
00688 #define SIZE_OP_POP_POS                 SIZE_OPCODE
00689 #define SIZE_OP_FAIL_POS                SIZE_OPCODE
00690 #define SIZE_OP_SET_OPTION             (SIZE_OPCODE + SIZE_OPTION)
00691 #define SIZE_OP_SET_OPTION_PUSH        (SIZE_OPCODE + SIZE_OPTION)
00692 #define SIZE_OP_FAIL                    SIZE_OPCODE
00693 #define SIZE_OP_MEMORY_START           (SIZE_OPCODE + SIZE_MEMNUM)
00694 #define SIZE_OP_MEMORY_START_PUSH      (SIZE_OPCODE + SIZE_MEMNUM)
00695 #define SIZE_OP_MEMORY_END_PUSH        (SIZE_OPCODE + SIZE_MEMNUM)
00696 #define SIZE_OP_MEMORY_END_PUSH_REC    (SIZE_OPCODE + SIZE_MEMNUM)
00697 #define SIZE_OP_MEMORY_END             (SIZE_OPCODE + SIZE_MEMNUM)
00698 #define SIZE_OP_MEMORY_END_REC         (SIZE_OPCODE + SIZE_MEMNUM)
00699 #define SIZE_OP_PUSH_STOP_BT            SIZE_OPCODE
00700 #define SIZE_OP_POP_STOP_BT             SIZE_OPCODE
00701 #define SIZE_OP_NULL_CHECK_START       (SIZE_OPCODE + SIZE_MEMNUM)
00702 #define SIZE_OP_NULL_CHECK_END         (SIZE_OPCODE + SIZE_MEMNUM)
00703 #define SIZE_OP_LOOK_BEHIND            (SIZE_OPCODE + SIZE_LENGTH)
00704 #define SIZE_OP_PUSH_LOOK_BEHIND_NOT   (SIZE_OPCODE + SIZE_RELADDR + SIZE_LENGTH)
00705 #define SIZE_OP_FAIL_LOOK_BEHIND_NOT    SIZE_OPCODE
00706 #define SIZE_OP_CALL                   (SIZE_OPCODE + SIZE_ABSADDR)
00707 #define SIZE_OP_RETURN                  SIZE_OPCODE
00708 #define SIZE_OP_CONDITION              (SIZE_OPCODE + SIZE_MEMNUM + SIZE_RELADDR)
00709 
00710 #ifdef USE_COMBINATION_EXPLOSION_CHECK
00711 #define SIZE_OP_STATE_CHECK            (SIZE_OPCODE + SIZE_STATE_CHECK_NUM)
00712 #define SIZE_OP_STATE_CHECK_PUSH       (SIZE_OPCODE + SIZE_STATE_CHECK_NUM + SIZE_RELADDR)
00713 #define SIZE_OP_STATE_CHECK_PUSH_OR_JUMP (SIZE_OPCODE + SIZE_STATE_CHECK_NUM + SIZE_RELADDR)
00714 #define SIZE_OP_STATE_CHECK_ANYCHAR_STAR (SIZE_OPCODE + SIZE_STATE_CHECK_NUM)
00715 #endif
00716 
00717 #define MC_ESC(syn)               (syn)->meta_char_table.esc
00718 #define MC_ANYCHAR(syn)           (syn)->meta_char_table.anychar
00719 #define MC_ANYTIME(syn)           (syn)->meta_char_table.anytime
00720 #define MC_ZERO_OR_ONE_TIME(syn)  (syn)->meta_char_table.zero_or_one_time
00721 #define MC_ONE_OR_MORE_TIME(syn)  (syn)->meta_char_table.one_or_more_time
00722 #define MC_ANYCHAR_ANYTIME(syn)   (syn)->meta_char_table.anychar_anytime
00723 
00724 #define IS_MC_ESC_CODE(code, syn) \
00725   ((code) == MC_ESC(syn) && \
00726    !IS_SYNTAX_OP2((syn), ONIG_SYN_OP2_INEFFECTIVE_ESCAPE))
00727 
00728 
00729 #define SYN_POSIX_COMMON_OP \
00730  ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_POSIX_BRACKET | \
00731    ONIG_SYN_OP_DECIMAL_BACKREF | \
00732    ONIG_SYN_OP_BRACKET_CC | ONIG_SYN_OP_ASTERISK_ZERO_INF | \
00733    ONIG_SYN_OP_LINE_ANCHOR | \
00734    ONIG_SYN_OP_ESC_CONTROL_CHARS )
00735 
00736 #define SYN_GNU_REGEX_OP \
00737   ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC | \
00738     ONIG_SYN_OP_POSIX_BRACKET | ONIG_SYN_OP_DECIMAL_BACKREF | \
00739     ONIG_SYN_OP_BRACE_INTERVAL | ONIG_SYN_OP_LPAREN_SUBEXP | \
00740     ONIG_SYN_OP_VBAR_ALT | \
00741     ONIG_SYN_OP_ASTERISK_ZERO_INF | ONIG_SYN_OP_PLUS_ONE_INF | \
00742     ONIG_SYN_OP_QMARK_ZERO_ONE | \
00743     ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR | ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR | \
00744     ONIG_SYN_OP_ESC_W_WORD | \
00745     ONIG_SYN_OP_ESC_B_WORD_BOUND | ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END | \
00746     ONIG_SYN_OP_ESC_S_WHITE_SPACE | ONIG_SYN_OP_ESC_D_DIGIT | \
00747     ONIG_SYN_OP_LINE_ANCHOR )
00748 
00749 #define SYN_GNU_REGEX_BV \
00750   ( ONIG_SYN_CONTEXT_INDEP_ANCHORS | ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS | \
00751     ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS | ONIG_SYN_ALLOW_INVALID_INTERVAL | \
00752     ONIG_SYN_BACKSLASH_ESCAPE_IN_CC | ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC )
00753 
00754 
00755 #define NCCLASS_FLAGS(cc)           ((cc)->flags)
00756 #define NCCLASS_FLAG_SET(cc,flag)    (NCCLASS_FLAGS(cc) |= (flag))
00757 #define NCCLASS_FLAG_CLEAR(cc,flag)  (NCCLASS_FLAGS(cc) &= ~(flag))
00758 #define IS_NCCLASS_FLAG_ON(cc,flag) ((NCCLASS_FLAGS(cc) & (flag)) != 0)
00759 
00760 /* cclass node */
00761 #define FLAG_NCCLASS_NOT           (1<<0)
00762 #define FLAG_NCCLASS_SHARE         (1<<1)
00763 
00764 #define NCCLASS_SET_NOT(nd)     NCCLASS_FLAG_SET(nd, FLAG_NCCLASS_NOT)
00765 #define NCCLASS_SET_SHARE(nd)   NCCLASS_FLAG_SET(nd, FLAG_NCCLASS_SHARE)
00766 #define NCCLASS_CLEAR_NOT(nd)   NCCLASS_FLAG_CLEAR(nd, FLAG_NCCLASS_NOT)
00767 #define IS_NCCLASS_NOT(nd)      IS_NCCLASS_FLAG_ON(nd, FLAG_NCCLASS_NOT)
00768 #define IS_NCCLASS_SHARE(nd)    IS_NCCLASS_FLAG_ON(nd, FLAG_NCCLASS_SHARE)
00769 
00770 typedef struct {
00771   int type;
00772   /* struct _Node* next; */
00773   /* unsigned int flags; */
00774 } NodeBase;
00775 
00776 typedef struct {
00777   NodeBase base;
00778   unsigned int flags;
00779   BitSet bs;
00780   BBuf*  mbuf;   /* multi-byte info or NULL */
00781 } CClassNode;
00782 
00783 typedef intptr_t OnigStackIndex;
00784 
00785 typedef struct _OnigStackType {
00786   unsigned int type;
00787   union {
00788     struct {
00789       UChar *pcode;      /* byte code position */
00790       UChar *pstr;       /* string position */
00791       UChar *pstr_prev;  /* previous char position of pstr */
00792 #ifdef USE_COMBINATION_EXPLOSION_CHECK
00793       unsigned int state_check;
00794 #endif
00795       UChar *pkeep;      /* keep pattern position */
00796     } state;
00797     struct {
00798       int   count;       /* for OP_REPEAT_INC, OP_REPEAT_INC_NG */
00799       UChar *pcode;      /* byte code position (head of repeated target) */
00800       int   num;         /* repeat id */
00801     } repeat;
00802     struct {
00803       OnigStackIndex si;     /* index of stack */
00804     } repeat_inc;
00805     struct {
00806       int num;           /* memory num */
00807       UChar *pstr;       /* start/end position */
00808       /* Following information is set, if this stack type is MEM-START */
00809       OnigStackIndex start;  /* prev. info (for backtrack  "(...)*" ) */
00810       OnigStackIndex end;    /* prev. info (for backtrack  "(...)*" ) */
00811     } mem;
00812     struct {
00813       int num;           /* null check id */
00814       UChar *pstr;       /* start position */
00815     } null_check;
00816 #ifdef USE_SUBEXP_CALL
00817     struct {
00818       UChar *ret_addr;   /* byte code position */
00819       int    num;        /* null check id */
00820       UChar *pstr;       /* string position */
00821     } call_frame;
00822 #endif
00823   } u;
00824 } OnigStackType;
00825 
00826 typedef struct {
00827   void* stack_p;
00828   size_t stack_n;
00829   OnigOptionType options;
00830   OnigRegion*    region;
00831   const UChar* start;   /* search start position */
00832   const UChar* gpos;    /* global position (for \G: BEGIN_POSITION) */
00833 #ifdef USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
00834   OnigPosition best_len;  /* for ONIG_OPTION_FIND_LONGEST */
00835   UChar* best_s;
00836 #endif
00837 #ifdef USE_COMBINATION_EXPLOSION_CHECK
00838   void* state_check_buff;
00839   int   state_check_buff_size;
00840 #endif
00841 } OnigMatchArg;
00842 
00843 
00844 #define IS_CODE_SB_WORD(enc,code) \
00845   (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_WORD(enc,code))
00846 
00847 #ifdef ONIG_DEBUG
00848 
00849 typedef struct {
00850   short int opcode;
00851   const char* name;
00852   short int arg_type;
00853 } OnigOpInfoType;
00854 
00855 extern OnigOpInfoType OnigOpInfo[];
00856 
00857 /* extern void onig_print_compiled_byte_code P_((FILE* f, UChar* bp, UChar* bpend, UChar** nextp, OnigEncoding enc)); */
00858 
00859 #ifdef ONIG_DEBUG_STATISTICS
00860 extern void onig_statistics_init P_((void));
00861 extern void onig_print_statistics P_((FILE* f));
00862 #endif
00863 #endif
00864 
00865 extern UChar* onig_error_code_to_format P_((OnigPosition code));
00866 extern void  onig_snprintf_with_pattern PV_((UChar buf[], int bufsize, OnigEncoding enc, UChar* pat, UChar* pat_end, const UChar *fmt, ...));
00867 extern int  onig_bbuf_init P_((BBuf* buf, OnigDistance size));
00868 extern int  onig_compile P_((regex_t* reg, const UChar* pattern, const UChar* pattern_end, OnigErrorInfo* einfo, const char *sourcefile, int sourceline));
00869 extern void onig_chain_reduce P_((regex_t* reg));
00870 extern void onig_chain_link_add P_((regex_t* to, regex_t* add));
00871 extern void onig_transfer P_((regex_t* to, regex_t* from));
00872 extern int  onig_is_code_in_cc P_((OnigEncoding enc, OnigCodePoint code, CClassNode* cc));
00873 extern int  onig_is_code_in_cc_len P_((int enclen, OnigCodePoint code, CClassNode* cc));
00874 
00875 /* strend hash */
00876 typedef void hash_table_type;
00877 #ifdef RUBY
00878 #include "ruby/st.h"
00879 typedef st_data_t hash_data_type;
00880 #else
00881 #include "st.h"
00882 typedef uintptr_t hash_data_type;
00883 #endif
00884 
00885 extern hash_table_type* onig_st_init_strend_table_with_size P_((st_index_t size));
00886 extern int onig_st_lookup_strend P_((hash_table_type* table, const UChar* str_key, const UChar* end_key, hash_data_type *value));
00887 extern int onig_st_insert_strend P_((hash_table_type* table, const UChar* str_key, const UChar* end_key, hash_data_type value));
00888 
00889 /* encoding property management */
00890 #define PROPERTY_LIST_ADD_PROP(Name, CR) \
00891   r = onigenc_property_list_add_property((UChar* )Name, CR,\
00892               &PropertyNameTable, &PropertyList, &PropertyListNum,\
00893               &PropertyListSize);\
00894   if (r != 0) goto end
00895 
00896 #define PROPERTY_LIST_INIT_CHECK \
00897   if (PropertyInited == 0) {\
00898     int r = onigenc_property_list_init(init_property_list);\
00899     if (r != 0) return r;\
00900   }
00901 
00902 extern int onigenc_property_list_add_property P_((UChar* name, const OnigCodePoint* prop, hash_table_type **table, const OnigCodePoint*** plist, int *pnum, int *psize));
00903 
00904 typedef int (*ONIGENC_INIT_PROPERTY_LIST_FUNC_TYPE)(void);
00905 
00906 extern int onigenc_property_list_init P_((ONIGENC_INIT_PROPERTY_LIST_FUNC_TYPE));
00907 
00908 extern size_t onig_memsize P_((const regex_t *reg));
00909 extern size_t onig_region_memsize P_((const struct re_registers *regs));
00910 
00911 #if defined __GNUC__ && __GNUC__ >= 4
00912 #pragma GCC visibility pop
00913 #endif
00914 
00915 #endif /* ONIGURUMA_REGINT_H */
00916