~ubuntu-branches/ubuntu/intrepid/ruby1.9/intrepid-updates

« back to all changes in this revision

Viewing changes to include/ruby/oniguruma.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-09-04 16:01:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070904160117-i15zckg2nhxe9fyw
Tags: 1.9.0+20070830-2ubuntu1
* Sync from Debian; remaining changes:
  - Add -g to CFLAGS.
* Fixes build failure on ia64.
* Fixes build failure with gcc-4.2 on lpia.
* Robustify check for target_os, fixing build failure on lpia.
* Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef ONIGURUMA_H
 
2
#define ONIGURUMA_H
 
3
/**********************************************************************
 
4
  oniguruma.h - Oniguruma (regular expression library)
 
5
**********************************************************************/
 
6
/*-
 
7
 * Copyright (c) 2002-2007  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
#ifdef __cplusplus
 
33
extern "C" {
 
34
#if 0
 
35
} /* satisfy cc-mode */
 
36
#endif
 
37
#endif
 
38
 
 
39
#define ONIGURUMA
 
40
#define ONIGURUMA_VERSION_MAJOR   5
 
41
#define ONIGURUMA_VERSION_MINOR   9
 
42
#define ONIGURUMA_VERSION_TEENY   0
 
43
 
 
44
#ifdef __cplusplus
 
45
# ifndef  HAVE_PROTOTYPES
 
46
#  define HAVE_PROTOTYPES 1
 
47
# endif
 
48
# ifndef  HAVE_STDARG_PROTOTYPES
 
49
#  define HAVE_STDARG_PROTOTYPES 1
 
50
# endif
 
51
#endif
 
52
 
 
53
/* escape Mac OS X/Xcode 2.4/gcc 4.0.1 problem */
 
54
#if defined(__APPLE__) && defined(__GNUC__) && __GNUC__ >= 4
 
55
# ifndef  HAVE_STDARG_PROTOTYPES
 
56
#  define HAVE_STDARG_PROTOTYPES 1
 
57
# endif
 
58
#endif
 
59
 
 
60
#ifndef P_
 
61
#if defined(__STDC__) || defined(_WIN32)
 
62
# define P_(args) args
 
63
#else
 
64
# define P_(args) ()
 
65
#endif
 
66
#endif
 
67
 
 
68
#ifndef PV_
 
69
#ifdef HAVE_STDARG_PROTOTYPES
 
70
# define PV_(args) args
 
71
#else
 
72
# define PV_(args) ()
 
73
#endif
 
74
#endif
 
75
 
 
76
#ifndef ONIG_EXTERN
 
77
#ifdef RUBY_EXTERN
 
78
#define ONIG_EXTERN   RUBY_EXTERN
 
79
#else
 
80
#if defined(_WIN32) && !defined(__GNUC__)
 
81
#if defined(EXPORT) || defined(RUBY_EXPORT)
 
82
#define ONIG_EXTERN   extern __declspec(dllexport)
 
83
#else
 
84
#define ONIG_EXTERN   extern __declspec(dllimport)
 
85
#endif
 
86
#endif
 
87
#endif
 
88
#endif
 
89
 
 
90
#ifndef ONIG_EXTERN
 
91
#define ONIG_EXTERN   extern
 
92
#endif
 
93
 
 
94
/* PART: character encoding */
 
95
 
 
96
#ifndef ONIG_ESCAPE_UCHAR_COLLISION
 
97
#define UChar OnigUChar
 
98
#endif
 
99
 
 
100
typedef unsigned char  OnigUChar;
 
101
typedef unsigned long  OnigCodePoint;
 
102
typedef unsigned int   OnigDistance;
 
103
 
 
104
#define ONIG_INFINITE_DISTANCE  ~((OnigDistance )0)
 
105
 
 
106
/* case fold flag */
 
107
typedef unsigned int OnigCaseFoldType;
 
108
 
 
109
ONIG_EXTERN OnigCaseFoldType OnigDefaultCaseFoldFlag;
 
110
 
 
111
/* #define ONIGENC_CASE_FOLD_HIRAGANA_KATAKANA  (1<<1) */
 
112
/* #define ONIGENC_CASE_FOLD_KATAKANA_WIDTH     (1<<2) */
 
113
#define ONIGENC_CASE_FOLD_TURKISH_AZERI         (1<<20)
 
114
#define INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR   (1<<30)
 
115
 
 
116
#define ONIGENC_CASE_FOLD_MIN      INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR
 
117
#define ONIGENC_CASE_FOLD_DEFAULT  OnigDefaultCaseFoldFlag
 
118
 
 
119
 
 
120
#define ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN       3
 
121
#define ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM      13
 
122
/* 13 => Unicode:0x1ffc */
 
123
 
 
124
/* code range */
 
125
#define ONIGENC_CODE_RANGE_NUM(range)     ((int )range[0])
 
126
#define ONIGENC_CODE_RANGE_FROM(range,i)  range[((i)*2) + 1]
 
127
#define ONIGENC_CODE_RANGE_TO(range,i)    range[((i)*2) + 2]
 
128
 
 
129
typedef struct {
 
130
  int byte_len;  /* argument(original) character(s) byte length */
 
131
  int code_len;  /* number of code */
 
132
  OnigCodePoint code[ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN];
 
133
} OnigCaseFoldCodeItem;
 
134
 
 
135
typedef struct {
 
136
  OnigCodePoint esc;
 
137
  OnigCodePoint anychar;
 
138
  OnigCodePoint anytime;
 
139
  OnigCodePoint zero_or_one_time;
 
140
  OnigCodePoint one_or_more_time;
 
141
  OnigCodePoint anychar_anytime;
 
142
} OnigMetaCharTableType;
 
143
  
 
144
typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg);
 
