PageRenderTime 54ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/harbour-2.0.0/external/pcre/pcredfa.c

#
C | 1941 lines | 1417 code | 237 blank | 287 comment | 419 complexity | 046e5561b38eaca4b13625dd753b7821 MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause, CC-BY-SA-3.0, LGPL-3.0, GPL-2.0, LGPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  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 (but see
  6. below for why this module is different).
  7. Written by Philip Hazel
  8. Copyright (c) 1997-2009 University of Cambridge
  9. -----------------------------------------------------------------------------
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. * Neither the name of the University of Cambridge nor the names of its
  18. contributors may be used to endorse or promote products derived from
  19. this software without specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  24. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. POSSIBILITY OF SUCH DAMAGE.
  31. -----------------------------------------------------------------------------
  32. */
  33. /* This module contains the external function pcre_dfa_exec(), which is an
  34. alternative matching function that uses a sort of DFA algorithm (not a true
  35. FSM). This is NOT Perl- compatible, but it has advantages in certain
  36. applications. */
  37. /* NOTE ABOUT PERFORMANCE: A user of this function sent some code that improved
  38. the performance of his patterns greatly. I could not use it as it stood, as it
  39. was not thread safe, and made assumptions about pattern sizes. Also, it caused
  40. test 7 to loop, and test 9 to crash with a segfault.
  41. The issue is the check for duplicate states, which is done by a simple linear
  42. search up the state list. (Grep for "duplicate" below to find the code.) For
  43. many patterns, there will never be many states active at one time, so a simple
  44. linear search is fine. In patterns that have many active states, it might be a
  45. bottleneck. The suggested code used an indexing scheme to remember which states
  46. had previously been used for each character, and avoided the linear search when
  47. it knew there was no chance of a duplicate. This was implemented when adding
  48. states to the state lists.
  49. I wrote some thread-safe, not-limited code to try something similar at the time
  50. of checking for duplicates (instead of when adding states), using index vectors
  51. on the stack. It did give a 13% improvement with one specially constructed
  52. pattern for certain subject strings, but on other strings and on many of the
  53. simpler patterns in the test suite it did worse. The major problem, I think,
  54. was the extra time to initialize the index. This had to be done for each call
  55. of internal_dfa_exec(). (The supplied patch used a static vector, initialized
  56. only once - I suspect this was the cause of the problems with the tests.)
  57. Overall, I concluded that the gains in some cases did not outweigh the losses
  58. in others, so I abandoned this code. */
  59. #ifdef HAVE_CONFIG_H
  60. #include "config.h"
  61. #endif
  62. #define NLBLOCK md /* Block containing newline information */
  63. #define PSSTART start_subject /* Field containing processed string start */
  64. #define PSEND end_subject /* Field containing processed string end */
  65. #include "pcreinal.h"
  66. /* For use to indent debugging output */
  67. #define SP " "
  68. /*************************************************
  69. * Code parameters and static tables *
  70. *************************************************/
  71. /* These are offsets that are used to turn the OP_TYPESTAR and friends opcodes
  72. into others, under special conditions. A gap of 20 between the blocks should be
  73. enough. The resulting opcodes don't have to be less than 256 because they are
  74. never stored, so we push them well clear of the normal opcodes. */
  75. #define OP_PROP_EXTRA 300
  76. #define OP_EXTUNI_EXTRA 320
  77. #define OP_ANYNL_EXTRA 340
  78. #define OP_HSPACE_EXTRA 360
  79. #define OP_VSPACE_EXTRA 380
  80. /* This table identifies those opcodes that are followed immediately by a
  81. character that is to be tested in some way. This makes is possible to
  82. centralize the loading of these characters. In the case of Type * etc, the
  83. "character" is the opcode for \D, \d, \S, \s, \W, or \w, which will always be a
  84. small value. Non-zero values in the table are the offsets from the opcode where
  85. the character is to be found. ***NOTE*** If the start of this table is
  86. modified, the three tables that follow must also be modified. */
  87. static const uschar coptable[] = {
  88. 0, /* End */
  89. 0, 0, 0, 0, 0, /* \A, \G, \K, \B, \b */
  90. 0, 0, 0, 0, 0, 0, /* \D, \d, \S, \s, \W, \w */
  91. 0, 0, 0, /* Any, AllAny, Anybyte */
  92. 0, 0, 0, /* NOTPROP, PROP, EXTUNI */
  93. 0, 0, 0, 0, 0, /* \R, \H, \h, \V, \v */
  94. 0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */
  95. 1, /* Char */
  96. 1, /* Charnc */
  97. 1, /* not */
  98. /* Positive single-char repeats */
  99. 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */
  100. 3, 3, 3, /* upto, minupto, exact */
  101. 1, 1, 1, 3, /* *+, ++, ?+, upto+ */
  102. /* Negative single-char repeats - only for chars < 256 */
  103. 1, 1, 1, 1, 1, 1, /* NOT *, *?, +, +?, ?, ?? */
  104. 3, 3, 3, /* NOT upto, minupto, exact */
  105. 1, 1, 1, 3, /* NOT *+, ++, ?+, updo+ */
  106. /* Positive type repeats */
  107. 1, 1, 1, 1, 1, 1, /* Type *, *?, +, +?, ?, ?? */
  108. 3, 3, 3, /* Type upto, minupto, exact */
  109. 1, 1, 1, 3, /* Type *+, ++, ?+, upto+ */
  110. /* Character class & ref repeats */
  111. 0, 0, 0, 0, 0, 0, /* *, *?, +, +?, ?, ?? */
  112. 0, 0, /* CRRANGE, CRMINRANGE */
  113. 0, /* CLASS */
  114. 0, /* NCLASS */
  115. 0, /* XCLASS - variable length */
  116. 0, /* REF */
  117. 0, /* RECURSE */
  118. 0, /* CALLOUT */
  119. 0, /* Alt */
  120. 0, /* Ket */
  121. 0, /* KetRmax */
  122. 0, /* KetRmin */
  123. 0, /* Assert */
  124. 0, /* Assert not */
  125. 0, /* Assert behind */
  126. 0, /* Assert behind not */
  127. 0, /* Reverse */
  128. 0, 0, 0, 0, /* ONCE, BRA, CBRA, COND */
  129. 0, 0, 0, /* SBRA, SCBRA, SCOND */
  130. 0, /* CREF */
  131. 0, /* RREF */
  132. 0, /* DEF */
  133. 0, 0, /* BRAZERO, BRAMINZERO */
  134. 0, 0, 0, 0, /* PRUNE, SKIP, THEN, COMMIT */
  135. 0, 0, 0, 0 /* FAIL, ACCEPT, CLOSE, SKIPZERO */
  136. };
  137. /* This table identifies those opcodes that inspect a character. It is used to
  138. remember the fact that a character could have been inspected when the end of
  139. the subject is reached. ***NOTE*** If the start of this table is modified, the
  140. two tables that follow must also be modified. */
  141. static const uschar poptable[] = {
  142. 0, /* End */
  143. 0, 0, 0, 1, 1, /* \A, \G, \K, \B, \b */
  144. 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */
  145. 1, 1, 1, /* Any, AllAny, Anybyte */
  146. 1, 1, 1, /* NOTPROP, PROP, EXTUNI */
  147. 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */
  148. 0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */
  149. 1, /* Char */
  150. 1, /* Charnc */
  151. 1, /* not */
  152. /* Positive single-char repeats */
  153. 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */
  154. 1, 1, 1, /* upto, minupto, exact */
  155. 1, 1, 1, 1, /* *+, ++, ?+, upto+ */
  156. /* Negative single-char repeats - only for chars < 256 */
  157. 1, 1, 1, 1, 1, 1, /* NOT *, *?, +, +?, ?, ?? */
  158. 1, 1, 1, /* NOT upto, minupto, exact */
  159. 1, 1, 1, 1, /* NOT *+, ++, ?+, upto+ */
  160. /* Positive type repeats */
  161. 1, 1, 1, 1, 1, 1, /* Type *, *?, +, +?, ?, ?? */
  162. 1, 1, 1, /* Type upto, minupto, exact */
  163. 1, 1, 1, 1, /* Type *+, ++, ?+, upto+ */
  164. /* Character class & ref repeats */
  165. 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */
  166. 1, 1, /* CRRANGE, CRMINRANGE */
  167. 1, /* CLASS */
  168. 1, /* NCLASS */
  169. 1, /* XCLASS - variable length */
  170. 0, /* REF */
  171. 0, /* RECURSE */
  172. 0, /* CALLOUT */
  173. 0, /* Alt */
  174. 0, /* Ket */
  175. 0, /* KetRmax */
  176. 0, /* KetRmin */
  177. 0, /* Assert */
  178. 0, /* Assert not */
  179. 0, /* Assert behind */
  180. 0, /* Assert behind not */
  181. 0, /* Reverse */
  182. 0, 0, 0, 0, /* ONCE, BRA, CBRA, COND */
  183. 0, 0, 0, /* SBRA, SCBRA, SCOND */
  184. 0, /* CREF */
  185. 0, /* RREF */
  186. 0, /* DEF */
  187. 0, 0, /* BRAZERO, BRAMINZERO */
  188. 0, 0, 0, 0, /* PRUNE, SKIP, THEN, COMMIT */
  189. 0, 0, 0, 0 /* FAIL, ACCEPT, CLOSE, SKIPZERO */
  190. };
  191. /* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W,
  192. and \w */
  193. static const uschar toptable1[] = {
  194. 0, 0, 0, 0, 0, 0,
  195. ctype_digit, ctype_digit,
  196. ctype_space, ctype_space,
  197. ctype_word, ctype_word,
  198. 0, 0 /* OP_ANY, OP_ALLANY */
  199. };
  200. static const uschar toptable2[] = {
  201. 0, 0, 0, 0, 0, 0,
  202. ctype_digit, 0,
  203. ctype_space, 0,
  204. ctype_word, 0,
  205. 1, 1 /* OP_ANY, OP_ALLANY */
  206. };
  207. /* Structure for holding data about a particular state, which is in effect the
  208. current data for an active path through the match tree. It must consist
  209. entirely of ints because the working vector we are passed, and which we put
  210. these structures in, is a vector of ints. */
  211. typedef struct stateblock {
  212. int offset; /* Offset to opcode */
  213. int count; /* Count for repeats */
  214. int ims; /* ims flag bits */
  215. int data; /* Some use extra data */
  216. } stateblock;
  217. #define INTS_PER_STATEBLOCK (sizeof(stateblock)/sizeof(int))
  218. #ifdef DEBUG
  219. /*************************************************
  220. * Print character string *
  221. *************************************************/
  222. /* Character string printing function for debugging.
  223. Arguments:
  224. p points to string
  225. length number of bytes
  226. f where to print
  227. Returns: nothing
  228. */
  229. static void
  230. pchars(unsigned char *p, int length, FILE *f)
  231. {
  232. int c;
  233. while (length-- > 0)
  234. {
  235. if (isprint(c = *(p++)))
  236. fprintf(f, "%c", c);
  237. else
  238. fprintf(f, "\\x%02x", c);
  239. }
  240. }
  241. #endif
  242. /*************************************************
  243. * Execute a Regular Expression - DFA engine *
  244. *************************************************/
  245. /* This internal function applies a compiled pattern to a subject string,
  246. starting at a given point, using a DFA engine. This function is called from the
  247. external one, possibly multiple times if the pattern is not anchored. The
  248. function calls itself recursively for some kinds of subpattern.
  249. Arguments:
  250. md the match_data block with fixed information
  251. this_start_code the opening bracket of this subexpression's code
  252. current_subject where we currently are in the subject string
  253. start_offset start offset in the subject string
  254. offsets vector to contain the matching string offsets
  255. offsetcount size of same
  256. workspace vector of workspace
  257. wscount size of same
  258. ims the current ims flags
  259. rlevel function call recursion level
  260. recursing regex recursive call level
  261. Returns: > 0 => number of match offset pairs placed in offsets
  262. = 0 => offsets overflowed; longest matches are present
  263. -1 => failed to match
  264. < -1 => some kind of unexpected problem
  265. The following macros are used for adding states to the two state vectors (one
  266. for the current character, one for the following character). */
  267. #define ADD_ACTIVE(x,y) \
  268. if (active_count++ < wscount) \
  269. { \
  270. next_active_state->offset = (x); \
  271. next_active_state->count = (y); \
  272. next_active_state->ims = ims; \
  273. next_active_state++; \
  274. DPRINTF(("%.*sADD_ACTIVE(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \
  275. } \
  276. else return PCRE_ERROR_DFA_WSSIZE
  277. #define ADD_ACTIVE_DATA(x,y,z) \
  278. if (active_count++ < wscount) \
  279. { \
  280. next_active_state->offset = (x); \
  281. next_active_state->count = (y); \
  282. next_active_state->ims = ims; \
  283. next_active_state->data = (z); \
  284. next_active_state++; \
  285. DPRINTF(("%.*sADD_ACTIVE_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \
  286. } \
  287. else return PCRE_ERROR_DFA_WSSIZE
  288. #define ADD_NEW(x,y) \
  289. if (new_count++ < wscount) \
  290. { \
  291. next_new_state->offset = (x); \
  292. next_new_state->count = (y); \
  293. next_new_state->ims = ims; \
  294. next_new_state++; \
  295. DPRINTF(("%.*sADD_NEW(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \
  296. } \
  297. else return PCRE_ERROR_DFA_WSSIZE
  298. #define ADD_NEW_DATA(x,y,z) \
  299. if (new_count++ < wscount) \
  300. { \
  301. next_new_state->offset = (x); \
  302. next_new_state->count = (y); \
  303. next_new_state->ims = ims; \
  304. next_new_state->data = (z); \
  305. next_new_state++; \
  306. DPRINTF(("%.*sADD_NEW_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \
  307. } \
  308. else return PCRE_ERROR_DFA_WSSIZE
  309. /* And now, here is the code */
  310. static int
  311. internal_dfa_exec(
  312. dfa_match_data *md,
  313. const uschar *this_start_code,
  314. const uschar *current_subject,
  315. int start_offset,
  316. int *offsets,
  317. int offsetcount,
  318. int *workspace,
  319. int wscount,
  320. int ims,
  321. int rlevel,
  322. int recursing)
  323. {
  324. stateblock *active_states, *new_states, *temp_states;
  325. stateblock *next_active_state, *next_new_state;
  326. const uschar *ctypes, *lcc, *fcc;
  327. const uschar *ptr;
  328. const uschar *end_code, *first_op;
  329. int active_count, new_count, match_count;
  330. /* Some fields in the md block are frequently referenced, so we load them into
  331. independent variables in the hope that this will perform better. */
  332. const uschar *start_subject = md->start_subject;
  333. const uschar *end_subject = md->end_subject;
  334. const uschar *start_code = md->start_code;
  335. #ifdef SUPPORT_UTF8
  336. BOOL utf8 = (md->poptions & PCRE_UTF8) != 0;
  337. #else
  338. BOOL utf8 = FALSE;
  339. #endif
  340. rlevel++;
  341. offsetcount &= (-2);
  342. wscount -= 2;
  343. wscount = (wscount - (wscount % (INTS_PER_STATEBLOCK * 2))) /
  344. (2 * INTS_PER_STATEBLOCK);
  345. DPRINTF(("\n%.*s---------------------\n"
  346. "%.*sCall to internal_dfa_exec f=%d r=%d\n",
  347. rlevel*2-2, SP, rlevel*2-2, SP, rlevel, recursing));
  348. ctypes = md->tables + ctypes_offset;
  349. lcc = md->tables + lcc_offset;
  350. fcc = md->tables + fcc_offset;
  351. match_count = PCRE_ERROR_NOMATCH; /* A negative number */
  352. active_states = (stateblock *)(workspace + 2);
  353. next_new_state = new_states = active_states + wscount;
  354. new_count = 0;
  355. first_op = this_start_code + 1 + LINK_SIZE +
  356. ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0);
  357. /* The first thing in any (sub) pattern is a bracket of some sort. Push all
  358. the alternative states onto the list, and find out where the end is. This
  359. makes is possible to use this function recursively, when we want to stop at a
  360. matching internal ket rather than at the end.
  361. If the first opcode in the first alternative is OP_REVERSE, we are dealing with
  362. a backward assertion. In that case, we have to find out the maximum amount to
  363. move back, and set up each alternative appropriately. */
  364. if (*first_op == OP_REVERSE)
  365. {
  366. int max_back = 0;
  367. int gone_back;
  368. end_code = this_start_code;
  369. do
  370. {
  371. int back = GET(end_code, 2+LINK_SIZE);
  372. if (back > max_back) max_back = back;
  373. end_code += GET(end_code, 1);
  374. }
  375. while (*end_code == OP_ALT);
  376. /* If we can't go back the amount required for the longest lookbehind
  377. pattern, go back as far as we can; some alternatives may still be viable. */
  378. #ifdef SUPPORT_UTF8
  379. /* In character mode we have to step back character by character */
  380. if (utf8)
  381. {
  382. for (gone_back = 0; gone_back < max_back; gone_back++)
  383. {
  384. if (current_subject <= start_subject) break;
  385. current_subject--;
  386. while (current_subject > start_subject &&
  387. (*current_subject & 0xc0) == 0x80)
  388. current_subject--;
  389. }
  390. }
  391. else
  392. #endif
  393. /* In byte-mode we can do this quickly. */
  394. {
  395. gone_back = (current_subject - max_back < start_subject)?
  396. current_subject - start_subject : max_back;
  397. current_subject -= gone_back;
  398. }
  399. /* Save the earliest consulted character */
  400. if (current_subject < md->start_used_ptr)
  401. md->start_used_ptr = current_subject;
  402. /* Now we can process the individual branches. */
  403. end_code = this_start_code;
  404. do
  405. {
  406. int back = GET(end_code, 2+LINK_SIZE);
  407. if (back <= gone_back)
  408. {
  409. int bstate = end_code - start_code + 2 + 2*LINK_SIZE;
  410. ADD_NEW_DATA(-bstate, 0, gone_back - back);
  411. }
  412. end_code += GET(end_code, 1);
  413. }
  414. while (*end_code == OP_ALT);
  415. }
  416. /* This is the code for a "normal" subpattern (not a backward assertion). The
  417. start of a whole pattern is always one of these. If we are at the top level,
  418. we may be asked to restart matching from the same point that we reached for a
  419. previous partial match. We still have to scan through the top-level branches to
  420. find the end state. */
  421. else
  422. {
  423. end_code = this_start_code;
  424. /* Restarting */
  425. if (rlevel == 1 && (md->moptions & PCRE_DFA_RESTART) != 0)
  426. {
  427. do { end_code += GET(end_code, 1); } while (*end_code == OP_ALT);
  428. new_count = workspace[1];
  429. if (!workspace[0])
  430. memcpy(new_states, active_states, new_count * sizeof(stateblock));
  431. }
  432. /* Not restarting */
  433. else
  434. {
  435. int length = 1 + LINK_SIZE +
  436. ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0);
  437. do
  438. {
  439. ADD_NEW(end_code - start_code + length, 0);
  440. end_code += GET(end_code, 1);
  441. length = 1 + LINK_SIZE;
  442. }
  443. while (*end_code == OP_ALT);
  444. }
  445. }
  446. workspace[0] = 0; /* Bit indicating which vector is current */
  447. DPRINTF(("%.*sEnd state = %d\n", rlevel*2-2, SP, end_code - start_code));
  448. /* Loop for scanning the subject */
  449. ptr = current_subject;
  450. for (;;)
  451. {
  452. int i, j;
  453. int clen, dlen;
  454. unsigned int c, d;
  455. int forced_fail = 0;
  456. BOOL could_continue = FALSE;
  457. /* Make the new state list into the active state list and empty the
  458. new state list. */
  459. temp_states = active_states;
  460. active_states = new_states;
  461. new_states = temp_states;
  462. active_count = new_count;
  463. new_count = 0;
  464. workspace[0] ^= 1; /* Remember for the restarting feature */
  465. workspace[1] = active_count;
  466. #ifdef DEBUG
  467. printf("%.*sNext character: rest of subject = \"", rlevel*2-2, SP);
  468. pchars((uschar *)ptr, strlen((char *)ptr), stdout);
  469. printf("\"\n");
  470. printf("%.*sActive states: ", rlevel*2-2, SP);
  471. for (i = 0; i < active_count; i++)
  472. printf("%d/%d ", active_states[i].offset, active_states[i].count);
  473. printf("\n");
  474. #endif
  475. /* Set the pointers for adding new states */
  476. next_active_state = active_states + active_count;
  477. next_new_state = new_states;
  478. /* Load the current character from the subject outside the loop, as many
  479. different states may want to look at it, and we assume that at least one
  480. will. */
  481. if (ptr < end_subject)
  482. {
  483. clen = 1; /* Number of bytes in the character */
  484. #ifdef SUPPORT_UTF8
  485. if (utf8) { GETCHARLEN(c, ptr, clen); } else
  486. #endif /* SUPPORT_UTF8 */
  487. c = *ptr;
  488. }
  489. else
  490. {
  491. clen = 0; /* This indicates the end of the subject */
  492. c = NOTACHAR; /* This value should never actually be used */
  493. }
  494. /* Scan up the active states and act on each one. The result of an action
  495. may be to add more states to the currently active list (e.g. on hitting a
  496. parenthesis) or it may be to put states on the new list, for considering
  497. when we move the character pointer on. */
  498. for (i = 0; i < active_count; i++)
  499. {
  500. stateblock *current_state = active_states + i;
  501. const uschar *code;
  502. int state_offset = current_state->offset;
  503. int count, codevalue, rrc;
  504. #ifdef DEBUG
  505. printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset);
  506. if (clen == 0) printf("EOL\n");
  507. else if (c > 32 && c < 127) printf("'%c'\n", c);
  508. else printf("0x%02x\n", c);
  509. #endif
  510. /* This variable is referred to implicity in the ADD_xxx macros. */
  511. ims = current_state->ims;
  512. /* A negative offset is a special case meaning "hold off going to this
  513. (negated) state until the number of characters in the data field have
  514. been skipped". */
  515. if (state_offset < 0)
  516. {
  517. if (current_state->data > 0)
  518. {
  519. DPRINTF(("%.*sSkipping this character\n", rlevel*2-2, SP));
  520. ADD_NEW_DATA(state_offset, current_state->count,
  521. current_state->data - 1);
  522. continue;
  523. }
  524. else
  525. {
  526. current_state->offset = state_offset = -state_offset;
  527. }
  528. }
  529. /* Check for a duplicate state with the same count, and skip if found.
  530. See the note at the head of this module about the possibility of improving
  531. performance here. */
  532. for (j = 0; j < i; j++)
  533. {
  534. if (active_states[j].offset == state_offset &&
  535. active_states[j].count == current_state->count)
  536. {
  537. DPRINTF(("%.*sDuplicate state: skipped\n", rlevel*2-2, SP));
  538. goto NEXT_ACTIVE_STATE;
  539. }
  540. }
  541. /* The state offset is the offset to the opcode */
  542. code = start_code + state_offset;
  543. codevalue = *code;
  544. /* If this opcode inspects a character, but we are at the end of the
  545. subject, remember the fact for use when testing for a partial match. */
  546. if (clen == 0 && poptable[codevalue] != 0)
  547. could_continue = TRUE;
  548. /* If this opcode is followed by an inline character, load it. It is
  549. tempting to test for the presence of a subject character here, but that
  550. is wrong, because sometimes zero repetitions of the subject are
  551. permitted.
  552. We also use this mechanism for opcodes such as OP_TYPEPLUS that take an
  553. argument that is not a data character - but is always one byte long. We
  554. have to take special action to deal with \P, \p, \H, \h, \V, \v and \X in
  555. this case. To keep the other cases fast, convert these ones to new opcodes.
  556. */
  557. if (coptable[codevalue] > 0)
  558. {
  559. dlen = 1;
  560. #ifdef SUPPORT_UTF8
  561. if (utf8) { GETCHARLEN(d, (code + coptable[codevalue]), dlen); } else
  562. #endif /* SUPPORT_UTF8 */
  563. d = code[coptable[codevalue]];
  564. if (codevalue >= OP_TYPESTAR)
  565. {
  566. switch(d)
  567. {
  568. case OP_ANYBYTE: return PCRE_ERROR_DFA_UITEM;
  569. case OP_NOTPROP:
  570. case OP_PROP: codevalue += OP_PROP_EXTRA; break;
  571. case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break;
  572. case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break;
  573. case OP_NOT_HSPACE:
  574. case OP_HSPACE: codevalue += OP_HSPACE_EXTRA; break;
  575. case OP_NOT_VSPACE:
  576. case OP_VSPACE: codevalue += OP_VSPACE_EXTRA; break;
  577. default: break;
  578. }
  579. }
  580. }
  581. else
  582. {
  583. dlen = 0; /* Not strictly necessary, but compilers moan */
  584. d = NOTACHAR; /* if these variables are not set. */
  585. }
  586. /* Now process the individual opcodes */
  587. switch (codevalue)
  588. {
  589. /* ========================================================================== */
  590. /* Reached a closing bracket. If not at the end of the pattern, carry
  591. on with the next opcode. Otherwise, unless we have an empty string and
  592. PCRE_NOTEMPTY is set, or PCRE_NOTEMPTY_ATSTART is set and we are at the
  593. start of the subject, save the match data, shifting up all previous
  594. matches so we always have the longest first. */
  595. case OP_KET:
  596. case OP_KETRMIN:
  597. case OP_KETRMAX:
  598. if (code != end_code)
  599. {
  600. ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0);
  601. if (codevalue != OP_KET)
  602. {
  603. ADD_ACTIVE(state_offset - GET(code, 1), 0);
  604. }
  605. }
  606. else
  607. {
  608. if (ptr > current_subject ||
  609. ((md->moptions & PCRE_NOTEMPTY) == 0 &&
  610. ((md->moptions & PCRE_NOTEMPTY_ATSTART) == 0 ||
  611. current_subject > start_subject + md->start_offset)))
  612. {
  613. if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0;
  614. else if (match_count > 0 && ++match_count * 2 >= offsetcount)
  615. match_count = 0;
  616. count = ((match_count == 0)? offsetcount : match_count * 2) - 2;
  617. if (count > 0) memmove(offsets + 2, offsets, count * sizeof(int));
  618. if (offsetcount >= 2)
  619. {
  620. offsets[0] = current_subject - start_subject;
  621. offsets[1] = ptr - start_subject;
  622. DPRINTF(("%.*sSet matched string = \"%.*s\"\n", rlevel*2-2, SP,
  623. offsets[1] - offsets[0], current_subject));
  624. }
  625. if ((md->moptions & PCRE_DFA_SHORTEST) != 0)
  626. {
  627. DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n"
  628. "%.*s---------------------\n\n", rlevel*2-2, SP, rlevel,
  629. match_count, rlevel*2-2, SP));
  630. return match_count;
  631. }
  632. }
  633. }
  634. break;
  635. /* ========================================================================== */
  636. /* These opcodes add to the current list of states without looking
  637. at the current character. */
  638. /*-----------------------------------------------------------------*/
  639. case OP_ALT:
  640. do { code += GET(code, 1); } while (*code == OP_ALT);
  641. ADD_ACTIVE(code - start_code, 0);
  642. break;
  643. /*-----------------------------------------------------------------*/
  644. case OP_BRA:
  645. case OP_SBRA:
  646. do
  647. {
  648. ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0);
  649. code += GET(code, 1);
  650. }
  651. while (*code == OP_ALT);
  652. break;
  653. /*-----------------------------------------------------------------*/
  654. case OP_CBRA:
  655. case OP_SCBRA:
  656. ADD_ACTIVE(code - start_code + 3 + LINK_SIZE, 0);
  657. code += GET(code, 1);
  658. while (*code == OP_ALT)
  659. {
  660. ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0);
  661. code += GET(code, 1);
  662. }
  663. break;
  664. /*-----------------------------------------------------------------*/
  665. case OP_BRAZERO:
  666. case OP_BRAMINZERO:
  667. ADD_ACTIVE(state_offset + 1, 0);
  668. code += 1 + GET(code, 2);
  669. while (*code == OP_ALT) code += GET(code, 1);
  670. ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0);
  671. break;
  672. /*-----------------------------------------------------------------*/
  673. case OP_SKIPZERO:
  674. code += 1 + GET(code, 2);
  675. while (*code == OP_ALT) code += GET(code, 1);
  676. ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0);
  677. break;
  678. /*-----------------------------------------------------------------*/
  679. case OP_CIRC:
  680. if ((ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0) ||
  681. ((ims & PCRE_MULTILINE) != 0 &&
  682. ptr != end_subject &&
  683. WAS_NEWLINE(ptr)))
  684. { ADD_ACTIVE(state_offset + 1, 0); }
  685. break;
  686. /*-----------------------------------------------------------------*/
  687. case OP_EOD:
  688. if (ptr >= end_subject) { ADD_ACTIVE(state_offset + 1, 0); }
  689. break;
  690. /*-----------------------------------------------------------------*/
  691. case OP_OPT:
  692. ims = code[1];
  693. ADD_ACTIVE(state_offset + 2, 0);
  694. break;
  695. /*-----------------------------------------------------------------*/
  696. case OP_SOD:
  697. if (ptr == start_subject) { ADD_ACTIVE(state_offset + 1, 0); }
  698. break;
  699. /*-----------------------------------------------------------------*/
  700. case OP_SOM:
  701. if (ptr == start_subject + start_offset) { ADD_ACTIVE(state_offset + 1, 0); }
  702. break;
  703. /* ========================================================================== */
  704. /* These opcodes inspect the next subject character, and sometimes
  705. the previous one as well, but do not have an argument. The variable
  706. clen contains the length of the current character and is zero if we are
  707. at the end of the subject. */
  708. /*-----------------------------------------------------------------*/
  709. case OP_ANY:
  710. if (clen > 0 && !IS_NEWLINE(ptr))
  711. { ADD_NEW(state_offset + 1, 0); }
  712. break;
  713. /*-----------------------------------------------------------------*/
  714. case OP_ALLANY:
  715. if (clen > 0)
  716. { ADD_NEW(state_offset + 1, 0); }
  717. break;
  718. /*-----------------------------------------------------------------*/
  719. case OP_EODN:
  720. if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - md->nllen))
  721. { ADD_ACTIVE(state_offset + 1, 0); }
  722. break;
  723. /*-----------------------------------------------------------------*/
  724. case OP_DOLL:
  725. if ((md->moptions & PCRE_NOTEOL) == 0)
  726. {
  727. if (clen == 0 ||
  728. ((md->poptions & PCRE_DOLLAR_ENDONLY) == 0 && IS_NEWLINE(ptr) &&
  729. ((ims & PCRE_MULTILINE) != 0 || ptr == end_subject - md->nllen)
  730. ))
  731. { ADD_ACTIVE(state_offset + 1, 0); }
  732. }
  733. else if ((ims & PCRE_MULTILINE) != 0 && IS_NEWLINE(ptr))
  734. { ADD_ACTIVE(state_offset + 1, 0); }
  735. break;
  736. /*-----------------------------------------------------------------*/
  737. case OP_DIGIT:
  738. case OP_WHITESPACE:
  739. case OP_WORDCHAR:
  740. if (clen > 0 && c < 256 &&
  741. ((ctypes[c] & toptable1[codevalue]) ^ toptable2[codevalue]) != 0)
  742. { ADD_NEW(state_offset + 1, 0); }
  743. break;
  744. /*-----------------------------------------------------------------*/
  745. case OP_NOT_DIGIT:
  746. case OP_NOT_WHITESPACE:
  747. case OP_NOT_WORDCHAR:
  748. if (clen > 0 && (c >= 256 ||
  749. ((ctypes[c] & toptable1[codevalue]) ^ toptable2[codevalue]) != 0))
  750. { ADD_NEW(state_offset + 1, 0); }
  751. break;
  752. /*-----------------------------------------------------------------*/
  753. case OP_WORD_BOUNDARY:
  754. case OP_NOT_WORD_BOUNDARY:
  755. {
  756. int left_word, right_word;
  757. if (ptr > start_subject)
  758. {
  759. const uschar *temp = ptr - 1;
  760. if (temp < md->start_used_ptr) md->start_used_ptr = temp;
  761. #ifdef SUPPORT_UTF8
  762. if (utf8) BACKCHAR(temp);
  763. #endif
  764. GETCHARTEST(d, temp);
  765. left_word = d < 256 && (ctypes[d] & ctype_word) != 0;
  766. }
  767. else left_word = 0;
  768. if (clen > 0)
  769. right_word = c < 256 && (ctypes[c] & ctype_word) != 0;
  770. else right_word = 0;
  771. if ((left_word == right_word) == (codevalue == OP_NOT_WORD_BOUNDARY))
  772. { ADD_ACTIVE(state_offset + 1, 0); }
  773. }
  774. break;
  775. /*-----------------------------------------------------------------*/
  776. /* Check the next character by Unicode property. We will get here only
  777. if the support is in the binary; otherwise a compile-time error occurs.
  778. */
  779. #ifdef SUPPORT_UCP
  780. case OP_PROP:
  781. case OP_NOTPROP:
  782. if (clen > 0)
  783. {
  784. BOOL OK;
  785. const ucd_record * prop = GET_UCD(c);
  786. switch(code[1])
  787. {
  788. case PT_ANY:
  789. OK = TRUE;
  790. break;
  791. case PT_LAMP:
  792. OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll || prop->chartype == ucp_Lt;
  793. break;
  794. case PT_GC:
  795. OK = _pcre_ucp_gentype[prop->chartype] == code[2];
  796. break;
  797. case PT_PC:
  798. OK = prop->chartype == code[2];
  799. break;
  800. case PT_SC:
  801. OK = prop->script == code[2];
  802. break;
  803. /* Should never occur, but keep compilers from grumbling. */
  804. default:
  805. OK = codevalue != OP_PROP;
  806. break;
  807. }
  808. if (OK == (codevalue == OP_PROP)) { ADD_NEW(state_offset + 3, 0); }
  809. }
  810. break;
  811. #endif
  812. /* ========================================================================== */
  813. /* These opcodes likewise inspect the subject character, but have an
  814. argument that is not a data character. It is one of these opcodes:
  815. OP_ANY, OP_ALLANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE,
  816. OP_WORDCHAR, OP_NOT_WORDCHAR. The value is loaded into d. */
  817. case OP_TYPEPLUS:
  818. case OP_TYPEMINPLUS:
  819. case OP_TYPEPOSPLUS:
  820. count = current_state->count; /* Already matched */
  821. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  822. if (clen > 0)
  823. {
  824. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  825. (c < 256 &&
  826. (d != OP_ANY || !IS_NEWLINE(ptr)) &&
  827. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  828. {
  829. if (count > 0 && codevalue == OP_TYPEPOSPLUS)
  830. {
  831. active_count--; /* Remove non-match possibility */
  832. next_active_state--;
  833. }
  834. count++;
  835. ADD_NEW(state_offset, count);
  836. }
  837. }
  838. break;
  839. /*-----------------------------------------------------------------*/
  840. case OP_TYPEQUERY:
  841. case OP_TYPEMINQUERY:
  842. case OP_TYPEPOSQUERY:
  843. ADD_ACTIVE(state_offset + 2, 0);
  844. if (clen > 0)
  845. {
  846. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  847. (c < 256 &&
  848. (d != OP_ANY || !IS_NEWLINE(ptr)) &&
  849. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  850. {
  851. if (codevalue == OP_TYPEPOSQUERY)
  852. {
  853. active_count--; /* Remove non-match possibility */
  854. next_active_state--;
  855. }
  856. ADD_NEW(state_offset + 2, 0);
  857. }
  858. }
  859. break;
  860. /*-----------------------------------------------------------------*/
  861. case OP_TYPESTAR:
  862. case OP_TYPEMINSTAR:
  863. case OP_TYPEPOSSTAR:
  864. ADD_ACTIVE(state_offset + 2, 0);
  865. if (clen > 0)
  866. {
  867. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  868. (c < 256 &&
  869. (d != OP_ANY || !IS_NEWLINE(ptr)) &&
  870. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  871. {
  872. if (codevalue == OP_TYPEPOSSTAR)
  873. {
  874. active_count--; /* Remove non-match possibility */
  875. next_active_state--;
  876. }
  877. ADD_NEW(state_offset, 0);
  878. }
  879. }
  880. break;
  881. /*-----------------------------------------------------------------*/
  882. case OP_TYPEEXACT:
  883. count = current_state->count; /* Number already matched */
  884. if (clen > 0)
  885. {
  886. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  887. (c < 256 &&
  888. (d != OP_ANY || !IS_NEWLINE(ptr)) &&
  889. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  890. {
  891. if (++count >= GET2(code, 1))
  892. { ADD_NEW(state_offset + 4, 0); }
  893. else
  894. { ADD_NEW(state_offset, count); }
  895. }
  896. }
  897. break;
  898. /*-----------------------------------------------------------------*/
  899. case OP_TYPEUPTO:
  900. case OP_TYPEMINUPTO:
  901. case OP_TYPEPOSUPTO:
  902. ADD_ACTIVE(state_offset + 4, 0);
  903. count = current_state->count; /* Number already matched */
  904. if (clen > 0)
  905. {
  906. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  907. (c < 256 &&
  908. (d != OP_ANY || !IS_NEWLINE(ptr)) &&
  909. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  910. {
  911. if (codevalue == OP_TYPEPOSUPTO)
  912. {
  913. active_count--; /* Remove non-match possibility */
  914. next_active_state--;
  915. }
  916. if (++count >= GET2(code, 1))
  917. { ADD_NEW(state_offset + 4, 0); }
  918. else
  919. { ADD_NEW(state_offset, count); }
  920. }
  921. }
  922. break;
  923. /* ========================================================================== */
  924. /* These are virtual opcodes that are used when something like
  925. OP_TYPEPLUS has OP_PROP, OP_NOTPROP, OP_ANYNL, or OP_EXTUNI as its
  926. argument. It keeps the code above fast for the other cases. The argument
  927. is in the d variable. */
  928. #ifdef SUPPORT_UCP
  929. case OP_PROP_EXTRA + OP_TYPEPLUS:
  930. case OP_PROP_EXTRA + OP_TYPEMINPLUS:
  931. case OP_PROP_EXTRA + OP_TYPEPOSPLUS:
  932. count = current_state->count; /* Already matched */
  933. if (count > 0) { ADD_ACTIVE(state_offset + 4, 0); }
  934. if (clen > 0)
  935. {
  936. BOOL OK;
  937. const ucd_record * prop = GET_UCD(c);
  938. switch(code[2])
  939. {
  940. case PT_ANY:
  941. OK = TRUE;
  942. break;
  943. case PT_LAMP:
  944. OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll || prop->chartype == ucp_Lt;
  945. break;
  946. case PT_GC:
  947. OK = _pcre_ucp_gentype[prop->chartype] == code[3];
  948. break;
  949. case PT_PC:
  950. OK = prop->chartype == code[3];
  951. break;
  952. case PT_SC:
  953. OK = prop->script == code[3];
  954. break;
  955. /* Should never occur, but keep compilers from grumbling. */
  956. default:
  957. OK = codevalue != OP_PROP;
  958. break;
  959. }
  960. if (OK == (d == OP_PROP))
  961. {
  962. if (count > 0 && codevalue == OP_PROP_EXTRA + OP_TYPEPOSPLUS)
  963. {
  964. active_count--; /* Remove non-match possibility */
  965. next_active_state--;
  966. }
  967. count++;
  968. ADD_NEW(state_offset, count);
  969. }
  970. }
  971. break;
  972. /*-----------------------------------------------------------------*/
  973. case OP_EXTUNI_EXTRA + OP_TYPEPLUS:
  974. case OP_EXTUNI_EXTRA + OP_TYPEMINPLUS:
  975. case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS:
  976. count = current_state->count; /* Already matched */
  977. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  978. if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
  979. {
  980. const uschar *nptr = ptr + clen;
  981. int ncount = 0;
  982. if (count > 0 && codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS)
  983. {
  984. active_count--; /* Remove non-match possibility */
  985. next_active_state--;
  986. }
  987. while (nptr < end_subject)
  988. {
  989. int nd;
  990. int ndlen = 1;
  991. GETCHARLEN(nd, nptr, ndlen);
  992. if (UCD_CATEGORY(nd) != ucp_M) break;
  993. ncount++;
  994. nptr += ndlen;
  995. }
  996. count++;
  997. ADD_NEW_DATA(-state_offset, count, ncount);
  998. }
  999. break;
  1000. #endif
  1001. /*-----------------------------------------------------------------*/
  1002. case OP_ANYNL_EXTRA + OP_TYPEPLUS:
  1003. case OP_ANYNL_EXTRA + OP_TYPEMINPLUS:
  1004. case OP_ANYNL_EXTRA + OP_TYPEPOSPLUS:
  1005. count = current_state->count; /* Already matched */
  1006. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  1007. if (clen > 0)
  1008. {
  1009. int ncount = 0;
  1010. switch (c)
  1011. {
  1012. case 0x000b:
  1013. case 0x000c:
  1014. case 0x0085:
  1015. case 0x2028:
  1016. case 0x2029:
  1017. if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
  1018. goto ANYNL01;
  1019. case 0x000d:
  1020. if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
  1021. /* Fall through */
  1022. ANYNL01:
  1023. case 0x000a:
  1024. if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS)
  1025. {
  1026. active_count--; /* Remove non-match possibility */
  1027. next_active_state--;
  1028. }
  1029. count++;
  1030. ADD_NEW_DATA(-state_offset, count, ncount);
  1031. break;
  1032. default:
  1033. break;
  1034. }
  1035. }
  1036. break;
  1037. /*-----------------------------------------------------------------*/
  1038. case OP_VSPACE_EXTRA + OP_TYPEPLUS:
  1039. case OP_VSPACE_EXTRA + OP_TYPEMINPLUS:
  1040. case OP_VSPACE_EXTRA + OP_TYPEPOSPLUS:
  1041. count = current_state->count; /* Already matched */
  1042. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  1043. if (clen > 0)
  1044. {
  1045. BOOL OK;
  1046. switch (c)
  1047. {
  1048. case 0x000a:
  1049. case 0x000b:
  1050. case 0x000c:
  1051. case 0x000d:
  1052. case 0x0085:
  1053. case 0x2028:
  1054. case 0x2029:
  1055. OK = TRUE;
  1056. break;
  1057. default:
  1058. OK = FALSE;
  1059. break;
  1060. }
  1061. if (OK == (d == OP_VSPACE))
  1062. {
  1063. if (count > 0 && codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSPLUS)
  1064. {
  1065. active_count--; /* Remove non-match possibility */
  1066. next_active_state--;
  1067. }
  1068. count++;
  1069. ADD_NEW_DATA(-state_offset, count, 0);
  1070. }
  1071. }
  1072. break;
  1073. /*-----------------------------------------------------------------*/
  1074. case OP_HSPACE_EXTRA + OP_TYPEPLUS:
  1075. case OP_HSPACE_EXTRA + OP_TYPEMINPLUS:
  1076. case OP_HSPACE_EXTRA + OP_TYPEPOSPLUS:
  1077. count = current_state->count; /* Already matched */
  1078. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  1079. if (clen > 0)
  1080. {
  1081. BOOL OK;
  1082. switch (c)
  1083. {
  1084. case 0x09: /* HT */
  1085. case 0x20: /* SPACE */
  1086. case 0xa0: /* NBSP */
  1087. case 0x1680: /* OGHAM SPACE MARK */
  1088. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
  1089. case 0x2000: /* EN QUAD */
  1090. case 0x2001: /* EM QUAD */
  1091. case 0x2002: /* EN SPACE */
  1092. case 0x2003: /* EM SPACE */
  1093. case 0x2004: /* THREE-PER-EM SPACE */
  1094. case 0x2005: /* FOUR-PER-EM SPACE */
  1095. case 0x2006: /* SIX-PER-EM SPACE */
  1096. case 0x2007: /* FIGURE SPACE */
  1097. case 0x2008: /* PUNCTUATION SPACE */
  1098. case 0x2009: /* THIN SPACE */
  1099. case 0x200A: /* HAIR SPACE */
  1100. case 0x202f: /* NARROW NO-BREAK SPACE */
  1101. case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
  1102. case 0x3000: /* IDEOGRAPHIC SPACE */
  1103. OK = TRUE;
  1104. break;
  1105. default:
  1106. OK = FALSE;
  1107. break;
  1108. }
  1109. if (OK == (d == OP_HSPACE))
  1110. {
  1111. if (count > 0 && codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSPLUS)
  1112. {
  1113. active_count--; /* Remove non-match possibility */
  1114. next_active_state--;
  1115. }
  1116. count++;
  1117. ADD_NEW_DATA(-state_offset, count, 0);
  1118. }
  1119. }
  1120. break;
  1121. /*-----------------------------------------------------------------*/
  1122. #ifdef SUPPORT_UCP
  1123. case OP_PROP_EXTRA + OP_TYPEQUERY:
  1124. case OP_PROP_EXTRA + OP_TYPEMINQUERY:
  1125. case OP_PROP_EXTRA + OP_TYPEPOSQUERY:
  1126. count = 4;
  1127. goto QS1;
  1128. case OP_PROP_EXTRA + OP_TYPESTAR:
  1129. case OP_PROP_EXTRA + OP_TYPEMINSTAR:
  1130. case OP_PROP_EXTRA + OP_TYPEPOSSTAR:
  1131. count = 0;
  1132. QS1:
  1133. ADD_ACTIVE(state_offset + 4, 0);
  1134. if (clen > 0)
  1135. {
  1136. BOOL OK;
  1137. const ucd_record * prop = GET_UCD(c);
  1138. switch(code[2])
  1139. {
  1140. case PT_ANY:
  1141. OK = TRUE;
  1142. break;
  1143. case PT_LAMP:
  1144. OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll || prop->chartype == ucp_Lt;
  1145. break;
  1146. case PT_GC:
  1147. OK = _pcre_ucp_gentype[prop->chartype] == code[3];
  1148. break;
  1149. case PT_PC:
  1150. OK = prop->chartype == code[3];
  1151. break;
  1152. case PT_SC:
  1153. OK = prop->script == code[3];
  1154. break;
  1155. /* Should never occur, but keep compilers from grumbling. */
  1156. default:
  1157. OK = codevalue != OP_PROP;
  1158. break;
  1159. }
  1160. if (OK == (d == OP_PROP))
  1161. {
  1162. if (codevalue == OP_PROP_EXTRA + OP_TYPEPOSSTAR ||
  1163. codevalue == OP_PROP_EXTRA + OP_TYPEPOSQUERY)
  1164. {
  1165. active_count--; /* Remove non-match possibility */
  1166. next_active_state--;
  1167. }
  1168. ADD_NEW(state_offset + count, 0);
  1169. }
  1170. }
  1171. break;
  1172. /*-----------------------------------------------------------------*/
  1173. case OP_EXTUNI_EXTRA + OP_TYPEQUERY:
  1174. case OP_EXTUNI_EXTRA + OP_TYPEMINQUERY:
  1175. case OP_EXTUNI_EXTRA + OP_TYPEPOSQUERY:
  1176. count = 2;
  1177. goto QS2;
  1178. case OP_EXTUNI_EXTRA + OP_TYPESTAR:
  1179. case OP_EXTUNI_EXTRA + OP_TYPEMINSTAR:
  1180. case OP_EXTUNI_EXTRA + OP_TYPEPOSSTAR:
  1181. count = 0;
  1182. QS2:
  1183. ADD_ACTIVE(state_offset + 2, 0);
  1184. if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
  1185. {
  1186. const uschar *nptr = ptr + clen;
  1187. int ncount = 0;
  1188. if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSSTAR ||
  1189. codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSQUERY)
  1190. {
  1191. active_count--; /* Remove non-match possibility */
  1192. next_active_state--;
  1193. }
  1194. while (nptr < end_subject)
  1195. {
  1196. int nd;
  1197. int ndlen = 1;
  1198. GETCHARLEN(nd, nptr, ndlen);
  1199. if (UCD_CATEGORY(nd) != ucp_M) break;
  1200. ncount++;
  1201. nptr += ndlen;
  1202. }
  1203. ADD_NEW_DATA(-(state_offset + count), 0, ncount);
  1204. }
  1205. break;
  1206. #endif
  1207. /*-----------------------------------------------------------------*/
  1208. case OP_ANYNL_EXTRA + OP_TYPEQUERY:
  1209. case OP_ANYNL_EXTRA + OP_TYPEMINQUERY:
  1210. case OP_ANYNL_EXTRA + OP_TYPEPOSQUERY:
  1211. count = 2;
  1212. goto QS

Large files files are truncated, but you can click here to view the full file