regex.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #ifndef _REGEX_H_
  2. #define _REGEX_H_ /* never again */
  3. /*
  4. * regular expressions
  5. *
  6. * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved.
  7. *
  8. * Development of this software was funded, in part, by Cray Research Inc.,
  9. * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics
  10. * Corporation, none of whom are responsible for the results. The author
  11. * thanks all of them.
  12. *
  13. * Redistribution and use in source and binary forms -- with or without
  14. * modification -- are permitted for any purpose, provided that
  15. * redistributions in source form retain this entire copyright notice and
  16. * indicate the origin and nature of any modifications.
  17. *
  18. * I'd appreciate being given credit for this package in the documentation
  19. * of software which uses it, but that is not a requirement.
  20. *
  21. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  22. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  24. * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  30. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * src/include/regex/regex.h
  33. */
  34. /*
  35. * Add your own defines, if needed, here.
  36. */
  37. #include "mb/pg_wchar.h"
  38. /*
  39. * interface types etc.
  40. */
  41. /*
  42. * regoff_t has to be large enough to hold either off_t or ssize_t,
  43. * and must be signed; it's only a guess that long is suitable.
  44. */
  45. typedef long regoff_t;
  46. /*
  47. * other interface types
  48. */
  49. /* the biggie, a compiled RE (or rather, a front end to same) */
  50. typedef struct
  51. {
  52. int re_magic; /* magic number */
  53. size_t re_nsub; /* number of subexpressions */
  54. long re_info; /* bitmask of the following flags: */
  55. #define REG_UBACKREF 000001 /* has back-reference (\n) */
  56. #define REG_ULOOKAROUND 000002 /* has lookahead/lookbehind constraint */
  57. #define REG_UBOUNDS 000004 /* has bounded quantifier ({m,n}) */
  58. #define REG_UBRACES 000010 /* has { that doesn't begin a quantifier */
  59. #define REG_UBSALNUM 000020 /* has backslash-alphanumeric in non-ARE */
  60. #define REG_UPBOTCH 000040 /* has unmatched right paren in ERE (legal
  61. * per spec, but that was a mistake) */
  62. #define REG_UBBS 000100 /* has backslash within bracket expr */
  63. #define REG_UNONPOSIX 000200 /* has any construct that extends POSIX */
  64. #define REG_UUNSPEC 000400 /* has any case disallowed by POSIX, e.g.
  65. * an empty branch */
  66. #define REG_UUNPORT 001000 /* has numeric character code dependency */
  67. #define REG_ULOCALE 002000 /* has locale dependency */
  68. #define REG_UEMPTYMATCH 004000 /* can match a zero-length string */
  69. #define REG_UIMPOSSIBLE 010000 /* provably cannot match anything */
  70. #define REG_USHORTEST 020000 /* has non-greedy quantifier */
  71. int re_csize; /* sizeof(character) */
  72. char *re_endp; /* backward compatibility kludge */
  73. Oid re_collation; /* Collation that defines LC_CTYPE behavior */
  74. /* the rest is opaque pointers to hidden innards */
  75. char *re_guts; /* `char *' is more portable than `void *' */
  76. char *re_fns;
  77. } regex_t;
  78. /* result reporting (may acquire more fields later) */
  79. typedef struct
  80. {
  81. regoff_t rm_so; /* start of substring */
  82. regoff_t rm_eo; /* end of substring */
  83. } regmatch_t;
  84. /* supplementary control and reporting */
  85. typedef struct
  86. {
  87. regmatch_t rm_extend; /* see REG_EXPECT */
  88. } rm_detail_t;
  89. /*
  90. * regex compilation flags
  91. */
  92. #define REG_BASIC 000000 /* BREs (convenience) */
  93. #define REG_EXTENDED 000001 /* EREs */
  94. #define REG_ADVF 000002 /* advanced features in EREs */
  95. #define REG_ADVANCED 000003 /* AREs (which are also EREs) */
  96. #define REG_QUOTE 000004 /* no special characters, none */
  97. #define REG_NOSPEC REG_QUOTE /* historical synonym */
  98. #define REG_ICASE 000010 /* ignore case */
  99. #define REG_NOSUB 000020 /* caller doesn't need subexpr match data */
  100. #define REG_EXPANDED 000040 /* expanded format, white space & comments */
  101. #define REG_NLSTOP 000100 /* \n doesn't match . or [^ ] */
  102. #define REG_NLANCH 000200 /* ^ matches after \n, $ before */
  103. #define REG_NEWLINE 000300 /* newlines are line terminators */
  104. #define REG_PEND 000400 /* ugh -- backward-compatibility hack */
  105. #define REG_EXPECT 001000 /* report details on partial/limited matches */
  106. #define REG_BOSONLY 002000 /* temporary kludge for BOS-only matches */
  107. #define REG_DUMP 004000 /* none of your business :-) */
  108. #define REG_FAKE 010000 /* none of your business :-) */
  109. #define REG_PROGRESS 020000 /* none of your business :-) */
  110. /*
  111. * regex execution flags
  112. */
  113. #define REG_NOTBOL 0001 /* BOS is not BOL */
  114. #define REG_NOTEOL 0002 /* EOS is not EOL */
  115. #define REG_STARTEND 0004 /* backward compatibility kludge */
  116. #define REG_FTRACE 0010 /* none of your business */
  117. #define REG_MTRACE 0020 /* none of your business */
  118. #define REG_SMALL 0040 /* none of your business */
  119. /*
  120. * error reporting
  121. * Be careful if modifying the list of error codes -- the table used by
  122. * regerror() is generated automatically from this file!
  123. */
  124. #define REG_OKAY 0 /* no errors detected */
  125. #define REG_NOMATCH 1 /* failed to match */
  126. #define REG_BADPAT 2 /* invalid regexp */
  127. #define REG_ECOLLATE 3 /* invalid collating element */
  128. #define REG_ECTYPE 4 /* invalid character class */
  129. #define REG_EESCAPE 5 /* invalid escape \ sequence */
  130. #define REG_ESUBREG 6 /* invalid backreference number */
  131. #define REG_EBRACK 7 /* brackets [] not balanced */
  132. #define REG_EPAREN 8 /* parentheses () not balanced */
  133. #define REG_EBRACE 9 /* braces {} not balanced */
  134. #define REG_BADBR 10 /* invalid repetition count(s) */
  135. #define REG_ERANGE 11 /* invalid character range */
  136. #define REG_ESPACE 12 /* out of memory */
  137. #define REG_BADRPT 13 /* quantifier operand invalid */
  138. #define REG_ASSERT 15 /* "can't happen" -- you found a bug */
  139. #define REG_INVARG 16 /* invalid argument to regex function */
  140. #define REG_MIXED 17 /* character widths of regex and string differ */
  141. #define REG_BADOPT 18 /* invalid embedded option */
  142. #define REG_ETOOBIG 19 /* regular expression is too complex */
  143. #define REG_ECOLORS 20 /* too many colors */
  144. #define REG_CANCEL 21 /* operation cancelled */
  145. /* two specials for debugging and testing */
  146. #define REG_ATOI 101 /* convert error-code name to number */
  147. #define REG_ITOA 102 /* convert error-code number to name */
  148. /* non-error result codes for pg_regprefix */
  149. #define REG_PREFIX (-1) /* identified a common prefix */
  150. #define REG_EXACT (-2) /* identified an exact match */
  151. /*
  152. * the prototypes for exported functions
  153. */
  154. /* regcomp.c */
  155. extern int pg_regcomp(regex_t *, const pg_wchar *, size_t, int, Oid);
  156. extern int pg_regexec(regex_t *, const pg_wchar *, size_t, size_t, rm_detail_t *, size_t, regmatch_t[], int);
  157. extern int pg_regprefix(regex_t *, pg_wchar **, size_t *);
  158. extern void pg_regfree(regex_t *);
  159. extern size_t pg_regerror(int, const regex_t *, char *, size_t);
  160. /* regexp.c */
  161. extern regex_t *RE_compile_and_cache(text *text_re, int cflags, Oid collation);
  162. extern bool RE_compile_and_execute(text *text_re, char *dat, int dat_len,
  163. int cflags, Oid collation,
  164. int nmatch, regmatch_t *pmatch);
  165. #endif /* _REGEX_H_ */