145
 
 
146
typedef struct OnigEncodingTypeST {
 
147
  int    (*mbc_enc_len)(const OnigUChar* p);
 
148
  const char*   name;
 
149
  int           max_enc_len;
 
150
  int           min_enc_len;
 
151
  int    (*is_mbc_newline)(const OnigUChar* p, const OnigUChar* end);
 
152
  OnigCodePoint (*mbc_to_code)(const OnigUChar* p, const OnigUChar* end);
 
153
  int    (*code_to_mbclen)(OnigCodePoint code);
 
154
  int    (*code_to_mbc)(OnigCodePoint code, OnigUChar *buf);
 
155
  int    (*mbc_case_fold)(OnigCaseFoldType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to);
 
156
  int    (*apply_all_case_fold)(OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg);
 
157
  int    (*get_case_fold_codes_by_str)(OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem acs[]);
 
158
  int    (*property_name_to_ctype)(struct OnigEncodingTypeST* enc, OnigUChar* p, OnigUChar* end);
 
159
  int    (*is_code_ctype)(OnigCodePoint code, unsigned int ctype);
 
160
  int    (*get_ctype_code_range)(int ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[]);
 
161
  OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p);
 
162
  int    (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end);
 
163
} OnigEncodingType;
 
164
 
 
165
typedef OnigEncodingType* OnigEncoding;
 
166
 
 
167
ONIG_EXTERN OnigEncodingType OnigEncodingASCII;
 
168
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_1;
 
169
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_2;
 
170
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_3;
 
171
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_4;
 
172
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_5;
 
173
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_6;
 
174
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_7;
 
175
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_8;
 
176
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_9;
 
177
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_10;
 
178
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_11;
 
179
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_13;
 
180
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_14;
 
181
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_15;
 
182
ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_16;
 
183
ONIG_EXTERN OnigEncodingType OnigEncodingUTF8;
 
184
ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_BE;
 
185
ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_LE;
 
186
ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_BE;
 
187
ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_LE;
 
188
ONIG_EXTERN OnigEncodingType OnigEncodingEUC_JP;
 
189
ONIG_EXTERN OnigEncodingType OnigEncodingEUC_TW;
 
190
ONIG_EXTERN OnigEncodingType OnigEncodingEUC_KR;
 
191
ONIG_EXTERN OnigEncodingType OnigEncodingEUC_CN;
 
192
ONIG_EXTERN OnigEncodingType OnigEncodingSJIS;
 
193
ONIG_EXTERN OnigEncodingType OnigEncodingKOI8;
 
194
ONIG_EXTERN OnigEncodingType OnigEncodingKOI8_R;
 
195
ONIG_EXTERN OnigEncodingType OnigEncodingCP1251;
 
196
ONIG_EXTERN OnigEncodingType OnigEncodingBIG5;
 
197
ONIG_EXTERN OnigEncodingType OnigEncodingGB18030;
 
198
 
 
199
#define ONIG_ENCODING_ASCII        (&OnigEncodingASCII)
 
200
#define ONIG_ENCODING_ISO_8859_1   (&OnigEncodingISO_8859_1)
 
201
#define ONIG_ENCODING_ISO_8859_2   (&OnigEncodingISO_8859_2)
 
202
#define ONIG_ENCODING_ISO_8859_3   (&OnigEncodingISO_8859_3)
 
203
#define ONIG_ENCODING_ISO_8859_4   (&OnigEncodingISO_8859_4)
 
204
#define ONIG_ENCODING_ISO_8859_5   (&OnigEncodingISO_8859_5)
 
205
#define ONIG_ENCODING_ISO_8859_6   (&OnigEncodingISO_8859_6)
 
206
#define ONIG_ENCODING_ISO_8859_7   (&OnigEncodingISO_8859_7)
 
207
#define ONIG_ENCODING_ISO_8859_8   (&OnigEncodingISO_8859_8)
 
208
#define ONIG_ENCODING_ISO_8859_9   (&OnigEncodingISO_8859_9)
 
209
#define ONIG_ENCODING_ISO_8859_10  (&OnigEncodingISO_8859_10)
 
210
#define ONIG_ENCODING_ISO_8859_11  (&OnigEncodingISO_8859_11)
 
211
#define ONIG_ENCODING_ISO_8859_13  (&OnigEncodingISO_8859_13)
 
212
#define ONIG_ENCODING_ISO_8859_14  (&OnigEncodingISO_8859_14)
 
213
#define ONIG_ENCODING_ISO_8859_15  (&OnigEncodingISO_8859_15)
 
214
#define ONIG_ENCODING_ISO_8859_16  (&OnigEncodingISO_8859_16)
 
215
#define ONIG_ENCODING_UTF8         (&OnigEncodingUTF8)
 
216
#define ONIG_ENCODING_UTF16_BE     (&OnigEncodingUTF16_BE)
 
217
#define ONIG_ENCODING_UTF16_LE     (&OnigEncodingUTF16_LE)
 
218
#define ONIG_ENCODING_UTF32_BE     (&OnigEncodingUTF32_BE)
 
219
#define ONIG_ENCODING_UTF32_LE     (&OnigEncodingUTF32_LE)
 
220
#define ONIG_ENCODING_EUC_JP       (&OnigEncodingEUC_JP)
 
221
#define ONIG_ENCODING_EUC_TW       (&OnigEncodingEUC_TW)
 
222
#define ONIG_ENCODING_EUC_KR       (&OnigEncodingEUC_KR)
 
223
#define ONIG_ENCODING_EUC_CN       (&OnigEncodingEUC_CN)
 
224
#define ONIG_ENCODING_SJIS         (&OnigEncodingSJIS)
 
225
#define ONIG_ENCODING_KOI8         (&OnigEncodingKOI8)
 
226
#define ONIG_ENCODING_KOI8_R       (&OnigEncodingKOI8_R)
 
227
#define ONIG_ENCODING_CP1251       (&OnigEncodingCP1251)
 
228
#define ONIG_ENCODING_BIG5         (&OnigEncodingBIG5)
 
229
#define ONIG_ENCODING_GB18030      (&OnigEncodingGB18030)
 
230
 
 
231
#define ONIG_ENCODING_UNDEF    ((OnigEncoding )0)
 
232
 
 
233
 
 
234
/* work size */
 
235
#define ONIGENC_CODE_TO_MBC_MAXLEN       7
 
236
#define ONIGENC_MBC_CASE_FOLD_MAXLEN    18
 
237
/* 18: 6(max-byte) * 3(case-fold chars) */
 
