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