xref: /PHP-5.4/ext/mbstring/oniguruma/onigposix.h (revision 5b5e012b)
1 #ifndef ONIGPOSIX_H
2 #define ONIGPOSIX_H
3 /**********************************************************************
4   onigposix.h - Oniguruma (regular expression library)
5 **********************************************************************/
6 /*-
7  * Copyright (c) 2002-2005  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp>
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 #include <stdlib.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /* options */
38 #define REG_ICASE          (1<<0)
39 #define REG_NEWLINE        (1<<1)
40 #define REG_NOTBOL         (1<<2)
41 #define REG_NOTEOL         (1<<3)
42 #define REG_EXTENDED       (1<<4) /* if not setted, Basic Onigular Expression */
43 #define REG_NOSUB          (1<<5)
44 
45 /* POSIX error codes */
46 #define REG_NOMATCH          1
47 #define REG_BADPAT           2
48 #define REG_ECOLLATE         3
49 #define REG_ECTYPE           4
50 #define REG_EESCAPE          5
51 #define REG_ESUBREG          6
52 #define REG_EBRACK           7
53 #define REG_EPAREN           8
54 #define REG_EBRACE           9
55 #define REG_BADBR           10
56 #define REG_ERANGE          11
57 #define REG_ESPACE          12
58 #define REG_BADRPT          13
59 
60 /* extended error codes */
61 #define REG_EONIG_INTERNAL  14
62 #define REG_EONIG_BADWC     15
63 #define REG_EONIG_BADARG    16
64 #define REG_EONIG_THREAD    17
65 
66 /* character encodings (for reg_set_encoding()) */
67 #define REG_POSIX_ENCODING_ASCII     0
68 #define REG_POSIX_ENCODING_EUC_JP    1
69 #define REG_POSIX_ENCODING_SJIS      2
70 #define REG_POSIX_ENCODING_UTF8      3
71 #define REG_POSIX_ENCODING_UTF16_BE  4
72 #define REG_POSIX_ENCODING_UTF16_LE  5
73 
74 
75 typedef int regoff_t;
76 
77 typedef struct {
78   regoff_t  rm_so;
79   regoff_t  rm_eo;
80 } regmatch_t;
81 
82 /* POSIX regex_t */
83 typedef struct {
84   void*   onig;          /* Oniguruma regex_t*  */
85   size_t  re_nsub;
86   int     comp_options;
87 } regex_t;
88 
89 
90 #ifndef P_
91 #if defined(__STDC__) || defined(_WIN32)
92 # define P_(args) args
93 #else
94 # define P_(args) ()
95 #endif
96 #endif
97 
98 #ifndef ONIG_EXTERN
99 #if defined(_WIN32) && !defined(__GNUC__)
100 #if defined(EXPORT) || defined(RUBY_EXPORT)
101 #define ONIG_EXTERN   extern __declspec(dllexport)
102 #else
103 #define ONIG_EXTERN   extern __declspec(dllimport)
104 #endif
105 #endif
106 #endif
107 
108 #ifndef ONIG_EXTERN
109 #define ONIG_EXTERN   extern
110 #endif
111 
112 #ifndef ONIGURUMA_H
113 typedef unsigned int        OnigOptionType;
114 
115 /* syntax */
116 typedef struct {
117   unsigned int op;
118   unsigned int op2;
119   unsigned int behavior;
120   OnigOptionType options;    /* default option */
121 } OnigSyntaxType;
122 
123 ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
124 ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
125 ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
126 ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
127 ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
128 ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
129 ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
130 ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
131 
132 /* predefined syntaxes (see regsyntax.c) */
133 #define ONIG_SYNTAX_POSIX_BASIC        (&OnigSyntaxPosixBasic)
134 #define ONIG_SYNTAX_POSIX_EXTENDED     (&OnigSyntaxPosixExtended)
135 #define ONIG_SYNTAX_EMACS              (&OnigSyntaxEmacs)
136 #define ONIG_SYNTAX_GREP               (&OnigSyntaxGrep)
137 #define ONIG_SYNTAX_GNU_REGEX          (&OnigSyntaxGnuRegex)
138 #define ONIG_SYNTAX_JAVA               (&OnigSyntaxJava)
139 #define ONIG_SYNTAX_PERL               (&OnigSyntaxPerl)
140 #define ONIG_SYNTAX_RUBY               (&OnigSyntaxRuby)
141 /* default syntax */
142 #define ONIG_SYNTAX_DEFAULT             OnigDefaultSyntax
143 
144 ONIG_EXTERN OnigSyntaxType*  OnigDefaultSyntax;
145 
146 ONIG_EXTERN int  onig_set_default_syntax P_((OnigSyntaxType* syntax));
147 ONIG_EXTERN void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
148 ONIG_EXTERN const char* onig_version P_((void));
149 ONIG_EXTERN const char* onig_copyright P_((void));
150 
151 #endif /* ONIGURUMA_H */
152 
153 
154 ONIG_EXTERN int    regcomp P_((regex_t* reg, const char* pat, int options));
155 ONIG_EXTERN int    regexec P_((regex_t* reg, const char* str, size_t nmatch, regmatch_t* matches, int options));
156 ONIG_EXTERN void   regfree P_((regex_t* reg));
157 ONIG_EXTERN size_t regerror P_((int code, const regex_t* reg, char* buf, size_t size));
158 
159 /* extended API */
160 ONIG_EXTERN void reg_set_encoding P_((int enc));
161 ONIG_EXTERN int  reg_name_to_group_numbers P_((regex_t* reg, const unsigned char* name, const unsigned char* name_end, int** nums));
162 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));
163 ONIG_EXTERN int  reg_number_of_names P_((regex_t* reg));
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* ONIGPOSIX_H */
170