238
 
 
239
/* character types */
 
240
#define ONIGENC_CTYPE_NEWLINE   0
 
241
#define ONIGENC_CTYPE_ALPHA     1
 
242
#define ONIGENC_CTYPE_BLANK     2
 
243
#define ONIGENC_CTYPE_CNTRL     3
 
244
#define ONIGENC_CTYPE_DIGIT     4
 
245
#define ONIGENC_CTYPE_GRAPH     5
 
246
#define ONIGENC_CTYPE_LOWER     6
 
247
#define ONIGENC_CTYPE_PRINT     7
 
248
#define ONIGENC_CTYPE_PUNCT     8
 
249
#define ONIGENC_CTYPE_SPACE     9
 
250
#define ONIGENC_CTYPE_UPPER    10
 
251
#define ONIGENC_CTYPE_XDIGIT   11
 
252
#define ONIGENC_CTYPE_WORD     12
 
253
#define ONIGENC_CTYPE_ALNUM    13  /* alpha || digit */
 
254
#define ONIGENC_CTYPE_ASCII    14
 
255
#define ONIGENC_MAX_STD_CTYPE  ONIGENC_CTYPE_ASCII
 
256
 
 
257
 
 
258
#define enc_len(enc,p)                ONIGENC_MBC_ENC_LEN(enc, p)
 
259
 
 
260
#define ONIGENC_IS_UNDEF(enc)          ((enc) == ONIG_ENCODING_UNDEF)
 
261
#define ONIGENC_IS_SINGLEBYTE(enc)     (ONIGENC_MBC_MAXLEN(enc) == 1)
 
262
#define ONIGENC_IS_MBC_HEAD(enc,p)     (ONIGENC_MBC_ENC_LEN(enc,p) != 1)
 
263
#define ONIGENC_IS_MBC_ASCII(p)           (*(p)   < 128)
 
264
#define ONIGENC_IS_CODE_ASCII(code)       ((code) < 128)
 
265
#define ONIGENC_IS_MBC_WORD(enc,s,end) \
 
266
   ONIGENC_IS_CODE_WORD(enc,ONIGENC_MBC_TO_CODE(enc,s,end))
 
267
 
 
268
 
 
269
#define ONIGENC_NAME(enc)                      ((enc)->name)
 
270
 
 
271
#define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \
 
272
  (enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf)
 
273
#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
 
274
        (enc)->is_allowed_reverse_match(s,end)
 
275
#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s) \
 
276
        (enc)->left_adjust_char_head(start, s)
 
277
#define ONIGENC_APPLY_ALL_CASE_FOLD(enc,case_fold_flag,f,arg) \
 
278
        (enc)->apply_all_case_fold(case_fold_flag,f,arg)
 
279
#define ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc,case_fold_flag,p,end,acs) \
 
280
       (enc)->get_case_fold_codes_by_str(case_fold_flag,p,end,acs)
 
281
#define ONIGENC_STEP_BACK(enc,start,s,n) \
 
282
        onigenc_step_back((enc),(start),(s),(n))
 
283
 
 
284
#define ONIGENC_MBC_ENC_LEN(enc,p)             (enc)->mbc_enc_len(p)
 
285
#define ONIGENC_MBC_MAXLEN(enc)               ((enc)->max_enc_len)
 
286
#define ONIGENC_MBC_MAXLEN_DIST(enc)           ONIGENC_MBC_MAXLEN(enc)
 
287
#define ONIGENC_MBC_MINLEN(enc)               ((enc)->min_enc_len)
 
288
#define ONIGENC_IS_MBC_NEWLINE(enc,p,end)      (enc)->is_mbc_newline((p),(end))
 
289
#define ONIGENC_MBC_TO_CODE(enc,p,end)         (enc)->mbc_to_code((p),(end))
 
290
#define ONIGENC_CODE_TO_MBCLEN(enc,code)       (enc)->code_to_mbclen(code)
 
291
#define ONIGENC_CODE_TO_MBC(enc,code,buf)      (enc)->code_to_mbc(code,buf)
 
292
#define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc,p,end) \
 
293
  (enc)->property_name_to_ctype(enc,p,end)
 
294
 
 
295
#define ONIGENC_IS_CODE_CTYPE(enc,code,ctype)  (enc)->is_code_ctype(code,ctype)
 
296
 
 
297
#define ONIGENC_IS_CODE_NEWLINE(enc,code) \
 
298
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_NEWLINE)
 
299
#define ONIGENC_IS_CODE_GRAPH(enc,code) \
 
300
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_GRAPH)
 
301
#define ONIGENC_IS_CODE_PRINT(enc,code) \
 
302
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PRINT)
 
303
#define ONIGENC_IS_CODE_ALNUM(enc,code) \
 
304
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALNUM)
 
305
#define ONIGENC_IS_CODE_ALPHA(enc,code) \
 
306
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALPHA)
 
307
#define ONIGENC_IS_CODE_LOWER(enc,code) \
 
308
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_LOWER)
 
309
#define ONIGENC_IS_CODE_UPPER(enc,code) \
 
310
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_UPPER)
 
311
#define ONIGENC_IS_CODE_CNTRL(enc,code) \
 
312
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_CNTRL)
 
313
#define ONIGENC_IS_CODE_PUNCT(enc,code) \
 
314
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PUNCT)
 
315
#define ONIGENC_IS_CODE_SPACE(enc,code) \
 
316
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_SPACE)
 
317
#define ONIGENC_IS_CODE_BLANK(enc,code) \
 
318
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_BLANK)
 
319
#define ONIGENC_IS_CODE_DIGIT(enc,code) \
 
320
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_DIGIT)
 
321
#define ONIGENC_IS_CODE_XDIGIT(enc,code) \
 
322
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_XDIGIT)
 
323
#define ONIGENC_IS_CODE_WORD(enc,code) \
 
324
        ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_WORD)
 
325
 
 
326
#define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbout,ranges) \
 
327
        (enc)->get_ctype_code_range(ctype,sbout,ranges)
 
328
 
 
329
ONIG_EXTERN
 
