1 #ifndef ONIGURUMA_H
2 #define ONIGURUMA_H
3 /**********************************************************************
4   oniguruma.h - Oniguruma (regular expression library)
5 **********************************************************************/
6 /*-
7  * Copyright (c) 2002-2018  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 
32 #include "OnigurumaUefiPort.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #define ONIGURUMA
39 #define ONIGURUMA_VERSION_MAJOR   6
40 #define ONIGURUMA_VERSION_MINOR   9
41 #define ONIGURUMA_VERSION_TEENY   0
42 
43 #define ONIGURUMA_VERSION_INT     60900
44 
45 #ifndef P_
46 #if defined(__STDC__) || defined(_WIN32)
47 # define P_(args) args
48 #else
49 # define P_(args) ()
50 #endif
51 #endif
52 
53 #ifndef PV_
54 # define PV_(args) args
55 #endif
56 
57 #ifndef ONIG_EXTERN
58 #if defined(_WIN32) && !defined(__GNUC__)
59 #if defined(ONIGURUMA_EXPORT)
60 #define ONIG_EXTERN   extern __declspec(dllexport)
61 #else
62 #define ONIG_EXTERN   extern __declspec(dllimport)
63 #endif
64 #endif
65 #endif
66 
67 #ifndef ONIG_EXTERN
68 #define ONIG_EXTERN   extern
69 #endif
70 
71 /* PART: character encoding */
72 
73 #ifndef ONIG_ESCAPE_UCHAR_COLLISION
74 #define UChar OnigUChar
75 #endif
76 
77 typedef unsigned int   OnigCodePoint;
78 typedef unsigned char  OnigUChar;
79 typedef unsigned int   OnigCtype;
80 typedef unsigned int   OnigLen;
81 
82 #define ONIG_INFINITE_DISTANCE  ~((OnigLen )0)
83 
84 typedef unsigned int OnigCaseFoldType; /* case fold flag */
85 
86 ONIG_EXTERN OnigCaseFoldType OnigDefaultCaseFoldFlag;
87 
88 /* #define ONIGENC_CASE_FOLD_HIRAGANA_KATAKANA  (1<<1) */
89 /* #define ONIGENC_CASE_FOLD_KATAKANA_WIDTH     (1<<2) */
90 #define ONIGENC_CASE_FOLD_TURKISH_AZERI         (1<<20)
91 #define INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR   (1<<30)
92 
93 #define ONIGENC_CASE_FOLD_MIN      INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR
94 #define ONIGENC_CASE_FOLD_DEFAULT  OnigDefaultCaseFoldFlag
95 
96 
97 #define ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN       3
98 #define ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM      13
99 /* 13 => Unicode:0x1ffc */
100 
101 /* code range */
102 #define ONIGENC_CODE_RANGE_NUM(range)     ((int )range[0])
103 #define ONIGENC_CODE_RANGE_FROM(range,i)  range[((i)*2) + 1]
104 #define ONIGENC_CODE_RANGE_TO(range,i)    range[((i)*2) + 2]
105 
106 typedef struct {
107   int byte_len;  /* argument(original) character(s) byte length */
108   int code_len;  /* number of code */
109   OnigCodePoint code[ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN];
110 } OnigCaseFoldCodeItem;
111 
112 typedef struct {
113   OnigCodePoint esc;
114   OnigCodePoint anychar;
115   OnigCodePoint anytime;
116   OnigCodePoint zero_or_one_time;
117   OnigCodePoint one_or_more_time;
118   OnigCodePoint anychar_anytime;
119 } OnigMetaCharTableType;
120 
121 typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg);
122 
123 typedef struct OnigEncodingTypeST {
124   int    (*mbc_enc_len)(const OnigUChar* p);
125   const char*   name;
126   int           max_enc_len;
127   int           min_enc_len;
128   int    (*is_mbc_newline)(const OnigUChar* p, const OnigUChar* end);
129   OnigCodePoint (*mbc_to_code)(const OnigUChar* p, const OnigUChar* end);
130   int    (*code_to_mbclen)(OnigCodePoint code);
131   int    (*code_to_mbc)(OnigCodePoint code, OnigUChar *buf);
132   int    (*mbc_case_fold)(OnigCaseFoldType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to);
133   int    (*apply_all_case_fold)(OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg);
134   int    (*get_case_fold_codes_by_str)(OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem acs[]);
135   int    (*property_name_to_ctype)(struct OnigEncodingTypeST* enc, OnigUChar* p, OnigUChar* end);
136   int    (*is_code_ctype)(OnigCodePoint code, OnigCtype ctype);
137   int    (*get_ctype_code_range)(OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[]);
138   OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p);
139   int    (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end);
140   int    (*init)(void);
141   int    (*is_initialized)(void);
142   int    (*is_valid_mbc_string)(const OnigUChar* s, const OnigUChar* end);
143   unsigned int flag;
144   OnigCodePoint sb_range;
145   int index;
146 } OnigEncodingType;
147 
148 typedef OnigEncodingType* OnigEncoding;
149 
150 ONIG_EXTERN OnigEncodingType OnigEncodingASCII;
151 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_1;
152 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_2;
153 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_3;
154 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_4;
155 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_5;
156 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_6;
157 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_7;
158 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_8;
159 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_9;
160 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_10;
161 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_11;
162 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_13;
163 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_14;
164 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_15;
165 ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_16;
166 ONIG_EXTERN OnigEncodingType OnigEncodingUTF8;
167 ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_BE;
168 ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_LE;
169 ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_BE;
170 ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_LE;
171 ONIG_EXTERN OnigEncodingType OnigEncodingEUC_JP;
172 ONIG_EXTERN OnigEncodingType OnigEncodingEUC_TW;
173 ONIG_EXTERN OnigEncodingType OnigEncodingEUC_KR;
174 ONIG_EXTERN OnigEncodingType OnigEncodingEUC_CN;
175 ONIG_EXTERN OnigEncodingType OnigEncodingSJIS;
176 ONIG_EXTERN OnigEncodingType OnigEncodingKOI8;
177 ONIG_EXTERN OnigEncodingType OnigEncodingKOI8_R;
178 ONIG_EXTERN OnigEncodingType OnigEncodingCP1251;
179 ONIG_EXTERN OnigEncodingType OnigEncodingBIG5;
180 ONIG_EXTERN OnigEncodingType OnigEncodingGB18030;
181 
182 #define ONIG_ENCODING_ASCII        (&OnigEncodingASCII)
183 #define ONIG_ENCODING_ISO_8859_1   (&OnigEncodingISO_8859_1)
184 #define ONIG_ENCODING_ISO_8859_2   (&OnigEncodingISO_8859_2)
185 #define ONIG_ENCODING_ISO_8859_3   (&OnigEncodingISO_8859_3)
186 #define ONIG_ENCODING_ISO_8859_4   (&OnigEncodingISO_8859_4)
187 #define ONIG_ENCODING_ISO_8859_5   (&OnigEncodingISO_8859_5)
188 #define ONIG_ENCODING_ISO_8859_6   (&OnigEncodingISO_8859_6)
189 #define ONIG_ENCODING_ISO_8859_7   (&OnigEncodingISO_8859_7)
190 #define ONIG_ENCODING_ISO_8859_8   (&OnigEncodingISO_8859_8)
191 #define ONIG_ENCODING_ISO_8859_9   (&OnigEncodingISO_8859_9)
192 #define ONIG_ENCODING_ISO_8859_10  (&OnigEncodingISO_8859_10)
193 #define ONIG_ENCODING_ISO_8859_11  (&OnigEncodingISO_8859_11)
194 #define ONIG_ENCODING_ISO_8859_13  (&OnigEncodingISO_8859_13)
195 #define ONIG_ENCODING_ISO_8859_14  (&OnigEncodingISO_8859_14)
196 #define ONIG_ENCODING_ISO_8859_15  (&OnigEncodingISO_8859_15)
197 #define ONIG_ENCODING_ISO_8859_16  (&OnigEncodingISO_8859_16)
198 #define ONIG_ENCODING_UTF8         (&OnigEncodingUTF8)
199 #define ONIG_ENCODING_UTF16_BE     (&OnigEncodingUTF16_BE)
200 #define ONIG_ENCODING_UTF16_LE     (&OnigEncodingUTF16_LE)
201 #define ONIG_ENCODING_UTF32_BE     (&OnigEncodingUTF32_BE)
202 #define ONIG_ENCODING_UTF32_LE     (&OnigEncodingUTF32_LE)
203 #define ONIG_ENCODING_EUC_JP       (&OnigEncodingEUC_JP)
204 #define ONIG_ENCODING_EUC_TW       (&OnigEncodingEUC_TW)
205 #define ONIG_ENCODING_EUC_KR       (&OnigEncodingEUC_KR)
206 #define ONIG_ENCODING_EUC_CN       (&OnigEncodingEUC_CN)
207 #define ONIG_ENCODING_SJIS         (&OnigEncodingSJIS)
208 #define ONIG_ENCODING_KOI8         (&OnigEncodingKOI8)
209 #define ONIG_ENCODING_KOI8_R       (&OnigEncodingKOI8_R)
210 #define ONIG_ENCODING_CP1251       (&OnigEncodingCP1251)
211 #define ONIG_ENCODING_BIG5         (&OnigEncodingBIG5)
212 #define ONIG_ENCODING_GB18030      (&OnigEncodingGB18030)
213 
214 #define ONIG_ENCODING_UNDEF    ((OnigEncoding )0)
215 
216 
217 /* work size */
218 #define ONIGENC_CODE_TO_MBC_MAXLEN       7
219 #define ONIGENC_MBC_CASE_FOLD_MAXLEN    18
220 /* 18: 6(max-byte) * 3(case-fold chars) */
221 
222 /* character types */
223 typedef enum {
224   ONIGENC_CTYPE_NEWLINE = 0,
225   ONIGENC_CTYPE_ALPHA   = 1,
226   ONIGENC_CTYPE_BLANK   = 2,
227   ONIGENC_CTYPE_CNTRL   = 3,
228   ONIGENC_CTYPE_DIGIT   = 4,
229   ONIGENC_CTYPE_GRAPH   = 5,
230   ONIGENC_CTYPE_LOWER   = 6,
231   ONIGENC_CTYPE_PRINT   = 7,
232   ONIGENC_CTYPE_PUNCT   = 8,
233   ONIGENC_CTYPE_SPACE   = 9,
234   ONIGENC_CTYPE_UPPER   = 10,
235   ONIGENC_CTYPE_XDIGIT  = 11,
236   ONIGENC_CTYPE_WORD    = 12,
237   ONIGENC_CTYPE_ALNUM   = 13,  /* alpha || digit */
238   ONIGENC_CTYPE_ASCII   = 14
239 } OnigEncCtype;
240 
241 #define ONIGENC_MAX_STD_CTYPE  ONIGENC_CTYPE_ASCII
242 
243 
244 #define onig_enc_len(enc,p,end)        ONIGENC_MBC_ENC_LEN(enc,p)
245 
246 #define ONIGENC_IS_UNDEF(enc)          ((enc) == ONIG_ENCODING_UNDEF)
247 #define ONIGENC_IS_SINGLEBYTE(enc)     (ONIGENC_MBC_MAXLEN(enc) == 1)
248 #define ONIGENC_IS_MBC_HEAD(enc,p)     (ONIGENC_MBC_ENC_LEN(enc,p) != 1)
249 #define ONIGENC_IS_MBC_ASCII(p)           (*(p)   < 128)
250 #define ONIGENC_IS_CODE_ASCII(code)       ((code) < 128)
251 #define ONIGENC_IS_MBC_WORD(enc,s,end) \
252    ONIGENC_IS_CODE_WORD(enc,ONIGENC_MBC_TO_CODE(enc,s,end))
253 #define ONIGENC_IS_MBC_WORD_ASCII(enc,s,end) onigenc_is_mbc_word_ascii(enc,s,end)
254 
255 #define ONIGENC_NAME(enc)                      ((enc)->name)
256 
257 #define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \
258   (enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf)
259 #define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
260         (enc)->is_allowed_reverse_match(s,end)
261 #define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s) \
262         (enc)->left_adjust_char_head(start, s)
263 #define ONIGENC_IS_VALID_MBC_STRING(enc,s,end) \
264         (enc)->is_valid_mbc_string(s,end)
265 #define ONIGENC_APPLY_ALL_CASE_FOLD(enc,case_fold_flag,f,arg) \
266         (enc)->apply_all_case_fold(case_fold_flag,f,arg)
267 #define ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc,case_fold_flag,p,end,acs) \
268        (enc)->get_case_fold_codes_by_str(case_fold_flag,p,end,acs)
269 #define ONIGENC_STEP_BACK(enc,start,s,n) \
270         onigenc_step_back((enc),(start),(s),(n))
271 
272 #define ONIGENC_MBC_ENC_LEN(enc,p)             (enc)->mbc_enc_len(p)
273 #define ONIGENC_MBC_MAXLEN(enc)               ((enc)->max_enc_len)
274 #define ONIGENC_MBC_MAXLEN_DIST(enc)           ONIGENC_MBC_MAXLEN(enc)
275 #define ONIGENC_MBC_MINLEN(enc)               ((enc)->min_enc_len)
276 #define ONIGENC_IS_MBC_NEWLINE(enc,p,end)      (enc)->is_mbc_newline((p),(end))
277 #define ONIGENC_MBC_TO_CODE(enc,p,end)         (enc)->mbc_to_code((p),(end))
278 #define ONIGENC_CODE_TO_MBCLEN(enc,code)       (enc)->code_to_mbclen(code)
279 #define ONIGENC_CODE_TO_MBC(enc,code,buf)      (enc)->code_to_mbc(code,buf)
280 #define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc,p,end) \
281   (enc)->property_name_to_ctype(enc,p,end)
282 
283 #define ONIGENC_IS_CODE_CTYPE(enc,code,ctype)  (enc)->is_code_ctype(code,ctype)
284 
285 #define ONIGENC_IS_CODE_NEWLINE(enc,code) \
286         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_NEWLINE)
287 #define ONIGENC_IS_CODE_GRAPH(enc,code) \
288         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_GRAPH)
289 #define ONIGENC_IS_CODE_PRINT(enc,code) \
290         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PRINT)
291 #define ONIGENC_IS_CODE_ALNUM(enc,code) \
292         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALNUM)
293 #define ONIGENC_IS_CODE_ALPHA(enc,code) \
294         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALPHA)
295 #define ONIGENC_IS_CODE_LOWER(enc,code) \
296         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_LOWER)
297 #define ONIGENC_IS_CODE_UPPER(enc,code) \
298         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_UPPER)
299 #define ONIGENC_IS_CODE_CNTRL(enc,code) \
300         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_CNTRL)
301 #define ONIGENC_IS_CODE_PUNCT(enc,code) \
302         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PUNCT)
303 #define ONIGENC_IS_CODE_SPACE(enc,code) \
304         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_SPACE)
305 #define ONIGENC_IS_CODE_BLANK(enc,code) \
306         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_BLANK)
307 #define ONIGENC_IS_CODE_DIGIT(enc,code) \
308         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_DIGIT)
309 #define ONIGENC_IS_CODE_XDIGIT(enc,code) \
310         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_XDIGIT)
311 #define ONIGENC_IS_CODE_WORD(enc,code) \
312         ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_WORD)
313 
314 #define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbout,ranges) \
315         (enc)->get_ctype_code_range(ctype,sbout,ranges)
316 
317 ONIG_EXTERN
318 OnigUChar* onigenc_step_back P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, int n));
319 
320 
321 /* encoding API */
322 ONIG_EXTERN
323 int onigenc_init P_((void));
324 ONIG_EXTERN
325 int onig_initialize_encoding P_((OnigEncoding enc));
326 ONIG_EXTERN
327 int onigenc_set_default_encoding P_((OnigEncoding enc));
328 ONIG_EXTERN
329 OnigEncoding onigenc_get_default_encoding P_((void));
330 ONIG_EXTERN
331 void  onigenc_set_default_caseconv_table P_((const OnigUChar* table));
332 ONIG_EXTERN
333 OnigUChar* onigenc_get_right_adjust_char_head_with_prev P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar** prev));
334 ONIG_EXTERN
335 OnigUChar* onigenc_get_prev_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
336 ONIG_EXTERN
337 OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
338 ONIG_EXTERN
339 OnigUChar* onigenc_get_right_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
340 ONIG_EXTERN
341 int onigenc_strlen P_((OnigEncoding enc, const OnigUChar* p, const OnigUChar* end));
342 ONIG_EXTERN
343 int onigenc_strlen_null P_((OnigEncoding enc, const OnigUChar* p));
344 ONIG_EXTERN
345 int onigenc_str_bytelen_null P_((OnigEncoding enc, const OnigUChar* p));
346 ONIG_EXTERN
347 int onigenc_is_valid_mbc_string P_((OnigEncoding enc, const OnigUChar* s, const OnigUChar* end));
348 ONIG_EXTERN
349 OnigUChar* onigenc_strdup P_((OnigEncoding enc, const OnigUChar* s, const OnigUChar* end));
350 
351 
352 /* PART: regular expression */
353 
354 /* config parameters */
355 #define ONIG_NREGION                          10
356 #define ONIG_MAX_CAPTURE_NUM          2147483647  /* 2**31 - 1 */
357 #define ONIG_MAX_BACKREF_NUM                1000
358 #define ONIG_MAX_REPEAT_NUM               100000
359 #define ONIG_MAX_MULTI_BYTE_RANGES_NUM     10000
360 /* constants */
361 #define ONIG_MAX_ERROR_MESSAGE_LEN            90
362 
363 typedef unsigned int        OnigOptionType;
364 
365 #define ONIG_OPTION_DEFAULT            ONIG_OPTION_NONE
366 
367 /* options */
368 #define ONIG_OPTION_NONE                 0U
369 /* options (compile time) */
370 #define ONIG_OPTION_IGNORECASE           1U
371 #define ONIG_OPTION_EXTEND               (ONIG_OPTION_IGNORECASE         << 1)
372 #define ONIG_OPTION_MULTILINE            (ONIG_OPTION_EXTEND             << 1)
373 #define ONIG_OPTION_SINGLELINE           (ONIG_OPTION_MULTILINE          << 1)
374 #define ONIG_OPTION_FIND_LONGEST         (ONIG_OPTION_SINGLELINE         << 1)
375 #define ONIG_OPTION_FIND_NOT_EMPTY       (ONIG_OPTION_FIND_LONGEST       << 1)
376 #define ONIG_OPTION_NEGATE_SINGLELINE    (ONIG_OPTION_FIND_NOT_EMPTY     << 1)
377 #define ONIG_OPTION_DONT_CAPTURE_GROUP   (ONIG_OPTION_NEGATE_SINGLELINE  << 1)
378 #define ONIG_OPTION_CAPTURE_GROUP        (ONIG_OPTION_DONT_CAPTURE_GROUP << 1)
379 /* options (search time) */
380 #define ONIG_OPTION_NOTBOL                    (ONIG_OPTION_CAPTURE_GROUP << 1)
381 #define ONIG_OPTION_NOTEOL                    (ONIG_OPTION_NOTBOL << 1)
382 #define ONIG_OPTION_POSIX_REGION              (ONIG_OPTION_NOTEOL << 1)
383 #define ONIG_OPTION_CHECK_VALIDITY_OF_STRING  (ONIG_OPTION_POSIX_REGION << 1)
384 /* #define ONIG_OPTION_CRLF_AS_LINE_SEPARATOR    (ONIG_OPTION_CHECK_VALIDITY_OF_STRING << 1) */
385 /* options (compile time) */
386 #define ONIG_OPTION_WORD_IS_ASCII        (ONIG_OPTION_CHECK_VALIDITY_OF_STRING << 4)
387 #define ONIG_OPTION_DIGIT_IS_ASCII       (ONIG_OPTION_WORD_IS_ASCII << 1)
388 #define ONIG_OPTION_SPACE_IS_ASCII       (ONIG_OPTION_DIGIT_IS_ASCII << 1)
389 #define ONIG_OPTION_POSIX_IS_ASCII       (ONIG_OPTION_SPACE_IS_ASCII << 1)
390 
391 #define ONIG_OPTION_MAXBIT               ONIG_OPTION_POSIX_IS_ASCII  /* limit */
392 
393 #define ONIG_OPTION_ON(options,regopt)      ((options) |= (regopt))
394 #define ONIG_OPTION_OFF(options,regopt)     ((options) &= ~(regopt))
395 #define ONIG_IS_OPTION_ON(options,option)   ((options) & (option))
396 
397 /* syntax */
398 typedef struct {
399   unsigned int   op;
400   unsigned int   op2;
401   unsigned int   behavior;
402   OnigOptionType options;   /* default option */
403   OnigMetaCharTableType meta_char_table;
404 } OnigSyntaxType;
405 
406 ONIG_EXTERN OnigSyntaxType OnigSyntaxASIS;
407 ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
408 ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
409 ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
410 ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
411 ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
412 ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
413 ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
414 ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl_NG;
415 ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
416 ONIG_EXTERN OnigSyntaxType OnigSyntaxOniguruma;
417 
418 /* predefined syntaxes (see regsyntax.c) */
419 #define ONIG_SYNTAX_ASIS               (&OnigSyntaxASIS)
420 #define ONIG_SYNTAX_POSIX_BASIC        (&OnigSyntaxPosixBasic)
421 #define ONIG_SYNTAX_POSIX_EXTENDED     (&OnigSyntaxPosixExtended)
422 #define ONIG_SYNTAX_EMACS              (&OnigSyntaxEmacs)
423 #define ONIG_SYNTAX_GREP               (&OnigSyntaxGrep)
424 #define ONIG_SYNTAX_GNU_REGEX          (&OnigSyntaxGnuRegex)
425 #define ONIG_SYNTAX_JAVA               (&OnigSyntaxJava)
426 #define ONIG_SYNTAX_PERL               (&OnigSyntaxPerl)
427 #define ONIG_SYNTAX_PERL_NG            (&OnigSyntaxPerl_NG)
428 #define ONIG_SYNTAX_RUBY               (&OnigSyntaxRuby)
429 #define ONIG_SYNTAX_ONIGURUMA          (&OnigSyntaxOniguruma)
430 
431 /* default syntax */
432 ONIG_EXTERN OnigSyntaxType*   OnigDefaultSyntax;
433 #define ONIG_SYNTAX_DEFAULT   OnigDefaultSyntax
434 
435 /* syntax (operators) */
436 #define ONIG_SYN_OP_VARIABLE_META_CHARACTERS    (1U<<0)
437 #define ONIG_SYN_OP_DOT_ANYCHAR                 (1U<<1)   /* . */
438 #define ONIG_SYN_OP_ASTERISK_ZERO_INF           (1U<<2)   /* * */
439 #define ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF       (1U<<3)
440 #define ONIG_SYN_OP_PLUS_ONE_INF                (1U<<4)   /* + */
441 #define ONIG_SYN_OP_ESC_PLUS_ONE_INF            (1U<<5)
442 #define ONIG_SYN_OP_QMARK_ZERO_ONE              (1U<<6)   /* ? */
443 #define ONIG_SYN_OP_ESC_QMARK_ZERO_ONE          (1U<<7)
444 #define ONIG_SYN_OP_BRACE_INTERVAL              (1U<<8)   /* {lower,upper} */
445 #define ONIG_SYN_OP_ESC_BRACE_INTERVAL          (1U<<9)   /* \{lower,upper\} */
446 #define ONIG_SYN_OP_VBAR_ALT                    (1U<<10)   /* | */
447 #define ONIG_SYN_OP_ESC_VBAR_ALT                (1U<<11)  /* \| */
448 #define ONIG_SYN_OP_LPAREN_SUBEXP               (1U<<12)  /* (...)   */
449 #define ONIG_SYN_OP_ESC_LPAREN_SUBEXP           (1U<<13)  /* \(...\) */
450 #define ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR           (1U<<14)  /* \A, \Z, \z */
451 #define ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR  (1U<<15)  /* \G     */
452 #define ONIG_SYN_OP_DECIMAL_BACKREF             (1U<<16)  /* \num   */
453 #define ONIG_SYN_OP_BRACKET_CC                  (1U<<17)  /* [...]  */
454 #define ONIG_SYN_OP_ESC_W_WORD                  (1U<<18)  /* \w, \W */
455 #define ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END     (1U<<19)  /* \<. \> */
456 #define ONIG_SYN_OP_ESC_B_WORD_BOUND            (1U<<20)  /* \b, \B */
457 #define ONIG_SYN_OP_ESC_S_WHITE_SPACE           (1U<<21)  /* \s, \S */
458 #define ONIG_SYN_OP_ESC_D_DIGIT                 (1U<<22)  /* \d, \D */
459 #define ONIG_SYN_OP_LINE_ANCHOR                 (1U<<23)  /* ^, $   */
460 #define ONIG_SYN_OP_POSIX_BRACKET               (1U<<24)  /* [:xxxx:] */
461 #define ONIG_SYN_OP_QMARK_NON_GREEDY            (1U<<25)  /* ??,*?,+?,{n,m}? */
462 #define ONIG_SYN_OP_ESC_CONTROL_CHARS           (1U<<26)  /* \n,\r,\t,\a ... */
463 #define ONIG_SYN_OP_ESC_C_CONTROL               (1U<<27)  /* \cx  */
464 #define ONIG_SYN_OP_ESC_OCTAL3                  (1U<<28)  /* \OOO */
465 #define ONIG_SYN_OP_ESC_X_HEX2                  (1U<<29)  /* \xHH */
466 #define ONIG_SYN_OP_ESC_X_BRACE_HEX8            (1U<<30)  /* \x{7HHHHHHH} */
467 #define ONIG_SYN_OP_ESC_O_BRACE_OCTAL           (1U<<31)  /* \o{1OOOOOOOOOO} */
468 
469 #define ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE        (1U<<0)  /* \Q...\E */
470 #define ONIG_SYN_OP2_QMARK_GROUP_EFFECT         (1U<<1)  /* (?...) */
471 #define ONIG_SYN_OP2_OPTION_PERL                (1U<<2)  /* (?imsx),(?-imsx) */
472 #define ONIG_SYN_OP2_OPTION_RUBY                (1U<<3)  /* (?imx), (?-imx)  */
473 #define ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT     (1U<<4)  /* ?+,*+,++ */
474 #define ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL   (1U<<5)  /* {n,m}+   */
475 #define ONIG_SYN_OP2_CCLASS_SET_OP              (1U<<6)  /* [...&&..[..]..] */
476 #define ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP       (1U<<7)  /* (?<name>...) */
477 #define ONIG_SYN_OP2_ESC_K_NAMED_BACKREF        (1U<<8)  /* \k<name> */
478 #define ONIG_SYN_OP2_ESC_G_SUBEXP_CALL          (1U<<9)  /* \g<name>, \g<n> */
479 #define ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY     (1U<<10) /* (?@..),(?@<x>..) */
480 #define ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL  (1U<<11) /* \C-x */
481 #define ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META     (1U<<12) /* \M-x */
482 #define ONIG_SYN_OP2_ESC_V_VTAB                 (1U<<13) /* \v as VTAB */
483 #define ONIG_SYN_OP2_ESC_U_HEX4                 (1U<<14) /* \uHHHH */
484 #define ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR         (1U<<15) /* \`, \' */
485 #define ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY  (1U<<16) /* \p{...}, \P{...} */
486 #define ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT (1U<<17) /* \p{^..}, \P{^..} */
487 /* #define ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS (1U<<18) */
488 #define ONIG_SYN_OP2_ESC_H_XDIGIT               (1U<<19) /* \h, \H */
489 #define ONIG_SYN_OP2_INEFFECTIVE_ESCAPE         (1U<<20) /* \ */
490 #define ONIG_SYN_OP2_QMARK_LPAREN_IF_ELSE       (1U<<21) /* (?(n)) (?(...)...|...) */
491 #define ONIG_SYN_OP2_ESC_CAPITAL_K_KEEP         (1U<<22) /* \K */
492 #define ONIG_SYN_OP2_ESC_CAPITAL_R_GENERAL_NEWLINE (1U<<23) /* \R \r\n else [\x0a-\x0d] */
493 #define ONIG_SYN_OP2_ESC_CAPITAL_N_O_SUPER_DOT  (1U<<24) /* \N (?-m:.), \O (?m:.) */
494 #define ONIG_SYN_OP2_QMARK_TILDE_ABSENT_GROUP   (1U<<25) /* (?~...) */
495 #define ONIG_SYN_OP2_ESC_X_Y_GRAPHEME_CLUSTER   (1U<<26) /* \X \y \Y */
496 #define ONIG_SYN_OP2_QMARK_PERL_SUBEXP_CALL     (1U<<27) /* (?R), (?&name)... */
497 #define ONIG_SYN_OP2_QMARK_BRACE_CALLOUT_CONTENTS (1U<<28) /* (?{...}) (?{{...}}) */
498 #define ONIG_SYN_OP2_ASTERISK_CALLOUT_NAME      (1U<<29) /* (*name) (*name{a,..}) */
499 
500 /* syntax (behavior) */
501 #define ONIG_SYN_CONTEXT_INDEP_ANCHORS           (1U<<31) /* not implemented */
502 #define ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS        (1U<<0)  /* ?, *, +, {n,m} */
503 #define ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS      (1U<<1)  /* error or ignore */
504 #define ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP    (1U<<2)  /* ...)... */
505 #define ONIG_SYN_ALLOW_INVALID_INTERVAL          (1U<<3)  /* {??? */
506 #define ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV       (1U<<4)  /* {,n} => {0,n} */
507 #define ONIG_SYN_STRICT_CHECK_BACKREF            (1U<<5)  /* /(\1)/,/\1()/ ..*/
508 #define ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND   (1U<<6)  /* (?<=a|bc) */
509 #define ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP        (1U<<7)  /* see doc/RE */
510 #define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME (1U<<8)  /* (?<x>)(?<x>) */
511 #define ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY   (1U<<9)  /* a{n}?=(?:a{n})? */
512 
513 /* syntax (behavior) in char class [...] */
514 #define ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC      (1U<<20) /* [^...] */
515 #define ONIG_SYN_BACKSLASH_ESCAPE_IN_CC          (1U<<21) /* [..\w..] etc.. */
516 #define ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC         (1U<<22)
517 #define ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC     (1U<<23) /* [0-9-a]=[0-9\-a] */
518 /* syntax (behavior) warning */
519 #define ONIG_SYN_WARN_CC_OP_NOT_ESCAPED          (1U<<24) /* [,-,] */
520 #define ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT    (1U<<25) /* (?:a*)+ */
521 
522 /* meta character specifiers (onig_set_meta_char()) */
523 #define ONIG_META_CHAR_ESCAPE               0
524 #define ONIG_META_CHAR_ANYCHAR              1
525 #define ONIG_META_CHAR_ANYTIME              2
526 #define ONIG_META_CHAR_ZERO_OR_ONE_TIME     3
527 #define ONIG_META_CHAR_ONE_OR_MORE_TIME     4
528 #define ONIG_META_CHAR_ANYCHAR_ANYTIME      5
529 
530 #define ONIG_INEFFECTIVE_META_CHAR          0
531 
532 /* error codes */
533 #define ONIG_IS_PATTERN_ERROR(ecode)   ((ecode) <= -100 && (ecode) > -1000)
534 /* normal return */
535 #define ONIG_NORMAL                                            0
536 #define ONIG_MISMATCH                                         -1
537 #define ONIG_NO_SUPPORT_CONFIG                                -2
538 #define ONIG_ABORT                                            -3
539 
540 /* internal error */
541 #define ONIGERR_MEMORY                                         -5
542 #define ONIGERR_TYPE_BUG                                       -6
543 #define ONIGERR_PARSER_BUG                                    -11
544 #define ONIGERR_STACK_BUG                                     -12
545 #define ONIGERR_UNDEFINED_BYTECODE                            -13
546 #define ONIGERR_UNEXPECTED_BYTECODE                           -14
547 #define ONIGERR_MATCH_STACK_LIMIT_OVER                        -15
548 #define ONIGERR_PARSE_DEPTH_LIMIT_OVER                        -16
549 #define ONIGERR_RETRY_LIMIT_IN_MATCH_OVER                     -17
550 #define ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED                -21
551 #define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR  -22
552 #define ONIGERR_FAIL_TO_INITIALIZE                            -23
553 /* general error */
554 #define ONIGERR_INVALID_ARGUMENT                              -30
555 /* syntax error */
556 #define ONIGERR_END_PATTERN_AT_LEFT_BRACE                    -100
557 #define ONIGERR_END_PATTERN_AT_LEFT_BRACKET                  -101
558 #define ONIGERR_EMPTY_CHAR_CLASS                             -102
559 #define ONIGERR_PREMATURE_END_OF_CHAR_CLASS                  -103
560 #define ONIGERR_END_PATTERN_AT_ESCAPE                        -104
561 #define ONIGERR_END_PATTERN_AT_META                          -105
562 #define ONIGERR_END_PATTERN_AT_CONTROL                       -106
563 #define ONIGERR_META_CODE_SYNTAX                             -108
564 #define ONIGERR_CONTROL_CODE_SYNTAX                          -109
565 #define ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE             -110
566 #define ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE           -111
567 #define ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS      -112
568 #define ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED      -113
569 #define ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID            -114
570 #define ONIGERR_NESTED_REPEAT_OPERATOR                       -115
571 #define ONIGERR_UNMATCHED_CLOSE_PARENTHESIS                  -116
572 #define ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS       -117
573 #define ONIGERR_END_PATTERN_IN_GROUP                         -118
574 #define ONIGERR_UNDEFINED_GROUP_OPTION                       -119
575 #define ONIGERR_INVALID_POSIX_BRACKET_TYPE                   -121
576 #define ONIGERR_INVALID_LOOK_BEHIND_PATTERN                  -122
577 #define ONIGERR_INVALID_REPEAT_RANGE_PATTERN                 -123
578 /* values error (syntax error) */
579 #define ONIGERR_TOO_BIG_NUMBER                               -200
580 #define ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE              -201
581 #define ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE     -202
582 #define ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS                    -203
583 #define ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE          -204
584 #define ONIGERR_TOO_MANY_MULTI_BYTE_RANGES                   -205
585 #define ONIGERR_TOO_SHORT_MULTI_BYTE_STRING                  -206
586 #define ONIGERR_TOO_BIG_BACKREF_NUMBER                       -207
587 #define ONIGERR_INVALID_BACKREF                              -208
588 #define ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED         -209
589 #define ONIGERR_TOO_MANY_CAPTURES                            -210
590 #define ONIGERR_TOO_LONG_WIDE_CHAR_VALUE                     -212
591 #define ONIGERR_EMPTY_GROUP_NAME                             -214
592 #define ONIGERR_INVALID_GROUP_NAME                           -215
593 #define ONIGERR_INVALID_CHAR_IN_GROUP_NAME                   -216
594 #define ONIGERR_UNDEFINED_NAME_REFERENCE                     -217
595 #define ONIGERR_UNDEFINED_GROUP_REFERENCE                    -218
596 #define ONIGERR_MULTIPLEX_DEFINED_NAME                       -219
597 #define ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL               -220
598 #define ONIGERR_NEVER_ENDING_RECURSION                       -221
599 #define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY        -222
600 #define ONIGERR_INVALID_CHAR_PROPERTY_NAME                   -223
601 #define ONIGERR_INVALID_IF_ELSE_SYNTAX                       -224
602 #define ONIGERR_INVALID_ABSENT_GROUP_PATTERN                 -225
603 #define ONIGERR_INVALID_ABSENT_GROUP_GENERATOR_PATTERN       -226
604 #define ONIGERR_INVALID_CALLOUT_PATTERN                      -227
605 #define ONIGERR_INVALID_CALLOUT_NAME                         -228
606 #define ONIGERR_UNDEFINED_CALLOUT_NAME                       -229
607 #define ONIGERR_INVALID_CALLOUT_BODY                         -230
608 #define ONIGERR_INVALID_CALLOUT_TAG_NAME                     -231
609 #define ONIGERR_INVALID_CALLOUT_ARG                          -232
610 #define ONIGERR_INVALID_CODE_POINT_VALUE                     -400
611 #define ONIGERR_INVALID_WIDE_CHAR_VALUE                      -400
612 #define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE                      -401
613 #define ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION           -402
614 #define ONIGERR_INVALID_COMBINATION_OF_OPTIONS               -403
615 #define ONIGERR_TOO_MANY_USER_DEFINED_OBJECTS                -404
616 #define ONIGERR_TOO_LONG_PROPERTY_NAME                       -405
617 #define ONIGERR_LIBRARY_IS_NOT_INITIALIZED                   -500
618 
619 /* errors related to thread */
620 /* #define ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT                -1001 */
621 
622 
623 /* must be smaller than MEM_STATUS_BITS_NUM (unsigned int * 8) */
624 #define ONIG_MAX_CAPTURE_HISTORY_GROUP   31
625 #define ONIG_IS_CAPTURE_HISTORY_GROUP(r, i) \
626   ((i) <= ONIG_MAX_CAPTURE_HISTORY_GROUP && (r)->list && (r)->list[i])
627 
628 typedef struct OnigCaptureTreeNodeStruct {
629   int group;   /* group number */
630   int beg;
631   int end;
632   int allocated;
633   int num_childs;
634   struct OnigCaptureTreeNodeStruct** childs;
635 } OnigCaptureTreeNode;
636 
637 /* match result region type */
638 struct re_registers {
639   int  allocated;
640   int  num_regs;
641   int* beg;
642   int* end;
643   /* extended */
644   OnigCaptureTreeNode* history_root;  /* capture history tree root */
645 };
646 
647 /* capture tree traverse */
648 #define ONIG_TRAVERSE_CALLBACK_AT_FIRST   1
649 #define ONIG_TRAVERSE_CALLBACK_AT_LAST    2
650 #define ONIG_TRAVERSE_CALLBACK_AT_BOTH \
651   ( ONIG_TRAVERSE_CALLBACK_AT_FIRST | ONIG_TRAVERSE_CALLBACK_AT_LAST )
652 
653 
654 #define ONIG_REGION_NOTPOS            -1
655 
656 typedef struct re_registers   OnigRegion;
657 
658 typedef struct {
659   OnigEncoding enc;
660   OnigUChar* par;
661   OnigUChar* par_end;
662 } OnigErrorInfo;
663 
664 typedef struct {
665   int lower;
666   int upper;
667 } OnigRepeatRange;
668 
669 typedef void (*OnigWarnFunc) P_((const char* s));
670 extern void onig_null_warn P_((const char* s));
671 #define ONIG_NULL_WARN       onig_null_warn
672 
673 #define ONIG_CHAR_TABLE_SIZE   256
674 
675 struct re_pattern_buffer;
676 typedef struct re_pattern_buffer OnigRegexType;
677 typedef OnigRegexType*  OnigRegex;
678 
679 #ifndef ONIG_ESCAPE_REGEX_T_COLLISION
680   typedef OnigRegexType  regex_t;
681 #endif
682 
683 
684 typedef struct {
685   int             num_of_elements;
686   OnigEncoding    pattern_enc;
687   OnigEncoding    target_enc;
688   OnigSyntaxType* syntax;
689   OnigOptionType  option;
690   OnigCaseFoldType   case_fold_flag;
691 } OnigCompileInfo;
692 
693 
694 /* types for callout */
695 typedef enum {
696   ONIG_CALLOUT_IN_PROGRESS   = 1, /* 1<<0 */
697   ONIG_CALLOUT_IN_RETRACTION = 2  /* 1<<1 */
698 } OnigCalloutIn;
699 
700 #define ONIG_CALLOUT_IN_BOTH  (ONIG_CALLOUT_IN_PROGRESS | ONIG_CALLOUT_IN_RETRACTION)
701 
702 typedef enum {
703   ONIG_CALLOUT_OF_CONTENTS = 0,
704   ONIG_CALLOUT_OF_NAME     = 1
705 } OnigCalloutOf;
706 
707 typedef enum {
708   ONIG_CALLOUT_TYPE_SINGLE              = 0,
709   ONIG_CALLOUT_TYPE_START_CALL          = 1,
710   ONIG_CALLOUT_TYPE_BOTH_CALL           = 2,
711   ONIG_CALLOUT_TYPE_START_MARK_END_CALL = 3,
712 } OnigCalloutType;
713 
714 
715 #define ONIG_NON_NAME_ID        -1
716 #define ONIG_NON_CALLOUT_NUM     0
717 
718 #define ONIG_CALLOUT_MAX_ARGS_NUM     4
719 #define ONIG_CALLOUT_DATA_SLOT_NUM    5
720 
721 struct OnigCalloutArgsStruct;
722 typedef struct OnigCalloutArgsStruct OnigCalloutArgs;
723 
724 typedef int (*OnigCalloutFunc)(OnigCalloutArgs* args, void* user_data);
725 
726 /* callout function return values (less than -1: error code) */
727 typedef enum {
728   ONIG_CALLOUT_FAIL     =  1,
729   ONIG_CALLOUT_SUCCESS  =  0
730 } OnigCalloutResult;
731 
732 typedef enum {
733   ONIG_TYPE_VOID     = 0,
734   ONIG_TYPE_LONG     = 1<<0,
735   ONIG_TYPE_CHAR     = 1<<1,
736   ONIG_TYPE_STRING   = 1<<2,
737   ONIG_TYPE_POINTER  = 1<<3,
738   ONIG_TYPE_TAG      = 1<<4,
739 } OnigType;
740 
741 typedef union {
742   long l;
743   OnigCodePoint c;
744   struct {
745     OnigUChar* start;
746     OnigUChar* end;
747   } s;
748   void* p;
749   int tag;  /* tag -> callout_num */
750 } OnigValue;
751 
752 
753 struct OnigMatchParamStruct;
754 typedef struct OnigMatchParamStruct OnigMatchParam;
755 
756 
757 /* Oniguruma Native API */
758 
759 ONIG_EXTERN
760 int onig_initialize P_((OnigEncoding encodings[], int number_of_encodings));
761 /* onig_init(): deprecated function. Use onig_initialize(). */
762 ONIG_EXTERN
763 int onig_init P_((void));
764 ONIG_EXTERN
765 int EFIAPI onig_error_code_to_str PV_((OnigUChar* s, int err_code, ...));
766 ONIG_EXTERN
767 void onig_set_warn_func P_((OnigWarnFunc f));
768 ONIG_EXTERN
769 void onig_set_verb_warn_func P_((OnigWarnFunc f));
770 ONIG_EXTERN
771 int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
772 ONIG_EXTERN
773 int  onig_reg_init P_((OnigRegex reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, OnigSyntaxType* syntax));
774 int onig_new_without_alloc P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
775 ONIG_EXTERN
776 int onig_new_deluxe P_((OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
777 ONIG_EXTERN
778 void onig_free P_((OnigRegex));
779 ONIG_EXTERN
780 void onig_free_body P_((OnigRegex));
781 ONIG_EXTERN
782 int onig_scan(OnigRegex reg, const OnigUChar* str, const OnigUChar* end, OnigRegion* region, OnigOptionType option, int (*scan_callback)(int, int, OnigRegion*, void*), void* callback_arg);
783 ONIG_EXTERN
784 int onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
785 ONIG_EXTERN
786 int onig_search_with_param P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option, OnigMatchParam* mp));
787 ONIG_EXTERN
788 int onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option));
789 ONIG_EXTERN
790 int onig_match_with_param P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option, OnigMatchParam* mp));
791 ONIG_EXTERN
792 OnigRegion* onig_region_new P_((void));
793 ONIG_EXTERN
794 void onig_region_init P_((OnigRegion* region));
795 ONIG_EXTERN
796 void onig_region_free P_((OnigRegion* region, int free_self));
797 ONIG_EXTERN
798 void onig_region_copy P_((OnigRegion* to, OnigRegion* from));
799 ONIG_EXTERN
800 void onig_region_clear P_((OnigRegion* region));
801 ONIG_EXTERN
802 int onig_region_resize P_((OnigRegion* region, int n));
803 ONIG_EXTERN
804 int onig_region_set P_((OnigRegion* region, int at, int beg, int end));
805 ONIG_EXTERN
806 int onig_name_to_group_numbers P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, int** nums));
807 ONIG_EXTERN
808 int onig_name_to_backref_number P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, OnigRegion *region));
809 ONIG_EXTERN
810 int onig_foreach_name P_((OnigRegex reg, int (*func)(const OnigUChar*, const OnigUChar*,int,int*,OnigRegex,void*), void* arg));
811 ONIG_EXTERN
812 int onig_number_of_names P_((OnigRegex reg));
813 ONIG_EXTERN
814 int onig_number_of_captures P_((OnigRegex reg));
815 ONIG_EXTERN
816 int onig_number_of_capture_histories P_((OnigRegex reg));
817 ONIG_EXTERN
818 OnigCaptureTreeNode* onig_get_capture_tree P_((OnigRegion* region));
819 ONIG_EXTERN
820 int onig_capture_tree_traverse P_((OnigRegion* region, int at, int(*callback_func)(int,int,int,int,int,void*), void* arg));
821 ONIG_EXTERN
822 int onig_noname_group_capture_is_active P_((OnigRegex reg));
823 ONIG_EXTERN
824 OnigEncoding onig_get_encoding P_((OnigRegex reg));
825 ONIG_EXTERN
826 OnigOptionType onig_get_options P_((OnigRegex reg));
827 ONIG_EXTERN
828 OnigCaseFoldType onig_get_case_fold_flag P_((OnigRegex reg));
829 ONIG_EXTERN
830 OnigSyntaxType* onig_get_syntax P_((OnigRegex reg));
831 ONIG_EXTERN
832 int onig_set_default_syntax P_((OnigSyntaxType* syntax));
833 ONIG_EXTERN
834 void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
835 ONIG_EXTERN
836 unsigned int onig_get_syntax_op P_((OnigSyntaxType* syntax));
837 ONIG_EXTERN
838 unsigned int onig_get_syntax_op2 P_((OnigSyntaxType* syntax));
839 ONIG_EXTERN
840 unsigned int onig_get_syntax_behavior P_((OnigSyntaxType* syntax));
841 ONIG_EXTERN
842 OnigOptionType onig_get_syntax_options P_((OnigSyntaxType* syntax));
843 ONIG_EXTERN
844 void onig_set_syntax_op P_((OnigSyntaxType* syntax, unsigned int op));
845 ONIG_EXTERN
846 void onig_set_syntax_op2 P_((OnigSyntaxType* syntax, unsigned int op2));
847 ONIG_EXTERN
848 void onig_set_syntax_behavior P_((OnigSyntaxType* syntax, unsigned int behavior));
849 ONIG_EXTERN
850 void onig_set_syntax_options P_((OnigSyntaxType* syntax, OnigOptionType options));
851 ONIG_EXTERN
852 int onig_set_meta_char P_((OnigSyntaxType* syntax, unsigned int what, OnigCodePoint code));
853 ONIG_EXTERN
854 void onig_copy_encoding P_((OnigEncoding to, OnigEncoding from));
855 ONIG_EXTERN
856 OnigCaseFoldType onig_get_default_case_fold_flag P_((void));
857 ONIG_EXTERN
858 int onig_set_default_case_fold_flag P_((OnigCaseFoldType case_fold_flag));
859 ONIG_EXTERN
860 unsigned int onig_get_match_stack_limit_size P_((void));
861 ONIG_EXTERN
862 int onig_set_match_stack_limit_size P_((unsigned int size));
863 ONIG_EXTERN
864 unsigned long onig_get_retry_limit_in_match P_((void));
865 ONIG_EXTERN
866 int onig_set_retry_limit_in_match P_((unsigned long n));
867 ONIG_EXTERN
868 unsigned int onig_get_parse_depth_limit P_((void));
869 ONIG_EXTERN
870 int onig_set_capture_num_limit P_((int num));
871 ONIG_EXTERN
872 int onig_set_parse_depth_limit P_((unsigned int depth));
873 ONIG_EXTERN
874 int onig_unicode_define_user_property P_((const char* name, OnigCodePoint* ranges));
875 ONIG_EXTERN
876 int onig_end P_((void));
877 ONIG_EXTERN
878 const char* onig_version P_((void));
879 ONIG_EXTERN
880 const char* onig_copyright P_((void));
881 
882 /* for OnigMatchParam */
883 ONIG_EXTERN
884 OnigMatchParam* onig_new_match_param P_((void));
885 ONIG_EXTERN
886 void onig_free_match_param P_((OnigMatchParam* p));
887 ONIG_EXTERN
888 void onig_free_match_param_content P_((OnigMatchParam* p));
889 ONIG_EXTERN
890 int onig_initialize_match_param P_((OnigMatchParam* mp));
891 ONIG_EXTERN
892 int onig_set_match_stack_limit_size_of_match_param P_((OnigMatchParam* param, unsigned int limit));
893 ONIG_EXTERN
894 int onig_set_retry_limit_in_match_of_match_param P_((OnigMatchParam* param, unsigned long limit));
895 ONIG_EXTERN
896 int onig_set_progress_callout_of_match_param P_((OnigMatchParam* param, OnigCalloutFunc f));
897 ONIG_EXTERN
898 int onig_set_retraction_callout_of_match_param P_((OnigMatchParam* param, OnigCalloutFunc f));
899 ONIG_EXTERN
900 int onig_set_callout_user_data_of_match_param P_((OnigMatchParam* param, void* user_data));
901 
902 /* for callout functions */
903 ONIG_EXTERN
904 OnigCalloutFunc onig_get_progress_callout P_((void));
905 ONIG_EXTERN
906 int onig_set_progress_callout P_((OnigCalloutFunc f));
907 ONIG_EXTERN
908 OnigCalloutFunc onig_get_retraction_callout P_((void));
909 ONIG_EXTERN
910 int onig_set_retraction_callout P_((OnigCalloutFunc f));
911 ONIG_EXTERN
912 int onig_set_callout_of_name P_((OnigEncoding enc, OnigCalloutType type, OnigUChar* name, OnigUChar* name_end, int callout_in, OnigCalloutFunc callout, OnigCalloutFunc end_callout, int arg_num, unsigned int arg_types[], int optional_arg_num, OnigValue opt_defaults[]));
913 ONIG_EXTERN
914 OnigUChar* onig_get_callout_name_by_name_id P_((int id));
915 ONIG_EXTERN
916 int onig_get_callout_num_by_tag P_((OnigRegex reg, const OnigUChar* tag, const OnigUChar* tag_end));
917 ONIG_EXTERN
918 int onig_get_callout_data_by_tag P_((OnigRegex reg, OnigMatchParam* mp, const OnigUChar* tag, const OnigUChar* tag_end, int slot, OnigType* type, OnigValue* val));
919 ONIG_EXTERN
920 int onig_set_callout_data_by_tag P_((OnigRegex reg, OnigMatchParam* mp, const OnigUChar* tag, const OnigUChar* tag_end, int slot, OnigType type, OnigValue* val));
921 
922 /* used in callout functions */
923 ONIG_EXTERN
924 int onig_get_callout_num_by_callout_args P_((OnigCalloutArgs* args));
925 ONIG_EXTERN
926 OnigCalloutIn onig_get_callout_in_by_callout_args P_((OnigCalloutArgs* args));
927 ONIG_EXTERN
928 int onig_get_name_id_by_callout_args P_((OnigCalloutArgs* args));
929 ONIG_EXTERN
930 const OnigUChar* onig_get_contents_by_callout_args P_((OnigCalloutArgs* args));
931 ONIG_EXTERN
932 const OnigUChar* onig_get_contents_end_by_callout_args P_((OnigCalloutArgs* args));
933 ONIG_EXTERN
934 int onig_get_args_num_by_callout_args P_((OnigCalloutArgs* args));
935 ONIG_EXTERN
936 int onig_get_passed_args_num_by_callout_args P_((OnigCalloutArgs* args));
937 ONIG_EXTERN
938 int onig_get_arg_by_callout_args P_((OnigCalloutArgs* args, int index, OnigType* type, OnigValue* val));
939 ONIG_EXTERN
940 const OnigUChar* onig_get_string_by_callout_args P_((OnigCalloutArgs* args));
941 ONIG_EXTERN
942 const OnigUChar* onig_get_string_end_by_callout_args P_((OnigCalloutArgs* args));
943 ONIG_EXTERN
944 const OnigUChar* onig_get_start_by_callout_args P_((OnigCalloutArgs* args));
945 ONIG_EXTERN
946 const OnigUChar* onig_get_right_range_by_callout_args P_((OnigCalloutArgs* args));
947 ONIG_EXTERN
948 const OnigUChar* onig_get_current_by_callout_args P_((OnigCalloutArgs* args));
949 ONIG_EXTERN
950 OnigRegex onig_get_regex_by_callout_args P_((OnigCalloutArgs* args));
951 ONIG_EXTERN
952 unsigned long onig_get_retry_counter_by_callout_args P_((OnigCalloutArgs* args));
953 ONIG_EXTERN
954 int onig_callout_tag_is_exist_at_callout_num P_((OnigRegex reg, int callout_num));
955 ONIG_EXTERN
956 const OnigUChar* onig_get_callout_tag_start P_((OnigRegex reg, int callout_num));
957 ONIG_EXTERN
958 const OnigUChar* onig_get_callout_tag_end P_((OnigRegex reg, int callout_num));
959 ONIG_EXTERN
960 int onig_get_callout_data_dont_clear_old P_((OnigRegex reg, OnigMatchParam* mp, int callout_num, int slot, OnigType* type, OnigValue* val));
961 ONIG_EXTERN
962 int onig_get_callout_data_by_callout_args_self_dont_clear_old P_((OnigCalloutArgs* args, int slot, OnigType* type, OnigValue* val));
963 ONIG_EXTERN
964 int onig_get_callout_data P_((OnigRegex reg, OnigMatchParam* mp, int callout_num, int slot, OnigType* type, OnigValue* val));
965 ONIG_EXTERN
966 int onig_get_callout_data_by_callout_args P_((OnigCalloutArgs* args, int callout_num, int slot, OnigType* type, OnigValue* val));
967 ONIG_EXTERN
968 int onig_get_callout_data_by_callout_args_self P_((OnigCalloutArgs* args, int slot, OnigType* type, OnigValue* val));
969 ONIG_EXTERN
970 int onig_set_callout_data P_((OnigRegex reg, OnigMatchParam* mp, int callout_num, int slot, OnigType type, OnigValue* val));
971 ONIG_EXTERN
972 int onig_set_callout_data_by_callout_args P_((OnigCalloutArgs* args, int callout_num, int slot, OnigType type, OnigValue* val));
973 ONIG_EXTERN
974 int onig_set_callout_data_by_callout_args_self P_((OnigCalloutArgs* args, int slot, OnigType type, OnigValue* val));
975 ONIG_EXTERN
976 int onig_get_capture_range_in_callout P_((OnigCalloutArgs* args, int mem_num, int* begin, int* end));
977 ONIG_EXTERN
978 int onig_get_used_stack_size_in_callout P_((OnigCalloutArgs* args, int* used_num, int* used_bytes));
979 
980 /* builtin callout functions */
981 ONIG_EXTERN
982 int onig_builtin_fail P_((OnigCalloutArgs* args, void* user_data));
983 ONIG_EXTERN
984 int onig_builtin_mismatch P_((OnigCalloutArgs* args, void* user_data));
985 ONIG_EXTERN
986 int onig_builtin_error P_((OnigCalloutArgs* args, void* user_data));
987 ONIG_EXTERN
988 int onig_builtin_count P_((OnigCalloutArgs* args, void* user_data));
989 ONIG_EXTERN
990 int onig_builtin_total_count P_((OnigCalloutArgs* args, void* user_data));
991 ONIG_EXTERN
992 int onig_builtin_max P_((OnigCalloutArgs* args, void* user_data));
993 ONIG_EXTERN
994 int onig_builtin_cmp P_((OnigCalloutArgs* args, void* user_data));
995 
996 ONIG_EXTERN
997 int onig_setup_builtin_monitors_by_ascii_encoded_name P_((void* fp));
998 
999 #ifdef __cplusplus
1000 }
1001 #endif
1002 
1003 #endif /* ONIGURUMA_H */
1004