xref: /aosp_15_r20/external/pcre/src/pcre2posix.h (revision 22dc650d8ae982c6770746019a6f94af92b0f024)
1 /*************************************************
2 *      Perl-Compatible Regular Expressions       *
3 *************************************************/
4 
5 /* PCRE2 is a library of functions to support regular expressions whose syntax
6 and semantics are as close as possible to those of the Perl 5 language. This is
7 the public header file to be #included by applications that call PCRE2 via the
8 POSIX wrapper interface.
9 
10                        Written by Philip Hazel
11      Original API code Copyright (c) 1997-2012 University of Cambridge
12           New API code Copyright (c) 2016-2023 University of Cambridge
13 
14 -----------------------------------------------------------------------------
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions are met:
17 
18     * Redistributions of source code must retain the above copyright notice,
19       this list of conditions and the following disclaimer.
20 
21     * Redistributions in binary form must reproduce the above copyright
22       notice, this list of conditions and the following disclaimer in the
23       documentation and/or other materials provided with the distribution.
24 
25     * Neither the name of the University of Cambridge nor the names of its
26       contributors may be used to endorse or promote products derived from
27       this software without specific prior written permission.
28 
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 POSSIBILITY OF SUCH DAMAGE.
40 -----------------------------------------------------------------------------
41 */
42 
43 #ifndef PCRE2POSIX_H_IDEMPOTENT_GUARD
44 #define PCRE2POSIX_H_IDEMPOTENT_GUARD
45 
46 /* Have to include stdlib.h in order to ensure that size_t is defined. */
47 
48 #include <stdlib.h>
49 
50 /* Allow for C++ users */
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /* Options, mostly defined by POSIX, but with some extras. */
57 
58 #define REG_ICASE     0x0001  /* Maps to PCRE2_CASELESS */
59 #define REG_NEWLINE   0x0002  /* Maps to PCRE2_MULTILINE */
60 #define REG_NOTBOL    0x0004  /* Maps to PCRE2_NOTBOL */
61 #define REG_NOTEOL    0x0008  /* Maps to PCRE2_NOTEOL */
62 #define REG_DOTALL    0x0010  /* NOT defined by POSIX; maps to PCRE2_DOTALL */
63 #define REG_NOSUB     0x0020  /* Do not report what was matched */
64 #define REG_UTF       0x0040  /* NOT defined by POSIX; maps to PCRE2_UTF */
65 #define REG_STARTEND  0x0080  /* BSD feature: pass subject string by so,eo */
66 #define REG_NOTEMPTY  0x0100  /* NOT defined by POSIX; maps to PCRE2_NOTEMPTY */
67 #define REG_UNGREEDY  0x0200  /* NOT defined by POSIX; maps to PCRE2_UNGREEDY */
68 #define REG_UCP       0x0400  /* NOT defined by POSIX; maps to PCRE2_UCP */
69 #define REG_PEND      0x0800  /* GNU feature: pass end pattern by re_endp */
70 #define REG_NOSPEC    0x1000  /* Maps to PCRE2_LITERAL */
71 
72 /* This is not used by PCRE2, but by defining it we make it easier
73 to slot PCRE2 into existing programs that make POSIX calls. */
74 
75 #define REG_EXTENDED  0
76 
77 /* Error values. Not all these are relevant or used by the wrapper. */
78 
79 enum {
80   REG_ASSERT = 1,  /* internal error ? */
81   REG_BADBR,       /* invalid repeat counts in {} */
82   REG_BADPAT,      /* pattern error */
83   REG_BADRPT,      /* ? * + invalid */
84   REG_EBRACE,      /* unbalanced {} */
85   REG_EBRACK,      /* unbalanced [] */
86   REG_ECOLLATE,    /* collation error - not relevant */
87   REG_ECTYPE,      /* bad class */
88   REG_EESCAPE,     /* bad escape sequence */
89   REG_EMPTY,       /* empty expression */
90   REG_EPAREN,      /* unbalanced () */
91   REG_ERANGE,      /* bad range inside [] */
92   REG_ESIZE,       /* expression too big */
93   REG_ESPACE,      /* failed to get memory */
94   REG_ESUBREG,     /* bad back reference */
95   REG_INVARG,      /* bad argument */
96   REG_NOMATCH      /* match failed */
97 };
98 
99 
100 /* The structure representing a compiled regular expression. It is also used
101 for passing the pattern end pointer when REG_PEND is set. */
102 
103 typedef struct {
104   void *re_pcre2_code;
105   void *re_match_data;
106   const char *re_endp;
107   size_t re_nsub;
108   size_t re_erroffset;
109   int re_cflags;
110 } regex_t;
111 
112 /* The structure in which a captured offset is returned. */
113 
114 typedef int regoff_t;
115 
116 typedef struct {
117   regoff_t rm_so;
118   regoff_t rm_eo;
119 } regmatch_t;
120 
121 /* When compiling with the MSVC compiler, it is sometimes necessary to include
122 a "calling convention" before exported function names. (This is secondhand
123 information; I know nothing about MSVC myself). For example, something like
124 
125   void __cdecl function(....)
126 
127 might be needed. In order to make this easy, all the exported functions have
128 PCRE2_CALL_CONVENTION just before their names. It is rarely needed; if not
129 set, we ensure here that it has no effect. */
130 
131 #ifndef PCRE2_CALL_CONVENTION
132 #define PCRE2_CALL_CONVENTION
133 #endif
134 
135 #ifndef PCRE2_EXPORT
136 #define PCRE2_EXPORT
137 #endif
138 
139 /* When an application links to a PCRE2 DLL in Windows, the symbols that are
140 imported have to be identified as such. When building PCRE2, the appropriate
141 export settings are needed, and are set in pcre2posix.c before including this
142 file. */
143 
144 /* By default, we use the standard "extern" declarations. */
145 
146 #ifndef PCRE2POSIX_EXP_DECL
147 #  if defined(_WIN32) && defined(PCRE2POSIX_SHARED) && !defined(PCRE2_STATIC)
148 #    define PCRE2POSIX_EXP_DECL		extern __declspec(dllimport)
149 #    define PCRE2POSIX_EXP_DEFN		__declspec(dllimport)
150 #  else
151 #    define PCRE2POSIX_EXP_DECL		extern PCRE2_EXPORT
152 #    define PCRE2POSIX_EXP_DEFN
153 #  endif
154 #endif
155 
156 /* The functions. The actual code is in functions with pcre2_xxx names for
157 uniqueness. POSIX names are provided as macros for API compatibility with POSIX
158 regex functions. It's done this way to ensure to they are always linked from
159 the PCRE2 library and not by accident from elsewhere (regex_t differs in size
160 elsewhere). */
161 
162 PCRE2POSIX_EXP_DECL int PCRE2_CALL_CONVENTION pcre2_regcomp(regex_t *, const char *, int);
163 PCRE2POSIX_EXP_DECL int PCRE2_CALL_CONVENTION pcre2_regexec(const regex_t *, const char *, size_t,
164                      regmatch_t *, int);
165 PCRE2POSIX_EXP_DECL size_t PCRE2_CALL_CONVENTION pcre2_regerror(int, const regex_t *, char *, size_t);
166 PCRE2POSIX_EXP_DECL void PCRE2_CALL_CONVENTION pcre2_regfree(regex_t *);
167 
168 #define regcomp  pcre2_regcomp
169 #define regexec  pcre2_regexec
170 #define regerror pcre2_regerror
171 #define regfree  pcre2_regfree
172 
173 /* Debian had a patch that used different names. These are now here to save
174 them having to maintain their own patch, but are not documented by PCRE2. */
175 
176 #define PCRE2regcomp  pcre2_regcomp
177 #define PCRE2regexec  pcre2_regexec
178 #define PCRE2regerror pcre2_regerror
179 #define PCRE2regfree  pcre2_regfree
180 
181 #ifdef __cplusplus
182 }   /* extern "C" */
183 #endif
184 
185 #endif /* PCRE2POSIX_H_IDEMPOTENT_GUARD */
186 
187 /* End of pcre2posix.h */
188