330
OnigUChar* onigenc_step_back P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, int n));
 
331
 
 
332
 
 
333
/* encoding API */
 
334
ONIG_EXTERN
 
335
int onigenc_init P_((void));
 
336
ONIG_EXTERN
 
337
int onigenc_set_default_encoding P_((OnigEncoding enc));
 
338
ONIG_EXTERN
 
339
OnigEncoding onigenc_get_default_encoding P_((void));
 
340
ONIG_EXTERN
 
341
void  onigenc_set_default_caseconv_table P_((const OnigUChar* table));
 
342
ONIG_EXTERN
 
343
OnigUChar* onigenc_get_right_adjust_char_head_with_prev P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar** prev));
 
344
ONIG_EXTERN
 
345
OnigUChar* onigenc_get_prev_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
 
346
ONIG_EXTERN
 
347
OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
 
348
ONIG_EXTERN
 
349
OnigUChar* onigenc_get_right_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
 
350
ONIG_EXTERN
 
351
int onigenc_strlen P_((OnigEncoding enc, const OnigUChar* p, const OnigUChar* end));
 
352
ONIG_EXTERN
 
353
int onigenc_strlen_null P_((OnigEncoding enc, const OnigUChar* p));
 
354
ONIG_EXTERN
 
355
int onigenc_str_bytelen_null P_((OnigEncoding enc, const OnigUChar* p));
 
356
 
 
357
 
 
358
 
 
359
/* PART: regular expression */
 
360
 
 
361
/* config parameters */
 
362
#define ONIG_NREGION                          10
 
363
#define ONIG_MAX_BACKREF_NUM                1000
 
364
#define ONIG_MAX_REPEAT_NUM               100000
 
365
#define ONIG_MAX_MULTI_BYTE_RANGES_NUM     10000
 
366
/* constants */
 
367
#define ONIG_MAX_ERROR_MESSAGE_LEN            90
 
368
 
 
369
typedef unsigned int        OnigOptionType;
 
370
 
 
371
#define ONIG_OPTION_DEFAULT            ONIG_OPTION_NONE
 
372
 
 
373
/* options */
 
374
#define ONIG_OPTION_NONE                 0U
 
375
#define ONIG_OPTION_IGNORECASE           1U
 
376
#define ONIG_OPTION_EXTEND               (ONIG_OPTION_IGNORECASE         << 1)
 
377
#define ONIG_OPTION_MULTILINE            (ONIG_OPTION_EXTEND             << 1)
 
378
#define ONIG_OPTION_SINGLELINE           (ONIG_OPTION_MULTILINE          << 1)
 
379
#define ONIG_OPTION_FIND_LONGEST         (ONIG_OPTION_SINGLELINE         << 1)
 
380
#define ONIG_OPTION_FIND_NOT_EMPTY       (ONIG_OPTION_FIND_LONGEST       << 1)
 
381
#define ONIG_OPTION_NEGATE_SINGLELINE    (ONIG_OPTION_FIND_NOT_EMPTY     << 1)
 
382
#define ONIG_OPTION_DONT_CAPTURE_GROUP   (ONIG_OPTION_NEGATE_SINGLELINE  << 1)
 
383
#define ONIG_OPTION_CAPTURE_GROUP        (ONIG_OPTION_DONT_CAPTURE_GROUP << 1)
 
384
/* options (search time) */
 
385
#define ONIG_OPTION_NOTBOL               (ONIG_OPTION_CAPTURE_GROUP << 1)
 
386
#define ONIG_OPTION_NOTEOL               (ONIG_OPTION_NOTBOL << 1)
 
387
#define ONIG_OPTION_POSIX_REGION         (ONIG_OPTION_NOTEOL << 1)
 
388
#define ONIG_OPTION_MAXBIT               ONIG_OPTION_POSIX_REGION  /* limit */
 
389
 
 
390
#define ONIG_OPTION_ON(options,regopt)      ((options) |= (regopt))
 
391
#define ONIG_OPTION_OFF(options,regopt)     ((options) &= ~(regopt))
 
392
#define ONIG_IS_OPTION_ON(options,option)   ((options) & (option))
 
393
 
 
394
/* syntax */
 
395
typedef struct {
 
396
  unsigned int   op;
 
397
  unsigned int   op2;
 
398
  unsigned int   behavior;
 
399
  OnigOptionType options;   /* default option */
 
400
  OnigMetaCharTableType meta_char_table;
 
401
} OnigSyntaxType;
 
402
 
 
403
ONIG_EXTERN OnigSyntaxType OnigSyntaxASIS;
 
404
ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
 
405
ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
 
406
ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
 
407
ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
 
408
ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
 
409
ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
 
410
ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
 
411
ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl_NG;
 
412
ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
 
413
 
 
414
/* predefined syntaxes (see regsyntax.c) */
 
415
#define ONIG_SYNTAX_ASIS               (&OnigSyntaxASIS)
 
416
#define ONIG_SYNTAX_POSIX_BASIC        (&OnigSyntaxPosixBasic)
 
417
#define ONIG_SYNTAX_POSIX_EXTENDED     (&OnigSyntaxPosixExtended)
 
418
#define ONIG_SYNTAX_EMACS              (&OnigSyntaxEmacs)
 
419
#define ONIG_SYNTAX_GREP               (&OnigSyntaxGrep)
 
420
#define ONIG_SYNTAX_GNU_REGEX          (&OnigSyntaxGnuRegex)
 
421
#define ONIG_SYNTAX_JAVA               (&OnigSyntaxJava)
 
422
#define ONIG_SYNTAX_PERL               (&OnigSyntaxPerl)
 
423
#define ONIG_SYNTAX_PERL_NG            (&OnigSyntaxPerl_NG)
 
424
#define ONIG_SYNTAX_RUBY               (&OnigSyntaxRuby)
 
425
 
 
426
/* default syntax */
 
427
ONIG_EXTERN OnigSyntaxType*   OnigDefaultSyntax;
 
428
#define ONIG_SYNTAX_DEFAULT   OnigDefaultSyntax
 
429
 
 
430
/* syntax (operators) */
 
431
#define ONIG_SYN_OP_VARIABLE_META_CHARACTERS    (1U<<0)
 
