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