pcre.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*************************************************
  2. * Perl-Compatible Regular Expressions *
  3. *************************************************/
  4. /* This is the public header file for the PCRE library, to be #included by
  5. applications that call the PCRE functions.
  6. Copyright (c) 1997-2006 University of Cambridge
  7. -----------------------------------------------------------------------------
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions are met:
  10. * Redistributions of source code must retain the above copyright notice,
  11. this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. * Neither the name of the University of Cambridge nor the names of its
  16. contributors may be used to endorse or promote products derived from
  17. this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. POSSIBILITY OF SUCH DAMAGE.
  29. -----------------------------------------------------------------------------
  30. */
  31. #ifndef _PCRE_H
  32. #define _PCRE_H
  33. /* The current PCRE version information. */
  34. /* NOTES FOR FUTURE MAINTAINERS: Do not use numbers with leading zeros, because
  35. they may be treated as octal constants. The PCRE_PRERELEASE feature is for
  36. identifying release candidates. It might be defined as -RC2, for example. In
  37. real releases, it should be defined empty. Do not change the alignment of these
  38. statments. The code in ./configure greps out the version numbers by using "cut"
  39. to get values from column 29 onwards. These are substituted into pcre-config
  40. and libpcre.pc. The values are not put into configure.ac and substituted here
  41. (which would simplify this issue) because that makes life harder for those who
  42. cannot run ./configure. As it now stands, this file need not be edited in that
  43. circumstance. */
  44. #define PCRE_MAJOR 7
  45. #define PCRE_MINOR 0
  46. #define PCRE_PRERELEASE
  47. #define PCRE_DATE 18-Dec-2006
  48. /* Win32 uses DLL by default; it needs special stuff for exported functions
  49. when building PCRE. */
  50. #ifdef _WIN32
  51. # ifdef PCRE_DEFINITION
  52. # ifdef DLL_EXPORT
  53. # define PCRE_DATA_SCOPE __declspec(dllexport)
  54. # endif
  55. # else
  56. # ifndef PCRE_STATIC
  57. # define PCRE_DATA_SCOPE extern __declspec(dllimport)
  58. # endif
  59. # endif
  60. #endif
  61. /* Otherwise, we use the standard "extern". */
  62. #ifndef PCRE_DATA_SCOPE
  63. # ifdef __cplusplus
  64. # define PCRE_DATA_SCOPE extern "C"
  65. # else
  66. # define PCRE_DATA_SCOPE extern
  67. # endif
  68. #endif
  69. /* Have to include stdlib.h in order to ensure that size_t is defined;
  70. it is needed here for malloc. */
  71. #include <stdlib.h>
  72. /* Allow for C++ users */
  73. #ifdef __cplusplus
  74. extern "C" {
  75. #endif
  76. /* Options */
  77. #define PCRE_CASELESS 0x00000001
  78. #define PCRE_MULTILINE 0x00000002
  79. #define PCRE_DOTALL 0x00000004
  80. #define PCRE_EXTENDED 0x00000008
  81. #define PCRE_ANCHORED 0x00000010
  82. #define PCRE_DOLLAR_ENDONLY 0x00000020
  83. #define PCRE_EXTRA 0x00000040
  84. #define PCRE_NOTBOL 0x00000080
  85. #define PCRE_NOTEOL 0x00000100
  86. #define PCRE_UNGREEDY 0x00000200
  87. #define PCRE_NOTEMPTY 0x00000400
  88. #define PCRE_UTF8 0x00000800
  89. #define PCRE_NO_AUTO_CAPTURE 0x00001000
  90. #define PCRE_NO_UTF8_CHECK 0x00002000
  91. #define PCRE_AUTO_CALLOUT 0x00004000
  92. #define PCRE_PARTIAL 0x00008000
  93. #define PCRE_DFA_SHORTEST 0x00010000
  94. #define PCRE_DFA_RESTART 0x00020000
  95. #define PCRE_FIRSTLINE 0x00040000
  96. #define PCRE_DUPNAMES 0x00080000
  97. #define PCRE_NEWLINE_CR 0x00100000
  98. #define PCRE_NEWLINE_LF 0x00200000
  99. #define PCRE_NEWLINE_CRLF 0x00300000
  100. #define PCRE_NEWLINE_ANY 0x00400000
  101. /* Exec-time and get/set-time error codes */
  102. #define PCRE_ERROR_NOMATCH (-1)
  103. #define PCRE_ERROR_NULL (-2)
  104. #define PCRE_ERROR_BADOPTION (-3)
  105. #define PCRE_ERROR_BADMAGIC (-4)
  106. #define PCRE_ERROR_UNKNOWN_OPCODE (-5)
  107. #define PCRE_ERROR_UNKNOWN_NODE (-5) /* For backward compatibility */
  108. #define PCRE_ERROR_NOMEMORY (-6)
  109. #define PCRE_ERROR_NOSUBSTRING (-7)
  110. #define PCRE_ERROR_MATCHLIMIT (-8)
  111. #define PCRE_ERROR_CALLOUT (-9) /* Never used by PCRE itself */
  112. #define PCRE_ERROR_BADUTF8 (-10)
  113. #define PCRE_ERROR_BADUTF8_OFFSET (-11)
  114. #define PCRE_ERROR_PARTIAL (-12)
  115. #define PCRE_ERROR_BADPARTIAL (-13)
  116. #define PCRE_ERROR_INTERNAL (-14)
  117. #define PCRE_ERROR_BADCOUNT (-15)
  118. #define PCRE_ERROR_DFA_UITEM (-16)
  119. #define PCRE_ERROR_DFA_UCOND (-17)
  120. #define PCRE_ERROR_DFA_UMLIMIT (-18)
  121. #define PCRE_ERROR_DFA_WSSIZE (-19)
  122. #define PCRE_ERROR_DFA_RECURSE (-20)
  123. #define PCRE_ERROR_RECURSIONLIMIT (-21)
  124. #define PCRE_ERROR_NULLWSLIMIT (-22)
  125. #define PCRE_ERROR_BADNEWLINE (-23)
  126. /* Request types for pcre_fullinfo() */
  127. #define PCRE_INFO_OPTIONS 0
  128. #define PCRE_INFO_SIZE 1
  129. #define PCRE_INFO_CAPTURECOUNT 2
  130. #define PCRE_INFO_BACKREFMAX 3
  131. #define PCRE_INFO_FIRSTBYTE 4
  132. #define PCRE_INFO_FIRSTCHAR 4 /* For backwards compatibility */
  133. #define PCRE_INFO_FIRSTTABLE 5
  134. #define PCRE_INFO_LASTLITERAL 6
  135. #define PCRE_INFO_NAMEENTRYSIZE 7
  136. #define PCRE_INFO_NAMECOUNT 8
  137. #define PCRE_INFO_NAMETABLE 9
  138. #define PCRE_INFO_STUDYSIZE 10
  139. #define PCRE_INFO_DEFAULT_TABLES 11
  140. /* Request types for pcre_config(). Do not re-arrange, in order to remain
  141. compatible. */
  142. #define PCRE_CONFIG_UTF8 0
  143. #define PCRE_CONFIG_NEWLINE 1
  144. #define PCRE_CONFIG_LINK_SIZE 2
  145. #define PCRE_CONFIG_POSIX_MALLOC_THRESHOLD 3
  146. #define PCRE_CONFIG_MATCH_LIMIT 4
  147. #define PCRE_CONFIG_STACKRECURSE 5
  148. #define PCRE_CONFIG_UNICODE_PROPERTIES 6
  149. #define PCRE_CONFIG_MATCH_LIMIT_RECURSION 7
  150. /* Bit flags for the pcre_extra structure. Do not re-arrange or redefine
  151. these bits, just add new ones on the end, in order to remain compatible. */
  152. #define PCRE_EXTRA_STUDY_DATA 0x0001
  153. #define PCRE_EXTRA_MATCH_LIMIT 0x0002
  154. #define PCRE_EXTRA_CALLOUT_DATA 0x0004
  155. #define PCRE_EXTRA_TABLES 0x0008
  156. #define PCRE_EXTRA_MATCH_LIMIT_RECURSION 0x0010
  157. /* Types */
  158. struct real_pcre; /* declaration; the definition is private */
  159. typedef struct real_pcre pcre;
  160. /* When PCRE is compiled as a C++ library, the subject pointer type can be
  161. replaced with a custom type. For conventional use, the public interface is a
  162. const char *. */
  163. #ifndef PCRE_SPTR
  164. #define PCRE_SPTR const char *
  165. #endif
  166. /* The structure for passing additional data to pcre_exec(). This is defined in
  167. such as way as to be extensible. Always add new fields at the end, in order to
  168. remain compatible. */
  169. typedef struct pcre_extra {
  170. unsigned long int flags; /* Bits for which fields are set */
  171. void *study_data; /* Opaque data from pcre_study() */
  172. unsigned long int match_limit; /* Maximum number of calls to match() */
  173. void *callout_data; /* Data passed back in callouts */
  174. const unsigned char *tables; /* Pointer to character tables */
  175. unsigned long int match_limit_recursion; /* Max recursive calls to match() */
  176. } pcre_extra;
  177. /* The structure for passing out data via the pcre_callout_function. We use a
  178. structure so that new fields can be added on the end in future versions,
  179. without changing the API of the function, thereby allowing old clients to work
  180. without modification. */
  181. typedef struct pcre_callout_block {
  182. int version; /* Identifies version of block */
  183. /* ------------------------ Version 0 ------------------------------- */
  184. int callout_number; /* Number compiled into pattern */
  185. int *offset_vector; /* The offset vector */
  186. PCRE_SPTR subject; /* The subject being matched */
  187. int subject_length; /* The length of the subject */
  188. int start_match; /* Offset to start of this match attempt */
  189. int current_position; /* Where we currently are in the subject */
  190. int capture_top; /* Max current capture */
  191. int capture_last; /* Most recently closed capture */
  192. void *callout_data; /* Data passed in with the call */
  193. /* ------------------- Added for Version 1 -------------------------- */
  194. int pattern_position; /* Offset to next item in the pattern */
  195. int next_item_length; /* Length of next item in the pattern */
  196. /* ------------------------------------------------------------------ */
  197. } pcre_callout_block;
  198. /* Indirection for store get and free functions. These can be set to
  199. alternative malloc/free functions if required. Special ones are used in the
  200. non-recursive case for "frames". There is also an optional callout function
  201. that is triggered by the (?) regex item. For Virtual Pascal, these definitions
  202. have to take another form. */
  203. #ifndef VPCOMPAT
  204. PCRE_DATA_SCOPE void *(*pcre_malloc)(size_t);
  205. PCRE_DATA_SCOPE void (*pcre_free)(void *);
  206. PCRE_DATA_SCOPE void *(*pcre_stack_malloc)(size_t);
  207. PCRE_DATA_SCOPE void (*pcre_stack_free)(void *);
  208. PCRE_DATA_SCOPE int (*pcre_callout)(pcre_callout_block *);
  209. #else /* VPCOMPAT */
  210. PCRE_DATA_SCOPE void *pcre_malloc(size_t);
  211. PCRE_DATA_SCOPE void pcre_free(void *);
  212. PCRE_DATA_SCOPE void *pcre_stack_malloc(size_t);
  213. PCRE_DATA_SCOPE void pcre_stack_free(void *);
  214. PCRE_DATA_SCOPE int pcre_callout(pcre_callout_block *);
  215. #endif /* VPCOMPAT */
  216. /* Exported PCRE functions */
  217. PCRE_DATA_SCOPE pcre *pcre_compile(const char *, int, const char **, int *,
  218. const unsigned char *);
  219. PCRE_DATA_SCOPE pcre *pcre_compile2(const char *, int, int *, const char **,
  220. int *, const unsigned char *);
  221. PCRE_DATA_SCOPE int pcre_config(int, void *);
  222. PCRE_DATA_SCOPE int pcre_copy_named_substring(const pcre *, const char *,
  223. int *, int, const char *, char *, int);
  224. PCRE_DATA_SCOPE int pcre_copy_substring(const char *, int *, int, int, char *,
  225. int);
  226. PCRE_DATA_SCOPE int pcre_dfa_exec(const pcre *, const pcre_extra *,
  227. const char *, int, int, int, int *, int , int *, int);
  228. PCRE_DATA_SCOPE int pcre_exec(const pcre *, const pcre_extra *, PCRE_SPTR,
  229. int, int, int, int *, int);
  230. PCRE_DATA_SCOPE void pcre_free_substring(const char *);
  231. PCRE_DATA_SCOPE void pcre_free_substring_list(const char **);
  232. PCRE_DATA_SCOPE int pcre_fullinfo(const pcre *, const pcre_extra *, int,
  233. void *);
  234. PCRE_DATA_SCOPE int pcre_get_named_substring(const pcre *, const char *,
  235. int *, int, const char *, const char **);
  236. PCRE_DATA_SCOPE int pcre_get_stringnumber(const pcre *, const char *);
  237. PCRE_DATA_SCOPE int pcre_get_stringtable_entries(const pcre *, const char *,
  238. char **, char **);
  239. PCRE_DATA_SCOPE int pcre_get_substring(const char *, int *, int, int,
  240. const char **);
  241. PCRE_DATA_SCOPE int pcre_get_substring_list(const char *, int *, int,
  242. const char ***);
  243. PCRE_DATA_SCOPE int pcre_info(const pcre *, int *, int *);
  244. PCRE_DATA_SCOPE const unsigned char *pcre_maketables(void);
  245. PCRE_DATA_SCOPE int pcre_refcount(pcre *, int);
  246. PCRE_DATA_SCOPE pcre_extra *pcre_study(const pcre *, int, const char **);
  247. PCRE_DATA_SCOPE const char *pcre_version(void);
  248. #ifdef __cplusplus
  249. } /* extern "C" */
  250. #endif
  251. #endif /* End of pcre.h */