432
#define ONIG_SYN_OP_DOT_ANYCHAR                 (1U<<1)   /* . */
 
433
#define ONIG_SYN_OP_ASTERISK_ZERO_INF           (1U<<2)   /* * */
 
434
#define ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF       (1U<<3)
 
435
#define ONIG_SYN_OP_PLUS_ONE_INF                (1U<<4)   /* + */
 
436
#define ONIG_SYN_OP_ESC_PLUS_ONE_INF            (1U<<5)
 
437
#define ONIG_SYN_OP_QMARK_ZERO_ONE              (1U<<6)   /* ? */
 
438
#define ONIG_SYN_OP_ESC_QMARK_ZERO_ONE          (1U<<7)
 
439
#define ONIG_SYN_OP_BRACE_INTERVAL              (1U<<8)   /* {lower,upper} */
 
440
#define ONIG_SYN_OP_ESC_BRACE_INTERVAL          (1U<<9)   /* \{lower,upper\} */
 
441
#define ONIG_SYN_OP_VBAR_ALT                    (1U<<10)   /* | */
 
442
#define ONIG_SYN_OP_ESC_VBAR_ALT                (1U<<11)  /* \| */
 
443
#define ONIG_SYN_OP_LPAREN_SUBEXP               (1U<<12)  /* (...)   */
 
444
#define ONIG_SYN_OP_ESC_LPAREN_SUBEXP           (1U<<13)  /* \(...\) */
 
445
#define ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR           (1U<<14)  /* \A, \Z, \z */
 
446
#define ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR  (1U<<15)  /* \G     */
 
447
#define ONIG_SYN_OP_DECIMAL_BACKREF             (1U<<16)  /* \num   */
 
448
#define ONIG_SYN_OP_BRACKET_CC                  (1U<<17)  /* [...]  */
 
449
#define ONIG_SYN_OP_ESC_W_WORD                  (1U<<18)  /* \w, \W */
 
450
#define ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END     (1U<<19)  /* \<. \> */
 
451
#define ONIG_SYN_OP_ESC_B_WORD_BOUND            (1U<<20)  /* \b, \B */
 
452
#define ONIG_SYN_OP_ESC_S_WHITE_SPACE           (1U<<21)  /* \s, \S */
 
453
#define ONIG_SYN_OP_ESC_D_DIGIT                 (1U<<22)  /* \d, \D */
 
454
#define ONIG_SYN_OP_LINE_ANCHOR                 (1U<<23)  /* ^, $   */
 
455
#define ONIG_SYN_OP_POSIX_BRACKET               (1U<<24)  /* [:xxxx:] */
 
456
#define ONIG_SYN_OP_QMARK_NON_GREEDY            (1U<<25)  /* ??,*?,+?,{n,m}? */
 
457
#define ONIG_SYN_OP_ESC_CONTROL_CHARS           (1U<<26)  /* \n,\r,\t,\a ... */
 
458
#define ONIG_SYN_OP_ESC_C_CONTROL               (1U<<27)  /* \cx  */
 
459
#define ONIG_SYN_OP_ESC_OCTAL3                  (1U<<28)  /* \OOO */
 
460
#define ONIG_SYN_OP_ESC_X_HEX2                  (1U<<29)  /* \xHH */
 
461
#define ONIG_SYN_OP_ESC_X_BRACE_HEX8            (1U<<30)  /* \x{7HHHHHHH} */
 
462
 
 
463
#define ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE        (1U<<0)  /* \Q...\E */
 
464
#define ONIG_SYN_OP2_QMARK_GROUP_EFFECT         (1U<<1)  /* (?...) */
 
465
#define ONIG_SYN_OP2_OPTION_PERL                (1U<<2)  /* (?imsx),(?-imsx) */
 
466
#define ONIG_SYN_OP2_OPTION_RUBY                (1U<<3)  /* (?imx), (?-imx)  */
 
467
#define ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT     (1U<<4)  /* ?+,*+,++ */
 
468
#define ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL   (1U<<5)  /* {n,m}+   */
 
469
#define ONIG_SYN_OP2_CCLASS_SET_OP              (1U<<6)  /* [...&&..[..]..] */
 
470
#define ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP       (1U<<7)  /* (?<name>...) */
 
471
#define ONIG_SYN_OP2_ESC_K_NAMED_BACKREF        (1U<<8)  /* \k<name> */
 
472
#define ONIG_SYN_OP2_ESC_G_SUBEXP_CALL          (1U<<9)  /* \g<name>, \g<n> */
 
473
#define ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY     (1U<<10) /* (?@..),(?@<x>..) */
 
474
#define ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL  (1U<<11) /* \C-x */
 
475
#define ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META     (1U<<12) /* \M-x */
 
476
#define ONIG_SYN_OP2_ESC_V_VTAB                 (1U<<13) /* \v as VTAB */
 
477
#define ONIG_SYN_OP2_ESC_U_HEX4                 (1U<<14) /* \uHHHH */
 
478
#define ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR         (1U<<15) /* \`, \' */
 
479
#define ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY  (1U<<16) /* \p{...}, \P{...} */
 
480
#define ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT (1U<<17) /* \p{^..}, \P{^..} */
 
481
/* #define ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS (1U<<18) */
 
482
#define ONIG_SYN_OP2_ESC_H_XDIGIT               (1U<<19) /* \h, \H */
 
483
#define ONIG_SYN_OP2_INEFFECTIVE_ESCAPE         (1U<<20) /* \ */
 
484
 
 
485
/* syntax (behavior) */
 
486
#define ONIG_SYN_CONTEXT_INDEP_ANCHORS           (1U<<31) /* not implemented */
 
487
#define ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS        (1U<<0)  /* ?, *, +, {n,m} */
 
488
#define ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS      (1U<<1)  /* error or ignore */
 
489
#define ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP    (1U<<2)  /* ...)... */
 
490
#define ONIG_SYN_ALLOW_INVALID_INTERVAL          (1U<<3)  /* {??? */
 
491
#define ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV       (1U<<4)  /* {,n} => {0,n} */
 
