• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/text/pcreposix.h

00001 /*************************************************
00002 *       Perl-Compatible Regular Expressions      *
00003 *************************************************/
00004 
00005 #ifndef _PCREPOSIX_H
00006 #define _PCREPOSIX_H
00007 
00008 /* This is the header for the POSIX wrapper interface to the PCRE Perl-
00009 Compatible Regular Expression library. It defines the things POSIX says should
00010 be there. I hope.
00011 
00012             Copyright (c) 1997-2009 University of Cambridge
00013 
00014 -----------------------------------------------------------------------------
00015 Redistribution and use in source and binary forms, with or without
00016 modification, are permitted provided that the following conditions are met:
00017 
00018     * Redistributions of source code must retain the above copyright notice,
00019       this list of conditions and the following disclaimer.
00020 
00021     * Redistributions in binary form must reproduce the above copyright
00022       notice, this list of conditions and the following disclaimer in the
00023       documentation and/or other materials provided with the distribution.
00024 
00025     * Neither the name of the University of Cambridge nor the names of its
00026       contributors may be used to endorse or promote products derived from
00027       this software without specific prior written permission.
00028 
00029 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00030 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00031 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00032 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00033 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00034 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00035 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00036 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00037 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00038 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00039 POSSIBILITY OF SUCH DAMAGE.
00040 -----------------------------------------------------------------------------
00041 */
00042 
00043 /* Have to include stdlib.h in order to ensure that size_t is defined. */
00044 
00045 #include <stdlib.h>
00046 
00047 /* Allow for C++ users */
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 /* Options, mostly defined by POSIX, but with some extras. */
00054 
00055 #define REG_ICASE     0x0001   /* Maps to PCRE_CASELESS */
00056 #define REG_NEWLINE   0x0002   /* Maps to PCRE_MULTILINE */
00057 #define REG_NOTBOL    0x0004   /* Maps to PCRE_NOTBOL */
00058 #define REG_NOTEOL    0x0008   /* Maps to PCRE_NOTEOL */
00059 #define REG_DOTALL    0x0010   /* NOT defined by POSIX; maps to PCRE_DOTALL */
00060 #define REG_NOSUB     0x0020   /* Maps to PCRE_NO_AUTO_CAPTURE */
00061 #define REG_UTF8      0x0040   /* NOT defined by POSIX; maps to PCRE_UTF8 */
00062 #define REG_STARTEND  0x0080   /* BSD feature: pass subject string by so,eo */
00063 #define REG_NOTEMPTY  0x0100   /* NOT defined by POSIX; maps to PCRE_NOTEMPTY */
00064 #define REG_UNGREEDY  0x0200   /* NOT defined by POSIX; maps to PCRE_UNGREEDY */
00065 
00066 /* This is not used by PCRE, but by defining it we make it easier
00067 to slot PCRE into existing programs that make POSIX calls. */
00068 
00069 #define REG_EXTENDED  0
00070 
00071 /* Error values. Not all these are relevant or used by the wrapper. */
00072 
00073 enum {
00074   REG_ASSERT = 1,  /* internal error ? */
00075   REG_BADBR,       /* invalid repeat counts in {} */
00076   REG_BADPAT,      /* pattern error */
00077   REG_BADRPT,      /* ? * + invalid */
00078   REG_EBRACE,      /* unbalanced {} */
00079   REG_EBRACK,      /* unbalanced [] */
00080   REG_ECOLLATE,    /* collation error - not relevant */
00081   REG_ECTYPE,      /* bad class */
00082   REG_EESCAPE,     /* bad escape sequence */
00083   REG_EMPTY,       /* empty expression */
00084   REG_EPAREN,      /* unbalanced () */
00085   REG_ERANGE,      /* bad range inside [] */
00086   REG_ESIZE,       /* expression too big */
00087   REG_ESPACE,      /* failed to get memory */
00088   REG_ESUBREG,     /* bad back reference */
00089   REG_INVARG,      /* bad argument */
00090   REG_NOMATCH      /* match failed */
00091 };
00092 
00093 
00094 /* The structure representing a compiled regular expression. */
00095 
00096 typedef struct {
00097   void *re_pcre;
00098   size_t re_nsub;
00099   size_t re_erroffset;
00100 } regex_t;
00101 
00102 /* The structure in which a captured offset is returned. */
00103 
00104 typedef int regoff_t;
00105 
00106 typedef struct {
00107   regoff_t rm_so;
00108   regoff_t rm_eo;
00109 } regmatch_t;
00110 
00111 /* When an application links to a PCRE DLL in Windows, the symbols that are
00112 imported have to be identified as such. When building PCRE, the appropriate
00113 export settings are needed, and are set in pcreposix.c before including this
00114 file. */
00115 
00116 //#if defined(_WIN32) && !defined(PCRE_STATIC) && !defined(PCREPOSIX_EXP_DECL)
00117 //#  define PCREPOSIX_EXP_DECL  extern __declspec(dllimport)
00118 //#  define PCREPOSIX_EXP_DEFN  __declspec(dllimport)
00119 //#endif
00120 
00121 /* By default, we use the standard "extern" declarations. */
00122 
00123 #ifndef PCREPOSIX_EXP_DECL
00124 #  ifdef __cplusplus
00125 #    define PCREPOSIX_EXP_DECL  extern "C"
00126 #    define PCREPOSIX_EXP_DEFN  extern "C"
00127 #  else
00128 #    define PCREPOSIX_EXP_DECL  extern
00129 #    define PCREPOSIX_EXP_DEFN  extern
00130 #  endif
00131 #endif
00132 
00133 /* The functions */
00134 
00135 PCREPOSIX_EXP_DECL int regcomp(regex_t *, const char *, int);
00136 PCREPOSIX_EXP_DECL int regexec(const regex_t *, const char *, size_t, regmatch_t *, int);
00137 PCREPOSIX_EXP_DECL size_t regerror(int, const regex_t *, char *, size_t);
00138 PCREPOSIX_EXP_DECL void regfree(regex_t *);
00139 
00140 #ifdef __cplusplus
00141 }   /* extern "C" */
00142 #endif
00143 
00144 #endif /* End of pcreposix.h */