regint.h

来自「PHP v6.0 For Linux 运行环境:Win9X/ WinME/ Wi」· C头文件 代码 · 共 794 行 · 第 1/2 页

H
794
字号
#ifndef REGINT_H#define REGINT_H/**********************************************************************  regint.h -  Oniguruma (regular expression library)**********************************************************************//*- * Copyright (c) 2002-2005  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *//* for debug *//* #define ONIG_DEBUG_PARSE_TREE *//* #define ONIG_DEBUG_COMPILE *//* #define ONIG_DEBUG_SEARCH *//* #define ONIG_DEBUG_MATCH *//* #define ONIG_DONT_OPTIMIZE *//* for byte-code statistical data. *//* #define ONIG_DEBUG_STATISTICS */#if defined(ONIG_DEBUG_PARSE_TREE) || defined(ONIG_DEBUG_MATCH) || \    defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) || \    defined(ONIG_DEBUG_STATISTICS)#ifndef ONIG_DEBUG#define ONIG_DEBUG#endif#endif#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \    (defined(__ppc__) && defined(__APPLE__)) || \    defined(__x86_64) || defined(__x86_64__) || \    defined(__mc68020__)#define PLATFORM_UNALIGNED_WORD_ACCESS#endif/* config *//* spec. config *//* #define USE_UNICODE_FULL_RANGE_CTYPE */ /* --> move to regenc.h */#define USE_NAMED_GROUP#define USE_SUBEXP_CALL#define USE_INFINITE_REPEAT_MONOMANIAC_MEM_STATUS_CHECK /* /(?:()|())*\2/ */#define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE     /* /\n$/ =~ "\n" */#define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR/* internal config */#define USE_RECYCLE_NODE#define USE_OP_PUSH_OR_JUMP_EXACT#define USE_QUALIFIER_PEEK_NEXT#define USE_ST_HASH_TABLE#define USE_SHARED_CCLASS_TABLE#define INIT_MATCH_STACK_SIZE                     160#define DEFAULT_MATCH_STACK_LIMIT_SIZE              0 /* unlimited *//* interface to external system */#ifdef NOT_RUBY      /* given from Makefile */#include "config.h"#define USE_CAPTURE_HISTORY#define USE_VARIABLE_META_CHARS#define USE_WORD_BEGIN_END          /* "\<": word-begin, "\>": word-end */#define USE_POSIX_REGION_OPTION     /* needed for POSIX API support *//* #define USE_MULTI_THREAD_SYSTEM */#define THREAD_ATOMIC_START         /* depend on thread system */#define THREAD_ATOMIC_END           /* depend on thread system */#define THREAD_PASS                 /* depend on thread system */#define CHECK_INTERRUPT             /* depend on application */#define xmalloc     malloc#define xrealloc    realloc#define xcalloc     calloc#define xfree       free#else#include "ruby.h"#include "version.h"#include "rubysig.h"      /* for DEFER_INTS, ENABLE_INTS */#define USE_MULTI_THREAD_SYSTEM#define THREAD_ATOMIC_START          DEFER_INTS#define THREAD_ATOMIC_END            ENABLE_INTS#define THREAD_PASS                  rb_thread_schedule()#define CHECK_INTERRUPT do {\  if (rb_trap_pending) {\    if (! rb_prohibit_interrupt) {\      rb_trap_exec();\    }\  }\} while (0)#define DEFAULT_WARN_FUNCTION        rb_warn#define DEFAULT_VERB_WARN_FUNCTION   rb_warning#endif /* else NOT_RUBY */#define THREAD_PASS_LIMIT_COUNT     8#define xmemset     memset#define xmemcpy     memcpy#define xmemmove    memmove#if defined(_WIN32) && !defined(__GNUC__)#define xalloca     _alloca#ifdef NOT_RUBY#define vsnprintf   _vsnprintf#endif#else#define xalloca     alloca#endif#ifdef USE_MULTI_THREAD_SYSTEM#define ONIG_STATE_INC(reg)    (reg)->state++#define ONIG_STATE_DEC(reg)    (reg)->state--#else#define ONIG_STATE_INC(reg)    /* Nothing */#define ONIG_STATE_DEC(reg)    /* Nothing */#endif /* USE_MULTI_THREAD_SYSTEM */#define onig_st_is_member              st_is_member#ifdef NOT_RUBY#define st_init_table                  onig_st_init_table#define st_init_table_with_size        onig_st_init_table_with_size#define st_init_numtable               onig_st_init_numtable#define st_init_numtable_with_size     onig_st_init_numtable_with_size#define st_init_strtable               onig_st_init_strtable#define st_init_strtable_with_size     onig_st_init_strtable_with_size#define st_init_strend_table_with_size onig_st_init_strend_table_with_size#define st_delete                      onig_st_delete#define st_delete_safe                 onig_st_delete_safe#define st_insert                      onig_st_insert#define st_insert_strend               onig_st_insert_strend#define st_lookup                      onig_st_lookup#define st_lookup_strend               onig_st_lookup_strend#define st_foreach                     onig_st_foreach#define st_add_direct                  onig_st_add_direct#define st_add_direct_strend           onig_st_add_direct_strend#define st_free_table                  onig_st_free_table#define st_cleanup_safe                onig_st_cleanup_safe#define st_copy                        onig_st_copy#define st_nothing_key_clone           onig_st_nothing_key_clone#define st_nothing_key_free            onig_st_nothing_key_free#else /* NOT_RUBY */#define onig_st_init_table                  st_init_table#define onig_st_init_table_with_size        st_init_table_with_size#define onig_st_init_numtable               st_init_numtable#define onig_st_init_numtable_with_size     st_init_numtable_with_size#define onig_st_init_strtable               st_init_strtable#define onig_st_init_strtable_with_size     st_init_strtable_with_size#define onig_st_init_strend_table_with_size st_init_strend_table_with_size#define onig_st_delete                      st_delete#define onig_st_delete_safe                 st_delete_safe#define onig_st_insert                      st_insert#define onig_st_insert_strend               st_insert_strend#define onig_st_lookup                      st_lookup#define onig_st_lookup_strend               st_lookup_strend#define onig_st_foreach                     st_foreach#define onig_st_add_direct                  st_add_direct#define onig_st_add_direct_strend           st_add_direct_strend#define onig_st_free_table                  st_free_table#define onig_st_cleanup_safe                st_cleanup_safe#define onig_st_copy                        st_copy#define onig_st_nothing_key_clone           st_nothing_key_clone#define onig_st_nothing_key_free            st_nothing_key_free#endif /* NOT_RUBY */#ifdef HAVE_STDLIB_H#include <stdlib.h>#endif#if defined(HAVE_ALLOCA_H) && !defined(__GNUC__)#include <alloca.h>#endif#ifdef HAVE_STRING_H# include <string.h>#else# include <strings.h>#endif#include <ctype.h>#ifdef HAVE_SYS_TYPES_H#ifndef __BORLANDC__#include <sys/types.h>#endif#endif#ifdef ONIG_DEBUG# include <stdio.h>#endif#include "regenc.h"#include "oniguruma.h"#ifdef MIN#undef MIN#endif#ifdef MAX#undef MAX#endif#define MIN(a,b) (((a)>(b))?(b):(a))#define MAX(a,b) (((a)<(b))?(b):(a))#define IS_NULL(p)                    (((void*)(p)) == (void*)0)#define IS_NOT_NULL(p)                (((void*)(p)) != (void*)0)#define CHECK_NULL_RETURN(p)          if (IS_NULL(p)) return NULL#define CHECK_NULL_RETURN_VAL(p,val)  if (IS_NULL(p)) return (val)#define NULL_UCHARP                   ((UChar* )0)#ifndef PLATFORM_UNALIGNED_WORD_ACCESS#define WORD_ALIGNMENT_SIZE       SIZEOF_INT#define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\  (pad_size) = WORD_ALIGNMENT_SIZE \               - ((unsigned int )(addr) % WORD_ALIGNMENT_SIZE);\  if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\} while (0)#define ALIGNMENT_RIGHT(addr) do {\  (addr) += (WORD_ALIGNMENT_SIZE - 1);\  (addr) -= ((unsigned int )(addr) % WORD_ALIGNMENT_SIZE);\} while (0)#define B_SHIFT  8#define B_MASK   0xff#define SERIALIZE_2BYTE_INT(i,p) do {\  *(p)     = ((i) >> B_SHIFT) & B_MASK;\  *((p)+1) = (i) & B_MASK;\} while (0)#define SERIALIZE_4BYTE_INT(i,p) do {\  *(p)     = ((i) >> B_SHIFT*3) & B_MASK;\  *((p)+1) = ((i) >> B_SHIFT*2) & B_MASK;\  *((p)+2) = ((i) >> B_SHIFT  ) & B_MASK;\  *((p)+3) = (i) & B_MASK;\} while (0)#define SERIALIZE_8BYTE_INT(i,p) do {\  *(p)     = ((i) >> B_SHIFT*7) & B_MASK;\  *((p)+1) = ((i) >> B_SHIFT*6) & B_MASK;\  *((p)+2) = ((i) >> B_SHIFT*5) & B_MASK;\  *((p)+3) = ((i) >> B_SHIFT*4) & B_MASK;\  *((p)+4) = ((i) >> B_SHIFT*3) & B_MASK;\  *((p)+5) = ((i) >> B_SHIFT*2) & B_MASK;\  *((p)+6) = ((i) >> B_SHIFT  ) & B_MASK;\  *((p)+7) = (i) & B_MASK;\} while (0)#define GET_2BYTE_INT_INC(type,i,p) do {\  (i) = (type )(((unsigned int )(*(p)) << B_SHIFT) | (unsigned int )((p)[1]));\  (p) += 2;\} while (0)#define GET_4BYTE_INT_INC(type,i,p) do {\  (i) = (type )(((unsigned int )((p)[0]) << B_SHIFT*3) | \		((unsigned int )((p)[1]) << B_SHIFT*2) | \		((unsigned int )((p)[2]) << B_SHIFT  ) | \		((unsigned int )((p)[3])             )); \  (p) += 4;\} while (0)#define GET_8BYTE_INT_INC(type,i,p) do {\  (i) = (type )(((unsigned long )((p)[0]) << B_SHIFT*7) | \		((unsigned long )((p)[1]) << B_SHIFT*6) | \		((unsigned long )((p)[2]) << B_SHIFT*5) | \		((unsigned long )((p)[3]) << B_SHIFT*4) | \		((unsigned long )((p)[4]) << B_SHIFT*3) | \		((unsigned long )((p)[5]) << B_SHIFT*2) | \		((unsigned long )((p)[6]) << B_SHIFT  ) | \		((unsigned long )((p)[7])             )); \  (p) += 8;\} while (0)#if SIZEOF_SHORT == 2#define GET_SHORT_INC(i,p)     GET_2BYTE_INT_INC(short,i,p)#define SERIALIZE_SHORT(i,p)   SERIALIZE_2BYTE_INT(i,p)#elif SIZEOF_SHORT == 4#define GET_SHORT_INC(i,p)     GET_4BYTE_INT_INC(short,i,p)#define SERIALIZE_SHORT(i,p)   SERIALIZE_4BYTE_INT(i,p)#elif SIZEOF_SHORT == 8#define GET_SHORT_INC(i,p)     GET_8BYTE_INT_INC(short,i,p)#define SERIALIZE_SHORT(i,p)   SERIALIZE_8BYTE_INT(i,p)#endif#if SIZEOF_INT == 2#define GET_INT_INC(i,p)       GET_2BYTE_INT_INC(int,i,p)#define GET_UINT_INC(i,p)      GET_2BYTE_INT_INC(unsigned,i,p)#define SERIALIZE_INT(i,p)     SERIALIZE_2BYTE_INT(i,p)#define SERIALIZE_UINT(i,p)    SERIALIZE_2BYTE_INT(i,p)#elif SIZEOF_INT == 4#define GET_INT_INC(i,p)       GET_4BYTE_INT_INC(int,i,p)#define GET_UINT_INC(i,p)      GET_4BYTE_INT_INC(unsigned,i,p)#define SERIALIZE_INT(i,p)     SERIALIZE_4BYTE_INT(i,p)#define SERIALIZE_UINT(i,p)    SERIALIZE_4BYTE_INT(i,p)#elif SIZEOF_INT == 8#define GET_INT_INC(i,p)       GET_8BYTE_INT_INC(int,i,p)#define GET_UINT_INC(i,p)      GET_8BYTE_INT_INC(unsigned,i,p)#define SERIALIZE_INT(i,p)     SERIALIZE_8BYTE_INT(i,p)#define SERIALIZE_UINT(i,p)    SERIALIZE_8BYTE_INT(i,p)#endif#endif /* PLATFORM_UNALIGNED_WORD_ACCESS *//* stack pop level */#define STACK_POP_LEVEL_FREE        0#define STACK_POP_LEVEL_MEM_START   1#define STACK_POP_LEVEL_ALL         2/* optimize flags */#define ONIG_OPTIMIZE_NONE              0#define ONIG_OPTIMIZE_EXACT             1   /* Slow Search */#define ONIG_OPTIMIZE_EXACT_BM          2   /* Boyer Moore Search */#define ONIG_OPTIMIZE_EXACT_BM_NOT_REV  3   /* BM   (but not simple match) */#define ONIG_OPTIMIZE_EXACT_IC          4   /* Slow Search (ignore case) */#define ONIG_OPTIMIZE_MAP               5   /* char map *//* bit status */typedef unsigned int  BitStatusType;#define BIT_STATUS_BITS_NUM          (sizeof(BitStatusType) * 8)#define BIT_STATUS_CLEAR(stats)      (stats) = 0#define BIT_STATUS_ON_ALL(stats)     (stats) = ~((BitStatusType )0)#define BIT_STATUS_AT(stats,n) \  ((n) < BIT_STATUS_BITS_NUM  ?  ((stats) & (1 << n)) : ((stats) & 1))#define BIT_STATUS_ON_AT(stats,n) do {\  if ((n) < BIT_STATUS_BITS_NUM)\    (stats) |= (1 << (n));\  else\    (stats) |= 1;\} while (0)#define BIT_STATUS_ON_AT_SIMPLE(stats,n) do {\  if ((n) < BIT_STATUS_BITS_NUM)\    (stats) |= (1 << (n));\} while (0)#define INT_MAX_LIMIT           ((1UL << (SIZEOF_INT * 8 - 1)) - 1)#define DIGITVAL(code)    ((code) - '0')#define ODIGITVAL(code)   DIGITVAL(code)#define XDIGITVAL(enc,code) \  (ONIGENC_IS_CODE_DIGIT(enc,code) ? DIGITVAL(code) \   : (ONIGENC_IS_CODE_UPPER(enc,code) ? (code) - 'A' + 10 : (code) - 'a' + 10))#define IS_SINGLELINE(option)     ((option) & ONIG_OPTION_SINGLELINE)#define IS_MULTILINE(option)      ((option) & ONIG_OPTION_MULTILINE)#define IS_IGNORECASE(option)     ((option) & ONIG_OPTION_IGNORECASE)#define IS_EXTEND(option)         ((option) & ONIG_OPTION_EXTEND)#define IS_FIND_LONGEST(option)   ((option) & ONIG_OPTION_FIND_LONGEST)#define IS_FIND_NOT_EMPTY(option) ((option) & ONIG_OPTION_FIND_NOT_EMPTY)#define IS_POSIXLINE(option)      (IS_SINGLELINE(option) && IS_MULTILINE(option))#define IS_FIND_CONDITION(option) ((option) & \          (ONIG_OPTION_FIND_LONGEST | ONIG_OPTION_FIND_NOT_EMPTY))#define IS_NOTBOL(option)         ((option) & ONIG_OPTION_NOTBOL)#define IS_NOTEOL(option)         ((option) & ONIG_OPTION_NOTEOL)#define IS_POSIX_REGION(option)   ((option) & ONIG_OPTION_POSIX_REGION)/* OP_SET_OPTION is required for these options.#define IS_DYNAMIC_OPTION(option) \  (((option) & (ONIG_OPTION_MULTILINE | ONIG_OPTION_IGNORECASE)) != 0)*//* ignore-case and multibyte status are included in compiled code. */#define IS_DYNAMIC_OPTION(option)  0#define REPEAT_INFINITE         -1#define IS_REPEAT_INFINITE(n)   ((n) == REPEAT_INFINITE)/* bitset */#define BITS_PER_BYTE      8#define SINGLE_BYTE_SIZE   (1 << BITS_PER_BYTE)#define BITS_IN_ROOM       (sizeof(Bits) * BITS_PER_BYTE)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?