492
#define ONIG_SYN_STRICT_CHECK_BACKREF            (1U<<5)  /* /(\1)/,/\1()/ ..*/
 
493
#define ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND   (1U<<6)  /* (?<=a|bc) */
 
494
#define ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP        (1U<<7)  /* see doc/RE */
 
495
#define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME (1U<<8)  /* (?<x>)(?<x>) */
 
496
#define ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY   (1U<<9)  /* a{n}?=(?:a{n})? */
 
497
 
 
498
/* syntax (behavior) in char class [...] */
 
499
#define ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC      (1U<<20) /* [^...] */
 
500
#define ONIG_SYN_BACKSLASH_ESCAPE_IN_CC          (1U<<21) /* [..\w..] etc.. */
 
501
#define ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC         (1U<<22)
 
502
#define ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC     (1U<<23) /* [0-9-a]=[0-9\-a] */
 
503
/* syntax (behavior) warning */
 
504
#define ONIG_SYN_WARN_CC_OP_NOT_ESCAPED          (1U<<24) /* [,-,] */
 
505
#define ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT    (1U<<25) /* (?:a*)+ */
 
506
 
 
507
/* meta character specifiers (onig_set_meta_char()) */
 
508
#define ONIG_META_CHAR_ESCAPE               0
 
509
#define ONIG_META_CHAR_ANYCHAR              1
 
510
#define ONIG_META_CHAR_ANYTIME              2
 
511
#define ONIG_META_CHAR_ZERO_OR_ONE_TIME     3
 
512
#define ONIG_META_CHAR_ONE_OR_MORE_TIME     4
 
513
#define ONIG_META_CHAR_ANYCHAR_ANYTIME      5
 
514
 
 
515
#define ONIG_INEFFECTIVE_META_CHAR          0
 
516
 
 
517
/* error codes */
 
518
#define ONIG_IS_PATTERN_ERROR(ecode)   ((ecode) <= -100 && (ecode) > -1000)
 
519
/* normal return */
 
520
#define ONIG_NORMAL                                            0
 
521
#define ONIG_MISMATCH                                         -1
 
522
#define ONIG_NO_SUPPORT_CONFIG                                -2
 
523
 
 
524
/* internal error */
 
525
#define ONIGERR_MEMORY                                         -5
 
526
#define ONIGERR_TYPE_BUG                                       -6
 
527
#define ONIGERR_PARSER_BUG                                    -11
 
528
#define ONIGERR_STACK_BUG                                     -12
 
529
#define ONIGERR_UNDEFINED_BYTECODE                            -13
 
530
#define ONIGERR_UNEXPECTED_BYTECODE                           -14
 
531
#define ONIGERR_MATCH_STACK_LIMIT_OVER                        -15
 
532
#define ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED                -21
 
533
#define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR  -22
 
534
/* general error */
 
535
#define ONIGERR_INVALID_ARGUMENT                              -30 
 
536
/* syntax error */
 
537
#define ONIGERR_END_PATTERN_AT_LEFT_BRACE                    -100
 
538
#define ONIGERR_END_PATTERN_AT_LEFT_BRACKET                  -101
 
539
#define ONIGERR_EMPTY_CHAR_CLASS                             -102
 
540
#define ONIGERR_PREMATURE_END_OF_CHAR_CLASS                  -103
 
541
#define ONIGERR_END_PATTERN_AT_ESCAPE                        -104
 
542
#define ONIGERR_END_PATTERN_AT_META                          -105
 
543
#define ONIGERR_END_PATTERN_AT_CONTROL                       -106
 
544
#define ONIGERR_META_CODE_SYNTAX                             -108
 
545
#define ONIGERR_CONTROL_CODE_SYNTAX                          -109
 
546
#define ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE             -110
 
547
#define ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE           -111
 
548
#define ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS      -112
 
549
#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED      -113
 
550
#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID            -114
 
551
#define ONIGERR_NESTED_REPEAT_OPERATOR                       -115
 
552
#define ONIGERR_UNMATCHED_CLOSE_PARENTHESIS                  -116
 
553
#define ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS       -117
 
554
#define ONIGERR_END_PATTERN_IN_GROUP                         -118
 
555
#define ONIGERR_UNDEFINED_GROUP_OPTION                       -119
 
556
#define ONIGERR_INVALID_POSIX_BRACKET_TYPE                   -121
 
557
#define ONIGERR_INVALID_LOOK_BEHIND_PATTERN                  -122
 
558
#define ONIGERR_INVALID_REPEAT_RANGE_PATTERN                 -123
 
559
/* values error (syntax error) */
 
560
#define ONIGERR_TOO_BIG_NUMBER                               -200
 
561
#define ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE              -201
 
562
#define ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE     -202
 
563
#define ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS                    -203
 
564
#define ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE          -204
 
565
#define ONIGERR_TOO_MANY_MULTI_BYTE_RANGES                   -205
 
566
#define ONIGERR_TOO_SHORT_MULTI_BYTE_STRING                  -206
 
567
#define ONIGERR_TOO_BIG_BACKREF_NUMBER                       -207
 
568
#define ONIGERR_INVALID_BACKREF                              -208
 
569
#define ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED         -209
 
570
#define ONIGERR_TOO_LONG_WIDE_CHAR_VALUE                     -212
 
571
#define ONIGERR_EMPTY_GROUP_NAME                             -214
 
572
#define ONIGERR_INVALID_GROUP_NAME                           -215
 
573
#define ONIGERR_INVALID_CHAR_IN_GROUP_NAME                   -216
 
574
#define ONIGERR_UNDEFINED_NAME_REFERENCE                     -217
 
575
#define ONIGERR_UNDEFINED_GROUP_REFERENCE                    -218
 
576
#define ONIGERR_MULTIPLEX_DEFINED_NAME                       -219
 
577
#define ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL               -220
 
578
#define ONIGERR_NEVER_ENDING_RECURSION                       -221
 
579
#define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY        -222
 
580
#define ONIGERR_INVALID_CHAR_PROPERTY_NAME                   -223
 
581
#define ONIGERR_INVALID_WIDE_CHAR_VALUE                      -400
 
