Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:30:10

0001 /*************************************************
0002 *      Perl-Compatible Regular Expressions       *
0003 *************************************************/
0004 
0005 /* PCRE2 is a library of functions to support regular expressions whose syntax
0006 and semantics are as close as possible to those of the Perl 5 language. This is
0007 the public header file to be #included by applications that call PCRE2 via the
0008 POSIX wrapper interface.
0009 
0010                        Written by Philip Hazel
0011      Original API code Copyright (c) 1997-2012 University of Cambridge
0012           New API code Copyright (c) 2016-2022 University of Cambridge
0013 
0014 -----------------------------------------------------------------------------
0015 Redistribution and use in source and binary forms, with or without
0016 modification, are permitted provided that the following conditions are met:
0017 
0018     * Redistributions of source code must retain the above copyright notice,
0019       this list of conditions and the following disclaimer.
0020 
0021     * Redistributions in binary form must reproduce the above copyright
0022       notice, this list of conditions and the following disclaimer in the
0023       documentation and/or other materials provided with the distribution.
0024 
0025     * Neither the name of the University of Cambridge nor the names of its
0026       contributors may be used to endorse or promote products derived from
0027       this software without specific prior written permission.
0028 
0029 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0030 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0031 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0032 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0033 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0034 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0035 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0036 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0037 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0038 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0039 POSSIBILITY OF SUCH DAMAGE.
0040 -----------------------------------------------------------------------------
0041 */
0042 
0043 
0044 /* Have to include stdlib.h in order to ensure that size_t is defined. */
0045 
0046 #include <stdlib.h>
0047 
0048 /* Allow for C++ users */
0049 
0050 #ifdef __cplusplus
0051 extern "C" {
0052 #endif
0053 
0054 /* Options, mostly defined by POSIX, but with some extras. */
0055 
0056 #define REG_ICASE     0x0001  /* Maps to PCRE2_CASELESS */
0057 #define REG_NEWLINE   0x0002  /* Maps to PCRE2_MULTILINE */
0058 #define REG_NOTBOL    0x0004  /* Maps to PCRE2_NOTBOL */
0059 #define REG_NOTEOL    0x0008  /* Maps to PCRE2_NOTEOL */
0060 #define REG_DOTALL    0x0010  /* NOT defined by POSIX; maps to PCRE2_DOTALL */
0061 #define REG_NOSUB     0x0020  /* Do not report what was matched */
0062 #define REG_UTF       0x0040  /* NOT defined by POSIX; maps to PCRE2_UTF */
0063 #define REG_STARTEND  0x0080  /* BSD feature: pass subject string by so,eo */
0064 #define REG_NOTEMPTY  0x0100  /* NOT defined by POSIX; maps to PCRE2_NOTEMPTY */
0065 #define REG_UNGREEDY  0x0200  /* NOT defined by POSIX; maps to PCRE2_UNGREEDY */
0066 #define REG_UCP       0x0400  /* NOT defined by POSIX; maps to PCRE2_UCP */
0067 #define REG_PEND      0x0800  /* GNU feature: pass end pattern by re_endp */
0068 #define REG_NOSPEC    0x1000  /* Maps to PCRE2_LITERAL */
0069 
0070 /* This is not used by PCRE2, but by defining it we make it easier
0071 to slot PCRE2 into existing programs that make POSIX calls. */
0072 
0073 #define REG_EXTENDED  0
0074 
0075 /* Error values. Not all these are relevant or used by the wrapper. */
0076 
0077 enum {
0078   REG_ASSERT = 1,  /* internal error ? */
0079   REG_BADBR,       /* invalid repeat counts in {} */
0080   REG_BADPAT,      /* pattern error */
0081   REG_BADRPT,      /* ? * + invalid */
0082   REG_EBRACE,      /* unbalanced {} */
0083   REG_EBRACK,      /* unbalanced [] */
0084   REG_ECOLLATE,    /* collation error - not relevant */
0085   REG_ECTYPE,      /* bad class */
0086   REG_EESCAPE,     /* bad escape sequence */
0087   REG_EMPTY,       /* empty expression */
0088   REG_EPAREN,      /* unbalanced () */
0089   REG_ERANGE,      /* bad range inside [] */
0090   REG_ESIZE,       /* expression too big */
0091   REG_ESPACE,      /* failed to get memory */
0092   REG_ESUBREG,     /* bad back reference */
0093   REG_INVARG,      /* bad argument */
0094   REG_NOMATCH      /* match failed */
0095 };
0096 
0097 
0098 /* The structure representing a compiled regular expression. It is also used
0099 for passing the pattern end pointer when REG_PEND is set. */
0100 
0101 typedef struct {
0102   void *re_pcre2_code;
0103   void *re_match_data;
0104   const char *re_endp;
0105   size_t re_nsub;
0106   size_t re_erroffset;
0107   int re_cflags;
0108 } regex_t;
0109 
0110 /* The structure in which a captured offset is returned. */
0111 
0112 typedef int regoff_t;
0113 
0114 typedef struct {
0115   regoff_t rm_so;
0116   regoff_t rm_eo;
0117 } regmatch_t;
0118 
0119 /* When compiling with the MSVC compiler, it is sometimes necessary to include
0120 a "calling convention" before exported function names. (This is secondhand
0121 information; I know nothing about MSVC myself). For example, something like
0122 
0123   void __cdecl function(....)
0124 
0125 might be needed. In order to make this easy, all the exported functions have
0126 PCRE2_CALL_CONVENTION just before their names. It is rarely needed; if not
0127 set, we ensure here that it has no effect. */
0128 
0129 #ifndef PCRE2_CALL_CONVENTION
0130 #define PCRE2_CALL_CONVENTION
0131 #endif
0132 
0133 /* When an application links to a PCRE2 DLL in Windows, the symbols that are
0134 imported have to be identified as such. When building PCRE2, the appropriate
0135 export settings are needed, and are set in pcre2posix.c before including this
0136 file. */
0137 
0138 #if defined(_WIN32) && !defined(PCRE2_STATIC) && !defined(PCRE2POSIX_EXP_DECL)
0139 #  define PCRE2POSIX_EXP_DECL  extern __declspec(dllimport)
0140 #  define PCRE2POSIX_EXP_DEFN  __declspec(dllimport)
0141 #endif
0142 
0143 /* By default, we use the standard "extern" declarations. */
0144 
0145 #ifndef PCRE2POSIX_EXP_DECL
0146 #  ifdef __cplusplus
0147 #    define PCRE2POSIX_EXP_DECL  extern "C"
0148 #    define PCRE2POSIX_EXP_DEFN  extern "C"
0149 #  else
0150 #    define PCRE2POSIX_EXP_DECL  extern
0151 #    define PCRE2POSIX_EXP_DEFN  extern
0152 #  endif
0153 #endif
0154 
0155 /* The functions. The actual code is in functions with pcre2_xxx names for
0156 uniqueness. POSIX names are provided as macros for API compatibility with POSIX
0157 regex functions. It's done this way to ensure to they are always linked from
0158 the PCRE2 library and not by accident from elsewhere (regex_t differs in size
0159 elsewhere). */
0160 
0161 PCRE2POSIX_EXP_DECL int PCRE2_CALL_CONVENTION pcre2_regcomp(regex_t *, const char *, int);
0162 PCRE2POSIX_EXP_DECL int PCRE2_CALL_CONVENTION pcre2_regexec(const regex_t *, const char *, size_t,
0163                      regmatch_t *, int);
0164 PCRE2POSIX_EXP_DECL size_t PCRE2_CALL_CONVENTION pcre2_regerror(int, const regex_t *, char *, size_t);
0165 PCRE2POSIX_EXP_DECL void PCRE2_CALL_CONVENTION pcre2_regfree(regex_t *);
0166 
0167 #define regcomp  pcre2_regcomp
0168 #define regexec  pcre2_regexec
0169 #define regerror pcre2_regerror
0170 #define regfree  pcre2_regfree
0171 
0172 /* Debian had a patch that used different names. These are now here to save
0173 them having to maintain their own patch, but are not documented by PCRE2. */
0174 
0175 #define PCRE2regcomp  pcre2_regcomp
0176 #define PCRE2regexec  pcre2_regexec
0177 #define PCRE2regerror pcre2_regerror
0178 #define PCRE2regfree  pcre2_regfree
0179 
0180 #ifdef __cplusplus
0181 }   /* extern "C" */
0182 #endif
0183 
0184 /* End of pcre2posix.h */