pcre.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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-2008 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. #define PCRE_MAJOR 7
  35. #define PCRE_MINOR 6
  36. #define PCRE_PRERELEASE
  37. #define PCRE_DATE 2008-01-28
  38. /* When an application links to a PCRE DLL in Windows, the symbols that are
  39. imported have to be identified as such. When building PCRE, the appropriate
  40. export setting is defined in pcre_internal.h, which includes this file. So we
  41. don't change existing definitions of PCRE_EXP_DECL and PCRECPP_EXP_DECL. */
  42. #if defined(_WIN32) && !defined(PCRE_STATIC)
  43. # ifndef PCRE_EXP_DECL
  44. # define PCRE_EXP_DECL extern __declspec(dllimport)
  45. # endif
  46. # ifdef __cplusplus
  47. # ifndef PCRECPP_EXP_DECL
  48. # define PCRECPP_EXP_DECL extern __declspec(dllimport)
  49. # endif
  50. # ifndef PCRECPP_EXP_DEFN
  51. # define PCRECPP_EXP_DEFN __declspec(dllimport)
  52. # endif
  53. # endif
  54. #endif
  55. /* By default, we use the standard "extern" declarations. */
  56. #ifndef PCRE_EXP_DECL
  57. # ifdef __cplusplus
  58. # define PCRE_EXP_DECL extern "C"
  59. # else
  60. # define PCRE_EXP_DECL extern
  61. # endif
  62. #endif
  63. #ifdef __cplusplus
  64. # ifndef PCRECPP_EXP_DECL
  65. # define PCRECPP_EXP_DECL extern
  66. # endif
  67. # ifndef PCRECPP_EXP_DEFN
  68. # define PCRECPP_EXP_DEFN
  69. # endif
  70. #endif
  71. /* Have to include stdlib.h in order to ensure that size_t is defined;
  72. it is needed here for malloc. */
  73. #include <stdlib.h>
  74. /* Allow for C++ users */
  75. #ifdef __cplusplus
  76. extern "C" {
  77. #endif
  78. /* Options */
  79. #define PCRE_CASELESS 0x00000001
  80. #define PCRE_MULTILINE 0x00000002
  81. #define PCRE_DOTALL 0x00000004
  82. #define PCRE_EXTENDED 0x00000008
  83. #define PCRE_ANCHORED 0x00000010
  84. #define PCRE_DOLLAR_ENDONLY 0x00000020
  85. #define PCRE_EXTRA 0x00000040
  86. #define PCRE_NOTBOL 0x00000080
  87. #define PCRE_NOTEOL 0x00000100
  88. #define PCRE_UNGREEDY 0x00000200
  89. #define PCRE_NOTEMPTY 0x00000400
  90. #define PCRE_UTF8 0x00000800
  91. #define PCRE_NO_AUTO_CAPTURE 0x00001000
  92. #define PCRE_NO_UTF8_CHECK 0x00002000
  93. #define PCRE_AUTO_CALLOUT 0x00004000
  94. #define PCRE_PARTIAL 0x00008000
  95. #define PCRE_DFA_SHORTEST 0x00010000
  96. #define PCRE_DFA_RESTART 0x00020000
  97. #define PCRE_FIRSTLINE 0x00040000
  98. #define PCRE_DUPNAMES 0x00080000
  99. #define PCRE_NEWLINE_CR 0x00100000
  100. #define PCRE_NEWLINE_LF 0x00200000
  101. #define PCRE_NEWLINE_CRLF 0x00300000
  102. #define PCRE_NEWLINE_ANY 0x00400000
  103. #define PCRE_NEWLINE_ANYCRLF 0x00500000
  104. #define PCRE_BSR_ANYCRLF 0x00800000
  105. #define PCRE_BSR_UNICODE 0x01000000
  106. /* Exec-time and get/set-time error codes */
  107. #define PCRE_ERROR_NOMATCH (-1)
  108. #define PCRE_ERROR_NULL (-2)
  109. #define PCRE_ERROR_BADOPTION (-3)
  110. #define PCRE_ERROR_BADMAGIC (-4)
  111. #define PCRE_ERROR_UNKNOWN_OPCODE (-5)
  112. #define PCRE_ERROR_UNKNOWN_NODE (-5) /* For backward compatibility */
  113. #define PCRE_ERROR_NOMEMORY (-6)
  114. #define PCRE_ERROR_NOSUBSTRING (-7)
  115. #define PCRE_ERROR_MATCHLIMIT (-8)
  116. #define PCRE_ERROR_CALLOUT (-9) /* Never used by PCRE itself */
  117. #define PCRE_ERROR_BADUTF8 (-10)
  118. #define PCRE_ERROR_BADUTF8_OFFSET (-11)
  119. #define PCRE_ERROR_PARTIAL (-12)
  120. #define PCRE_ERROR_BADPARTIAL (-13)
  121. #define PCRE_ERROR_INTERNAL (-14)
  122. #define PCRE_ERROR_BADCOUNT (-15)
  123. #define PCRE_ERROR_DFA_UITEM (-16)
  124. #define PCRE_ERROR_DFA_UCOND (-17)
  125. #define PCRE_ERROR_DFA_UMLIMIT (-18)
  126. #define PCRE_ERROR_DFA_WSSIZE (-19)
  127. #define PCRE_ERROR_DFA_RECURSE (-20)
  128. #define PCRE_ERROR_RECURSIONLIMIT (-21)
  129. #define PCRE_ERROR_NULLWSLIMIT (-22) /* No longer actually used */
  130. #define PCRE_ERROR_BADNEWLINE (-23)
  131. /* Request types for pcre_fullinfo() */
  132. #define PCRE_INFO_OPTIONS 0
  133. #define PCRE_INFO_SIZE 1
  134. #define PCRE_INFO_CAPTURECOUNT 2
  135. #define PCRE_INFO_BACKREFMAX 3
  136. #define PCRE_INFO_FIRSTBYTE 4
  137. #define PCRE_INFO_FIRSTCHAR 4 /* For backwards compatibility */
  138. #define PCRE_INFO_FIRSTTABLE 5
  139. #define PCRE_INFO_LASTLITERAL 6
  140. #define PCRE_INFO_NAMEENTRYSIZE 7
  141. #define PCRE_INFO_NAMECOUNT 8
  142. #define PCRE_INFO_NAMETABLE 9
  143. #define PCRE_INFO_STUDYSIZE 10
  144. #define PCRE_INFO_DEFAULT_TABLES 11
  145. #define PCRE_INFO_OKPARTIAL 12
  146. #define PCRE_INFO_JCHANGED 13
  147. #define PCRE_INFO_HASCRORLF 14
  148. /* Request types for pcre_config(). Do not re-arrange, in order to remain
  149. compatible. */
  150. #define PCRE_CONFIG_UTF8 0
  151. #define PCRE_CONFIG_NEWLINE 1
  152. #define PCRE_CONFIG_LINK_SIZE 2
  153. #define PCRE_CONFIG_POSIX_MALLOC_THRESHOLD 3
  154. #define PCRE_CONFIG_MATCH_LIMIT 4
  155. #define PCRE_CONFIG_STACKRECURSE 5
  156. #define PCRE_CONFIG_UNICODE_PROPERTIES 6
  157. #define PCRE_CONFIG_MATCH_LIMIT_RECURSION 7
  158. #define PCRE_CONFIG_BSR 8
  159. /* Bit flags for the pcre_extra structure. Do not re-arrange or redefine
  160. these bits, just add new ones on the end, in order to remain compatible. */
  161. #define PCRE_EXTRA_STUDY_DATA 0x0001
  162. #define PCRE_EXTRA_MATCH_LIMIT 0x0002
  163. #define PCRE_EXTRA_CALLOUT_DATA 0x0004
  164. #define PCRE_EXTRA_TABLES 0x0008
  165. #define PCRE_EXTRA_MATCH_LIMIT_RECURSION 0x0010
  166. /* Types */
  167. struct real_pcre; /* declaration; the definition is private */
  168. typedef struct real_pcre pcre;
  169. /* When PCRE is compiled as a C++ library, the subject pointer type can be
  170. replaced with a custom type. For conventional use, the public interface is a
  171. const char *. */
  172. #ifndef PCRE_SPTR
  173. #define PCRE_SPTR const char *
  174. #endif
  175. /* The structure for passing additional data to pcre_exec(). This is defined in
  176. such as way as to be extensible. Always add new fields at the end, in order to
  177. remain compatible. */
  178. typedef struct pcre_extra {
  179. unsigned long int flags; /* Bits for which fields are set */
  180. void *study_data; /* Opaque data from pcre_study() */
  181. unsigned long int match_limit; /* Maximum number of calls to match() */
  182. void *callout_data; /* Data passed back in callouts */
  183. const unsigned char *tables; /* Pointer to character tables */
  184. unsigned long int match_limit_recursion; /* Max recursive calls to match() */
  185. } pcre_extra;
  186. /* The structure for passing out data via the pcre_callout_function. We use a
  187. structure so that new fields can be added on the end in future versions,
  188. without changing the API of the function, thereby allowing old clients to work
  189. without modification. */
  190. typedef struct pcre_callout_block {
  191. int version; /* Identifies version of block */
  192. /* ------------------------ Version 0 ------------------------------- */
  193. int callout_number; /* Number compiled into pattern */
  194. int *offset_vector; /* The offset vector */
  195. PCRE_SPTR subject; /* The subject being matched */
  196. int subject_length; /* The length of the subject */
  197. int start_match; /* Offset to start of this match attempt */
  198. int current_position; /* Where we currently are in the subject */
  199. int capture_top; /* Max current capture */
  200. int capture_last; /* Most recently closed capture */
  201. void *callout_data; /* Data passed in with the call */
  202. /* ------------------- Added for Version 1 -------------------------- */
  203. int pattern_position; /* Offset to next item in the pattern */
  204. int next_item_length; /* Length of next item in the pattern */
  205. /* ------------------------------------------------------------------ */
  206. } pcre_callout_block;
  207. /* Indirection for store get and free functions. These can be set to
  208. alternative malloc/free functions if required. Special ones are used in the
  209. non-recursive case for "frames". There is also an optional callout function
  210. that is triggered by the (?) regex item. For Virtual Pascal, these definitions
  211. have to take another form. */
  212. #ifndef VPCOMPAT
  213. PCRE_EXP_DECL void *(*pcre_malloc)(size_t);
  214. PCRE_EXP_DECL void (*pcre_free)(void *);
  215. PCRE_EXP_DECL void *(*pcre_stack_malloc)(size_t);
  216. PCRE_EXP_DECL void (*pcre_stack_free)(void *);
  217. PCRE_EXP_DECL int (*pcre_callout)(pcre_callout_block *);
  218. #else /* VPCOMPAT */
  219. PCRE_EXP_DECL void *pcre_malloc(size_t);
  220. PCRE_EXP_DECL void pcre_free(void *);
  221. PCRE_EXP_DECL void *pcre_stack_malloc(size_t);
  222. PCRE_EXP_DECL void pcre_stack_free(void *);
  223. PCRE_EXP_DECL int pcre_callout(pcre_callout_block *);
  224. #endif /* VPCOMPAT */
  225. /* Exported PCRE functions */
  226. PCRE_EXP_DECL pcre *pcre_compile(const char *, int, const char **, int *,
  227. const unsigned char *);
  228. PCRE_EXP_DECL pcre *pcre_compile2(const char *, int, int *, const char **,
  229. int *, const unsigned char *);
  230. PCRE_EXP_DECL int pcre_config(int, void *);
  231. PCRE_EXP_DECL int pcre_copy_named_substring(const pcre *, const char *,
  232. int *, int, const char *, char *, int);
  233. PCRE_EXP_DECL int pcre_copy_substring(const char *, int *, int, int, char *,
  234. int);
  235. PCRE_EXP_DECL int pcre_dfa_exec(const pcre *, const pcre_extra *,
  236. const char *, int, int, int, int *, int , int *, int);
  237. PCRE_EXP_DECL int pcre_exec(const pcre *, const pcre_extra *, PCRE_SPTR,
  238. int, int, int, int *, int);
  239. PCRE_EXP_DECL void pcre_free_substring(const char *);
  240. PCRE_EXP_DECL void pcre_free_substring_list(const char **);
  241. PCRE_EXP_DECL int pcre_fullinfo(const pcre *, const pcre_extra *, int,
  242. void *);
  243. PCRE_EXP_DECL int pcre_get_named_substring(const pcre *, const char *,
  244. int *, int, const char *, const char **);
  245. PCRE_EXP_DECL int pcre_get_stringnumber(const pcre *, const char *);
  246. PCRE_EXP_DECL int pcre_get_stringtable_entries(const pcre *, const char *,
  247. char **, char **);
  248. PCRE_EXP_DECL int pcre_get_substring(const char *, int *, int, int,
  249. const char **);
  250. PCRE_EXP_DECL int pcre_get_substring_list(const char *, int *, int,
  251. const char ***);
  252. PCRE_EXP_DECL int pcre_info(const pcre *, int *, int *);
  253. PCRE_EXP_DECL const unsigned char *pcre_maketables(void);
  254. PCRE_EXP_DECL int pcre_refcount(pcre *, int);
  255. PCRE_EXP_DECL pcre_extra *pcre_study(const pcre *, int, const char **);
  256. PCRE_EXP_DECL const char *pcre_version(void);
  257. #ifdef __cplusplus
  258. } /* extern "C" */
  259. #endif
  260. #endif /* End of pcre.h */