582
#define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE                      -401
 
583
#define ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION           -402
 
584
#define ONIGERR_INVALID_COMBINATION_OF_OPTIONS               -403
 
585
 
 
586
/* errors related to thread */
 
587
#define ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT                -1001
 
588
 
 
589
 
 
590
/* must be smaller than BIT_STATUS_BITS_NUM (unsigned int * 8) */
 
591
#define ONIG_MAX_CAPTURE_HISTORY_GROUP   31
 
592
#define ONIG_IS_CAPTURE_HISTORY_GROUP(r, i) \
 
593
  ((i) <= ONIG_MAX_CAPTURE_HISTORY_GROUP && (r)->list && (r)->list[i])
 
594
 
 
595
typedef struct OnigCaptureTreeNodeStruct {
 
596
  int group;   /* group number */
 
597
  int beg;
 
598
  int end;
 
599
  int allocated;
 
600
  int num_childs;
 
601
  struct OnigCaptureTreeNodeStruct** childs;
 
602
} OnigCaptureTreeNode;
 
603
 
 
604
/* match result region type */
 
605
struct re_registers {
 
606
  int  allocated;
 
607
  int  num_regs;
 
608
  int* beg;
 
609
  int* end;
 
610
  /* extended */
 
611
  OnigCaptureTreeNode* history_root;  /* capture history tree root */
 
612
};
 
613
 
 
614
/* capture tree traverse */
 
615
#define ONIG_TRAVERSE_CALLBACK_AT_FIRST   1
 
616
#define ONIG_TRAVERSE_CALLBACK_AT_LAST    2
 
617
#define ONIG_TRAVERSE_CALLBACK_AT_BOTH \
 
618
  ( ONIG_TRAVERSE_CALLBACK_AT_FIRST | ONIG_TRAVERSE_CALLBACK_AT_LAST )
 
619
 
 
620
 
 
621
#define ONIG_REGION_NOTPOS            -1
 
622
 
 
623
typedef struct re_registers   OnigRegion;
 
624
 
 
625
typedef struct {
 
626
  OnigEncoding enc;
 
627
  OnigUChar* par;
 
628
  OnigUChar* par_end;
 
629
} OnigErrorInfo;
 
630
 
 
631
typedef struct {
 
632
  int lower;
 
633
  int upper;
 
634
} OnigRepeatRange;
 
635
 
 
636
typedef void (*OnigWarnFunc) P_((const char* s));
 
637
extern void onig_null_warn P_((const char* s));
 
638
#define ONIG_NULL_WARN       onig_null_warn
 
639
 
 
640
#define ONIG_CHAR_TABLE_SIZE   256
 
641
 
 
642
/* regex_t state */
 
643
#define ONIG_STATE_NORMAL              0
 
644
#define ONIG_STATE_SEARCHING           1
 
645
#define ONIG_STATE_COMPILING          -1
 
646
#define ONIG_STATE_MODIFY             -2
 
647
 
 
648
#define ONIG_STATE(reg) \
 
649
  ((reg)->state > 0 ? ONIG_STATE_SEARCHING : (reg)->state)
 
650
 
 
651
typedef struct re_pattern_buffer {
 
652
  /* common members of BBuf(bytes-buffer) */
 
653
  unsigned char* p;         /* compiled pattern */
 
654
  unsigned int used;        /* used space for p */
 
655
  unsigned int alloc;       /* allocated space for p */
 
656
 
 
657
  int state;                     /* normal, searching, compiling */
 
658
  int num_mem;                   /* used memory(...) num counted from 1 */
 
659
  int num_repeat;                /* OP_REPEAT/OP_REPEAT_NG id-counter */
 
660
  int num_null_check;            /* OP_NULL_CHECK_START/END id counter */
 
661
  int num_comb_exp_check;        /* combination explosion check */
 
662
  int num_call;                  /* number of subexp call */
 
663
  unsigned int capture_history;  /* (?@...) flag (1-31) */
 
664
  unsigned int bt_mem_start;     /* need backtrack flag */
 
665
  unsigned int bt_mem_end;       /* need backtrack flag */
 
666
  int stack_pop_level;
 
667
  int repeat_range_alloc;
 
668
  OnigRepeatRange* repeat_range;
 
669
 
 
670
  OnigEncoding      enc;
 
671
  OnigOptionType    options;
 
672
  OnigSyntaxType*   syntax;
 
673
  OnigCaseFoldType  case_fold_flag;
 
674
  void*             name_table;
 
675
 
 
676
  /* optimization info (string search, char-map and anchors) */
 
677
  int            optimize;          /* optimize flag */
 
678
  int            threshold_len;     /* search str-length for apply optimize */
 
679
  int            anchor;            /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */
 
680
  OnigDistance   anchor_dmin;       /* (SEMI_)END_BUF anchor distance */
 
681
  OnigDistance   anchor_dmax;       /* (SEMI_)END_BUF anchor distance */
 
682
  int            sub_anchor;        /* start-anchor for exact or map */
 
683
  unsigned char *exact;
 
684
  unsigned char *exact_end;
 
685
  unsigned char  map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */
 
686
  int           *int_map;                   /* BM skip for exact_len > 255 */
 
687
  int           *int_map_backward;          /* BM skip for backward search */
 
688
  OnigDistance   dmin;                      /* min-distance of exact or map */
 
689
  OnigDistance   dmax;                      /* max-distance of exact or map */
 
690
 
 
691
  /* regex_t link chain */
 
692
  struct re_pattern_buffer* chain;  /* escape compile-conflict */
 
693
} OnigRegexType;
 
694
 
 
695
typedef OnigRegexType*  OnigRegex;
 
696
 
 
697
#ifndef ONIG_ESCAPE_REGEX_T_COLLISION
 
698
  typedef OnigRegexType  regex_t;
 
699
#endif
 
700
 
 
701
 
 
702
typedef struct {
 
703
  int             num_of_elements;
 
704
  OnigEncoding    pattern_enc;
 
705
  OnigEncoding    target_enc;
 
706
  OnigSyntaxType* syntax;
 
707
  OnigOptionType  option;
 
708
  OnigCaseFoldType   case_fold_flag;
 
709
} OnigCompileInfo;
 
