1 /*************************************************
2 *       Perl-Compatible Regular Expressions      *
3 *************************************************/
4 
5 #ifndef _PCREPOSIX_H
6 #define _PCREPOSIX_H
7 
8 /* This is the header for the POSIX wrapper interface to the PCRE Perl-
9 Compatible Regular Expression library. It defines the things POSIX says should
10 be there. I hope.
11 
12             Copyright (c) 1997-2012 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 /* Have to include stdlib.h in order to ensure that size_t is defined. */
44 
45 #include <stdlib.h>
46 
47 #define PCREPOSIX_EXP_DEFN  extern
48 #define PCREPOSIX_EXP_DECL  extern
49 
50 /* Options, mostly defined by POSIX, but with some extras. */
51 
52 #define PCRE_REG_ICASE     0x0001   /* Maps to PCRE_CASELESS */
53 #define PCRE_REG_NEWLINE   0x0002   /* Maps to PCRE_MULTILINE */
54 #define PCRE_REG_NOTBOL    0x0004   /* Maps to PCRE_NOTBOL */
55 #define PCRE_REG_NOTEOL    0x0008   /* Maps to PCRE_NOTEOL */
56 #define PCRE_REG_DOTALL    0x0010   /* NOT defined by POSIX; maps to PCRE_DOTALL */
57 #define PCRE_REG_NOSUB     0x0020   /* Maps to PCRE_NO_AUTO_CAPTURE */
58 #define PCRE_REG_UTF8      0x0040   /* NOT defined by POSIX; maps to PCRE_UTF8 */
59 #define PCRE_REG_STARTEND  0x0080   /* BSD feature: pass subject string by so,eo */
60 #define PCRE_REG_NOTEMPTY  0x0100   /* NOT defined by POSIX; maps to PCRE_NOTEMPTY */
61 #define PCRE_REG_UNGREEDY  0x0200   /* NOT defined by POSIX; maps to PCRE_UNGREEDY */
62 #define PCRE_REG_UCP       0x0400   /* NOT defined by POSIX; maps to PCRE_UCP */
63 
64 /* This is not used by PCRE, but by defining it we make it easier
65 to slot PCRE into existing programs that make POSIX calls. */
66 
67 #define PCRE_REG_EXTENDED  0
68 
69 /* Error values. Not all these are relevant or used by the wrapper. */
70 
71 enum {
72   PCRE_REG_ASSERT = 1,  /* internal error ? */
73   PCRE_REG_BADBR,       /* invalid repeat counts in {} */
74   PCRE_REG_BADPAT,      /* pattern error */
75   PCRE_REG_BADRPT,      /* ? * + invalid */
76   PCRE_REG_EBRACE,      /* unbalanced {} */
77   PCRE_REG_EBRACK,      /* unbalanced [] */
78   PCRE_REG_ECOLLATE,    /* collation error - not relevant */
79   PCRE_REG_ECTYPE,      /* bad class */
80   PCRE_REG_EESCAPE,     /* bad escape sequence */
81   PCRE_REG_EMPTY,       /* empty expression */
82   PCRE_REG_EPAREN,      /* unbalanced () */
83   PCRE_REG_ERANGE,      /* bad range inside [] */
84   PCRE_REG_ESIZE,       /* expression too big */
85   PCRE_REG_ESPACE,      /* failed to get memory */
86   PCRE_REG_ESUBREG,     /* bad back reference */
87   PCRE_REG_INVARG,      /* bad argument */
88   PCRE_REG_NOMATCH      /* match failed */
89 };
90 
91 
92 /* The structure representing a compiled regular expression. */
93 
94 typedef struct {
95   void *re_pcre;
96   size_t re_nsub;
97   size_t re_erroffset;
98 } pcre_regex_t;
99 
100 /* The structure in which a captured offset is returned. */
101 
102 typedef int pcre_regoff_t;
103 
104 typedef struct {
105   pcre_regoff_t rm_so;
106   pcre_regoff_t rm_eo;
107 } pcre_regmatch_t;
108 
109 /* The functions */
110 
111 PCREPOSIX_EXP_DECL int pcre_regcomp(pcre_regex_t *, const char *, int);
112 PCREPOSIX_EXP_DECL int pcre_regexec(const pcre_regex_t *, const char *, size_t,
113                      pcre_regmatch_t *, int);
114 PCREPOSIX_EXP_DECL size_t pcre_regerror(int, const pcre_regex_t *, char *, size_t);
115 PCREPOSIX_EXP_DECL void pcre_regfree(pcre_regex_t *);
116 
117 #endif /* End of pcreposix.h */
118