Back to index

php5  5.3.10
onigposix.h
Go to the documentation of this file.
00001 #ifndef ONIGPOSIX_H
00002 #define ONIGPOSIX_H
00003 /**********************************************************************
00004   onigposix.h - Oniguruma (regular expression library)
00005 **********************************************************************/
00006 /*-
00007  * Copyright (c) 2002-2005  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp>
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00020  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00023  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00024  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00025  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00026  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00028  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00029  * SUCH DAMAGE.
00030  */
00031 #include <stdlib.h>
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 /* options */
00038 #define REG_ICASE          (1<<0)
00039 #define REG_NEWLINE        (1<<1)
00040 #define REG_NOTBOL         (1<<2)
00041 #define REG_NOTEOL         (1<<3)
00042 #define REG_EXTENDED       (1<<4) /* if not setted, Basic Onigular Expression */
00043 #define REG_NOSUB          (1<<5)
00044 
00045 /* POSIX error codes */
00046 #define REG_NOMATCH          1
00047 #define REG_BADPAT           2
00048 #define REG_ECOLLATE         3
00049 #define REG_ECTYPE           4
00050 #define REG_EESCAPE          5
00051 #define REG_ESUBREG          6
00052 #define REG_EBRACK           7
00053 #define REG_EPAREN           8
00054 #define REG_EBRACE           9
00055 #define REG_BADBR           10
00056 #define REG_ERANGE          11
00057 #define REG_ESPACE          12
00058 #define REG_BADRPT          13
00059 
00060 /* extended error codes */
00061 #define REG_EONIG_INTERNAL  14
00062 #define REG_EONIG_BADWC     15
00063 #define REG_EONIG_BADARG    16
00064 #define REG_EONIG_THREAD    17
00065 
00066 /* character encodings (for reg_set_encoding()) */
00067 #define REG_POSIX_ENCODING_ASCII     0
00068 #define REG_POSIX_ENCODING_EUC_JP    1
00069 #define REG_POSIX_ENCODING_SJIS      2
00070 #define REG_POSIX_ENCODING_UTF8      3
00071 #define REG_POSIX_ENCODING_UTF16_BE  4
00072 #define REG_POSIX_ENCODING_UTF16_LE  5
00073 
00074 
00075 typedef int regoff_t;
00076 
00077 typedef struct {
00078   regoff_t  rm_so;
00079   regoff_t  rm_eo;
00080 } regmatch_t;
00081 
00082 /* POSIX regex_t */
00083 typedef struct {
00084   void*   onig;          /* Oniguruma regex_t*  */
00085   size_t  re_nsub;
00086   int     comp_options;
00087 } regex_t;
00088 
00089 
00090 #ifndef P_
00091 #if defined(__STDC__) || defined(_WIN32)
00092 # define P_(args) args
00093 #else
00094 # define P_(args) ()
00095 #endif
00096 #endif
00097 
00098 #ifndef ONIG_EXTERN
00099 #if defined(_WIN32) && !defined(__GNUC__)
00100 #if defined(EXPORT) || defined(RUBY_EXPORT)
00101 #define ONIG_EXTERN   extern __declspec(dllexport)
00102 #else
00103 #define ONIG_EXTERN   extern __declspec(dllimport)
00104 #endif
00105 #endif
00106 #endif
00107 
00108 #ifndef ONIG_EXTERN
00109 #define ONIG_EXTERN   extern
00110 #endif
00111 
00112 #ifndef ONIGURUMA_H
00113 typedef unsigned int        OnigOptionType;
00114 
00115 /* syntax */
00116 typedef struct {
00117   unsigned int op;
00118   unsigned int op2;
00119   unsigned int behavior;
00120   OnigOptionType options;    /* default option */
00121 } OnigSyntaxType;
00122 
00123 ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
00124 ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
00125 ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
00126 ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
00127 ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
00128 ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
00129 ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
00130 ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
00131 
00132 /* predefined syntaxes (see regsyntax.c) */
00133 #define ONIG_SYNTAX_POSIX_BASIC        (&OnigSyntaxPosixBasic)
00134 #define ONIG_SYNTAX_POSIX_EXTENDED     (&OnigSyntaxPosixExtended)
00135 #define ONIG_SYNTAX_EMACS              (&OnigSyntaxEmacs)
00136 #define ONIG_SYNTAX_GREP               (&OnigSyntaxGrep)
00137 #define ONIG_SYNTAX_GNU_REGEX          (&OnigSyntaxGnuRegex)
00138 #define ONIG_SYNTAX_JAVA               (&OnigSyntaxJava)
00139 #define ONIG_SYNTAX_PERL               (&OnigSyntaxPerl)
00140 #define ONIG_SYNTAX_RUBY               (&OnigSyntaxRuby)
00141 /* default syntax */
00142 #define ONIG_SYNTAX_DEFAULT             OnigDefaultSyntax
00143 
00144 ONIG_EXTERN OnigSyntaxType*  OnigDefaultSyntax;
00145 
00146 ONIG_EXTERN int  onig_set_default_syntax P_((OnigSyntaxType* syntax));
00147 ONIG_EXTERN void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
00148 ONIG_EXTERN const char* onig_version P_((void));
00149 ONIG_EXTERN const char* onig_copyright P_((void));
00150 
00151 #endif /* ONIGURUMA_H */
00152 
00153 
00154 ONIG_EXTERN int    regcomp P_((regex_t* reg, const char* pat, int options));
00155 ONIG_EXTERN int    regexec P_((regex_t* reg, const char* str, size_t nmatch, regmatch_t* matches, int options));
00156 ONIG_EXTERN void   regfree P_((regex_t* reg));
00157 ONIG_EXTERN size_t regerror P_((int code, const regex_t* reg, char* buf, size_t size));
00158 
00159 /* extended API */
00160 ONIG_EXTERN void reg_set_encoding P_((int enc));
00161 ONIG_EXTERN int  reg_name_to_group_numbers P_((regex_t* reg, const unsigned char* name, const unsigned char* name_end, int** nums));
00162 ONIG_EXTERN int  reg_foreach_name P_((regex_t* reg, int (*func)(const unsigned char*, const unsigned char*,int,int*,regex_t*,void*), void* arg));
00163 ONIG_EXTERN int  reg_number_of_names P_((regex_t* reg));
00164 
00165 #ifdef __cplusplus
00166 }
00167 #endif
00168 
00169 #endif /* ONIGPOSIX_H */