| 1 |
nigel |
3 |
/************************************************* |
| 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 |
nigel |
75 |
be there. I hope. |
| 11 |
nigel |
3 |
|
| 12 |
ph10 |
305 |
Copyright (c) 1997-2008 University of Cambridge |
| 13 |
nigel |
75 |
|
| 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 |
nigel |
3 |
/* Have to include stdlib.h in order to ensure that size_t is defined. */ |
| 44 |
|
|
|
| 45 |
|
|
#include <stdlib.h> |
| 46 |
|
|
|
| 47 |
nigel |
15 |
/* Allow for C++ users */ |
| 48 |
|
|
|
| 49 |
|
|
#ifdef __cplusplus |
| 50 |
|
|
extern "C" { |
| 51 |
|
|
#endif |
| 52 |
|
|
|
| 53 |
nigel |
87 |
/* Options, mostly defined by POSIX, but with a couple of extras. */ |
| 54 |
nigel |
3 |
|
| 55 |
nigel |
87 |
#define REG_ICASE 0x0001 |
| 56 |
|
|
#define REG_NEWLINE 0x0002 |
| 57 |
|
|
#define REG_NOTBOL 0x0004 |
| 58 |
|
|
#define REG_NOTEOL 0x0008 |
| 59 |
|
|
#define REG_DOTALL 0x0010 /* NOT defined by POSIX. */ |
| 60 |
|
|
#define REG_NOSUB 0x0020 |
| 61 |
|
|
#define REG_UTF8 0x0040 /* NOT defined by POSIX. */ |
| 62 |
nigel |
3 |
|
| 63 |
nigel |
87 |
/* This is not used by PCRE, but by defining it we make it easier |
| 64 |
nigel |
43 |
to slot PCRE into existing programs that make POSIX calls. */ |
| 65 |
|
|
|
| 66 |
|
|
#define REG_EXTENDED 0 |
| 67 |
|
|
|
| 68 |
nigel |
3 |
/* Error values. Not all these are relevant or used by the wrapper. */ |
| 69 |
|
|
|
| 70 |
|
|
enum { |
| 71 |
|
|
REG_ASSERT = 1, /* internal error ? */ |
| 72 |
|
|
REG_BADBR, /* invalid repeat counts in {} */ |
| 73 |
|
|
REG_BADPAT, /* pattern error */ |
| 74 |
|
|
REG_BADRPT, /* ? * + invalid */ |
| 75 |
|
|
REG_EBRACE, /* unbalanced {} */ |
| 76 |
|
|
REG_EBRACK, /* unbalanced [] */ |
| 77 |
|
|
REG_ECOLLATE, /* collation error - not relevant */ |
| 78 |
|
|
REG_ECTYPE, /* bad class */ |
| 79 |
|
|
REG_EESCAPE, /* bad escape sequence */ |
| 80 |
|
|
REG_EMPTY, /* empty expression */ |
| 81 |
|
|
REG_EPAREN, /* unbalanced () */ |
| 82 |
|
|
REG_ERANGE, /* bad range inside [] */ |
| 83 |
|
|
REG_ESIZE, /* expression too big */ |
| 84 |
|
|
REG_ESPACE, /* failed to get memory */ |
| 85 |
|
|
REG_ESUBREG, /* bad back reference */ |
| 86 |
|
|
REG_INVARG, /* bad argument */ |
| 87 |
|
|
REG_NOMATCH /* match failed */ |
| 88 |
|
|
}; |
| 89 |
|
|
|
| 90 |
|
|
|
| 91 |
|
|
/* The structure representing a compiled regular expression. */ |
| 92 |
|
|
|
| 93 |
|
|
typedef struct { |
| 94 |
|
|
void *re_pcre; |
| 95 |
|
|
size_t re_nsub; |
| 96 |
|
|
size_t re_erroffset; |
| 97 |
|
|
} regex_t; |
| 98 |
|
|
|
| 99 |
|
|
/* The structure in which a captured offset is returned. */ |
| 100 |
|
|
|
| 101 |
|
|
typedef int regoff_t; |
| 102 |
|
|
|
| 103 |
|
|
typedef struct { |
| 104 |
|
|
regoff_t rm_so; |
| 105 |
|
|
regoff_t rm_eo; |
| 106 |
|
|
} regmatch_t; |
| 107 |
|
|
|
| 108 |
ph10 |
145 |
/* When an application links to a PCRE DLL in Windows, the symbols that are |
| 109 |
|
|
imported have to be identified as such. When building PCRE, the appropriate |
| 110 |
ph10 |
200 |
export settings are needed, and are set in pcreposix.c before including this |
| 111 |
ph10 |
199 |
file. */ |
| 112 |
nigel |
89 |
|
| 113 |
ph10 |
199 |
#if defined(_WIN32) && !defined(PCRE_STATIC) && !defined(PCREPOSIX_EXP_DECL) |
| 114 |
|
|
# define PCREPOSIX_EXP_DECL extern __declspec(dllimport) |
| 115 |
|
|
# define PCREPOSIX_EXP_DEFN __declspec(dllimport) |
| 116 |
nigel |
89 |
#endif |
| 117 |
|
|
|
| 118 |
ph10 |
145 |
/* By default, we use the standard "extern" declarations. */ |
| 119 |
nigel |
89 |
|
| 120 |
ph10 |
145 |
#ifndef PCREPOSIX_EXP_DECL |
| 121 |
nigel |
89 |
# ifdef __cplusplus |
| 122 |
ph10 |
145 |
# define PCREPOSIX_EXP_DECL extern "C" |
| 123 |
|
|
# define PCREPOSIX_EXP_DEFN extern "C" |
| 124 |
nigel |
89 |
# else |
| 125 |
ph10 |
145 |
# define PCREPOSIX_EXP_DECL extern |
| 126 |
|
|
# define PCREPOSIX_EXP_DEFN extern |
| 127 |
nigel |
89 |
# endif |
| 128 |
|
|
#endif |
| 129 |
|
|
|
| 130 |
nigel |
3 |
/* The functions */ |
| 131 |
|
|
|
| 132 |
ph10 |
145 |
PCREPOSIX_EXP_DECL int regcomp(regex_t *, const char *, int); |
| 133 |
|
|
PCREPOSIX_EXP_DECL int regexec(const regex_t *, const char *, size_t, |
| 134 |
|
|
regmatch_t *, int); |
| 135 |
|
|
PCREPOSIX_EXP_DECL size_t regerror(int, const regex_t *, char *, size_t); |
| 136 |
|
|
PCREPOSIX_EXP_DECL void regfree(regex_t *); |
| 137 |
nigel |
3 |
|
| 138 |
nigel |
15 |
#ifdef __cplusplus |
| 139 |
|
|
} /* extern "C" */ |
| 140 |
|
|
#endif |
| 141 |
|
|
|
| 142 |
nigel |
3 |
#endif /* End of pcreposix.h */ |