pcre_internal.h 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807
  1. /*************************************************
  2. * Perl-Compatible Regular Expressions *
  3. *************************************************/
  4. /* PCRE is a library of functions to support regular expressions whose syntax
  5. and semantics are as close as possible to those of the Perl 5 language.
  6. Written by Philip Hazel
  7. Copyright (c) 1997-2016 University of Cambridge
  8. -----------------------------------------------------------------------------
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. * Neither the name of the University of Cambridge nor the names of its
  17. contributors may be used to endorse or promote products derived from
  18. this software without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. POSSIBILITY OF SUCH DAMAGE.
  30. -----------------------------------------------------------------------------
  31. */
  32. /* This header contains definitions that are shared between the different
  33. modules, but which are not relevant to the exported API. This includes some
  34. functions whose names all begin with "_pcre_", "_pcre16_" or "_pcre32_"
  35. depending on the PRIV macro. */
  36. #ifndef PCRE_INTERNAL_H
  37. #define PCRE_INTERNAL_H
  38. /* Define PCRE_DEBUG to get debugging output on stdout. */
  39. #if 0
  40. #define PCRE_DEBUG
  41. #endif
  42. /* PCRE is compiled as an 8 bit library if it is not requested otherwise. */
  43. #if !defined COMPILE_PCRE16 && !defined COMPILE_PCRE32
  44. #define COMPILE_PCRE8
  45. #endif
  46. /* If SUPPORT_UCP is defined, SUPPORT_UTF must also be defined. The
  47. "configure" script ensures this, but not everybody uses "configure". */
  48. #if defined SUPPORT_UCP && !(defined SUPPORT_UTF)
  49. #define SUPPORT_UTF 1
  50. #endif
  51. /* We define SUPPORT_UTF if SUPPORT_UTF8 is enabled for compatibility
  52. reasons with existing code. */
  53. #if defined SUPPORT_UTF8 && !(defined SUPPORT_UTF)
  54. #define SUPPORT_UTF 1
  55. #endif
  56. /* Fixme: SUPPORT_UTF8 should be eventually disappear from the code.
  57. Until then we define it if SUPPORT_UTF is defined. */
  58. #if defined SUPPORT_UTF && !(defined SUPPORT_UTF8)
  59. #define SUPPORT_UTF8 1
  60. #endif
  61. /* We do not support both EBCDIC and UTF-8/16/32 at the same time. The "configure"
  62. script prevents both being selected, but not everybody uses "configure". */
  63. #if defined EBCDIC && defined SUPPORT_UTF
  64. #error The use of both EBCDIC and SUPPORT_UTF is not supported.
  65. #endif
  66. /* Use a macro for debugging printing, 'cause that eliminates the use of #ifdef
  67. inline, and there are *still* stupid compilers about that don't like indented
  68. pre-processor statements, or at least there were when I first wrote this. After
  69. all, it had only been about 10 years then...
  70. It turns out that the Mac Debugging.h header also defines the macro DPRINTF, so
  71. be absolutely sure we get our version. */
  72. #undef DPRINTF
  73. #ifdef PCRE_DEBUG
  74. #define DPRINTF(p) printf p
  75. #else
  76. #define DPRINTF(p) /* Nothing */
  77. #endif
  78. /* Standard C headers plus the external interface definition. The only time
  79. setjmp and stdarg are used is when NO_RECURSE is set. */
  80. #include <ctype.h>
  81. #include <limits.h>
  82. #include <stddef.h>
  83. #include <stdio.h>
  84. #include <stdlib.h>
  85. #include <string.h>
  86. /* Valgrind (memcheck) support */
  87. #ifdef SUPPORT_VALGRIND
  88. #include <valgrind/memcheck.h>
  89. #endif
  90. /* When compiling a DLL for Windows, the exported symbols have to be declared
  91. using some MS magic. I found some useful information on this web page:
  92. http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the
  93. information there, using __declspec(dllexport) without "extern" we have a
  94. definition; with "extern" we have a declaration. The settings here override the
  95. setting in pcre.h (which is included below); it defines only PCRE_EXP_DECL,
  96. which is all that is needed for applications (they just import the symbols). We
  97. use:
  98. PCRE_EXP_DECL for declarations
  99. PCRE_EXP_DEFN for definitions of exported functions
  100. PCRE_EXP_DATA_DEFN for definitions of exported variables
  101. The reason for the two DEFN macros is that in non-Windows environments, one
  102. does not want to have "extern" before variable definitions because it leads to
  103. compiler warnings. So we distinguish between functions and variables. In
  104. Windows, the two should always be the same.
  105. The reason for wrapping this in #ifndef PCRE_EXP_DECL is so that pcretest,
  106. which is an application, but needs to import this file in order to "peek" at
  107. internals, can #include pcre.h first to get an application's-eye view.
  108. In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon,
  109. special-purpose environments) might want to stick other stuff in front of
  110. exported symbols. That's why, in the non-Windows case, we set PCRE_EXP_DEFN and
  111. PCRE_EXP_DATA_DEFN only if they are not already set. */
  112. #ifndef PCRE_EXP_DECL
  113. # ifdef _WIN32
  114. # ifndef PCRE_STATIC
  115. # define PCRE_EXP_DECL extern __declspec(dllexport)
  116. # define PCRE_EXP_DEFN __declspec(dllexport)
  117. # define PCRE_EXP_DATA_DEFN __declspec(dllexport)
  118. # else
  119. # define PCRE_EXP_DECL extern
  120. # define PCRE_EXP_DEFN
  121. # define PCRE_EXP_DATA_DEFN
  122. # endif
  123. # else
  124. # ifdef __cplusplus
  125. # define PCRE_EXP_DECL extern "C"
  126. # else
  127. # define PCRE_EXP_DECL extern
  128. # endif
  129. # ifndef PCRE_EXP_DEFN
  130. # define PCRE_EXP_DEFN PCRE_EXP_DECL
  131. # endif
  132. # ifndef PCRE_EXP_DATA_DEFN
  133. # define PCRE_EXP_DATA_DEFN
  134. # endif
  135. # endif
  136. #endif
  137. /* When compiling with the MSVC compiler, it is sometimes necessary to include
  138. a "calling convention" before exported function names. (This is secondhand
  139. information; I know nothing about MSVC myself). For example, something like
  140. void __cdecl function(....)
  141. might be needed. In order so make this easy, all the exported functions have
  142. PCRE_CALL_CONVENTION just before their names. It is rarely needed; if not
  143. set, we ensure here that it has no effect. */
  144. #ifndef PCRE_CALL_CONVENTION
  145. #define PCRE_CALL_CONVENTION
  146. #endif
  147. /* We need to have types that specify unsigned 8, 16 and 32-bit integers. We
  148. cannot determine these outside the compilation (e.g. by running a program as
  149. part of "configure") because PCRE is often cross-compiled for use on other
  150. systems. Instead we make use of the maximum sizes that are available at
  151. preprocessor time in standard C environments. */
  152. typedef unsigned char pcre_uint8;
  153. #if USHRT_MAX == 65535
  154. typedef unsigned short pcre_uint16;
  155. typedef short pcre_int16;
  156. #define PCRE_UINT16_MAX USHRT_MAX
  157. #define PCRE_INT16_MAX SHRT_MAX
  158. #elif UINT_MAX == 65535
  159. typedef unsigned int pcre_uint16;
  160. typedef int pcre_int16;
  161. #define PCRE_UINT16_MAX UINT_MAX
  162. #define PCRE_INT16_MAX INT_MAX
  163. #else
  164. #error Cannot determine a type for 16-bit integers
  165. #endif
  166. #if UINT_MAX == 4294967295U
  167. typedef unsigned int pcre_uint32;
  168. typedef int pcre_int32;
  169. #define PCRE_UINT32_MAX UINT_MAX
  170. #define PCRE_INT32_MAX INT_MAX
  171. #elif ULONG_MAX == 4294967295UL
  172. typedef unsigned long int pcre_uint32;
  173. typedef long int pcre_int32;
  174. #define PCRE_UINT32_MAX ULONG_MAX
  175. #define PCRE_INT32_MAX LONG_MAX
  176. #else
  177. #error Cannot determine a type for 32-bit integers
  178. #endif
  179. /* When checking for integer overflow in pcre_compile(), we need to handle
  180. large integers. If a 64-bit integer type is available, we can use that.
  181. Otherwise we have to cast to double, which of course requires floating point
  182. arithmetic. Handle this by defining a macro for the appropriate type. If
  183. stdint.h is available, include it; it may define INT64_MAX. Systems that do not
  184. have stdint.h (e.g. Solaris) may have inttypes.h. The macro int64_t may be set
  185. by "configure". */
  186. #if defined HAVE_STDINT_H
  187. #include <stdint.h>
  188. #elif defined HAVE_INTTYPES_H
  189. #include <inttypes.h>
  190. #endif
  191. #if defined INT64_MAX || defined int64_t
  192. #define INT64_OR_DOUBLE int64_t
  193. #else
  194. #define INT64_OR_DOUBLE double
  195. #endif
  196. /* All character handling must be done as unsigned characters. Otherwise there
  197. are problems with top-bit-set characters and functions such as isspace().
  198. However, we leave the interface to the outside world as char * or short *,
  199. because that should make things easier for callers. This character type is
  200. called pcre_uchar.
  201. The IN_UCHARS macro multiply its argument with the byte size of the current
  202. pcre_uchar type. Useful for memcpy and such operations, whose require the
  203. byte size of their input/output buffers.
  204. The MAX_255 macro checks whether its pcre_uchar input is less than 256.
  205. The TABLE_GET macro is designed for accessing elements of tables whose contain
  206. exactly 256 items. When the character is able to contain more than 256
  207. items, some check is needed before accessing these tables.
  208. */
  209. #if defined COMPILE_PCRE8
  210. typedef unsigned char pcre_uchar;
  211. #define IN_UCHARS(x) (x)
  212. #define MAX_255(c) 1
  213. #define TABLE_GET(c, table, default) ((table)[c])
  214. #elif defined COMPILE_PCRE16
  215. #if USHRT_MAX != 65535
  216. /* This is a warning message. Change PCRE_UCHAR16 to a 16 bit data type in
  217. pcre.h(.in) and disable (comment out) this message. */
  218. #error Warning: PCRE_UCHAR16 is not a 16 bit data type.
  219. #endif
  220. typedef pcre_uint16 pcre_uchar;
  221. #define UCHAR_SHIFT (1)
  222. #define IN_UCHARS(x) ((x) * 2)
  223. #define MAX_255(c) ((c) <= 255u)
  224. #define TABLE_GET(c, table, default) (MAX_255(c)? ((table)[c]):(default))
  225. #elif defined COMPILE_PCRE32
  226. typedef pcre_uint32 pcre_uchar;
  227. #define UCHAR_SHIFT (2)
  228. #define IN_UCHARS(x) ((x) * 4)
  229. #define MAX_255(c) ((c) <= 255u)
  230. #define TABLE_GET(c, table, default) (MAX_255(c)? ((table)[c]):(default))
  231. #else
  232. #error Unsupported compiling mode
  233. #endif /* COMPILE_PCRE[8|16|32] */
  234. /* This is an unsigned int value that no character can ever have. UTF-8
  235. characters only go up to 0x7fffffff (though Unicode doesn't go beyond
  236. 0x0010ffff). */
  237. #define NOTACHAR 0xffffffff
  238. /* PCRE is able to support several different kinds of newline (CR, LF, CRLF,
  239. "any" and "anycrlf" at present). The following macros are used to package up
  240. testing for newlines. NLBLOCK, PSSTART, and PSEND are defined in the various
  241. modules to indicate in which datablock the parameters exist, and what the
  242. start/end of string field names are. */
  243. #define NLTYPE_FIXED 0 /* Newline is a fixed length string */
  244. #define NLTYPE_ANY 1 /* Newline is any Unicode line ending */
  245. #define NLTYPE_ANYCRLF 2 /* Newline is CR, LF, or CRLF */
  246. /* This macro checks for a newline at the given position */
  247. #define IS_NEWLINE(p) \
  248. ((NLBLOCK->nltype != NLTYPE_FIXED)? \
  249. ((p) < NLBLOCK->PSEND && \
  250. PRIV(is_newline)((p), NLBLOCK->nltype, NLBLOCK->PSEND, \
  251. &(NLBLOCK->nllen), utf)) \
  252. : \
  253. ((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \
  254. UCHAR21TEST(p) == NLBLOCK->nl[0] && \
  255. (NLBLOCK->nllen == 1 || UCHAR21TEST(p+1) == NLBLOCK->nl[1]) \
  256. ) \
  257. )
  258. /* This macro checks for a newline immediately preceding the given position */
  259. #define WAS_NEWLINE(p) \
  260. ((NLBLOCK->nltype != NLTYPE_FIXED)? \
  261. ((p) > NLBLOCK->PSSTART && \
  262. PRIV(was_newline)((p), NLBLOCK->nltype, NLBLOCK->PSSTART, \
  263. &(NLBLOCK->nllen), utf)) \
  264. : \
  265. ((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \
  266. UCHAR21TEST(p - NLBLOCK->nllen) == NLBLOCK->nl[0] && \
  267. (NLBLOCK->nllen == 1 || UCHAR21TEST(p - NLBLOCK->nllen + 1) == NLBLOCK->nl[1]) \
  268. ) \
  269. )
  270. /* When PCRE is compiled as a C++ library, the subject pointer can be replaced
  271. with a custom type. This makes it possible, for example, to allow pcre_exec()
  272. to process subject strings that are discontinuous by using a smart pointer
  273. class. It must always be possible to inspect all of the subject string in
  274. pcre_exec() because of the way it backtracks. Two macros are required in the
  275. normal case, for sign-unspecified and unsigned char pointers. The former is
  276. used for the external interface and appears in pcre.h, which is why its name
  277. must begin with PCRE_. */
  278. #ifdef CUSTOM_SUBJECT_PTR
  279. #define PCRE_PUCHAR CUSTOM_SUBJECT_PTR
  280. #else
  281. #define PCRE_PUCHAR const pcre_uchar *
  282. #endif
  283. /* Include the public PCRE header and the definitions of UCP character property
  284. values. */
  285. #include "pcre.h"
  286. #include "ucp.h"
  287. #ifdef COMPILE_PCRE32
  288. /* Assert that the public PCRE_UCHAR32 is a 32-bit type */
  289. typedef int __assert_pcre_uchar32_size[sizeof(PCRE_UCHAR32) == 4 ? 1 : -1];
  290. #endif
  291. /* When compiling for use with the Virtual Pascal compiler, these functions
  292. need to have their names changed. PCRE must be compiled with the -DVPCOMPAT
  293. option on the command line. */
  294. #ifdef VPCOMPAT
  295. #define strlen(s) _strlen(s)
  296. #define strncmp(s1,s2,m) _strncmp(s1,s2,m)
  297. #define memcmp(s,c,n) _memcmp(s,c,n)
  298. #define memcpy(d,s,n) _memcpy(d,s,n)
  299. #define memmove(d,s,n) _memmove(d,s,n)
  300. #define memset(s,c,n) _memset(s,c,n)
  301. #else /* VPCOMPAT */
  302. /* To cope with SunOS4 and other systems that lack memmove() but have bcopy(),
  303. define a macro for memmove() if HAVE_MEMMOVE is false, provided that HAVE_BCOPY
  304. is set. Otherwise, include an emulating function for those systems that have
  305. neither (there some non-Unix environments where this is the case). */
  306. #ifndef HAVE_MEMMOVE
  307. #undef memmove /* some systems may have a macro */
  308. #ifdef HAVE_BCOPY
  309. #define memmove(a, b, c) bcopy(b, a, c)
  310. #else /* HAVE_BCOPY */
  311. static void *
  312. pcre_memmove(void *d, const void *s, size_t n)
  313. {
  314. size_t i;
  315. unsigned char *dest = (unsigned char *)d;
  316. const unsigned char *src = (const unsigned char *)s;
  317. if (dest > src)
  318. {
  319. dest += n;
  320. src += n;
  321. for (i = 0; i < n; ++i) *(--dest) = *(--src);
  322. return (void *)dest;
  323. }
  324. else
  325. {
  326. for (i = 0; i < n; ++i) *dest++ = *src++;
  327. return (void *)(dest - n);
  328. }
  329. }
  330. #define memmove(a, b, c) pcre_memmove(a, b, c)
  331. #endif /* not HAVE_BCOPY */
  332. #endif /* not HAVE_MEMMOVE */
  333. #endif /* not VPCOMPAT */
  334. /* PCRE keeps offsets in its compiled code as 2-byte quantities (always stored
  335. in big-endian order) by default. These are used, for example, to link from the
  336. start of a subpattern to its alternatives and its end. The use of 2 bytes per
  337. offset limits the size of the compiled regex to around 64K, which is big enough
  338. for almost everybody. However, I received a request for an even bigger limit.
  339. For this reason, and also to make the code easier to maintain, the storing and
  340. loading of offsets from the byte string is now handled by the macros that are
  341. defined here.
  342. The macros are controlled by the value of LINK_SIZE. This defaults to 2 in
  343. the config.h file, but can be overridden by using -D on the command line. This
  344. is automated on Unix systems via the "configure" command. */
  345. #if defined COMPILE_PCRE8
  346. #if LINK_SIZE == 2
  347. #define PUT(a,n,d) \
  348. (a[n] = (d) >> 8), \
  349. (a[(n)+1] = (d) & 255)
  350. #define GET(a,n) \
  351. (((a)[n] << 8) | (a)[(n)+1])
  352. #define MAX_PATTERN_SIZE (1 << 16)
  353. #elif LINK_SIZE == 3
  354. #define PUT(a,n,d) \
  355. (a[n] = (d) >> 16), \
  356. (a[(n)+1] = (d) >> 8), \
  357. (a[(n)+2] = (d) & 255)
  358. #define GET(a,n) \
  359. (((a)[n] << 16) | ((a)[(n)+1] << 8) | (a)[(n)+2])
  360. #define MAX_PATTERN_SIZE (1 << 24)
  361. #elif LINK_SIZE == 4
  362. #define PUT(a,n,d) \
  363. (a[n] = (d) >> 24), \
  364. (a[(n)+1] = (d) >> 16), \
  365. (a[(n)+2] = (d) >> 8), \
  366. (a[(n)+3] = (d) & 255)
  367. #define GET(a,n) \
  368. (((a)[n] << 24) | ((a)[(n)+1] << 16) | ((a)[(n)+2] << 8) | (a)[(n)+3])
  369. /* Keep it positive */
  370. #define MAX_PATTERN_SIZE (1 << 30)
  371. #else
  372. #error LINK_SIZE must be either 2, 3, or 4
  373. #endif
  374. #elif defined COMPILE_PCRE16
  375. #if LINK_SIZE == 2
  376. /* Redefine LINK_SIZE as a multiple of sizeof(pcre_uchar) */
  377. #undef LINK_SIZE
  378. #define LINK_SIZE 1
  379. #define PUT(a,n,d) \
  380. (a[n] = (d))
  381. #define GET(a,n) \
  382. (a[n])
  383. #define MAX_PATTERN_SIZE (1 << 16)
  384. #elif LINK_SIZE == 3 || LINK_SIZE == 4
  385. /* Redefine LINK_SIZE as a multiple of sizeof(pcre_uchar) */
  386. #undef LINK_SIZE
  387. #define LINK_SIZE 2
  388. #define PUT(a,n,d) \
  389. (a[n] = (d) >> 16), \
  390. (a[(n)+1] = (d) & 65535)
  391. #define GET(a,n) \
  392. (((a)[n] << 16) | (a)[(n)+1])
  393. /* Keep it positive */
  394. #define MAX_PATTERN_SIZE (1 << 30)
  395. #else
  396. #error LINK_SIZE must be either 2, 3, or 4
  397. #endif
  398. #elif defined COMPILE_PCRE32
  399. /* Only supported LINK_SIZE is 4 */
  400. /* Redefine LINK_SIZE as a multiple of sizeof(pcre_uchar) */
  401. #undef LINK_SIZE
  402. #define LINK_SIZE 1
  403. #define PUT(a,n,d) \
  404. (a[n] = (d))
  405. #define GET(a,n) \
  406. (a[n])
  407. /* Keep it positive */
  408. #define MAX_PATTERN_SIZE (1 << 30)
  409. #else
  410. #error Unsupported compiling mode
  411. #endif /* COMPILE_PCRE[8|16|32] */
  412. /* Convenience macro defined in terms of the others */
  413. #define PUTINC(a,n,d) PUT(a,n,d), a += LINK_SIZE
  414. /* PCRE uses some other 2-byte quantities that do not change when the size of
  415. offsets changes. There are used for repeat counts and for other things such as
  416. capturing parenthesis numbers in back references. */
  417. #if defined COMPILE_PCRE8
  418. #define IMM2_SIZE 2
  419. #define PUT2(a,n,d) \
  420. a[n] = (d) >> 8; \
  421. a[(n)+1] = (d) & 255
  422. /* For reasons that I do not understand, the expression in this GET2 macro is
  423. treated by gcc as a signed expression, even when a is declared as unsigned. It
  424. seems that any kind of arithmetic results in a signed value. */
  425. #define GET2(a,n) \
  426. (unsigned int)(((a)[n] << 8) | (a)[(n)+1])
  427. #elif defined COMPILE_PCRE16
  428. #define IMM2_SIZE 1
  429. #define PUT2(a,n,d) \
  430. a[n] = d
  431. #define GET2(a,n) \
  432. a[n]
  433. #elif defined COMPILE_PCRE32
  434. #define IMM2_SIZE 1
  435. #define PUT2(a,n,d) \
  436. a[n] = d
  437. #define GET2(a,n) \
  438. a[n]
  439. #else
  440. #error Unsupported compiling mode
  441. #endif /* COMPILE_PCRE[8|16|32] */
  442. #define PUT2INC(a,n,d) PUT2(a,n,d), a += IMM2_SIZE
  443. /* The maximum length of a MARK name is currently one data unit; it may be
  444. changed in future to be a fixed number of bytes or to depend on LINK_SIZE. */
  445. #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
  446. #define MAX_MARK ((1u << 16) - 1)
  447. #else
  448. #define MAX_MARK ((1u << 8) - 1)
  449. #endif
  450. /* There is a proposed future special "UTF-21" mode, in which only the lowest
  451. 21 bits of a 32-bit character are interpreted as UTF, with the remaining 11
  452. high-order bits available to the application for other uses. In preparation for
  453. the future implementation of this mode, there are macros that load a data item
  454. and, if in this special mode, mask it to 21 bits. These macros all have names
  455. starting with UCHAR21. In all other modes, including the normal 32-bit
  456. library, the macros all have the same simple definitions. When the new mode is
  457. implemented, it is expected that these definitions will be varied appropriately
  458. using #ifdef when compiling the library that supports the special mode. */
  459. #define UCHAR21(eptr) (*(eptr))
  460. #define UCHAR21TEST(eptr) (*(eptr))
  461. #define UCHAR21INC(eptr) (*(eptr)++)
  462. #define UCHAR21INCTEST(eptr) (*(eptr)++)
  463. /* When UTF encoding is being used, a character is no longer just a single
  464. byte in 8-bit mode or a single short in 16-bit mode. The macros for character
  465. handling generate simple sequences when used in the basic mode, and more
  466. complicated ones for UTF characters. GETCHARLENTEST and other macros are not
  467. used when UTF is not supported. To make sure they can never even appear when
  468. UTF support is omitted, we don't even define them. */
  469. #ifndef SUPPORT_UTF
  470. /* #define MAX_VALUE_FOR_SINGLE_CHAR */
  471. /* #define HAS_EXTRALEN(c) */
  472. /* #define GET_EXTRALEN(c) */
  473. /* #define NOT_FIRSTCHAR(c) */
  474. #define GETCHAR(c, eptr) c = *eptr;
  475. #define GETCHARTEST(c, eptr) c = *eptr;
  476. #define GETCHARINC(c, eptr) c = *eptr++;
  477. #define GETCHARINCTEST(c, eptr) c = *eptr++;
  478. #define GETCHARLEN(c, eptr, len) c = *eptr;
  479. /* #define GETCHARLENTEST(c, eptr, len) */
  480. /* #define BACKCHAR(eptr) */
  481. /* #define FORWARDCHAR(eptr) */
  482. /* #define ACROSSCHAR(condition, eptr, action) */
  483. #else /* SUPPORT_UTF */
  484. /* Tests whether the code point needs extra characters to decode. */
  485. #define HASUTF8EXTRALEN(c) ((c) >= 0xc0)
  486. /* Base macro to pick up the remaining bytes of a UTF-8 character, not
  487. advancing the pointer. */
  488. #define GETUTF8(c, eptr) \
  489. { \
  490. if ((c & 0x20) == 0) \
  491. c = ((c & 0x1f) << 6) | (eptr[1] & 0x3f); \
  492. else if ((c & 0x10) == 0) \
  493. c = ((c & 0x0f) << 12) | ((eptr[1] & 0x3f) << 6) | (eptr[2] & 0x3f); \
  494. else if ((c & 0x08) == 0) \
  495. c = ((c & 0x07) << 18) | ((eptr[1] & 0x3f) << 12) | \
  496. ((eptr[2] & 0x3f) << 6) | (eptr[3] & 0x3f); \
  497. else if ((c & 0x04) == 0) \
  498. c = ((c & 0x03) << 24) | ((eptr[1] & 0x3f) << 18) | \
  499. ((eptr[2] & 0x3f) << 12) | ((eptr[3] & 0x3f) << 6) | \
  500. (eptr[4] & 0x3f); \
  501. else \
  502. c = ((c & 0x01) << 30) | ((eptr[1] & 0x3f) << 24) | \
  503. ((eptr[2] & 0x3f) << 18) | ((eptr[3] & 0x3f) << 12) | \
  504. ((eptr[4] & 0x3f) << 6) | (eptr[5] & 0x3f); \
  505. }
  506. /* Base macro to pick up the remaining bytes of a UTF-8 character, advancing
  507. the pointer. */
  508. #define GETUTF8INC(c, eptr) \
  509. { \
  510. if ((c & 0x20) == 0) \
  511. c = ((c & 0x1f) << 6) | (*eptr++ & 0x3f); \
  512. else if ((c & 0x10) == 0) \
  513. { \
  514. c = ((c & 0x0f) << 12) | ((*eptr & 0x3f) << 6) | (eptr[1] & 0x3f); \
  515. eptr += 2; \
  516. } \
  517. else if ((c & 0x08) == 0) \
  518. { \
  519. c = ((c & 0x07) << 18) | ((*eptr & 0x3f) << 12) | \
  520. ((eptr[1] & 0x3f) << 6) | (eptr[2] & 0x3f); \
  521. eptr += 3; \
  522. } \
  523. else if ((c & 0x04) == 0) \
  524. { \
  525. c = ((c & 0x03) << 24) | ((*eptr & 0x3f) << 18) | \
  526. ((eptr[1] & 0x3f) << 12) | ((eptr[2] & 0x3f) << 6) | \
  527. (eptr[3] & 0x3f); \
  528. eptr += 4; \
  529. } \
  530. else \
  531. { \
  532. c = ((c & 0x01) << 30) | ((*eptr & 0x3f) << 24) | \
  533. ((eptr[1] & 0x3f) << 18) | ((eptr[2] & 0x3f) << 12) | \
  534. ((eptr[3] & 0x3f) << 6) | (eptr[4] & 0x3f); \
  535. eptr += 5; \
  536. } \
  537. }
  538. #if defined COMPILE_PCRE8
  539. /* These macros were originally written in the form of loops that used data
  540. from the tables whose names start with PRIV(utf8_table). They were rewritten by
  541. a user so as not to use loops, because in some environments this gives a
  542. significant performance advantage, and it seems never to do any harm. */
  543. /* Tells the biggest code point which can be encoded as a single character. */
  544. #define MAX_VALUE_FOR_SINGLE_CHAR 127
  545. /* Tests whether the code point needs extra characters to decode. */
  546. #define HAS_EXTRALEN(c) ((c) >= 0xc0)
  547. /* Returns with the additional number of characters if IS_MULTICHAR(c) is TRUE.
  548. Otherwise it has an undefined behaviour. */
  549. #define GET_EXTRALEN(c) (PRIV(utf8_table4)[(c) & 0x3f])
  550. /* Returns TRUE, if the given character is not the first character
  551. of a UTF sequence. */
  552. #define NOT_FIRSTCHAR(c) (((c) & 0xc0) == 0x80)
  553. /* Get the next UTF-8 character, not advancing the pointer. This is called when
  554. we know we are in UTF-8 mode. */
  555. #define GETCHAR(c, eptr) \
  556. c = *eptr; \
  557. if (c >= 0xc0) GETUTF8(c, eptr);
  558. /* Get the next UTF-8 character, testing for UTF-8 mode, and not advancing the
  559. pointer. */
  560. #define GETCHARTEST(c, eptr) \
  561. c = *eptr; \
  562. if (utf && c >= 0xc0) GETUTF8(c, eptr);
  563. /* Get the next UTF-8 character, advancing the pointer. This is called when we
  564. know we are in UTF-8 mode. */
  565. #define GETCHARINC(c, eptr) \
  566. c = *eptr++; \
  567. if (c >= 0xc0) GETUTF8INC(c, eptr);
  568. /* Get the next character, testing for UTF-8 mode, and advancing the pointer.
  569. This is called when we don't know if we are in UTF-8 mode. */
  570. #define GETCHARINCTEST(c, eptr) \
  571. c = *eptr++; \
  572. if (utf && c >= 0xc0) GETUTF8INC(c, eptr);
  573. /* Base macro to pick up the remaining bytes of a UTF-8 character, not
  574. advancing the pointer, incrementing the length. */
  575. #define GETUTF8LEN(c, eptr, len) \
  576. { \
  577. if ((c & 0x20) == 0) \
  578. { \
  579. c = ((c & 0x1f) << 6) | (eptr[1] & 0x3f); \
  580. len++; \
  581. } \
  582. else if ((c & 0x10) == 0) \
  583. { \
  584. c = ((c & 0x0f) << 12) | ((eptr[1] & 0x3f) << 6) | (eptr[2] & 0x3f); \
  585. len += 2; \
  586. } \
  587. else if ((c & 0x08) == 0) \
  588. {\
  589. c = ((c & 0x07) << 18) | ((eptr[1] & 0x3f) << 12) | \
  590. ((eptr[2] & 0x3f) << 6) | (eptr[3] & 0x3f); \
  591. len += 3; \
  592. } \
  593. else if ((c & 0x04) == 0) \
  594. { \
  595. c = ((c & 0x03) << 24) | ((eptr[1] & 0x3f) << 18) | \
  596. ((eptr[2] & 0x3f) << 12) | ((eptr[3] & 0x3f) << 6) | \
  597. (eptr[4] & 0x3f); \
  598. len += 4; \
  599. } \
  600. else \
  601. {\
  602. c = ((c & 0x01) << 30) | ((eptr[1] & 0x3f) << 24) | \
  603. ((eptr[2] & 0x3f) << 18) | ((eptr[3] & 0x3f) << 12) | \
  604. ((eptr[4] & 0x3f) << 6) | (eptr[5] & 0x3f); \
  605. len += 5; \
  606. } \
  607. }
  608. /* Get the next UTF-8 character, not advancing the pointer, incrementing length
  609. if there are extra bytes. This is called when we know we are in UTF-8 mode. */
  610. #define GETCHARLEN(c, eptr, len) \
  611. c = *eptr; \
  612. if (c >= 0xc0) GETUTF8LEN(c, eptr, len);
  613. /* Get the next UTF-8 character, testing for UTF-8 mode, not advancing the
  614. pointer, incrementing length if there are extra bytes. This is called when we
  615. do not know if we are in UTF-8 mode. */
  616. #define GETCHARLENTEST(c, eptr, len) \
  617. c = *eptr; \
  618. if (utf && c >= 0xc0) GETUTF8LEN(c, eptr, len);
  619. /* If the pointer is not at the start of a character, move it back until
  620. it is. This is called only in UTF-8 mode - we don't put a test within the macro
  621. because almost all calls are already within a block of UTF-8 only code. */
  622. #define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr--
  623. /* Same as above, just in the other direction. */
  624. #define FORWARDCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr++
  625. /* Same as above, but it allows a fully customizable form. */
  626. #define ACROSSCHAR(condition, eptr, action) \
  627. while((condition) && ((eptr) & 0xc0) == 0x80) action
  628. #elif defined COMPILE_PCRE16
  629. /* Tells the biggest code point which can be encoded as a single character. */
  630. #define MAX_VALUE_FOR_SINGLE_CHAR 65535
  631. /* Tests whether the code point needs extra characters to decode. */
  632. #define HAS_EXTRALEN(c) (((c) & 0xfc00) == 0xd800)
  633. /* Returns with the additional number of characters if IS_MULTICHAR(c) is TRUE.
  634. Otherwise it has an undefined behaviour. */
  635. #define GET_EXTRALEN(c) 1
  636. /* Returns TRUE, if the given character is not the first character
  637. of a UTF sequence. */
  638. #define NOT_FIRSTCHAR(c) (((c) & 0xfc00) == 0xdc00)
  639. /* Base macro to pick up the low surrogate of a UTF-16 character, not
  640. advancing the pointer. */
  641. #define GETUTF16(c, eptr) \
  642. { c = (((c & 0x3ff) << 10) | (eptr[1] & 0x3ff)) + 0x10000; }
  643. /* Get the next UTF-16 character, not advancing the pointer. This is called when
  644. we know we are in UTF-16 mode. */
  645. #define GETCHAR(c, eptr) \
  646. c = *eptr; \
  647. if ((c & 0xfc00) == 0xd800) GETUTF16(c, eptr);
  648. /* Get the next UTF-16 character, testing for UTF-16 mode, and not advancing the
  649. pointer. */
  650. #define GETCHARTEST(c, eptr) \
  651. c = *eptr; \
  652. if (utf && (c & 0xfc00) == 0xd800) GETUTF16(c, eptr);
  653. /* Base macro to pick up the low surrogate of a UTF-16 character, advancing
  654. the pointer. */
  655. #define GETUTF16INC(c, eptr) \
  656. { c = (((c & 0x3ff) << 10) | (*eptr++ & 0x3ff)) + 0x10000; }
  657. /* Get the next UTF-16 character, advancing the pointer. This is called when we
  658. know we are in UTF-16 mode. */
  659. #define GETCHARINC(c, eptr) \
  660. c = *eptr++; \
  661. if ((c & 0xfc00) == 0xd800) GETUTF16INC(c, eptr);
  662. /* Get the next character, testing for UTF-16 mode, and advancing the pointer.
  663. This is called when we don't know if we are in UTF-16 mode. */
  664. #define GETCHARINCTEST(c, eptr) \
  665. c = *eptr++; \
  666. if (utf && (c & 0xfc00) == 0xd800) GETUTF16INC(c, eptr);
  667. /* Base macro to pick up the low surrogate of a UTF-16 character, not
  668. advancing the pointer, incrementing the length. */
  669. #define GETUTF16LEN(c, eptr, len) \
  670. { c = (((c & 0x3ff) << 10) | (eptr[1] & 0x3ff)) + 0x10000; len++; }
  671. /* Get the next UTF-16 character, not advancing the pointer, incrementing
  672. length if there is a low surrogate. This is called when we know we are in
  673. UTF-16 mode. */
  674. #define GETCHARLEN(c, eptr, len) \
  675. c = *eptr; \
  676. if ((c & 0xfc00) == 0xd800) GETUTF16LEN(c, eptr, len);
  677. /* Get the next UTF-816character, testing for UTF-16 mode, not advancing the
  678. pointer, incrementing length if there is a low surrogate. This is called when
  679. we do not know if we are in UTF-16 mode. */
  680. #define GETCHARLENTEST(c, eptr, len) \
  681. c = *eptr; \
  682. if (utf && (c & 0xfc00) == 0xd800) GETUTF16LEN(c, eptr, len);
  683. /* If the pointer is not at the start of a character, move it back until
  684. it is. This is called only in UTF-16 mode - we don't put a test within the
  685. macro because almost all calls are already within a block of UTF-16 only
  686. code. */
  687. #define BACKCHAR(eptr) if ((*eptr & 0xfc00) == 0xdc00) eptr--
  688. /* Same as above, just in the other direction. */
  689. #define FORWARDCHAR(eptr) if ((*eptr & 0xfc00) == 0xdc00) eptr++
  690. /* Same as above, but it allows a fully customizable form. */
  691. #define ACROSSCHAR(condition, eptr, action) \
  692. if ((condition) && ((eptr) & 0xfc00) == 0xdc00) action
  693. #elif defined COMPILE_PCRE32
  694. /* These are trivial for the 32-bit library, since all UTF-32 characters fit
  695. into one pcre_uchar unit. */
  696. #define MAX_VALUE_FOR_SINGLE_CHAR (0x10ffffu)
  697. #define HAS_EXTRALEN(c) (0)
  698. #define GET_EXTRALEN(c) (0)
  699. #define NOT_FIRSTCHAR(c) (0)
  700. /* Get the next UTF-32 character, not advancing the pointer. This is called when
  701. we know we are in UTF-32 mode. */
  702. #define GETCHAR(c, eptr) \
  703. c = *(eptr);
  704. /* Get the next UTF-32 character, testing for UTF-32 mode, and not advancing the
  705. pointer. */
  706. #define GETCHARTEST(c, eptr) \
  707. c = *(eptr);
  708. /* Get the next UTF-32 character, advancing the pointer. This is called when we
  709. know we are in UTF-32 mode. */
  710. #define GETCHARINC(c, eptr) \
  711. c = *((eptr)++);
  712. /* Get the next character, testing for UTF-32 mode, and advancing the pointer.
  713. This is called when we don't know if we are in UTF-32 mode. */
  714. #define GETCHARINCTEST(c, eptr) \
  715. c = *((eptr)++);
  716. /* Get the next UTF-32 character, not advancing the pointer, not incrementing
  717. length (since all UTF-32 is of length 1). This is called when we know we are in
  718. UTF-32 mode. */
  719. #define GETCHARLEN(c, eptr, len) \
  720. GETCHAR(c, eptr)
  721. /* Get the next UTF-32character, testing for UTF-32 mode, not advancing the
  722. pointer, not incrementing the length (since all UTF-32 is of length 1).
  723. This is called when we do not know if we are in UTF-32 mode. */
  724. #define GETCHARLENTEST(c, eptr, len) \
  725. GETCHARTEST(c, eptr)
  726. /* If the pointer is not at the start of a character, move it back until
  727. it is. This is called only in UTF-32 mode - we don't put a test within the
  728. macro because almost all calls are already within a block of UTF-32 only
  729. code.
  730. These are all no-ops since all UTF-32 characters fit into one pcre_uchar. */
  731. #define BACKCHAR(eptr) do { } while (0)
  732. /* Same as above, just in the other direction. */
  733. #define FORWARDCHAR(eptr) do { } while (0)
  734. /* Same as above, but it allows a fully customizable form. */
  735. #define ACROSSCHAR(condition, eptr, action) do { } while (0)
  736. #else
  737. #error Unsupported compiling mode
  738. #endif /* COMPILE_PCRE[8|16|32] */
  739. #endif /* SUPPORT_UTF */
  740. /* Tests for Unicode horizontal and vertical whitespace characters must check a
  741. number of different values. Using a switch statement for this generates the
  742. fastest code (no loop, no memory access), and there are several places in the
  743. interpreter code where this happens. In order to ensure that all the case lists
  744. remain in step, we use macros so that there is only one place where the lists
  745. are defined.
  746. These values are also required as lists in pcre_compile.c when processing \h,
  747. \H, \v and \V in a character class. The lists are defined in pcre_tables.c, but
  748. macros that define the values are here so that all the definitions are
  749. together. The lists must be in ascending character order, terminated by
  750. NOTACHAR (which is 0xffffffff).
  751. Any changes should ensure that the various macros are kept in step with each
  752. other. NOTE: The values also appear in pcre_jit_compile.c. */
  753. /* ------ ASCII/Unicode environments ------ */
  754. #ifndef EBCDIC
  755. #define HSPACE_LIST \
  756. CHAR_HT, CHAR_SPACE, CHAR_NBSP, \
  757. 0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, \
  758. 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202f, 0x205f, 0x3000, \
  759. NOTACHAR
  760. #define HSPACE_MULTIBYTE_CASES \
  761. case 0x1680: /* OGHAM SPACE MARK */ \
  762. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ \
  763. case 0x2000: /* EN QUAD */ \
  764. case 0x2001: /* EM QUAD */ \
  765. case 0x2002: /* EN SPACE */ \
  766. case 0x2003: /* EM SPACE */ \
  767. case 0x2004: /* THREE-PER-EM SPACE */ \
  768. case 0x2005: /* FOUR-PER-EM SPACE */ \
  769. case 0x2006: /* SIX-PER-EM SPACE */ \
  770. case 0x2007: /* FIGURE SPACE */ \
  771. case 0x2008: /* PUNCTUATION SPACE */ \
  772. case 0x2009: /* THIN SPACE */ \
  773. case 0x200A: /* HAIR SPACE */ \
  774. case 0x202f: /* NARROW NO-BREAK SPACE */ \
  775. case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ \
  776. case 0x3000 /* IDEOGRAPHIC SPACE */
  777. #define HSPACE_BYTE_CASES \
  778. case CHAR_HT: \
  779. case CHAR_SPACE: \
  780. case CHAR_NBSP
  781. #define HSPACE_CASES \
  782. HSPACE_BYTE_CASES: \
  783. HSPACE_MULTIBYTE_CASES
  784. #define VSPACE_LIST \
  785. CHAR_LF, CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, 0x2028, 0x2029, NOTACHAR
  786. #define VSPACE_MULTIBYTE_CASES \
  787. case 0x2028: /* LINE SEPARATOR */ \
  788. case 0x2029 /* PARAGRAPH SEPARATOR */
  789. #define VSPACE_BYTE_CASES \
  790. case CHAR_LF: \
  791. case CHAR_VT: \
  792. case CHAR_FF: \
  793. case CHAR_CR: \
  794. case CHAR_NEL
  795. #define VSPACE_CASES \
  796. VSPACE_BYTE_CASES: \
  797. VSPACE_MULTIBYTE_CASES
  798. /* ------ EBCDIC environments ------ */
  799. #else
  800. #define HSPACE_LIST CHAR_HT, CHAR_SPACE, CHAR_NBSP, NOTACHAR
  801. #define HSPACE_BYTE_CASES \
  802. case CHAR_HT: \
  803. case CHAR_SPACE: \
  804. case CHAR_NBSP
  805. #define HSPACE_CASES HSPACE_BYTE_CASES
  806. #ifdef EBCDIC_NL25
  807. #define VSPACE_LIST \
  808. CHAR_VT, CHAR_FF, CHAR_CR, CHAR_NEL, CHAR_LF, NOTACHAR
  809. #else
  810. #define VSPACE_LIST \
  811. CHAR_VT, CHAR_FF, CHAR_CR, CHAR_LF, CHAR_NEL, NOTACHAR
  812. #endif
  813. #define VSPACE_BYTE_CASES \
  814. case CHAR_LF: \
  815. case CHAR_VT: \
  816. case CHAR_FF: \
  817. case CHAR_CR: \
  818. case CHAR_NEL
  819. #define VSPACE_CASES VSPACE_BYTE_CASES
  820. #endif /* EBCDIC */
  821. /* ------ End of whitespace macros ------ */
  822. /* Private flags containing information about the compiled regex. They used to
  823. live at the top end of the options word, but that got almost full, so they were
  824. moved to a 16-bit flags word - which got almost full, so now they are in a
  825. 32-bit flags word. From release 8.00, PCRE_NOPARTIAL is unused, as the
  826. restrictions on partial matching have been lifted. It remains for backwards
  827. compatibility. */
  828. #define PCRE_MODE8 0x00000001 /* compiled in 8 bit mode */
  829. #define PCRE_MODE16 0x00000002 /* compiled in 16 bit mode */
  830. #define PCRE_MODE32 0x00000004 /* compiled in 32 bit mode */
  831. #define PCRE_FIRSTSET 0x00000010 /* first_char is set */
  832. #define PCRE_FCH_CASELESS 0x00000020 /* caseless first char */
  833. #define PCRE_REQCHSET 0x00000040 /* req_byte is set */
  834. #define PCRE_RCH_CASELESS 0x00000080 /* caseless requested char */
  835. #define PCRE_STARTLINE 0x00000100 /* start after \n for multiline */
  836. #define PCRE_NOPARTIAL 0x00000200 /* can't use partial with this regex */
  837. #define PCRE_JCHANGED 0x00000400 /* j option used in regex */
  838. #define PCRE_HASCRORLF 0x00000800 /* explicit \r or \n in pattern */
  839. #define PCRE_HASTHEN 0x00001000 /* pattern contains (*THEN) */
  840. #define PCRE_MLSET 0x00002000 /* match limit set by regex */
  841. #define PCRE_RLSET 0x00004000 /* recursion limit set by regex */
  842. #define PCRE_MATCH_EMPTY 0x00008000 /* pattern can match empty string */
  843. #if defined COMPILE_PCRE8
  844. #define PCRE_MODE PCRE_MODE8
  845. #elif defined COMPILE_PCRE16
  846. #define PCRE_MODE PCRE_MODE16
  847. #elif defined COMPILE_PCRE32
  848. #define PCRE_MODE PCRE_MODE32
  849. #endif
  850. #define PCRE_MODE_MASK (PCRE_MODE8 | PCRE_MODE16 | PCRE_MODE32)
  851. /* Flags for the "extra" block produced by pcre_study(). */
  852. #define PCRE_STUDY_MAPPED 0x0001 /* a map of starting chars exists */
  853. #define PCRE_STUDY_MINLEN 0x0002 /* a minimum length field exists */
  854. /* Masks for identifying the public options that are permitted at compile
  855. time, run time, or study time, respectively. */
  856. #define PCRE_NEWLINE_BITS (PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|PCRE_NEWLINE_ANY| \
  857. PCRE_NEWLINE_ANYCRLF)
  858. #define PUBLIC_COMPILE_OPTIONS \
  859. (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
  860. PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \
  861. PCRE_NO_AUTO_CAPTURE|PCRE_NO_AUTO_POSSESS| \
  862. PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE| \
  863. PCRE_DUPNAMES|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE| \
  864. PCRE_JAVASCRIPT_COMPAT|PCRE_UCP|PCRE_NO_START_OPTIMIZE|PCRE_NEVER_UTF)
  865. #define PUBLIC_EXEC_OPTIONS \
  866. (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NOTEMPTY_ATSTART| \
  867. PCRE_NO_UTF8_CHECK|PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT|PCRE_NEWLINE_BITS| \
  868. PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE|PCRE_NO_START_OPTIMIZE)
  869. #define PUBLIC_DFA_EXEC_OPTIONS \
  870. (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NOTEMPTY_ATSTART| \
  871. PCRE_NO_UTF8_CHECK|PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT|PCRE_DFA_SHORTEST| \
  872. PCRE_DFA_RESTART|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE| \
  873. PCRE_NO_START_OPTIMIZE)
  874. #define PUBLIC_STUDY_OPTIONS \
  875. (PCRE_STUDY_JIT_COMPILE|PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE| \
  876. PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE|PCRE_STUDY_EXTRA_NEEDED)
  877. #define PUBLIC_JIT_EXEC_OPTIONS \
  878. (PCRE_NO_UTF8_CHECK|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|\
  879. PCRE_NOTEMPTY_ATSTART|PCRE_PARTIAL_SOFT|PCRE_PARTIAL_HARD)
  880. /* Magic number to provide a small check against being handed junk. */
  881. #define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */
  882. /* This variable is used to detect a loaded regular expression
  883. in different endianness. */
  884. #define REVERSED_MAGIC_NUMBER 0x45524350UL /* 'ERCP' */
  885. /* The maximum remaining length of subject we are prepared to search for a
  886. req_byte match. */
  887. #define REQ_BYTE_MAX 1000
  888. /* Miscellaneous definitions. The #ifndef is to pacify compiler warnings in
  889. environments where these macros are defined elsewhere. Unfortunately, there
  890. is no way to do the same for the typedef. */
  891. typedef int BOOL;
  892. #ifndef FALSE
  893. #define FALSE 0
  894. #define TRUE 1
  895. #endif
  896. /* If PCRE is to support UTF-8 on EBCDIC platforms, we cannot use normal
  897. character constants like '*' because the compiler would emit their EBCDIC code,
  898. which is different from their ASCII/UTF-8 code. Instead we define macros for
  899. the characters so that they always use the ASCII/UTF-8 code when UTF-8 support
  900. is enabled. When UTF-8 support is not enabled, the definitions use character
  901. literals. Both character and string versions of each character are needed, and
  902. there are some longer strings as well.
  903. This means that, on EBCDIC platforms, the PCRE library can handle either
  904. EBCDIC, or UTF-8, but not both. To support both in the same compiled library
  905. would need different lookups depending on whether PCRE_UTF8 was set or not.
  906. This would make it impossible to use characters in switch/case statements,
  907. which would reduce performance. For a theoretical use (which nobody has asked
  908. for) in a minority area (EBCDIC platforms), this is not sensible. Any
  909. application that did need both could compile two versions of the library, using
  910. macros to give the functions distinct names. */
  911. #ifndef SUPPORT_UTF
  912. /* UTF-8 support is not enabled; use the platform-dependent character literals
  913. so that PCRE works in both ASCII and EBCDIC environments, but only in non-UTF
  914. mode. Newline characters are problematic in EBCDIC. Though it has CR and LF
  915. characters, a common practice has been to use its NL (0x15) character as the
  916. line terminator in C-like processing environments. However, sometimes the LF
  917. (0x25) character is used instead, according to this Unicode document:
  918. http://unicode.org/standard/reports/tr13/tr13-5.html
  919. PCRE defaults EBCDIC NL to 0x15, but has a build-time option to select 0x25
  920. instead. Whichever is *not* chosen is defined as NEL.
  921. In both ASCII and EBCDIC environments, CHAR_NL and CHAR_LF are synonyms for the
  922. same code point. */
  923. #ifdef EBCDIC
  924. #ifndef EBCDIC_NL25
  925. #define CHAR_NL '\x15'
  926. #define CHAR_NEL '\x25'
  927. #define STR_NL "\x15"
  928. #define STR_NEL "\x25"
  929. #else
  930. #define CHAR_NL '\x25'
  931. #define CHAR_NEL '\x15'
  932. #define STR_NL "\x25"
  933. #define STR_NEL "\x15"
  934. #endif
  935. #define CHAR_LF CHAR_NL
  936. #define STR_LF STR_NL
  937. #define CHAR_ESC '\047'
  938. #define CHAR_DEL '\007'
  939. #define CHAR_NBSP '\x41'
  940. #define STR_ESC "\047"
  941. #define STR_DEL "\007"
  942. #else /* Not EBCDIC */
  943. /* In ASCII/Unicode, linefeed is '\n' and we equate this to NL for
  944. compatibility. NEL is the Unicode newline character; make sure it is
  945. a positive value. */
  946. #define CHAR_LF '\n'
  947. #define CHAR_NL CHAR_LF
  948. #define CHAR_NEL ((unsigned char)'\x85')
  949. #define CHAR_ESC '\033'
  950. #define CHAR_DEL '\177'
  951. #define CHAR_NBSP ((unsigned char)'\xa0')
  952. #define STR_LF "\n"
  953. #define STR_NL STR_LF
  954. #define STR_NEL "\x85"
  955. #define STR_ESC "\033"
  956. #define STR_DEL "\177"
  957. #endif /* EBCDIC */
  958. /* The remaining definitions work in both environments. */
  959. #define CHAR_NULL '\0'
  960. #define CHAR_HT '\t'
  961. #define CHAR_VT '\v'
  962. #define CHAR_FF '\f'
  963. #define CHAR_CR '\r'
  964. #define CHAR_BS '\b'
  965. #define CHAR_BEL '\a'
  966. #define CHAR_SPACE ' '
  967. #define CHAR_EXCLAMATION_MARK '!'
  968. #define CHAR_QUOTATION_MARK '"'
  969. #define CHAR_NUMBER_SIGN '#'
  970. #define CHAR_DOLLAR_SIGN '$'
  971. #define CHAR_PERCENT_SIGN '%'
  972. #define CHAR_AMPERSAND '&'
  973. #define CHAR_APOSTROPHE '\''
  974. #define CHAR_LEFT_PARENTHESIS '('
  975. #define CHAR_RIGHT_PARENTHESIS ')'
  976. #define CHAR_ASTERISK '*'
  977. #define CHAR_PLUS '+'
  978. #define CHAR_COMMA ','
  979. #define CHAR_MINUS '-'
  980. #define CHAR_DOT '.'
  981. #define CHAR_SLASH '/'
  982. #define CHAR_0 '0'
  983. #define CHAR_1 '1'
  984. #define CHAR_2 '2'
  985. #define CHAR_3 '3'
  986. #define CHAR_4 '4'
  987. #define CHAR_5 '5'
  988. #define CHAR_6 '6'
  989. #define CHAR_7 '7'
  990. #define CHAR_8 '8'
  991. #define CHAR_9 '9'
  992. #define CHAR_COLON ':'
  993. #define CHAR_SEMICOLON ';'
  994. #define CHAR_LESS_THAN_SIGN '<'
  995. #define CHAR_EQUALS_SIGN '='
  996. #define CHAR_GREATER_THAN_SIGN '>'
  997. #define CHAR_QUESTION_MARK '?'
  998. #define CHAR_COMMERCIAL_AT '@'
  999. #define CHAR_A 'A'
  1000. #define CHAR_B 'B'
  1001. #define CHAR_C 'C'
  1002. #define CHAR_D 'D'
  1003. #define CHAR_E 'E'
  1004. #define CHAR_F 'F'
  1005. #define CHAR_G 'G'
  1006. #define CHAR_H 'H'
  1007. #define CHAR_I 'I'
  1008. #define CHAR_J 'J'
  1009. #define CHAR_K 'K'
  1010. #define CHAR_L 'L'
  1011. #define CHAR_M 'M'
  1012. #define CHAR_N 'N'
  1013. #define CHAR_O 'O'
  1014. #define CHAR_P 'P'
  1015. #define CHAR_Q 'Q'
  1016. #define CHAR_R 'R'
  1017. #define CHAR_S 'S'
  1018. #define CHAR_T 'T'
  1019. #define CHAR_U 'U'
  1020. #define CHAR_V 'V'
  1021. #define CHAR_W 'W'
  1022. #define CHAR_X 'X'
  1023. #define CHAR_Y 'Y'
  1024. #define CHAR_Z 'Z'
  1025. #define CHAR_LEFT_SQUARE_BRACKET '['
  1026. #define CHAR_BACKSLASH '\\'
  1027. #define CHAR_RIGHT_SQUARE_BRACKET ']'
  1028. #define CHAR_CIRCUMFLEX_ACCENT '^'
  1029. #define CHAR_UNDERSCORE '_'
  1030. #define CHAR_GRAVE_ACCENT '`'
  1031. #define CHAR_a 'a'
  1032. #define CHAR_b 'b'
  1033. #define CHAR_c 'c'
  1034. #define CHAR_d 'd'
  1035. #define CHAR_e 'e'
  1036. #define CHAR_f 'f'
  1037. #define CHAR_g 'g'
  1038. #define CHAR_h 'h'
  1039. #define CHAR_i 'i'
  1040. #define CHAR_j 'j'
  1041. #define CHAR_k 'k'
  1042. #define CHAR_l 'l'
  1043. #define CHAR_m 'm'
  1044. #define CHAR_n 'n'
  1045. #define CHAR_o 'o'
  1046. #define CHAR_p 'p'
  1047. #define CHAR_q 'q'
  1048. #define CHAR_r 'r'
  1049. #define CHAR_s 's'
  1050. #define CHAR_t 't'
  1051. #define CHAR_u 'u'
  1052. #define CHAR_v 'v'
  1053. #define CHAR_w 'w'
  1054. #define CHAR_x 'x'
  1055. #define CHAR_y 'y'
  1056. #define CHAR_z 'z'
  1057. #define CHAR_LEFT_CURLY_BRACKET '{'
  1058. #define CHAR_VERTICAL_LINE '|'
  1059. #define CHAR_RIGHT_CURLY_BRACKET '}'
  1060. #define CHAR_TILDE '~'
  1061. #define STR_HT "\t"
  1062. #define STR_VT "\v"
  1063. #define STR_FF "\f"
  1064. #define STR_CR "\r"
  1065. #define STR_BS "\b"
  1066. #define STR_BEL "\a"
  1067. #define STR_SPACE " "
  1068. #define STR_EXCLAMATION_MARK "!"
  1069. #define STR_QUOTATION_MARK "\""
  1070. #define STR_NUMBER_SIGN "#"
  1071. #define STR_DOLLAR_SIGN "$"
  1072. #define STR_PERCENT_SIGN "%"
  1073. #define STR_AMPERSAND "&"
  1074. #define STR_APOSTROPHE "'"
  1075. #define STR_LEFT_PARENTHESIS "("
  1076. #define STR_RIGHT_PARENTHESIS ")"
  1077. #define STR_ASTERISK "*"
  1078. #define STR_PLUS "+"
  1079. #define STR_COMMA ","
  1080. #define STR_MINUS "-"
  1081. #define STR_DOT "."
  1082. #define STR_SLASH "/"
  1083. #define STR_0 "0"
  1084. #define STR_1 "1"
  1085. #define STR_2 "2"
  1086. #define STR_3 "3"
  1087. #define STR_4 "4"
  1088. #define STR_5 "5"
  1089. #define STR_6 "6"
  1090. #define STR_7 "7"
  1091. #define STR_8 "8"
  1092. #define STR_9 "9"
  1093. #define STR_COLON ":"
  1094. #define STR_SEMICOLON ";"
  1095. #define STR_LESS_THAN_SIGN "<"
  1096. #define STR_EQUALS_SIGN "="
  1097. #define STR_GREATER_THAN_SIGN ">"
  1098. #define STR_QUESTION_MARK "?"
  1099. #define STR_COMMERCIAL_AT "@"
  1100. #define STR_A "A"
  1101. #define STR_B "B"
  1102. #define STR_C "C"
  1103. #define STR_D "D"
  1104. #define STR_E "E"
  1105. #define STR_F "F"
  1106. #define STR_G "G"
  1107. #define STR_H "H"
  1108. #define STR_I "I"
  1109. #define STR_J "J"
  1110. #define STR_K "K"
  1111. #define STR_L "L"
  1112. #define STR_M "M"
  1113. #define STR_N "N"
  1114. #define STR_O "O"
  1115. #define STR_P "P"
  1116. #define STR_Q "Q"
  1117. #define STR_R "R"
  1118. #define STR_S "S"
  1119. #define STR_T "T"
  1120. #define STR_U "U"
  1121. #define STR_V "V"
  1122. #define STR_W "W"
  1123. #define STR_X "X"
  1124. #define STR_Y "Y"
  1125. #define STR_Z "Z"
  1126. #define STR_LEFT_SQUARE_BRACKET "["
  1127. #define STR_BACKSLASH "\\"
  1128. #define STR_RIGHT_SQUARE_BRACKET "]"
  1129. #define STR_CIRCUMFLEX_ACCENT "^"
  1130. #define STR_UNDERSCORE "_"
  1131. #define STR_GRAVE_ACCENT "`"
  1132. #define STR_a "a"
  1133. #define STR_b "b"
  1134. #define STR_c "c"
  1135. #define STR_d "d"
  1136. #define STR_e "e"
  1137. #define STR_f "f"
  1138. #define STR_g "g"
  1139. #define STR_h "h"
  1140. #define STR_i "i"
  1141. #define STR_j "j"
  1142. #define STR_k "k"
  1143. #define STR_l "l"
  1144. #define STR_m "m"
  1145. #define STR_n "n"
  1146. #define STR_o "o"
  1147. #define STR_p "p"
  1148. #define STR_q "q"
  1149. #define STR_r "r"
  1150. #define STR_s "s"
  1151. #define STR_t "t"
  1152. #define STR_u "u"
  1153. #define STR_v "v"
  1154. #define STR_w "w"
  1155. #define STR_x "x"
  1156. #define STR_y "y"
  1157. #define STR_z "z"
  1158. #define STR_LEFT_CURLY_BRACKET "{"
  1159. #define STR_VERTICAL_LINE "|"
  1160. #define STR_RIGHT_CURLY_BRACKET "}"
  1161. #define STR_TILDE "~"
  1162. #define STRING_ACCEPT0 "ACCEPT\0"
  1163. #define STRING_COMMIT0 "COMMIT\0"
  1164. #define STRING_F0 "F\0"
  1165. #define STRING_FAIL0 "FAIL\0"
  1166. #define STRING_MARK0 "MARK\0"
  1167. #define STRING_PRUNE0 "PRUNE\0"
  1168. #define STRING_SKIP0 "SKIP\0"
  1169. #define STRING_THEN "THEN"
  1170. #define STRING_alpha0 "alpha\0"
  1171. #define STRING_lower0 "lower\0"
  1172. #define STRING_upper0 "upper\0"
  1173. #define STRING_alnum0 "alnum\0"
  1174. #define STRING_ascii0 "ascii\0"
  1175. #define STRING_blank0 "blank\0"
  1176. #define STRING_cntrl0 "cntrl\0"
  1177. #define STRING_digit0 "digit\0"
  1178. #define STRING_graph0 "graph\0"
  1179. #define STRING_print0 "print\0"
  1180. #define STRING_punct0 "punct\0"
  1181. #define STRING_space0 "space\0"
  1182. #define STRING_word0 "word\0"
  1183. #define STRING_xdigit "xdigit"
  1184. #define STRING_DEFINE "DEFINE"
  1185. #define STRING_WEIRD_STARTWORD "[:<:]]"
  1186. #define STRING_WEIRD_ENDWORD "[:>:]]"
  1187. #define STRING_CR_RIGHTPAR "CR)"
  1188. #define STRING_LF_RIGHTPAR "LF)"
  1189. #define STRING_CRLF_RIGHTPAR "CRLF)"
  1190. #define STRING_ANY_RIGHTPAR "ANY)"
  1191. #define STRING_ANYCRLF_RIGHTPAR "ANYCRLF)"
  1192. #define STRING_BSR_ANYCRLF_RIGHTPAR "BSR_ANYCRLF)"
  1193. #define STRING_BSR_UNICODE_RIGHTPAR "BSR_UNICODE)"
  1194. #define STRING_UTF8_RIGHTPAR "UTF8)"
  1195. #define STRING_UTF16_RIGHTPAR "UTF16)"
  1196. #define STRING_UTF32_RIGHTPAR "UTF32)"
  1197. #define STRING_UTF_RIGHTPAR "UTF)"
  1198. #define STRING_UCP_RIGHTPAR "UCP)"
  1199. #define STRING_NO_AUTO_POSSESS_RIGHTPAR "NO_AUTO_POSSESS)"
  1200. #define STRING_NO_START_OPT_RIGHTPAR "NO_START_OPT)"
  1201. #define STRING_LIMIT_MATCH_EQ "LIMIT_MATCH="
  1202. #define STRING_LIMIT_RECURSION_EQ "LIMIT_RECURSION="
  1203. #else /* SUPPORT_UTF */
  1204. /* UTF-8 support is enabled; always use UTF-8 (=ASCII) character codes. This
  1205. works in both modes non-EBCDIC platforms, and on EBCDIC platforms in UTF-8 mode
  1206. only. */
  1207. #define CHAR_HT '\011'
  1208. #define CHAR_VT '\013'
  1209. #define CHAR_FF '\014'
  1210. #define CHAR_CR '\015'
  1211. #define CHAR_LF '\012'
  1212. #define CHAR_NL CHAR_LF
  1213. #define CHAR_NEL ((unsigned char)'\x85')
  1214. #define CHAR_BS '\010'
  1215. #define CHAR_BEL '\007'
  1216. #define CHAR_ESC '\033'
  1217. #define CHAR_DEL '\177'
  1218. #define CHAR_NULL '\0'
  1219. #define CHAR_SPACE '\040'
  1220. #define CHAR_EXCLAMATION_MARK '\041'
  1221. #define CHAR_QUOTATION_MARK '\042'
  1222. #define CHAR_NUMBER_SIGN '\043'
  1223. #define CHAR_DOLLAR_SIGN '\044'
  1224. #define CHAR_PERCENT_SIGN '\045'
  1225. #define CHAR_AMPERSAND '\046'
  1226. #define CHAR_APOSTROPHE '\047'
  1227. #define CHAR_LEFT_PARENTHESIS '\050'
  1228. #define CHAR_RIGHT_PARENTHESIS '\051'
  1229. #define CHAR_ASTERISK '\052'
  1230. #define CHAR_PLUS '\053'
  1231. #define CHAR_COMMA '\054'
  1232. #define CHAR_MINUS '\055'
  1233. #define CHAR_DOT '\056'
  1234. #define CHAR_SLASH '\057'
  1235. #define CHAR_0 '\060'
  1236. #define CHAR_1 '\061'
  1237. #define CHAR_2 '\062'
  1238. #define CHAR_3 '\063'
  1239. #define CHAR_4 '\064'
  1240. #define CHAR_5 '\065'
  1241. #define CHAR_6 '\066'
  1242. #define CHAR_7 '\067'
  1243. #define CHAR_8 '\070'
  1244. #define CHAR_9 '\071'
  1245. #define CHAR_COLON '\072'
  1246. #define CHAR_SEMICOLON '\073'
  1247. #define CHAR_LESS_THAN_SIGN '\074'
  1248. #define CHAR_EQUALS_SIGN '\075'
  1249. #define CHAR_GREATER_THAN_SIGN '\076'
  1250. #define CHAR_QUESTION_MARK '\077'
  1251. #define CHAR_COMMERCIAL_AT '\100'
  1252. #define CHAR_A '\101'
  1253. #define CHAR_B '\102'
  1254. #define CHAR_C '\103'
  1255. #define CHAR_D '\104'
  1256. #define CHAR_E '\105'
  1257. #define CHAR_F '\106'
  1258. #define CHAR_G '\107'
  1259. #define CHAR_H '\110'
  1260. #define CHAR_I '\111'
  1261. #define CHAR_J '\112'
  1262. #define CHAR_K '\113'
  1263. #define CHAR_L '\114'
  1264. #define CHAR_M '\115'
  1265. #define CHAR_N '\116'
  1266. #define CHAR_O '\117'
  1267. #define CHAR_P '\120'
  1268. #define CHAR_Q '\121'
  1269. #define CHAR_R '\122'
  1270. #define CHAR_S '\123'
  1271. #define CHAR_T '\124'
  1272. #define CHAR_U '\125'
  1273. #define CHAR_V '\126'
  1274. #define CHAR_W '\127'
  1275. #define CHAR_X '\130'
  1276. #define CHAR_Y '\131'
  1277. #define CHAR_Z '\132'
  1278. #define CHAR_LEFT_SQUARE_BRACKET '\133'
  1279. #define CHAR_BACKSLASH '\134'
  1280. #define CHAR_RIGHT_SQUARE_BRACKET '\135'
  1281. #define CHAR_CIRCUMFLEX_ACCENT '\136'
  1282. #define CHAR_UNDERSCORE '\137'
  1283. #define CHAR_GRAVE_ACCENT '\140'
  1284. #define CHAR_a '\141'
  1285. #define CHAR_b '\142'
  1286. #define CHAR_c '\143'
  1287. #define CHAR_d '\144'
  1288. #define CHAR_e '\145'
  1289. #define CHAR_f '\146'
  1290. #define CHAR_g '\147'
  1291. #define CHAR_h '\150'
  1292. #define CHAR_i '\151'
  1293. #define CHAR_j '\152'
  1294. #define CHAR_k '\153'
  1295. #define CHAR_l '\154'
  1296. #define CHAR_m '\155'
  1297. #define CHAR_n '\156'
  1298. #define CHAR_o '\157'
  1299. #define CHAR_p '\160'
  1300. #define CHAR_q '\161'
  1301. #define CHAR_r '\162'
  1302. #define CHAR_s '\163'
  1303. #define CHAR_t '\164'
  1304. #define CHAR_u '\165'
  1305. #define CHAR_v '\166'
  1306. #define CHAR_w '\167'
  1307. #define CHAR_x '\170'
  1308. #define CHAR_y '\171'
  1309. #define CHAR_z '\172'
  1310. #define CHAR_LEFT_CURLY_BRACKET '\173'
  1311. #define CHAR_VERTICAL_LINE '\174'
  1312. #define CHAR_RIGHT_CURLY_BRACKET '\175'
  1313. #define CHAR_TILDE '\176'
  1314. #define CHAR_NBSP ((unsigned char)'\xa0')
  1315. #define STR_HT "\011"
  1316. #define STR_VT "\013"
  1317. #define STR_FF "\014"
  1318. #define STR_CR "\015"
  1319. #define STR_NL "\012"
  1320. #define STR_BS "\010"
  1321. #define STR_BEL "\007"
  1322. #define STR_ESC "\033"
  1323. #define STR_DEL "\177"
  1324. #define STR_SPACE "\040"
  1325. #define STR_EXCLAMATION_MARK "\041"
  1326. #define STR_QUOTATION_MARK "\042"
  1327. #define STR_NUMBER_SIGN "\043"
  1328. #define STR_DOLLAR_SIGN "\044"
  1329. #define STR_PERCENT_SIGN "\045"
  1330. #define STR_AMPERSAND "\046"
  1331. #define STR_APOSTROPHE "\047"
  1332. #define STR_LEFT_PARENTHESIS "\050"
  1333. #define STR_RIGHT_PARENTHESIS "\051"
  1334. #define STR_ASTERISK "\052"
  1335. #define STR_PLUS "\053"
  1336. #define STR_COMMA "\054"
  1337. #define STR_MINUS "\055"
  1338. #define STR_DOT "\056"
  1339. #define STR_SLASH "\057"
  1340. #define STR_0 "\060"
  1341. #define STR_1 "\061"
  1342. #define STR_2 "\062"
  1343. #define STR_3 "\063"
  1344. #define STR_4 "\064"
  1345. #define STR_5 "\065"
  1346. #define STR_6 "\066"
  1347. #define STR_7 "\067"
  1348. #define STR_8 "\070"
  1349. #define STR_9 "\071"
  1350. #define STR_COLON "\072"
  1351. #define STR_SEMICOLON "\073"
  1352. #define STR_LESS_THAN_SIGN "\074"
  1353. #define STR_EQUALS_SIGN "\075"
  1354. #define STR_GREATER_THAN_SIGN "\076"
  1355. #define STR_QUESTION_MARK "\077"
  1356. #define STR_COMMERCIAL_AT "\100"
  1357. #define STR_A "\101"
  1358. #define STR_B "\102"
  1359. #define STR_C "\103"
  1360. #define STR_D "\104"
  1361. #define STR_E "\105"
  1362. #define STR_F "\106"
  1363. #define STR_G "\107"
  1364. #define STR_H "\110"
  1365. #define STR_I "\111"
  1366. #define STR_J "\112"
  1367. #define STR_K "\113"
  1368. #define STR_L "\114"
  1369. #define STR_M "\115"
  1370. #define STR_N "\116"
  1371. #define STR_O "\117"
  1372. #define STR_P "\120"
  1373. #define STR_Q "\121"
  1374. #define STR_R "\122"
  1375. #define STR_S "\123"
  1376. #define STR_T "\124"
  1377. #define STR_U "\125"
  1378. #define STR_V "\126"
  1379. #define STR_W "\127"
  1380. #define STR_X "\130"
  1381. #define STR_Y "\131"
  1382. #define STR_Z "\132"
  1383. #define STR_LEFT_SQUARE_BRACKET "\133"
  1384. #define STR_BACKSLASH "\134"
  1385. #define STR_RIGHT_SQUARE_BRACKET "\135"
  1386. #define STR_CIRCUMFLEX_ACCENT "\136"
  1387. #define STR_UNDERSCORE "\137"
  1388. #define STR_GRAVE_ACCENT "\140"
  1389. #define STR_a "\141"
  1390. #define STR_b "\142"
  1391. #define STR_c "\143"
  1392. #define STR_d "\144"
  1393. #define STR_e "\145"
  1394. #define STR_f "\146"
  1395. #define STR_g "\147"
  1396. #define STR_h "\150"
  1397. #define STR_i "\151"
  1398. #define STR_j "\152"
  1399. #define STR_k "\153"
  1400. #define STR_l "\154"
  1401. #define STR_m "\155"
  1402. #define STR_n "\156"
  1403. #define STR_o "\157"
  1404. #define STR_p "\160"
  1405. #define STR_q "\161"
  1406. #define STR_r "\162"
  1407. #define STR_s "\163"
  1408. #define STR_t "\164"
  1409. #define STR_u "\165"
  1410. #define STR_v "\166"
  1411. #define STR_w "\167"
  1412. #define STR_x "\170"
  1413. #define STR_y "\171"
  1414. #define STR_z "\172"
  1415. #define STR_LEFT_CURLY_BRACKET "\173"
  1416. #define STR_VERTICAL_LINE "\174"
  1417. #define STR_RIGHT_CURLY_BRACKET "\175"
  1418. #define STR_TILDE "\176"
  1419. #define STRING_ACCEPT0 STR_A STR_C STR_C STR_E STR_P STR_T "\0"
  1420. #define STRING_COMMIT0 STR_C STR_O STR_M STR_M STR_I STR_T "\0"
  1421. #define STRING_F0 STR_F "\0"
  1422. #define STRING_FAIL0 STR_F STR_A STR_I STR_L "\0"
  1423. #define STRING_MARK0 STR_M STR_A STR_R STR_K "\0"
  1424. #define STRING_PRUNE0 STR_P STR_R STR_U STR_N STR_E "\0"
  1425. #define STRING_SKIP0 STR_S STR_K STR_I STR_P "\0"
  1426. #define STRING_THEN STR_T STR_H STR_E STR_N
  1427. #define STRING_alpha0 STR_a STR_l STR_p STR_h STR_a "\0"
  1428. #define STRING_lower0 STR_l STR_o STR_w STR_e STR_r "\0"
  1429. #define STRING_upper0 STR_u STR_p STR_p STR_e STR_r "\0"
  1430. #define STRING_alnum0 STR_a STR_l STR_n STR_u STR_m "\0"
  1431. #define STRING_ascii0 STR_a STR_s STR_c STR_i STR_i "\0"
  1432. #define STRING_blank0 STR_b STR_l STR_a STR_n STR_k "\0"
  1433. #define STRING_cntrl0 STR_c STR_n STR_t STR_r STR_l "\0"
  1434. #define STRING_digit0 STR_d STR_i STR_g STR_i STR_t "\0"
  1435. #define STRING_graph0 STR_g STR_r STR_a STR_p STR_h "\0"
  1436. #define STRING_print0 STR_p STR_r STR_i STR_n STR_t "\0"
  1437. #define STRING_punct0 STR_p STR_u STR_n STR_c STR_t "\0"
  1438. #define STRING_space0 STR_s STR_p STR_a STR_c STR_e "\0"
  1439. #define STRING_word0 STR_w STR_o STR_r STR_d "\0"
  1440. #define STRING_xdigit STR_x STR_d STR_i STR_g STR_i STR_t
  1441. #define STRING_DEFINE STR_D STR_E STR_F STR_I STR_N STR_E
  1442. #define STRING_WEIRD_STARTWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_LESS_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
  1443. #define STRING_WEIRD_ENDWORD STR_LEFT_SQUARE_BRACKET STR_COLON STR_GREATER_THAN_SIGN STR_COLON STR_RIGHT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
  1444. #define STRING_CR_RIGHTPAR STR_C STR_R STR_RIGHT_PARENTHESIS
  1445. #define STRING_LF_RIGHTPAR STR_L STR_F STR_RIGHT_PARENTHESIS
  1446. #define STRING_CRLF_RIGHTPAR STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
  1447. #define STRING_ANY_RIGHTPAR STR_A STR_N STR_Y STR_RIGHT_PARENTHESIS
  1448. #define STRING_ANYCRLF_RIGHTPAR STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
  1449. #define STRING_BSR_ANYCRLF_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
  1450. #define STRING_BSR_UNICODE_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_U STR_N STR_I STR_C STR_O STR_D STR_E STR_RIGHT_PARENTHESIS
  1451. #define STRING_UTF8_RIGHTPAR STR_U STR_T STR_F STR_8 STR_RIGHT_PARENTHESIS
  1452. #define STRING_UTF16_RIGHTPAR STR_U STR_T STR_F STR_1 STR_6 STR_RIGHT_PARENTHESIS
  1453. #define STRING_UTF32_RIGHTPAR STR_U STR_T STR_F STR_3 STR_2 STR_RIGHT_PARENTHESIS
  1454. #define STRING_UTF_RIGHTPAR STR_U STR_T STR_F STR_RIGHT_PARENTHESIS
  1455. #define STRING_UCP_RIGHTPAR STR_U STR_C STR_P STR_RIGHT_PARENTHESIS
  1456. #define STRING_NO_AUTO_POSSESS_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_A STR_U STR_T STR_O STR_UNDERSCORE STR_P STR_O STR_S STR_S STR_E STR_S STR_S STR_RIGHT_PARENTHESIS
  1457. #define STRING_NO_START_OPT_RIGHTPAR STR_N STR_O STR_UNDERSCORE STR_S STR_T STR_A STR_R STR_T STR_UNDERSCORE STR_O STR_P STR_T STR_RIGHT_PARENTHESIS
  1458. #define STRING_LIMIT_MATCH_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_M STR_A STR_T STR_C STR_H STR_EQUALS_SIGN
  1459. #define STRING_LIMIT_RECURSION_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_R STR_E STR_C STR_U STR_R STR_S STR_I STR_O STR_N STR_EQUALS_SIGN
  1460. #endif /* SUPPORT_UTF */
  1461. /* Escape items that are just an encoding of a particular data value. */
  1462. #ifndef ESC_a
  1463. #define ESC_a CHAR_BEL
  1464. #endif
  1465. #ifndef ESC_e
  1466. #define ESC_e CHAR_ESC
  1467. #endif
  1468. #ifndef ESC_f
  1469. #define ESC_f CHAR_FF
  1470. #endif
  1471. #ifndef ESC_n
  1472. #define ESC_n CHAR_LF
  1473. #endif
  1474. #ifndef ESC_r
  1475. #define ESC_r CHAR_CR
  1476. #endif
  1477. /* We can't officially use ESC_t because it is a POSIX reserved identifier
  1478. (presumably because of all the others like size_t). */
  1479. #ifndef ESC_tee
  1480. #define ESC_tee CHAR_HT
  1481. #endif
  1482. /* Codes for different types of Unicode property */
  1483. #define PT_ANY 0 /* Any property - matches all chars */
  1484. #define PT_LAMP 1 /* L& - the union of Lu, Ll, Lt */
  1485. #define PT_GC 2 /* Specified general characteristic (e.g. L) */
  1486. #define PT_PC 3 /* Specified particular characteristic (e.g. Lu) */
  1487. #define PT_SC 4 /* Script (e.g. Han) */
  1488. #define PT_ALNUM 5 /* Alphanumeric - the union of L and N */
  1489. #define PT_SPACE 6 /* Perl space - Z plus 9,10,12,13 */
  1490. #define PT_PXSPACE 7 /* POSIX space - Z plus 9,10,11,12,13 */
  1491. #define PT_WORD 8 /* Word - L plus N plus underscore */
  1492. #define PT_CLIST 9 /* Pseudo-property: match character list */
  1493. #define PT_UCNC 10 /* Universal Character nameable character */
  1494. #define PT_TABSIZE 11 /* Size of square table for autopossessify tests */
  1495. /* The following special properties are used only in XCLASS items, when POSIX
  1496. classes are specified and PCRE_UCP is set - in other words, for Unicode
  1497. handling of these classes. They are not available via the \p or \P escapes like
  1498. those in the above list, and so they do not take part in the autopossessifying
  1499. table. */
  1500. #define PT_PXGRAPH 11 /* [:graph:] - characters that mark the paper */
  1501. #define PT_PXPRINT 12 /* [:print:] - [:graph:] plus non-control spaces */
  1502. #define PT_PXPUNCT 13 /* [:punct:] - punctuation characters */
  1503. /* Flag bits and data types for the extended class (OP_XCLASS) for classes that
  1504. contain characters with values greater than 255. */
  1505. #define XCL_NOT 0x01 /* Flag: this is a negative class */
  1506. #define XCL_MAP 0x02 /* Flag: a 32-byte map is present */
  1507. #define XCL_HASPROP 0x04 /* Flag: property checks are present. */
  1508. #define XCL_END 0 /* Marks end of individual items */
  1509. #define XCL_SINGLE 1 /* Single item (one multibyte char) follows */
  1510. #define XCL_RANGE 2 /* A range (two multibyte chars) follows */
  1511. #define XCL_PROP 3 /* Unicode property (2-byte property code follows) */
  1512. #define XCL_NOTPROP 4 /* Unicode inverted property (ditto) */
  1513. /* These are escaped items that aren't just an encoding of a particular data
  1514. value such as \n. They must have non-zero values, as check_escape() returns 0
  1515. for a data character. Also, they must appear in the same order as in the
  1516. opcode definitions below, up to ESC_z. There's a dummy for OP_ALLANY because it
  1517. corresponds to "." in DOTALL mode rather than an escape sequence. It is also
  1518. used for [^] in JavaScript compatibility mode, and for \C in non-utf mode. In
  1519. non-DOTALL mode, "." behaves like \N.
  1520. The special values ESC_DU, ESC_du, etc. are used instead of ESC_D, ESC_d, etc.
  1521. when PCRE_UCP is set and replacement of \d etc by \p sequences is required.
  1522. They must be contiguous, and remain in order so that the replacements can be
  1523. looked up from a table.
  1524. Negative numbers are used to encode a backreference (\1, \2, \3, etc.) in
  1525. check_escape(). There are two tests in the code for an escape
  1526. greater than ESC_b and less than ESC_Z to detect the types that may be
  1527. repeated. These are the types that consume characters. If any new escapes are
  1528. put in between that don't consume a character, that code will have to change.
  1529. */
  1530. enum { ESC_A = 1, ESC_G, ESC_K, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s,
  1531. ESC_W, ESC_w, ESC_N, ESC_dum, ESC_C, ESC_P, ESC_p, ESC_R, ESC_H,
  1532. ESC_h, ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z,
  1533. ESC_E, ESC_Q, ESC_g, ESC_k,
  1534. ESC_DU, ESC_du, ESC_SU, ESC_su, ESC_WU, ESC_wu };
  1535. /********************** Opcode definitions ******************/
  1536. /****** NOTE NOTE NOTE ******
  1537. Starting from 1 (i.e. after OP_END), the values up to OP_EOD must correspond in
  1538. order to the list of escapes immediately above. Furthermore, values up to
  1539. OP_DOLLM must not be changed without adjusting the table called autoposstab in
  1540. pcre_compile.c
  1541. Whenever this list is updated, the two macro definitions that follow must be
  1542. updated to match. The possessification table called "opcode_possessify" in
  1543. pcre_compile.c must also be updated, and also the tables called "coptable"
  1544. and "poptable" in pcre_dfa_exec.c.
  1545. ****** NOTE NOTE NOTE ******/
  1546. /* The values between FIRST_AUTOTAB_OP and LAST_AUTOTAB_RIGHT_OP, inclusive,
  1547. are used in a table for deciding whether a repeated character type can be
  1548. auto-possessified. */
  1549. #define FIRST_AUTOTAB_OP OP_NOT_DIGIT
  1550. #define LAST_AUTOTAB_LEFT_OP OP_EXTUNI
  1551. #define LAST_AUTOTAB_RIGHT_OP OP_DOLLM
  1552. enum {
  1553. OP_END, /* 0 End of pattern */
  1554. /* Values corresponding to backslashed metacharacters */
  1555. OP_SOD, /* 1 Start of data: \A */
  1556. OP_SOM, /* 2 Start of match (subject + offset): \G */
  1557. OP_SET_SOM, /* 3 Set start of match (\K) */
  1558. OP_NOT_WORD_BOUNDARY, /* 4 \B */
  1559. OP_WORD_BOUNDARY, /* 5 \b */
  1560. OP_NOT_DIGIT, /* 6 \D */
  1561. OP_DIGIT, /* 7 \d */
  1562. OP_NOT_WHITESPACE, /* 8 \S */
  1563. OP_WHITESPACE, /* 9 \s */
  1564. OP_NOT_WORDCHAR, /* 10 \W */
  1565. OP_WORDCHAR, /* 11 \w */
  1566. OP_ANY, /* 12 Match any character except newline (\N) */
  1567. OP_ALLANY, /* 13 Match any character */
  1568. OP_ANYBYTE, /* 14 Match any byte (\C); different to OP_ANY for UTF-8 */
  1569. OP_NOTPROP, /* 15 \P (not Unicode property) */
  1570. OP_PROP, /* 16 \p (Unicode property) */
  1571. OP_ANYNL, /* 17 \R (any newline sequence) */
  1572. OP_NOT_HSPACE, /* 18 \H (not horizontal whitespace) */
  1573. OP_HSPACE, /* 19 \h (horizontal whitespace) */
  1574. OP_NOT_VSPACE, /* 20 \V (not vertical whitespace) */
  1575. OP_VSPACE, /* 21 \v (vertical whitespace) */
  1576. OP_EXTUNI, /* 22 \X (extended Unicode sequence */
  1577. OP_EODN, /* 23 End of data or \n at end of data (\Z) */
  1578. OP_EOD, /* 24 End of data (\z) */
  1579. /* Line end assertions */
  1580. OP_DOLL, /* 25 End of line - not multiline */
  1581. OP_DOLLM, /* 26 End of line - multiline */
  1582. OP_CIRC, /* 27 Start of line - not multiline */
  1583. OP_CIRCM, /* 28 Start of line - multiline */
  1584. /* Single characters; caseful must precede the caseless ones */
  1585. OP_CHAR, /* 29 Match one character, casefully */
  1586. OP_CHARI, /* 30 Match one character, caselessly */
  1587. OP_NOT, /* 31 Match one character, not the given one, casefully */
  1588. OP_NOTI, /* 32 Match one character, not the given one, caselessly */
  1589. /* The following sets of 13 opcodes must always be kept in step because
  1590. the offset from the first one is used to generate the others. */
  1591. /* Repeated characters; caseful must precede the caseless ones */
  1592. OP_STAR, /* 33 The maximizing and minimizing versions of */
  1593. OP_MINSTAR, /* 34 these six opcodes must come in pairs, with */
  1594. OP_PLUS, /* 35 the minimizing one second. */
  1595. OP_MINPLUS, /* 36 */
  1596. OP_QUERY, /* 37 */
  1597. OP_MINQUERY, /* 38 */
  1598. OP_UPTO, /* 39 From 0 to n matches of one character, caseful*/
  1599. OP_MINUPTO, /* 40 */
  1600. OP_EXACT, /* 41 Exactly n matches */
  1601. OP_POSSTAR, /* 42 Possessified star, caseful */
  1602. OP_POSPLUS, /* 43 Possessified plus, caseful */
  1603. OP_POSQUERY, /* 44 Posesssified query, caseful */
  1604. OP_POSUPTO, /* 45 Possessified upto, caseful */
  1605. /* Repeated characters; caseless must follow the caseful ones */
  1606. OP_STARI, /* 46 */
  1607. OP_MINSTARI, /* 47 */
  1608. OP_PLUSI, /* 48 */
  1609. OP_MINPLUSI, /* 49 */
  1610. OP_QUERYI, /* 50 */
  1611. OP_MINQUERYI, /* 51 */
  1612. OP_UPTOI, /* 52 From 0 to n matches of one character, caseless */
  1613. OP_MINUPTOI, /* 53 */
  1614. OP_EXACTI, /* 54 */
  1615. OP_POSSTARI, /* 55 Possessified star, caseless */
  1616. OP_POSPLUSI, /* 56 Possessified plus, caseless */
  1617. OP_POSQUERYI, /* 57 Posesssified query, caseless */
  1618. OP_POSUPTOI, /* 58 Possessified upto, caseless */
  1619. /* The negated ones must follow the non-negated ones, and match them */
  1620. /* Negated repeated character, caseful; must precede the caseless ones */
  1621. OP_NOTSTAR, /* 59 The maximizing and minimizing versions of */
  1622. OP_NOTMINSTAR, /* 60 these six opcodes must come in pairs, with */
  1623. OP_NOTPLUS, /* 61 the minimizing one second. They must be in */
  1624. OP_NOTMINPLUS, /* 62 exactly the same order as those above. */
  1625. OP_NOTQUERY, /* 63 */
  1626. OP_NOTMINQUERY, /* 64 */
  1627. OP_NOTUPTO, /* 65 From 0 to n matches, caseful */
  1628. OP_NOTMINUPTO, /* 66 */
  1629. OP_NOTEXACT, /* 67 Exactly n matches */
  1630. OP_NOTPOSSTAR, /* 68 Possessified versions, caseful */
  1631. OP_NOTPOSPLUS, /* 69 */
  1632. OP_NOTPOSQUERY, /* 70 */
  1633. OP_NOTPOSUPTO, /* 71 */
  1634. /* Negated repeated character, caseless; must follow the caseful ones */
  1635. OP_NOTSTARI, /* 72 */
  1636. OP_NOTMINSTARI, /* 73 */
  1637. OP_NOTPLUSI, /* 74 */
  1638. OP_NOTMINPLUSI, /* 75 */
  1639. OP_NOTQUERYI, /* 76 */
  1640. OP_NOTMINQUERYI, /* 77 */
  1641. OP_NOTUPTOI, /* 78 From 0 to n matches, caseless */
  1642. OP_NOTMINUPTOI, /* 79 */
  1643. OP_NOTEXACTI, /* 80 Exactly n matches */
  1644. OP_NOTPOSSTARI, /* 81 Possessified versions, caseless */
  1645. OP_NOTPOSPLUSI, /* 82 */
  1646. OP_NOTPOSQUERYI, /* 83 */
  1647. OP_NOTPOSUPTOI, /* 84 */
  1648. /* Character types */
  1649. OP_TYPESTAR, /* 85 The maximizing and minimizing versions of */
  1650. OP_TYPEMINSTAR, /* 86 these six opcodes must come in pairs, with */
  1651. OP_TYPEPLUS, /* 87 the minimizing one second. These codes must */
  1652. OP_TYPEMINPLUS, /* 88 be in exactly the same order as those above. */
  1653. OP_TYPEQUERY, /* 89 */
  1654. OP_TYPEMINQUERY, /* 90 */
  1655. OP_TYPEUPTO, /* 91 From 0 to n matches */
  1656. OP_TYPEMINUPTO, /* 92 */
  1657. OP_TYPEEXACT, /* 93 Exactly n matches */
  1658. OP_TYPEPOSSTAR, /* 94 Possessified versions */
  1659. OP_TYPEPOSPLUS, /* 95 */
  1660. OP_TYPEPOSQUERY, /* 96 */
  1661. OP_TYPEPOSUPTO, /* 97 */
  1662. /* These are used for character classes and back references; only the
  1663. first six are the same as the sets above. */
  1664. OP_CRSTAR, /* 98 The maximizing and minimizing versions of */
  1665. OP_CRMINSTAR, /* 99 all these opcodes must come in pairs, with */
  1666. OP_CRPLUS, /* 100 the minimizing one second. These codes must */
  1667. OP_CRMINPLUS, /* 101 be in exactly the same order as those above. */
  1668. OP_CRQUERY, /* 102 */
  1669. OP_CRMINQUERY, /* 103 */
  1670. OP_CRRANGE, /* 104 These are different to the three sets above. */
  1671. OP_CRMINRANGE, /* 105 */
  1672. OP_CRPOSSTAR, /* 106 Possessified versions */
  1673. OP_CRPOSPLUS, /* 107 */
  1674. OP_CRPOSQUERY, /* 108 */
  1675. OP_CRPOSRANGE, /* 109 */
  1676. /* End of quantifier opcodes */
  1677. OP_CLASS, /* 110 Match a character class, chars < 256 only */
  1678. OP_NCLASS, /* 111 Same, but the bitmap was created from a negative
  1679. class - the difference is relevant only when a
  1680. character > 255 is encountered. */
  1681. OP_XCLASS, /* 112 Extended class for handling > 255 chars within the
  1682. class. This does both positive and negative. */
  1683. OP_REF, /* 113 Match a back reference, casefully */
  1684. OP_REFI, /* 114 Match a back reference, caselessly */
  1685. OP_DNREF, /* 115 Match a duplicate name backref, casefully */
  1686. OP_DNREFI, /* 116 Match a duplicate name backref, caselessly */
  1687. OP_RECURSE, /* 117 Match a numbered subpattern (possibly recursive) */
  1688. OP_CALLOUT, /* 118 Call out to external function if provided */
  1689. OP_ALT, /* 119 Start of alternation */
  1690. OP_KET, /* 120 End of group that doesn't have an unbounded repeat */
  1691. OP_KETRMAX, /* 121 These two must remain together and in this */
  1692. OP_KETRMIN, /* 122 order. They are for groups the repeat for ever. */
  1693. OP_KETRPOS, /* 123 Possessive unlimited repeat. */
  1694. /* The assertions must come before BRA, CBRA, ONCE, and COND, and the four
  1695. asserts must remain in order. */
  1696. OP_REVERSE, /* 124 Move pointer back - used in lookbehind assertions */
  1697. OP_ASSERT, /* 125 Positive lookahead */
  1698. OP_ASSERT_NOT, /* 126 Negative lookahead */
  1699. OP_ASSERTBACK, /* 127 Positive lookbehind */
  1700. OP_ASSERTBACK_NOT, /* 128 Negative lookbehind */
  1701. /* ONCE, ONCE_NC, BRA, BRAPOS, CBRA, CBRAPOS, and COND must come immediately
  1702. after the assertions, with ONCE first, as there's a test for >= ONCE for a
  1703. subpattern that isn't an assertion. The POS versions must immediately follow
  1704. the non-POS versions in each case. */
  1705. OP_ONCE, /* 129 Atomic group, contains captures */
  1706. OP_ONCE_NC, /* 130 Atomic group containing no captures */
  1707. OP_BRA, /* 131 Start of non-capturing bracket */
  1708. OP_BRAPOS, /* 132 Ditto, with unlimited, possessive repeat */
  1709. OP_CBRA, /* 133 Start of capturing bracket */
  1710. OP_CBRAPOS, /* 134 Ditto, with unlimited, possessive repeat */
  1711. OP_COND, /* 135 Conditional group */
  1712. /* These five must follow the previous five, in the same order. There's a
  1713. check for >= SBRA to distinguish the two sets. */
  1714. OP_SBRA, /* 136 Start of non-capturing bracket, check empty */
  1715. OP_SBRAPOS, /* 137 Ditto, with unlimited, possessive repeat */
  1716. OP_SCBRA, /* 138 Start of capturing bracket, check empty */
  1717. OP_SCBRAPOS, /* 139 Ditto, with unlimited, possessive repeat */
  1718. OP_SCOND, /* 140 Conditional group, check empty */
  1719. /* The next two pairs must (respectively) be kept together. */
  1720. OP_CREF, /* 141 Used to hold a capture number as condition */
  1721. OP_DNCREF, /* 142 Used to point to duplicate names as a condition */
  1722. OP_RREF, /* 143 Used to hold a recursion number as condition */
  1723. OP_DNRREF, /* 144 Used to point to duplicate names as a condition */
  1724. OP_DEF, /* 145 The DEFINE condition */
  1725. OP_BRAZERO, /* 146 These two must remain together and in this */
  1726. OP_BRAMINZERO, /* 147 order. */
  1727. OP_BRAPOSZERO, /* 148 */
  1728. /* These are backtracking control verbs */
  1729. OP_MARK, /* 149 always has an argument */
  1730. OP_PRUNE, /* 150 */
  1731. OP_PRUNE_ARG, /* 151 same, but with argument */
  1732. OP_SKIP, /* 152 */
  1733. OP_SKIP_ARG, /* 153 same, but with argument */
  1734. OP_THEN, /* 154 */
  1735. OP_THEN_ARG, /* 155 same, but with argument */
  1736. OP_COMMIT, /* 156 */
  1737. /* These are forced failure and success verbs */
  1738. OP_FAIL, /* 157 */
  1739. OP_ACCEPT, /* 158 */
  1740. OP_ASSERT_ACCEPT, /* 159 Used inside assertions */
  1741. OP_CLOSE, /* 160 Used before OP_ACCEPT to close open captures */
  1742. /* This is used to skip a subpattern with a {0} quantifier */
  1743. OP_SKIPZERO, /* 161 */
  1744. /* This is not an opcode, but is used to check that tables indexed by opcode
  1745. are the correct length, in order to catch updating errors - there have been
  1746. some in the past. */
  1747. OP_TABLE_LENGTH
  1748. };
  1749. /* *** NOTE NOTE NOTE *** Whenever the list above is updated, the two macro
  1750. definitions that follow must also be updated to match. There are also tables
  1751. called "opcode_possessify" in pcre_compile.c and "coptable" and "poptable" in
  1752. pcre_dfa_exec.c that must be updated. */
  1753. /* This macro defines textual names for all the opcodes. These are used only
  1754. for debugging, and some of them are only partial names. The macro is referenced
  1755. only in pcre_printint.c, which fills out the full names in many cases (and in
  1756. some cases doesn't actually use these names at all). */
  1757. #define OP_NAME_LIST \
  1758. "End", "\\A", "\\G", "\\K", "\\B", "\\b", "\\D", "\\d", \
  1759. "\\S", "\\s", "\\W", "\\w", "Any", "AllAny", "Anybyte", \
  1760. "notprop", "prop", "\\R", "\\H", "\\h", "\\V", "\\v", \
  1761. "extuni", "\\Z", "\\z", \
  1762. "$", "$", "^", "^", "char", "chari", "not", "noti", \
  1763. "*", "*?", "+", "+?", "?", "??", \
  1764. "{", "{", "{", \
  1765. "*+","++", "?+", "{", \
  1766. "*", "*?", "+", "+?", "?", "??", \
  1767. "{", "{", "{", \
  1768. "*+","++", "?+", "{", \
  1769. "*", "*?", "+", "+?", "?", "??", \
  1770. "{", "{", "{", \
  1771. "*+","++", "?+", "{", \
  1772. "*", "*?", "+", "+?", "?", "??", \
  1773. "{", "{", "{", \
  1774. "*+","++", "?+", "{", \
  1775. "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \
  1776. "*+","++", "?+", "{", \
  1777. "*", "*?", "+", "+?", "?", "??", "{", "{", \
  1778. "*+","++", "?+", "{", \
  1779. "class", "nclass", "xclass", "Ref", "Refi", "DnRef", "DnRefi", \
  1780. "Recurse", "Callout", \
  1781. "Alt", "Ket", "KetRmax", "KetRmin", "KetRpos", \
  1782. "Reverse", "Assert", "Assert not", "AssertB", "AssertB not", \
  1783. "Once", "Once_NC", \
  1784. "Bra", "BraPos", "CBra", "CBraPos", \
  1785. "Cond", \
  1786. "SBra", "SBraPos", "SCBra", "SCBraPos", \
  1787. "SCond", \
  1788. "Cond ref", "Cond dnref", "Cond rec", "Cond dnrec", "Cond def", \
  1789. "Brazero", "Braminzero", "Braposzero", \
  1790. "*MARK", "*PRUNE", "*PRUNE", "*SKIP", "*SKIP", \
  1791. "*THEN", "*THEN", "*COMMIT", "*FAIL", \
  1792. "*ACCEPT", "*ASSERT_ACCEPT", \
  1793. "Close", "Skip zero"
  1794. /* This macro defines the length of fixed length operations in the compiled
  1795. regex. The lengths are used when searching for specific things, and also in the
  1796. debugging printing of a compiled regex. We use a macro so that it can be
  1797. defined close to the definitions of the opcodes themselves.
  1798. As things have been extended, some of these are no longer fixed lenths, but are
  1799. minima instead. For example, the length of a single-character repeat may vary
  1800. in UTF-8 mode. The code that uses this table must know about such things. */
  1801. #define OP_LENGTHS \
  1802. 1, /* End */ \
  1803. 1, 1, 1, 1, 1, /* \A, \G, \K, \B, \b */ \
  1804. 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */ \
  1805. 1, 1, 1, /* Any, AllAny, Anybyte */ \
  1806. 3, 3, /* \P, \p */ \
  1807. 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */ \
  1808. 1, /* \X */ \
  1809. 1, 1, 1, 1, 1, 1, /* \Z, \z, $, $M ^, ^M */ \
  1810. 2, /* Char - the minimum length */ \
  1811. 2, /* Chari - the minimum length */ \
  1812. 2, /* not */ \
  1813. 2, /* noti */ \
  1814. /* Positive single-char repeats ** These are */ \
  1815. 2, 2, 2, 2, 2, 2, /* *, *?, +, +?, ?, ?? ** minima in */ \
  1816. 2+IMM2_SIZE, 2+IMM2_SIZE, /* upto, minupto ** mode */ \
  1817. 2+IMM2_SIZE, /* exact */ \
  1818. 2, 2, 2, 2+IMM2_SIZE, /* *+, ++, ?+, upto+ */ \
  1819. 2, 2, 2, 2, 2, 2, /* *I, *?I, +I, +?I, ?I, ??I ** UTF-8 */ \
  1820. 2+IMM2_SIZE, 2+IMM2_SIZE, /* upto I, minupto I */ \
  1821. 2+IMM2_SIZE, /* exact I */ \
  1822. 2, 2, 2, 2+IMM2_SIZE, /* *+I, ++I, ?+I, upto+I */ \
  1823. /* Negative single-char repeats - only for chars < 256 */ \
  1824. 2, 2, 2, 2, 2, 2, /* NOT *, *?, +, +?, ?, ?? */ \
  1825. 2+IMM2_SIZE, 2+IMM2_SIZE, /* NOT upto, minupto */ \
  1826. 2+IMM2_SIZE, /* NOT exact */ \
  1827. 2, 2, 2, 2+IMM2_SIZE, /* Possessive NOT *, +, ?, upto */ \
  1828. 2, 2, 2, 2, 2, 2, /* NOT *I, *?I, +I, +?I, ?I, ??I */ \
  1829. 2+IMM2_SIZE, 2+IMM2_SIZE, /* NOT upto I, minupto I */ \
  1830. 2+IMM2_SIZE, /* NOT exact I */ \
  1831. 2, 2, 2, 2+IMM2_SIZE, /* Possessive NOT *I, +I, ?I, upto I */ \
  1832. /* Positive type repeats */ \
  1833. 2, 2, 2, 2, 2, 2, /* Type *, *?, +, +?, ?, ?? */ \
  1834. 2+IMM2_SIZE, 2+IMM2_SIZE, /* Type upto, minupto */ \
  1835. 2+IMM2_SIZE, /* Type exact */ \
  1836. 2, 2, 2, 2+IMM2_SIZE, /* Possessive *+, ++, ?+, upto+ */ \
  1837. /* Character class & ref repeats */ \
  1838. 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ \
  1839. 1+2*IMM2_SIZE, 1+2*IMM2_SIZE, /* CRRANGE, CRMINRANGE */ \
  1840. 1, 1, 1, 1+2*IMM2_SIZE, /* Possessive *+, ++, ?+, CRPOSRANGE */ \
  1841. 1+(32/sizeof(pcre_uchar)), /* CLASS */ \
  1842. 1+(32/sizeof(pcre_uchar)), /* NCLASS */ \
  1843. 0, /* XCLASS - variable length */ \
  1844. 1+IMM2_SIZE, /* REF */ \
  1845. 1+IMM2_SIZE, /* REFI */ \
  1846. 1+2*IMM2_SIZE, /* DNREF */ \
  1847. 1+2*IMM2_SIZE, /* DNREFI */ \
  1848. 1+LINK_SIZE, /* RECURSE */ \
  1849. 2+2*LINK_SIZE, /* CALLOUT */ \
  1850. 1+LINK_SIZE, /* Alt */ \
  1851. 1+LINK_SIZE, /* Ket */ \
  1852. 1+LINK_SIZE, /* KetRmax */ \
  1853. 1+LINK_SIZE, /* KetRmin */ \
  1854. 1+LINK_SIZE, /* KetRpos */ \
  1855. 1+LINK_SIZE, /* Reverse */ \
  1856. 1+LINK_SIZE, /* Assert */ \
  1857. 1+LINK_SIZE, /* Assert not */ \
  1858. 1+LINK_SIZE, /* Assert behind */ \
  1859. 1+LINK_SIZE, /* Assert behind not */ \
  1860. 1+LINK_SIZE, /* ONCE */ \
  1861. 1+LINK_SIZE, /* ONCE_NC */ \
  1862. 1+LINK_SIZE, /* BRA */ \
  1863. 1+LINK_SIZE, /* BRAPOS */ \
  1864. 1+LINK_SIZE+IMM2_SIZE, /* CBRA */ \
  1865. 1+LINK_SIZE+IMM2_SIZE, /* CBRAPOS */ \
  1866. 1+LINK_SIZE, /* COND */ \
  1867. 1+LINK_SIZE, /* SBRA */ \
  1868. 1+LINK_SIZE, /* SBRAPOS */ \
  1869. 1+LINK_SIZE+IMM2_SIZE, /* SCBRA */ \
  1870. 1+LINK_SIZE+IMM2_SIZE, /* SCBRAPOS */ \
  1871. 1+LINK_SIZE, /* SCOND */ \
  1872. 1+IMM2_SIZE, 1+2*IMM2_SIZE, /* CREF, DNCREF */ \
  1873. 1+IMM2_SIZE, 1+2*IMM2_SIZE, /* RREF, DNRREF */ \
  1874. 1, /* DEF */ \
  1875. 1, 1, 1, /* BRAZERO, BRAMINZERO, BRAPOSZERO */ \
  1876. 3, 1, 3, /* MARK, PRUNE, PRUNE_ARG */ \
  1877. 1, 3, /* SKIP, SKIP_ARG */ \
  1878. 1, 3, /* THEN, THEN_ARG */ \
  1879. 1, 1, 1, 1, /* COMMIT, FAIL, ACCEPT, ASSERT_ACCEPT */ \
  1880. 1+IMM2_SIZE, 1 /* CLOSE, SKIPZERO */
  1881. /* A magic value for OP_RREF to indicate the "any recursion" condition. */
  1882. #define RREF_ANY 0xffff
  1883. /* Compile time error code numbers. They are given names so that they can more
  1884. easily be tracked. When a new number is added, the table called eint in
  1885. pcreposix.c must be updated. */
  1886. enum { ERR0, ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9,
  1887. ERR10, ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19,
  1888. ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29,
  1889. ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39,
  1890. ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49,
  1891. ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59,
  1892. ERR60, ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69,
  1893. ERR70, ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERR78, ERR79,
  1894. ERR80, ERR81, ERR82, ERR83, ERR84, ERR85, ERR86, ERR87, ERRCOUNT };
  1895. /* JIT compiling modes. The function list is indexed by them. */
  1896. enum { JIT_COMPILE, JIT_PARTIAL_SOFT_COMPILE, JIT_PARTIAL_HARD_COMPILE,
  1897. JIT_NUMBER_OF_COMPILE_MODES };
  1898. /* The real format of the start of the pcre block; the index of names and the
  1899. code vector run on as long as necessary after the end. We store an explicit
  1900. offset to the name table so that if a regex is compiled on one host, saved, and
  1901. then run on another where the size of pointers is different, all might still
  1902. be well.
  1903. The size of the structure must be a multiple of 8 bytes. For the case of
  1904. compiled-on-4 and run-on-8, we include an extra pointer that is always NULL so
  1905. that there are an even number of pointers which therefore are a multiple of 8
  1906. bytes.
  1907. It is necessary to fork the struct for the 32 bit library, since it needs to
  1908. use pcre_uint32 for first_char and req_char. We can't put an ifdef inside the
  1909. typedef because pcretest needs access to the struct of the 8-, 16- and 32-bit
  1910. variants.
  1911. *** WARNING ***
  1912. When new fields are added to these structures, remember to adjust the code in
  1913. pcre_byte_order.c that is concerned with swapping the byte order of the fields
  1914. when a compiled regex is reloaded on a host with different endianness.
  1915. *** WARNING ***
  1916. There is also similar byte-flipping code in pcretest.c, which is used for
  1917. testing the byte-flipping features. It must also be kept in step.
  1918. *** WARNING ***
  1919. */
  1920. typedef struct real_pcre8_or_16 {
  1921. pcre_uint32 magic_number;
  1922. pcre_uint32 size; /* Total that was malloced */
  1923. pcre_uint32 options; /* Public options */
  1924. pcre_uint32 flags; /* Private flags */
  1925. pcre_uint32 limit_match; /* Limit set from regex */
  1926. pcre_uint32 limit_recursion; /* Limit set from regex */
  1927. pcre_uint16 first_char; /* Starting character */
  1928. pcre_uint16 req_char; /* This character must be seen */
  1929. pcre_uint16 max_lookbehind; /* Longest lookbehind (characters) */
  1930. pcre_uint16 top_bracket; /* Highest numbered group */
  1931. pcre_uint16 top_backref; /* Highest numbered back reference */
  1932. pcre_uint16 name_table_offset; /* Offset to name table that follows */
  1933. pcre_uint16 name_entry_size; /* Size of any name items */
  1934. pcre_uint16 name_count; /* Number of name items */
  1935. pcre_uint16 ref_count; /* Reference count */
  1936. pcre_uint16 dummy1; /* To ensure size is a multiple of 8 */
  1937. pcre_uint16 dummy2; /* To ensure size is a multiple of 8 */
  1938. pcre_uint16 dummy3; /* To ensure size is a multiple of 8 */
  1939. const pcre_uint8 *tables; /* Pointer to tables or NULL for std */
  1940. void *nullpad; /* NULL padding */
  1941. } real_pcre8_or_16;
  1942. typedef struct real_pcre8_or_16 real_pcre;
  1943. typedef struct real_pcre8_or_16 real_pcre16;
  1944. typedef struct real_pcre32 {
  1945. pcre_uint32 magic_number;
  1946. pcre_uint32 size; /* Total that was malloced */
  1947. pcre_uint32 options; /* Public options */
  1948. pcre_uint32 flags; /* Private flags */
  1949. pcre_uint32 limit_match; /* Limit set from regex */
  1950. pcre_uint32 limit_recursion; /* Limit set from regex */
  1951. pcre_uint32 first_char; /* Starting character */
  1952. pcre_uint32 req_char; /* This character must be seen */
  1953. pcre_uint16 max_lookbehind; /* Longest lookbehind (characters) */
  1954. pcre_uint16 top_bracket; /* Highest numbered group */
  1955. pcre_uint16 top_backref; /* Highest numbered back reference */
  1956. pcre_uint16 name_table_offset; /* Offset to name table that follows */
  1957. pcre_uint16 name_entry_size; /* Size of any name items */
  1958. pcre_uint16 name_count; /* Number of name items */
  1959. pcre_uint16 ref_count; /* Reference count */
  1960. pcre_uint16 dummy; /* To ensure size is a multiple of 8 */
  1961. const pcre_uint8 *tables; /* Pointer to tables or NULL for std */
  1962. void *nullpad; /* NULL padding */
  1963. } real_pcre32;
  1964. #if defined COMPILE_PCRE8
  1965. #define REAL_PCRE real_pcre
  1966. #elif defined COMPILE_PCRE16
  1967. #define REAL_PCRE real_pcre16
  1968. #elif defined COMPILE_PCRE32
  1969. #define REAL_PCRE real_pcre32
  1970. #endif
  1971. /* Assert that the size of REAL_PCRE is divisible by 8 */
  1972. typedef int __assert_real_pcre_size_divisible_8[(sizeof(REAL_PCRE) % 8) == 0 ? 1 : -1];
  1973. /* Needed in pcretest to access some fields in the real_pcre* structures
  1974. * directly. They're unified for 8/16/32 bits since the structs only differ
  1975. * after these fields; if that ever changes, need to fork those defines into
  1976. * 8/16 and 32 bit versions. */
  1977. #define REAL_PCRE_MAGIC(re) (((REAL_PCRE*)re)->magic_number)
  1978. #define REAL_PCRE_SIZE(re) (((REAL_PCRE*)re)->size)
  1979. #define REAL_PCRE_OPTIONS(re) (((REAL_PCRE*)re)->options)
  1980. #define REAL_PCRE_FLAGS(re) (((REAL_PCRE*)re)->flags)
  1981. /* The format of the block used to store data from pcre_study(). The same
  1982. remark (see NOTE above) about extending this structure applies. */
  1983. typedef struct pcre_study_data {
  1984. pcre_uint32 size; /* Total that was malloced */
  1985. pcre_uint32 flags; /* Private flags */
  1986. pcre_uint8 start_bits[32]; /* Starting char bits */
  1987. pcre_uint32 minlength; /* Minimum subject length */
  1988. } pcre_study_data;
  1989. /* Structure for building a chain of open capturing subpatterns during
  1990. compiling, so that instructions to close them can be compiled when (*ACCEPT) is
  1991. encountered. This is also used to identify subpatterns that contain recursive
  1992. back references to themselves, so that they can be made atomic. */
  1993. typedef struct open_capitem {
  1994. struct open_capitem *next; /* Chain link */
  1995. pcre_uint16 number; /* Capture number */
  1996. pcre_uint16 flag; /* Set TRUE if recursive back ref */
  1997. } open_capitem;
  1998. /* Structure for building a list of named groups during the first pass of
  1999. compiling. */
  2000. typedef struct named_group {
  2001. const pcre_uchar *name; /* Points to the name in the pattern */
  2002. int length; /* Length of the name */
  2003. pcre_uint32 number; /* Group number */
  2004. } named_group;
  2005. /* Structure for passing "static" information around between the functions
  2006. doing the compiling, so that they are thread-safe. */
  2007. typedef struct compile_data {
  2008. const pcre_uint8 *lcc; /* Points to lower casing table */
  2009. const pcre_uint8 *fcc; /* Points to case-flipping table */
  2010. const pcre_uint8 *cbits; /* Points to character type table */
  2011. const pcre_uint8 *ctypes; /* Points to table of type maps */
  2012. const pcre_uchar *start_workspace;/* The start of working space */
  2013. const pcre_uchar *start_code; /* The start of the compiled code */
  2014. const pcre_uchar *start_pattern; /* The start of the pattern */
  2015. const pcre_uchar *end_pattern; /* The end of the pattern */
  2016. pcre_uchar *hwm; /* High watermark of workspace */
  2017. open_capitem *open_caps; /* Chain of open capture items */
  2018. named_group *named_groups; /* Points to vector in pre-compile */
  2019. pcre_uchar *name_table; /* The name/number table */
  2020. int names_found; /* Number of entries so far */
  2021. int name_entry_size; /* Size of each entry */
  2022. int named_group_list_size; /* Number of entries in the list */
  2023. int workspace_size; /* Size of workspace */
  2024. unsigned int bracount; /* Count of capturing parens as we compile */
  2025. int final_bracount; /* Saved value after first pass */
  2026. int max_lookbehind; /* Maximum lookbehind (characters) */
  2027. int top_backref; /* Maximum back reference */
  2028. unsigned int backref_map; /* Bitmap of low back refs */
  2029. unsigned int namedrefcount; /* Number of backreferences by name */
  2030. int parens_depth; /* Depth of nested parentheses */
  2031. int assert_depth; /* Depth of nested assertions */
  2032. pcre_uint32 external_options; /* External (initial) options */
  2033. pcre_uint32 external_flags; /* External flag bits to be set */
  2034. int req_varyopt; /* "After variable item" flag for reqbyte */
  2035. BOOL had_accept; /* (*ACCEPT) encountered */
  2036. BOOL had_pruneorskip; /* (*PRUNE) or (*SKIP) encountered */
  2037. BOOL check_lookbehind; /* Lookbehinds need later checking */
  2038. BOOL dupnames; /* Duplicate names exist */
  2039. BOOL dupgroups; /* Duplicate groups exist: (?| found */
  2040. BOOL iscondassert; /* Next assert is a condition */
  2041. int nltype; /* Newline type */
  2042. int nllen; /* Newline string length */
  2043. pcre_uchar nl[4]; /* Newline string when fixed length */
  2044. } compile_data;
  2045. /* Structure for maintaining a chain of pointers to the currently incomplete
  2046. branches, for testing for left recursion while compiling. */
  2047. typedef struct branch_chain {
  2048. struct branch_chain *outer;
  2049. pcre_uchar *current_branch;
  2050. } branch_chain;
  2051. /* Structure for mutual recursion detection. */
  2052. typedef struct recurse_check {
  2053. struct recurse_check *prev;
  2054. const pcre_uchar *group;
  2055. } recurse_check;
  2056. /* Structure for items in a linked list that represents an explicit recursive
  2057. call within the pattern; used by pcre_exec(). */
  2058. typedef struct recursion_info {
  2059. struct recursion_info *prevrec; /* Previous recursion record (or NULL) */
  2060. unsigned int group_num; /* Number of group that was called */
  2061. int *offset_save; /* Pointer to start of saved offsets */
  2062. int saved_max; /* Number of saved offsets */
  2063. int saved_capture_last; /* Last capture number */
  2064. PCRE_PUCHAR subject_position; /* Position at start of recursion */
  2065. } recursion_info;
  2066. /* A similar structure for pcre_dfa_exec(). */
  2067. typedef struct dfa_recursion_info {
  2068. struct dfa_recursion_info *prevrec;
  2069. int group_num;
  2070. PCRE_PUCHAR subject_position;
  2071. } dfa_recursion_info;
  2072. /* Structure for building a chain of data for holding the values of the subject
  2073. pointer at the start of each subpattern, so as to detect when an empty string
  2074. has been matched by a subpattern - to break infinite loops; used by
  2075. pcre_exec(). */
  2076. typedef struct eptrblock {
  2077. struct eptrblock *epb_prev;
  2078. PCRE_PUCHAR epb_saved_eptr;
  2079. } eptrblock;
  2080. /* Structure for passing "static" information around between the functions
  2081. doing traditional NFA matching, so that they are thread-safe. */
  2082. typedef struct match_data {
  2083. unsigned long int match_call_count; /* As it says */
  2084. unsigned long int match_limit; /* As it says */
  2085. unsigned long int match_limit_recursion; /* As it says */
  2086. int *offset_vector; /* Offset vector */
  2087. int offset_end; /* One past the end */
  2088. int offset_max; /* The maximum usable for return data */
  2089. int nltype; /* Newline type */
  2090. int nllen; /* Newline string length */
  2091. int name_count; /* Number of names in name table */
  2092. int name_entry_size; /* Size of entry in names table */
  2093. unsigned int skip_arg_count; /* For counting SKIP_ARGs */
  2094. unsigned int ignore_skip_arg; /* For re-run when SKIP arg name not found */
  2095. pcre_uchar *name_table; /* Table of names */
  2096. pcre_uchar nl[4]; /* Newline string when fixed */
  2097. const pcre_uint8 *lcc; /* Points to lower casing table */
  2098. const pcre_uint8 *fcc; /* Points to case-flipping table */
  2099. const pcre_uint8 *ctypes; /* Points to table of type maps */
  2100. BOOL notbol; /* NOTBOL flag */
  2101. BOOL noteol; /* NOTEOL flag */
  2102. BOOL utf; /* UTF-8 / UTF-16 flag */
  2103. BOOL jscript_compat; /* JAVASCRIPT_COMPAT flag */
  2104. BOOL use_ucp; /* PCRE_UCP flag */
  2105. BOOL endonly; /* Dollar not before final \n */
  2106. BOOL notempty; /* Empty string match not wanted */
  2107. BOOL notempty_atstart; /* Empty string match at start not wanted */
  2108. BOOL hitend; /* Hit the end of the subject at some point */
  2109. BOOL bsr_anycrlf; /* \R is just any CRLF, not full Unicode */
  2110. BOOL hasthen; /* Pattern contains (*THEN) */
  2111. const pcre_uchar *start_code; /* For use when recursing */
  2112. PCRE_PUCHAR start_subject; /* Start of the subject string */
  2113. PCRE_PUCHAR end_subject; /* End of the subject string */
  2114. PCRE_PUCHAR start_match_ptr; /* Start of matched string */
  2115. PCRE_PUCHAR end_match_ptr; /* Subject position at end match */
  2116. PCRE_PUCHAR start_used_ptr; /* Earliest consulted character */
  2117. int partial; /* PARTIAL options */
  2118. int end_offset_top; /* Highwater mark at end of match */
  2119. pcre_int32 capture_last; /* Most recent capture number + overflow flag */
  2120. int start_offset; /* The start offset value */
  2121. int match_function_type; /* Set for certain special calls of MATCH() */
  2122. eptrblock *eptrchain; /* Chain of eptrblocks for tail recursions */
  2123. int eptrn; /* Next free eptrblock */
  2124. recursion_info *recursive; /* Linked list of recursion data */
  2125. void *callout_data; /* To pass back to callouts */
  2126. const pcre_uchar *mark; /* Mark pointer to pass back on success */
  2127. const pcre_uchar *nomatch_mark;/* Mark pointer to pass back on failure */
  2128. const pcre_uchar *once_target; /* Where to back up to for atomic groups */
  2129. #ifdef NO_RECURSE
  2130. void *match_frames_base; /* For remembering malloc'd frames */
  2131. #endif
  2132. } match_data;
  2133. /* A similar structure is used for the same purpose by the DFA matching
  2134. functions. */
  2135. typedef struct dfa_match_data {
  2136. const pcre_uchar *start_code; /* Start of the compiled pattern */
  2137. const pcre_uchar *start_subject ; /* Start of the subject string */
  2138. const pcre_uchar *end_subject; /* End of subject string */
  2139. const pcre_uchar *start_used_ptr; /* Earliest consulted character */
  2140. const pcre_uint8 *tables; /* Character tables */
  2141. int start_offset; /* The start offset value */
  2142. int moptions; /* Match options */
  2143. int poptions; /* Pattern options */
  2144. int nltype; /* Newline type */
  2145. int nllen; /* Newline string length */
  2146. pcre_uchar nl[4]; /* Newline string when fixed */
  2147. void *callout_data; /* To pass back to callouts */
  2148. dfa_recursion_info *recursive; /* Linked list of recursion data */
  2149. } dfa_match_data;
  2150. /* Bit definitions for entries in the pcre_ctypes table. */
  2151. #define ctype_space 0x01
  2152. #define ctype_letter 0x02
  2153. #define ctype_digit 0x04
  2154. #define ctype_xdigit 0x08
  2155. #define ctype_word 0x10 /* alphanumeric or '_' */
  2156. #define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */
  2157. /* Offsets for the bitmap tables in pcre_cbits. Each table contains a set
  2158. of bits for a class map. Some classes are built by combining these tables. */
  2159. #define cbit_space 0 /* [:space:] or \s */
  2160. #define cbit_xdigit 32 /* [:xdigit:] */
  2161. #define cbit_digit 64 /* [:digit:] or \d */
  2162. #define cbit_upper 96 /* [:upper:] */
  2163. #define cbit_lower 128 /* [:lower:] */
  2164. #define cbit_word 160 /* [:word:] or \w */
  2165. #define cbit_graph 192 /* [:graph:] */
  2166. #define cbit_print 224 /* [:print:] */
  2167. #define cbit_punct 256 /* [:punct:] */
  2168. #define cbit_cntrl 288 /* [:cntrl:] */
  2169. #define cbit_length 320 /* Length of the cbits table */
  2170. /* Offsets of the various tables from the base tables pointer, and
  2171. total length. */
  2172. #define lcc_offset 0
  2173. #define fcc_offset 256
  2174. #define cbits_offset 512
  2175. #define ctypes_offset (cbits_offset + cbit_length)
  2176. #define tables_length (ctypes_offset + 256)
  2177. /* Internal function and data prefixes. */
  2178. #if defined COMPILE_PCRE8
  2179. #ifndef PUBL
  2180. #define PUBL(name) pcre_##name
  2181. #endif
  2182. #ifndef PRIV
  2183. #define PRIV(name) _pcre_##name
  2184. #endif
  2185. #elif defined COMPILE_PCRE16
  2186. #ifndef PUBL
  2187. #define PUBL(name) pcre16_##name
  2188. #endif
  2189. #ifndef PRIV
  2190. #define PRIV(name) _pcre16_##name
  2191. #endif
  2192. #elif defined COMPILE_PCRE32
  2193. #ifndef PUBL
  2194. #define PUBL(name) pcre32_##name
  2195. #endif
  2196. #ifndef PRIV
  2197. #define PRIV(name) _pcre32_##name
  2198. #endif
  2199. #else
  2200. #error Unsupported compiling mode
  2201. #endif /* COMPILE_PCRE[8|16|32] */
  2202. /* Layout of the UCP type table that translates property names into types and
  2203. codes. Each entry used to point directly to a name, but to reduce the number of
  2204. relocations in shared libraries, it now has an offset into a single string
  2205. instead. */
  2206. typedef struct {
  2207. pcre_uint16 name_offset;
  2208. pcre_uint16 type;
  2209. pcre_uint16 value;
  2210. } ucp_type_table;
  2211. /* Internal shared data tables. These are tables that are used by more than one
  2212. of the exported public functions. They have to be "external" in the C sense,
  2213. but are not part of the PCRE public API. The data for these tables is in the
  2214. pcre_tables.c module. */
  2215. #ifdef COMPILE_PCRE8
  2216. extern const int PRIV(utf8_table1)[];
  2217. extern const int PRIV(utf8_table1_size);
  2218. extern const int PRIV(utf8_table2)[];
  2219. extern const int PRIV(utf8_table3)[];
  2220. extern const pcre_uint8 PRIV(utf8_table4)[];
  2221. #endif /* COMPILE_PCRE8 */
  2222. extern const char PRIV(utt_names)[];
  2223. extern const ucp_type_table PRIV(utt)[];
  2224. extern const int PRIV(utt_size);
  2225. extern const pcre_uint8 PRIV(OP_lengths)[];
  2226. extern const pcre_uint8 PRIV(default_tables)[];
  2227. extern const pcre_uint32 PRIV(hspace_list)[];
  2228. extern const pcre_uint32 PRIV(vspace_list)[];
  2229. /* Internal shared functions. These are functions that are used by more than
  2230. one of the exported public functions. They have to be "external" in the C
  2231. sense, but are not part of the PCRE public API. */
  2232. /* String comparison functions. */
  2233. #if defined COMPILE_PCRE8
  2234. #define STRCMP_UC_UC(str1, str2) \
  2235. strcmp((char *)(str1), (char *)(str2))
  2236. #define STRCMP_UC_C8(str1, str2) \
  2237. strcmp((char *)(str1), (str2))
  2238. #define STRNCMP_UC_UC(str1, str2, num) \
  2239. strncmp((char *)(str1), (char *)(str2), (num))
  2240. #define STRNCMP_UC_C8(str1, str2, num) \
  2241. strncmp((char *)(str1), (str2), (num))
  2242. #define STRLEN_UC(str) strlen((const char *)str)
  2243. #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
  2244. extern int PRIV(strcmp_uc_uc)(const pcre_uchar *,
  2245. const pcre_uchar *);
  2246. extern int PRIV(strcmp_uc_c8)(const pcre_uchar *,
  2247. const char *);
  2248. extern int PRIV(strncmp_uc_uc)(const pcre_uchar *,
  2249. const pcre_uchar *, unsigned int num);
  2250. extern int PRIV(strncmp_uc_c8)(const pcre_uchar *,
  2251. const char *, unsigned int num);
  2252. extern unsigned int PRIV(strlen_uc)(const pcre_uchar *str);
  2253. #define STRCMP_UC_UC(str1, str2) \
  2254. PRIV(strcmp_uc_uc)((str1), (str2))
  2255. #define STRCMP_UC_C8(str1, str2) \
  2256. PRIV(strcmp_uc_c8)((str1), (str2))
  2257. #define STRNCMP_UC_UC(str1, str2, num) \
  2258. PRIV(strncmp_uc_uc)((str1), (str2), (num))
  2259. #define STRNCMP_UC_C8(str1, str2, num) \
  2260. PRIV(strncmp_uc_c8)((str1), (str2), (num))
  2261. #define STRLEN_UC(str) PRIV(strlen_uc)(str)
  2262. #endif /* COMPILE_PCRE[8|16|32] */
  2263. #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
  2264. #define STRCMP_UC_UC_TEST(str1, str2) STRCMP_UC_UC(str1, str2)
  2265. #define STRCMP_UC_C8_TEST(str1, str2) STRCMP_UC_C8(str1, str2)
  2266. #elif defined COMPILE_PCRE32
  2267. extern int PRIV(strcmp_uc_uc_utf)(const pcre_uchar *,
  2268. const pcre_uchar *);
  2269. extern int PRIV(strcmp_uc_c8_utf)(const pcre_uchar *,
  2270. const char *);
  2271. #define STRCMP_UC_UC_TEST(str1, str2) \
  2272. (utf ? PRIV(strcmp_uc_uc_utf)((str1), (str2)) : PRIV(strcmp_uc_uc)((str1), (str2)))
  2273. #define STRCMP_UC_C8_TEST(str1, str2) \
  2274. (utf ? PRIV(strcmp_uc_c8_utf)((str1), (str2)) : PRIV(strcmp_uc_c8)((str1), (str2)))
  2275. #endif /* COMPILE_PCRE[8|16|32] */
  2276. extern const pcre_uchar *PRIV(find_bracket)(const pcre_uchar *, BOOL, int);
  2277. extern BOOL PRIV(is_newline)(PCRE_PUCHAR, int, PCRE_PUCHAR,
  2278. int *, BOOL);
  2279. extern unsigned int PRIV(ord2utf)(pcre_uint32, pcre_uchar *);
  2280. extern int PRIV(valid_utf)(PCRE_PUCHAR, int, int *);
  2281. extern BOOL PRIV(was_newline)(PCRE_PUCHAR, int, PCRE_PUCHAR,
  2282. int *, BOOL);
  2283. extern BOOL PRIV(xclass)(pcre_uint32, const pcre_uchar *, BOOL);
  2284. #ifdef SUPPORT_JIT
  2285. extern void PRIV(jit_compile)(const REAL_PCRE *,
  2286. PUBL(extra) *, int);
  2287. extern int PRIV(jit_exec)(const PUBL(extra) *,
  2288. const pcre_uchar *, int, int, int, int *, int);
  2289. extern void PRIV(jit_free)(void *);
  2290. extern int PRIV(jit_get_size)(void *);
  2291. extern const char* PRIV(jit_get_target)(void);
  2292. #endif
  2293. /* Unicode character database (UCD) */
  2294. typedef struct {
  2295. pcre_uint8 script; /* ucp_Arabic, etc. */
  2296. pcre_uint8 chartype; /* ucp_Cc, etc. (general categories) */
  2297. pcre_uint8 gbprop; /* ucp_gbControl, etc. (grapheme break property) */
  2298. pcre_uint8 caseset; /* offset to multichar other cases or zero */
  2299. pcre_int32 other_case; /* offset to other case, or zero if none */
  2300. } ucd_record;
  2301. extern const pcre_uint32 PRIV(ucd_caseless_sets)[];
  2302. extern const ucd_record PRIV(ucd_records)[];
  2303. extern const pcre_uint8 PRIV(ucd_stage1)[];
  2304. extern const pcre_uint16 PRIV(ucd_stage2)[];
  2305. extern const pcre_uint32 PRIV(ucp_gentype)[];
  2306. extern const pcre_uint32 PRIV(ucp_gbtable)[];
  2307. #ifdef COMPILE_PCRE32
  2308. extern const ucd_record PRIV(dummy_ucd_record)[];
  2309. #endif
  2310. #ifdef SUPPORT_JIT
  2311. extern const int PRIV(ucp_typerange)[];
  2312. #endif
  2313. #ifdef SUPPORT_UCP
  2314. /* UCD access macros */
  2315. #define UCD_BLOCK_SIZE 128
  2316. #define REAL_GET_UCD(ch) (PRIV(ucd_records) + \
  2317. PRIV(ucd_stage2)[PRIV(ucd_stage1)[(int)(ch) / UCD_BLOCK_SIZE] * \
  2318. UCD_BLOCK_SIZE + (int)(ch) % UCD_BLOCK_SIZE])
  2319. #ifdef COMPILE_PCRE32
  2320. #define GET_UCD(ch) ((ch > 0x10ffff)? PRIV(dummy_ucd_record) : REAL_GET_UCD(ch))
  2321. #else
  2322. #define GET_UCD(ch) REAL_GET_UCD(ch)
  2323. #endif
  2324. #define UCD_CHARTYPE(ch) GET_UCD(ch)->chartype
  2325. #define UCD_SCRIPT(ch) GET_UCD(ch)->script
  2326. #define UCD_CATEGORY(ch) PRIV(ucp_gentype)[UCD_CHARTYPE(ch)]
  2327. #define UCD_GRAPHBREAK(ch) GET_UCD(ch)->gbprop
  2328. #define UCD_CASESET(ch) GET_UCD(ch)->caseset
  2329. #define UCD_OTHERCASE(ch) ((pcre_uint32)((int)ch + (int)(GET_UCD(ch)->other_case)))
  2330. #endif /* SUPPORT_UCP */
  2331. #endif
  2332. /* End of pcre_internal.h */