1 #ifndef ONIGPOSIX_H
2 #define ONIGPOSIX_H
3 /**********************************************************************
4   onigposix.h - Oniguruma (regular expression library)
5 **********************************************************************/
6 /*-
7  * Copyright (c) 2002-2020  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 #ifndef ONIG_NO_STANDARD_C_HEADERS
32 #include <stddef.h>
33 #endif
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /* options */
40 #define REG_ICASE          (1<<0)
41 #define REG_NEWLINE        (1<<1)
42 #define REG_NOTBOL         (1<<2)
43 #define REG_NOTEOL         (1<<3)
44 #define REG_EXTENDED       (1<<4) /* if not set, Basic Onigular Expression */
45 #define REG_NOSUB          (1<<5)
46 
47 /* POSIX error codes */
48 #define REG_NOMATCH          1
49 #define REG_BADPAT           2
50 #define REG_ECOLLATE         3
51 #define REG_ECTYPE           4
52 #define REG_EESCAPE          5
53 #define REG_ESUBREG          6
54 #define REG_EBRACK           7
55 #define REG_EPAREN           8
56 #define REG_EBRACE           9
57 #define REG_BADBR           10
58 #define REG_ERANGE          11
59 #define REG_ESPACE          12
60 #define REG_BADRPT          13
61 
62 /* extended error codes */
63 #define REG_EONIG_INTERNAL  14
64 #define REG_EONIG_BADWC     15
65 #define REG_EONIG_BADARG    16
66 /* #define REG_EONIG_THREAD    17 */
67 
68 /* character encodings (for reg_set_encoding()) */
69 #define REG_POSIX_ENCODING_ASCII     0
70 #define REG_POSIX_ENCODING_EUC_JP    1
71 #define REG_POSIX_ENCODING_SJIS      2
72 #define REG_POSIX_ENCODING_UTF8      3
73 #define REG_POSIX_ENCODING_UTF16_BE  4
74 #define REG_POSIX_ENCODING_UTF16_LE  5
75 
76 
77 typedef int onig_posix_regoff_t;
78 
79 typedef struct {
80   onig_posix_regoff_t  rm_so;
81   onig_posix_regoff_t  rm_eo;
82 } onig_posix_regmatch_t;
83 
84 /* POSIX regex_t */
85 typedef struct {
86   void*   onig;          /* Oniguruma regex_t*  */
87   size_t  re_nsub;
88   int     comp_options;
89 } onig_posix_regex_t;
90 
91 
92 #ifndef P_
93 #if defined(__STDC__) || defined(_WIN32)
94 # define P_(args) args
95 #else
96 # define P_(args) ()
97 #endif
98 #endif
99 
100 #ifndef ONIG_STATIC
101 #ifndef ONIG_EXTERN
102 #if defined(_WIN32) && !defined(__GNUC__)
103 #if defined(ONIGURUMA_EXPORT)
104 #define ONIG_EXTERN   extern __declspec(dllexport)
105 #else
106 #define ONIG_EXTERN   extern __declspec(dllimport)
107 #endif
108 #endif
109 #endif
110 
111 #ifndef ONIG_EXTERN
112 #define ONIG_EXTERN   extern
113 #endif
114 #else
115 #define ONIG_EXTERN   extern
116 #endif
117 
118 #ifndef ONIGURUMA_H
119 typedef unsigned int        OnigOptionType;
120 
121 /* syntax */
122 typedef struct {
123   unsigned int op;
124   unsigned int op2;
125   unsigned int behavior;
126   OnigOptionType options;    /* default option */
127 } OnigSyntaxType;
128 
129 ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
130 ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
131 ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
132 ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
133 ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
134 ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
135 ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
136 ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
137 ONIG_EXTERN OnigSyntaxType OnigSyntaxOniguruma;
138 
139 /* predefined syntaxes (see regsyntax.c) */
140 #define ONIG_SYNTAX_POSIX_BASIC        (&OnigSyntaxPosixBasic)
141 #define ONIG_SYNTAX_POSIX_EXTENDED     (&OnigSyntaxPosixExtended)
142 #define ONIG_SYNTAX_EMACS              (&OnigSyntaxEmacs)
143 #define ONIG_SYNTAX_GREP               (&OnigSyntaxGrep)
144 #define ONIG_SYNTAX_GNU_REGEX          (&OnigSyntaxGnuRegex)
145 #define ONIG_SYNTAX_JAVA               (&OnigSyntaxJava)
146 #define ONIG_SYNTAX_PERL               (&OnigSyntaxPerl)
147 #define ONIG_SYNTAX_RUBY               (&OnigSyntaxRuby)
148 #define ONIG_SYNTAX_ONIGURUMA          (&OnigSyntaxOniguruma)
149 /* default syntax */
150 #define ONIG_SYNTAX_DEFAULT             OnigDefaultSyntax
151 
152 ONIG_EXTERN OnigSyntaxType*  OnigDefaultSyntax;
153 
154 ONIG_EXTERN int  onig_set_default_syntax P_((OnigSyntaxType* syntax));
155 ONIG_EXTERN void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
156 ONIG_EXTERN const char* onig_version P_((void));
157 ONIG_EXTERN const char* onig_copyright P_((void));
158 ONIG_EXTERN int onig_end P_((void));
159 
160 #endif /* ONIGURUMA_H */
161 
162 
163 ONIG_EXTERN int    onig_posix_regcomp P_((onig_posix_regex_t* reg, const char* pat, int options));
164 ONIG_EXTERN int    onig_posix_regexec P_((onig_posix_regex_t* reg, const char* str, size_t nmatch, onig_posix_regmatch_t* matches, int options));
165 ONIG_EXTERN void   onig_posix_regfree P_((onig_posix_regex_t* reg));
166 ONIG_EXTERN size_t onig_posix_regerror P_((int code, const onig_posix_regex_t* reg, char* buf, size_t size));
167 
168 /* extended API */
169 ONIG_EXTERN void onig_posix_reg_set_encoding P_((int enc));
170 ONIG_EXTERN int  onig_posix_reg_name_to_group_numbers P_((onig_posix_regex_t* reg, const unsigned char* name, const unsigned char* name_end, int** nums));
171 ONIG_EXTERN int  onig_posix_reg_foreach_name P_((onig_posix_regex_t* reg, int (*func)(const unsigned char*, const unsigned char*,int,int*,onig_posix_regex_t*,void*), void* arg));
172 ONIG_EXTERN int  onig_posix_reg_number_of_names P_((onig_posix_regex_t* reg));
173 
174 
175 /* aliases */
176 #define regex_t    onig_posix_regex_t
177 #define regmatch_t onig_posix_regmatch_t
178 #define regoff_t   onig_posix_regoff_t
179 
180 #define regcomp  onig_posix_regcomp
181 #define regexec  onig_posix_regexec
182 #define regfree  onig_posix_regfree
183 #define regerror onig_posix_regerror
184 #define reg_set_encoding          onig_posix_reg_set_encoding
185 #define reg_name_to_group_numbers onig_posix_reg_name_to_group_numbers
186 #define reg_foreach_name          onig_posix_reg_foreach_name
187 #define reg_number_of_names       onig_posix_reg_number_of_names
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 
193 #endif /* ONIGPOSIX_H */
194