710
 
 
711
/* Oniguruma Native API */
 
712
ONIG_EXTERN
 
713
int onig_init P_((void));
 
714
ONIG_EXTERN
 
715
int onig_error_code_to_str PV_((OnigUChar* s, int err_code, ...));
 
716
ONIG_EXTERN
 
717
void onig_set_warn_func P_((OnigWarnFunc f));
 
718
ONIG_EXTERN
 
719
void onig_set_verb_warn_func P_((OnigWarnFunc f));
 
720
ONIG_EXTERN
 
721
int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
 
722
ONIG_EXTERN
 
723
int onig_new_deluxe P_((OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
 
724
ONIG_EXTERN
 
725
void onig_free P_((OnigRegex));
 
726
ONIG_EXTERN
 
727
int onig_recompile P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
 
728
ONIG_EXTERN
 
729
int onig_recompile_deluxe P_((OnigRegex reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
 
730
ONIG_EXTERN
 
731
int onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
 
732
ONIG_EXTERN
 
733
int onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option));
 
734
ONIG_EXTERN
 
735
OnigRegion* onig_region_new P_((void));
 
736
ONIG_EXTERN
 
737
void onig_region_init P_((OnigRegion* region));
 
738
ONIG_EXTERN
 
739
void onig_region_free P_((OnigRegion* region, int free_self));
 
740
ONIG_EXTERN
 
741
void onig_region_copy P_((OnigRegion* to, OnigRegion* from));
 
742
ONIG_EXTERN
 
743
void onig_region_clear P_((OnigRegion* region));
 
744
ONIG_EXTERN
 
745
int onig_region_resize P_((OnigRegion* region, int n));
 
746
ONIG_EXTERN
 
747
int onig_region_set P_((OnigRegion* region, int at, int beg, int end));
 
748
ONIG_EXTERN
 
749
int onig_name_to_group_numbers P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, int** nums));
 
750
ONIG_EXTERN
 
751
int onig_name_to_backref_number P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, OnigRegion *region));
 
752
ONIG_EXTERN
 
753
int onig_foreach_name P_((OnigRegex reg, int (*func)(const OnigUChar*, const OnigUChar*,int,int*,OnigRegex,void*), void* arg));
 
754
ONIG_EXTERN
 
755
int onig_number_of_names P_((OnigRegex reg));
 
756
ONIG_EXTERN
 
757
int onig_number_of_captures P_((OnigRegex reg));
 
758
ONIG_EXTERN
 
759
int onig_number_of_capture_histories P_((OnigRegex reg));
 
760
ONIG_EXTERN
 
761
OnigCaptureTreeNode* onig_get_capture_tree P_((OnigRegion* region));
 
762
ONIG_EXTERN
 
763
int onig_capture_tree_traverse P_((OnigRegion* region, int at, int(*callback_func)(int,int,int,int,int,void*), void* arg));
 
764
ONIG_EXTERN
 
765
int onig_noname_group_capture_is_active P_((OnigRegex reg));
 
766
ONIG_EXTERN
 
767
OnigEncoding onig_get_encoding P_((OnigRegex reg));
 
768
ONIG_EXTERN
 
769
OnigOptionType onig_get_options P_((OnigRegex reg));
 
770
ONIG_EXTERN
 
771
OnigCaseFoldType onig_get_case_fold_flag P_((OnigRegex reg));
 
772
ONIG_EXTERN
 
773
OnigSyntaxType* onig_get_syntax P_((OnigRegex reg));
 
774
ONIG_EXTERN
 
775
int onig_set_default_syntax P_((OnigSyntaxType* syntax));
 
776
ONIG_EXTERN
 
777
void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
 
778
ONIG_EXTERN
 
779
unsigned int onig_get_syntax_op P_((OnigSyntaxType* syntax));
 
780
ONIG_EXTERN
 
781
unsigned int onig_get_syntax_op2 P_((OnigSyntaxType* syntax));
 
782
ONIG_EXTERN
 
783
unsigned int onig_get_syntax_behavior P_((OnigSyntaxType* syntax));
 
784
ONIG_EXTERN
 
785
OnigOptionType onig_get_syntax_options P_((OnigSyntaxType* syntax));
 
786
ONIG_EXTERN
 
787
void onig_set_syntax_op P_((OnigSyntaxType* syntax, unsigned int op));
 
788
ONIG_EXTERN
 
789
void onig_set_syntax_op2 P_((OnigSyntaxType* syntax, unsigned int op2));
 
790
ONIG_EXTERN
 
791
void onig_set_syntax_behavior P_((OnigSyntaxType* syntax, unsigned int behavior));
 
792
ONIG_EXTERN
 
793
void onig_set_syntax_options P_((OnigSyntaxType* syntax, OnigOptionType options));
 
794
ONIG_EXTERN
 
795
int onig_set_meta_char P_((OnigSyntaxType* syntax, unsigned int what, OnigCodePoint code));
 
796
ONIG_EXTERN
 
797
void onig_copy_encoding P_((OnigEncoding to, OnigEncoding from));
 
798
ONIG_EXTERN
 
799
OnigCaseFoldType onig_get_default_case_fold_flag P_((void));
 
800
ONIG_EXTERN
 
801
int onig_set_default_case_fold_flag P_((OnigCaseFoldType case_fold_flag));
 
802
ONIG_EXTERN
 
803
unsigned int onig_get_match_stack_limit_size P_((void));
 
804
ONIG_EXTERN
 
805
int onig_set_match_stack_limit_size P_((unsigned int size));
 
806
ONIG_EXTERN
 
807
int onig_end P_((void));
 
808
ONIG_EXTERN
 
809
const char* onig_version P_((void));
 
810
ONIG_EXTERN
 
811
const char* onig_copyright P_((void));
 
812
 
 
813
#ifdef __cplusplus
 
814
#if 0
 
815
{ /* satisfy cc-mode */
 
816
#endif
 
817
}
 
818
#endif
 
819
 
 
820
#endif /* ONIGURUMA_H */