pcre.h 13 KB

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