00001 #ifndef _REGEX_H_ 00002 #define _REGEX_H_ /* never again */ 00003 /* 00004 * regular expressions 00005 * 00006 * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. 00007 * 00008 * Development of this software was funded, in part, by Cray Research Inc., 00009 * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics 00010 * Corporation, none of whom are responsible for the results. The author 00011 * thanks all of them. 00012 * 00013 * Redistribution and use in source and binary forms -- with or without 00014 * modification -- are permitted for any purpose, provided that 00015 * redistributions in source form retain this entire copyright notice and 00016 * indicate the origin and nature of any modifications. 00017 * 00018 * I'd appreciate being given credit for this package in the documentation 00019 * of software which uses it, but that is not a requirement. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 00022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00023 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00024 * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00027 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00028 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00029 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00030 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 * 00032 * src/include/regex/regex.h 00033 */ 00034 00035 /* 00036 * Add your own defines, if needed, here. 00037 */ 00038 #include "mb/pg_wchar.h" 00039 00040 /* 00041 * interface types etc. 00042 */ 00043 00044 /* 00045 * regoff_t has to be large enough to hold either off_t or ssize_t, 00046 * and must be signed; it's only a guess that long is suitable. 00047 */ 00048 typedef long regoff_t; 00049 00050 /* 00051 * other interface types 00052 */ 00053 00054 /* the biggie, a compiled RE (or rather, a front end to same) */ 00055 typedef struct 00056 { 00057 int re_magic; /* magic number */ 00058 size_t re_nsub; /* number of subexpressions */ 00059 long re_info; /* information about RE */ 00060 #define REG_UBACKREF 000001 00061 #define REG_ULOOKAHEAD 000002 00062 #define REG_UBOUNDS 000004 00063 #define REG_UBRACES 000010 00064 #define REG_UBSALNUM 000020 00065 #define REG_UPBOTCH 000040 00066 #define REG_UBBS 000100 00067 #define REG_UNONPOSIX 000200 00068 #define REG_UUNSPEC 000400 00069 #define REG_UUNPORT 001000 00070 #define REG_ULOCALE 002000 00071 #define REG_UEMPTYMATCH 004000 00072 #define REG_UIMPOSSIBLE 010000 00073 #define REG_USHORTEST 020000 00074 int re_csize; /* sizeof(character) */ 00075 char *re_endp; /* backward compatibility kludge */ 00076 Oid re_collation; /* Collation that defines LC_CTYPE behavior */ 00077 /* the rest is opaque pointers to hidden innards */ 00078 char *re_guts; /* `char *' is more portable than `void *' */ 00079 char *re_fns; 00080 } regex_t; 00081 00082 /* result reporting (may acquire more fields later) */ 00083 typedef struct 00084 { 00085 regoff_t rm_so; /* start of substring */ 00086 regoff_t rm_eo; /* end of substring */ 00087 } regmatch_t; 00088 00089 /* supplementary control and reporting */ 00090 typedef struct 00091 { 00092 regmatch_t rm_extend; /* see REG_EXPECT */ 00093 } rm_detail_t; 00094 00095 00096 00097 /* 00098 * regex compilation flags 00099 */ 00100 #define REG_BASIC 000000 /* BREs (convenience) */ 00101 #define REG_EXTENDED 000001 /* EREs */ 00102 #define REG_ADVF 000002 /* advanced features in EREs */ 00103 #define REG_ADVANCED 000003 /* AREs (which are also EREs) */ 00104 #define REG_QUOTE 000004 /* no special characters, none */ 00105 #define REG_NOSPEC REG_QUOTE /* historical synonym */ 00106 #define REG_ICASE 000010 /* ignore case */ 00107 #define REG_NOSUB 000020 /* don't care about subexpressions */ 00108 #define REG_EXPANDED 000040 /* expanded format, white space & comments */ 00109 #define REG_NLSTOP 000100 /* \n doesn't match . or [^ ] */ 00110 #define REG_NLANCH 000200 /* ^ matches after \n, $ before */ 00111 #define REG_NEWLINE 000300 /* newlines are line terminators */ 00112 #define REG_PEND 000400 /* ugh -- backward-compatibility hack */ 00113 #define REG_EXPECT 001000 /* report details on partial/limited matches */ 00114 #define REG_BOSONLY 002000 /* temporary kludge for BOS-only matches */ 00115 #define REG_DUMP 004000 /* none of your business :-) */ 00116 #define REG_FAKE 010000 /* none of your business :-) */ 00117 #define REG_PROGRESS 020000 /* none of your business :-) */ 00118 00119 00120 00121 /* 00122 * regex execution flags 00123 */ 00124 #define REG_NOTBOL 0001 /* BOS is not BOL */ 00125 #define REG_NOTEOL 0002 /* EOS is not EOL */ 00126 #define REG_STARTEND 0004 /* backward compatibility kludge */ 00127 #define REG_FTRACE 0010 /* none of your business */ 00128 #define REG_MTRACE 0020 /* none of your business */ 00129 #define REG_SMALL 0040 /* none of your business */ 00130 00131 00132 /* 00133 * error reporting 00134 * Be careful if modifying the list of error codes -- the table used by 00135 * regerror() is generated automatically from this file! 00136 */ 00137 #define REG_OKAY 0 /* no errors detected */ 00138 #define REG_NOMATCH 1 /* failed to match */ 00139 #define REG_BADPAT 2 /* invalid regexp */ 00140 #define REG_ECOLLATE 3 /* invalid collating element */ 00141 #define REG_ECTYPE 4 /* invalid character class */ 00142 #define REG_EESCAPE 5 /* invalid escape \ sequence */ 00143 #define REG_ESUBREG 6 /* invalid backreference number */ 00144 #define REG_EBRACK 7 /* brackets [] not balanced */ 00145 #define REG_EPAREN 8 /* parentheses () not balanced */ 00146 #define REG_EBRACE 9 /* braces {} not balanced */ 00147 #define REG_BADBR 10 /* invalid repetition count(s) */ 00148 #define REG_ERANGE 11 /* invalid character range */ 00149 #define REG_ESPACE 12 /* out of memory */ 00150 #define REG_BADRPT 13 /* quantifier operand invalid */ 00151 #define REG_ASSERT 15 /* "can't happen" -- you found a bug */ 00152 #define REG_INVARG 16 /* invalid argument to regex function */ 00153 #define REG_MIXED 17 /* character widths of regex and string differ */ 00154 #define REG_BADOPT 18 /* invalid embedded option */ 00155 #define REG_ETOOBIG 19 /* nfa has too many states */ 00156 #define REG_ECOLORS 20 /* too many colors */ 00157 /* two specials for debugging and testing */ 00158 #define REG_ATOI 101 /* convert error-code name to number */ 00159 #define REG_ITOA 102 /* convert error-code number to name */ 00160 /* non-error result codes for pg_regprefix */ 00161 #define REG_PREFIX (-1) /* identified a common prefix */ 00162 #define REG_EXACT (-2) /* identified an exact match */ 00163 00164 00165 00166 /* 00167 * the prototypes for exported functions 00168 */ 00169 extern int pg_regcomp(regex_t *, const pg_wchar *, size_t, int, Oid); 00170 extern int pg_regexec(regex_t *, const pg_wchar *, size_t, size_t, rm_detail_t *, size_t, regmatch_t[], int); 00171 extern int pg_regprefix(regex_t *, pg_wchar **, size_t *); 00172 extern void pg_regfree(regex_t *); 00173 extern size_t pg_regerror(int, const regex_t *, char *, size_t); 00174 extern void pg_set_regex_collation(Oid collation); 00175 00176 #endif /* _REGEX_H_ */