jpayne@69
|
1 /*************************************************
|
jpayne@69
|
2 * Perl-Compatible Regular Expressions *
|
jpayne@69
|
3 *************************************************/
|
jpayne@69
|
4
|
jpayne@69
|
5 #ifndef _PCREPOSIX_H
|
jpayne@69
|
6 #define _PCREPOSIX_H
|
jpayne@69
|
7
|
jpayne@69
|
8 /* This is the header for the POSIX wrapper interface to the PCRE Perl-
|
jpayne@69
|
9 Compatible Regular Expression library. It defines the things POSIX says should
|
jpayne@69
|
10 be there. I hope.
|
jpayne@69
|
11
|
jpayne@69
|
12 Copyright (c) 1997-2012 University of Cambridge
|
jpayne@69
|
13
|
jpayne@69
|
14 -----------------------------------------------------------------------------
|
jpayne@69
|
15 Redistribution and use in source and binary forms, with or without
|
jpayne@69
|
16 modification, are permitted provided that the following conditions are met:
|
jpayne@69
|
17
|
jpayne@69
|
18 * Redistributions of source code must retain the above copyright notice,
|
jpayne@69
|
19 this list of conditions and the following disclaimer.
|
jpayne@69
|
20
|
jpayne@69
|
21 * Redistributions in binary form must reproduce the above copyright
|
jpayne@69
|
22 notice, this list of conditions and the following disclaimer in the
|
jpayne@69
|
23 documentation and/or other materials provided with the distribution.
|
jpayne@69
|
24
|
jpayne@69
|
25 * Neither the name of the University of Cambridge nor the names of its
|
jpayne@69
|
26 contributors may be used to endorse or promote products derived from
|
jpayne@69
|
27 this software without specific prior written permission.
|
jpayne@69
|
28
|
jpayne@69
|
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
jpayne@69
|
30 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
jpayne@69
|
31 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
jpayne@69
|
32 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
jpayne@69
|
33 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
jpayne@69
|
34 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
jpayne@69
|
35 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
jpayne@69
|
36 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
jpayne@69
|
37 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
jpayne@69
|
38 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
jpayne@69
|
39 POSSIBILITY OF SUCH DAMAGE.
|
jpayne@69
|
40 -----------------------------------------------------------------------------
|
jpayne@69
|
41 */
|
jpayne@69
|
42
|
jpayne@69
|
43 /* Have to include stdlib.h in order to ensure that size_t is defined. */
|
jpayne@69
|
44
|
jpayne@69
|
45 #include <stdlib.h>
|
jpayne@69
|
46
|
jpayne@69
|
47 /* Allow for C++ users */
|
jpayne@69
|
48
|
jpayne@69
|
49 #ifdef __cplusplus
|
jpayne@69
|
50 extern "C" {
|
jpayne@69
|
51 #endif
|
jpayne@69
|
52
|
jpayne@69
|
53 /* Options, mostly defined by POSIX, but with some extras. */
|
jpayne@69
|
54
|
jpayne@69
|
55 #define REG_ICASE 0x0001 /* Maps to PCRE_CASELESS */
|
jpayne@69
|
56 #define REG_NEWLINE 0x0002 /* Maps to PCRE_MULTILINE */
|
jpayne@69
|
57 #define REG_NOTBOL 0x0004 /* Maps to PCRE_NOTBOL */
|
jpayne@69
|
58 #define REG_NOTEOL 0x0008 /* Maps to PCRE_NOTEOL */
|
jpayne@69
|
59 #define REG_DOTALL 0x0010 /* NOT defined by POSIX; maps to PCRE_DOTALL */
|
jpayne@69
|
60 #define REG_NOSUB 0x0020 /* Maps to PCRE_NO_AUTO_CAPTURE */
|
jpayne@69
|
61 #define REG_UTF8 0x0040 /* NOT defined by POSIX; maps to PCRE_UTF8 */
|
jpayne@69
|
62 #define REG_STARTEND 0x0080 /* BSD feature: pass subject string by so,eo */
|
jpayne@69
|
63 #define REG_NOTEMPTY 0x0100 /* NOT defined by POSIX; maps to PCRE_NOTEMPTY */
|
jpayne@69
|
64 #define REG_UNGREEDY 0x0200 /* NOT defined by POSIX; maps to PCRE_UNGREEDY */
|
jpayne@69
|
65 #define REG_UCP 0x0400 /* NOT defined by POSIX; maps to PCRE_UCP */
|
jpayne@69
|
66
|
jpayne@69
|
67 /* This is not used by PCRE, but by defining it we make it easier
|
jpayne@69
|
68 to slot PCRE into existing programs that make POSIX calls. */
|
jpayne@69
|
69
|
jpayne@69
|
70 #define REG_EXTENDED 0
|
jpayne@69
|
71
|
jpayne@69
|
72 /* Error values. Not all these are relevant or used by the wrapper. */
|
jpayne@69
|
73
|
jpayne@69
|
74 enum {
|
jpayne@69
|
75 REG_ASSERT = 1, /* internal error ? */
|
jpayne@69
|
76 REG_BADBR, /* invalid repeat counts in {} */
|
jpayne@69
|
77 REG_BADPAT, /* pattern error */
|
jpayne@69
|
78 REG_BADRPT, /* ? * + invalid */
|
jpayne@69
|
79 REG_EBRACE, /* unbalanced {} */
|
jpayne@69
|
80 REG_EBRACK, /* unbalanced [] */
|
jpayne@69
|
81 REG_ECOLLATE, /* collation error - not relevant */
|
jpayne@69
|
82 REG_ECTYPE, /* bad class */
|
jpayne@69
|
83 REG_EESCAPE, /* bad escape sequence */
|
jpayne@69
|
84 REG_EMPTY, /* empty expression */
|
jpayne@69
|
85 REG_EPAREN, /* unbalanced () */
|
jpayne@69
|
86 REG_ERANGE, /* bad range inside [] */
|
jpayne@69
|
87 REG_ESIZE, /* expression too big */
|
jpayne@69
|
88 REG_ESPACE, /* failed to get memory */
|
jpayne@69
|
89 REG_ESUBREG, /* bad back reference */
|
jpayne@69
|
90 REG_INVARG, /* bad argument */
|
jpayne@69
|
91 REG_NOMATCH /* match failed */
|
jpayne@69
|
92 };
|
jpayne@69
|
93
|
jpayne@69
|
94
|
jpayne@69
|
95 /* The structure representing a compiled regular expression. */
|
jpayne@69
|
96
|
jpayne@69
|
97 typedef struct {
|
jpayne@69
|
98 void *re_pcre;
|
jpayne@69
|
99 size_t re_nsub;
|
jpayne@69
|
100 size_t re_erroffset;
|
jpayne@69
|
101 } regex_t;
|
jpayne@69
|
102
|
jpayne@69
|
103 /* The structure in which a captured offset is returned. */
|
jpayne@69
|
104
|
jpayne@69
|
105 typedef int regoff_t;
|
jpayne@69
|
106
|
jpayne@69
|
107 typedef struct {
|
jpayne@69
|
108 regoff_t rm_so;
|
jpayne@69
|
109 regoff_t rm_eo;
|
jpayne@69
|
110 } regmatch_t;
|
jpayne@69
|
111
|
jpayne@69
|
112 /* When an application links to a PCRE DLL in Windows, the symbols that are
|
jpayne@69
|
113 imported have to be identified as such. When building PCRE, the appropriate
|
jpayne@69
|
114 export settings are needed, and are set in pcreposix.c before including this
|
jpayne@69
|
115 file. */
|
jpayne@69
|
116
|
jpayne@69
|
117 #if defined(_WIN32) && !defined(PCRE_STATIC) && !defined(PCREPOSIX_EXP_DECL)
|
jpayne@69
|
118 # define PCREPOSIX_EXP_DECL extern __declspec(dllimport)
|
jpayne@69
|
119 # define PCREPOSIX_EXP_DEFN __declspec(dllimport)
|
jpayne@69
|
120 #endif
|
jpayne@69
|
121
|
jpayne@69
|
122 /* By default, we use the standard "extern" declarations. */
|
jpayne@69
|
123
|
jpayne@69
|
124 #ifndef PCREPOSIX_EXP_DECL
|
jpayne@69
|
125 # ifdef __cplusplus
|
jpayne@69
|
126 # define PCREPOSIX_EXP_DECL extern "C"
|
jpayne@69
|
127 # define PCREPOSIX_EXP_DEFN extern "C"
|
jpayne@69
|
128 # else
|
jpayne@69
|
129 # define PCREPOSIX_EXP_DECL extern
|
jpayne@69
|
130 # define PCREPOSIX_EXP_DEFN extern
|
jpayne@69
|
131 # endif
|
jpayne@69
|
132 #endif
|
jpayne@69
|
133
|
jpayne@69
|
134 /* The functions */
|
jpayne@69
|
135
|
jpayne@69
|
136 PCREPOSIX_EXP_DECL int regcomp(regex_t *, const char *, int);
|
jpayne@69
|
137 PCREPOSIX_EXP_DECL int regexec(const regex_t *, const char *, size_t,
|
jpayne@69
|
138 regmatch_t *, int);
|
jpayne@69
|
139 PCREPOSIX_EXP_DECL size_t regerror(int, const regex_t *, char *, size_t);
|
jpayne@69
|
140 PCREPOSIX_EXP_DECL void regfree(regex_t *);
|
jpayne@69
|
141
|
jpayne@69
|
142 #ifdef __cplusplus
|
jpayne@69
|
143 } /* extern "C" */
|
jpayne@69
|
144 #endif
|
jpayne@69
|
145
|
jpayne@69
|
146 #endif /* End of pcreposix.h */
|