xref: /PHP-7.3/ext/mbstring/oniguruma/src/onigposix.h (revision 1979c5d1)
1 #ifndef ONIGPOSIX_H
2 #define ONIGPOSIX_H
3 /**********************************************************************
4   onigposix.h - Oniguruma (regular expression library)
5 **********************************************************************/
6 /*-
7  * Copyright (c) 2002-2019  K.Kosako
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 set, 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_STATIC
99 #ifndef ONIG_EXTERN
100 #if defined(_WIN32) && !defined(__GNUC__)
101 #if defined(ONIGURUMA_EXPORT)
102 #define ONIG_EXTERN   extern __declspec(dllexport)
103 #else
104 #define ONIG_EXTERN   extern __declspec(dllimport)
105 #endif
106 #endif
107 #endif
108 
109 #ifndef ONIG_EXTERN
110 #define ONIG_EXTERN   extern
111 #endif
112 #else
113 #define ONIG_EXTERN   extern
114 #endif
115 
116 #ifndef ONIGURUMA_H
117 typedef unsigned int        OnigOptionType;
118 
119 /* syntax */
120 typedef struct {
121   unsigned int op;
122   unsigned int op2;
123   unsigned int behavior;
124   OnigOptionType options;    /* default option */
125 } OnigSyntaxType;
126 
127 ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
128 ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
129 ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
130 ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
131 ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
132 ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
133 ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
134 ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
135 ONIG_EXTERN OnigSyntaxType OnigSyntaxOniguruma;
136 
137 /* predefined syntaxes (see regsyntax.c) */
138 #define ONIG_SYNTAX_POSIX_BASIC        (&OnigSyntaxPosixBasic)
139 #define ONIG_SYNTAX_POSIX_EXTENDED     (&OnigSyntaxPosixExtended)
140 #define ONIG_SYNTAX_EMACS              (&OnigSyntaxEmacs)
141 #define ONIG_SYNTAX_GREP               (&OnigSyntaxGrep)
142 #define ONIG_SYNTAX_GNU_REGEX          (&OnigSyntaxGnuRegex)
143 #define ONIG_SYNTAX_JAVA               (&OnigSyntaxJava)
144 #define ONIG_SYNTAX_PERL               (&OnigSyntaxPerl)
145 #define ONIG_SYNTAX_RUBY               (&OnigSyntaxRuby)
146 #define ONIG_SYNTAX_ONIGURUMA          (&OnigSyntaxOniguruma)
147 /* default syntax */
148 #define ONIG_SYNTAX_DEFAULT             OnigDefaultSyntax
149 
150 ONIG_EXTERN OnigSyntaxType*  OnigDefaultSyntax;
151 
152 ONIG_EXTERN int  onig_set_default_syntax P_((OnigSyntaxType* syntax));
153 ONIG_EXTERN void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
154 ONIG_EXTERN const char* onig_version P_((void));
155 ONIG_EXTERN const char* onig_copyright P_((void));
156 ONIG_EXTERN int onig_end P_((void));
157 
158 #endif /* ONIGURUMA_H */
159 
160 
161 ONIG_EXTERN int    regcomp P_((regex_t* reg, const char* pat, int options));
162 ONIG_EXTERN int    regexec P_((regex_t* reg, const char* str, size_t nmatch, regmatch_t* matches, int options));
163 ONIG_EXTERN void   regfree P_((regex_t* reg));
164 ONIG_EXTERN size_t regerror P_((int code, const regex_t* reg, char* buf, size_t size));
165 
166 /* extended API */
167 ONIG_EXTERN void reg_set_encoding P_((int enc));
168 ONIG_EXTERN int  reg_name_to_group_numbers P_((regex_t* reg, const unsigned char* name, const unsigned char* name_end, int** nums));
169 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));
170 ONIG_EXTERN int  reg_number_of_names P_((regex_t* reg));
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif /* ONIGPOSIX_H */
177