PageRenderTime 68ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/beta1/harbour/source/hbpcre/pcredfa.c

#
C | 1888 lines | 1257 code | 270 blank | 361 comment | 501 complexity | 4794f7e0596dc77bcf9691efbe6a8702 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.
  6. Written by Philip Hazel
  7. Copyright (c) 1997-2005 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 module contains the external function pcre_dfa_exec(), which is an
  33. alternative matching function that uses a DFA algorithm. This is NOT Perl-
  34. compatible, but it has advantages in certain applications. */
  35. #include "pcreinal.h"
  36. /* For use to indent debugging output */
  37. #define SP " "
  38. /*************************************************
  39. * Code parameters and static tables *
  40. *************************************************/
  41. /* These are offsets that are used to turn the OP_TYPESTAR and friends opcodes
  42. into others, under special conditions. A gap of 10 between the blocks should be
  43. enough. */
  44. #define OP_PROP_EXTRA (EXTRACT_BASIC_MAX+1)
  45. #define OP_EXTUNI_EXTRA (EXTRACT_BASIC_MAX+11)
  46. /* This table identifies those opcodes that are followed immediately by a
  47. character that is to be tested in some way. This makes is possible to
  48. centralize the loading of these characters. In the case of Type * etc, the
  49. "character" is the opcode for \D, \d, \S, \s, \W, or \w, which will always be a
  50. small value. */
  51. static uschar coptable[] = {
  52. 0, /* End */
  53. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* \A, \G, \B, \b, \D, \d, \S, \s, \W, \w */
  54. 0, 0, /* Any, Anybyte */
  55. 0, 0, 0, /* NOTPROP, PROP, EXTUNI */
  56. 0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */
  57. 1, /* Char */
  58. 1, /* Charnc */
  59. 1, /* not */
  60. /* Positive single-char repeats */
  61. 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */
  62. 3, 3, 3, /* upto, minupto, exact */
  63. /* Negative single-char repeats - only for chars < 256 */
  64. 1, 1, 1, 1, 1, 1, /* NOT *, *?, +, +?, ?, ?? */
  65. 3, 3, 3, /* NOT upto, minupto, exact */
  66. /* Positive type repeats */
  67. 1, 1, 1, 1, 1, 1, /* Type *, *?, +, +?, ?, ?? */
  68. 3, 3, 3, /* Type upto, minupto, exact */
  69. /* Character class & ref repeats */
  70. 0, 0, 0, 0, 0, 0, /* *, *?, +, +?, ?, ?? */
  71. 0, 0, /* CRRANGE, CRMINRANGE */
  72. 0, /* CLASS */
  73. 0, /* NCLASS */
  74. 0, /* XCLASS - variable length */
  75. 0, /* REF */
  76. 0, /* RECURSE */
  77. 0, /* CALLOUT */
  78. 0, /* Alt */
  79. 0, /* Ket */
  80. 0, /* KetRmax */
  81. 0, /* KetRmin */
  82. 0, /* Assert */
  83. 0, /* Assert not */
  84. 0, /* Assert behind */
  85. 0, /* Assert behind not */
  86. 0, /* Reverse */
  87. 0, /* Once */
  88. 0, /* COND */
  89. 0, /* CREF */
  90. 0, 0, /* BRAZERO, BRAMINZERO */
  91. 0, /* BRANUMBER */
  92. 0 /* BRA */
  93. };
  94. /* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W,
  95. and \w */
  96. static uschar toptable1[] = {
  97. 0, 0, 0, 0, 0,
  98. ctype_digit, ctype_digit,
  99. ctype_space, ctype_space,
  100. ctype_word, ctype_word,
  101. 0 /* OP_ANY */
  102. };
  103. static uschar toptable2[] = {
  104. 0, 0, 0, 0, 0,
  105. ctype_digit, 0,
  106. ctype_space, 0,
  107. ctype_word, 0,
  108. 1 /* OP_ANY */
  109. };
  110. /* Structure for holding data about a particular state, which is in effect the
  111. current data for an active path through the match tree. It must consist
  112. entirely of ints because the working vector we are passed, and which we put
  113. these structures in, is a vector of ints. */
  114. typedef struct stateblock {
  115. int offset; /* Offset to opcode */
  116. int count; /* Count for repeats */
  117. int ims; /* ims flag bits */
  118. int data; /* Some use extra data */
  119. } stateblock;
  120. #define INTS_PER_STATEBLOCK (sizeof(stateblock)/sizeof(int))
  121. #ifdef DEBUG
  122. /*************************************************
  123. * Print character string *
  124. *************************************************/
  125. /* Character string printing function for debugging.
  126. Arguments:
  127. p points to string
  128. length number of bytes
  129. f where to print
  130. Returns: nothing
  131. */
  132. static void
  133. pchars(unsigned char *p, int length, FILE *f)
  134. {
  135. int c;
  136. while (length-- > 0)
  137. {
  138. if (isprint(c = *(p++)))
  139. fprintf(f, "%c", c);
  140. else
  141. fprintf(f, "\\x%02x", c);
  142. }
  143. }
  144. #endif
  145. /*************************************************
  146. * Execute a Regular Expression - DFA engine *
  147. *************************************************/
  148. /* This internal function applies a compiled pattern to a subject string,
  149. starting at a given point, using a DFA engine. This function is called from the
  150. external one, possibly multiple times if the pattern is not anchored. The
  151. function calls itself recursively for some kinds of subpattern.
  152. Arguments:
  153. md the match_data block with fixed information
  154. this_start_code the opening bracket of this subexpression's code
  155. current_subject where we currently are in the subject string
  156. start_offset start offset in the subject string
  157. offsets vector to contain the matching string offsets
  158. offsetcount size of same
  159. workspace vector of workspace
  160. wscount size of same
  161. ims the current ims flags
  162. rlevel function call recursion level
  163. recursing regex recursive call level
  164. Returns: > 0 =>
  165. = 0 =>
  166. -1 => failed to match
  167. < -1 => some kind of unexpected problem
  168. The following macros are used for adding states to the two state vectors (one
  169. for the current character, one for the following character). */
  170. #define ADD_ACTIVE(x,y) \
  171. if (active_count++ < wscount) \
  172. { \
  173. next_active_state->offset = (x); \
  174. next_active_state->count = (y); \
  175. next_active_state->ims = ims; \
  176. next_active_state++; \
  177. DPRINTF(("%.*sADD_ACTIVE(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \
  178. } \
  179. else return PCRE_ERROR_DFA_WSSIZE
  180. #define ADD_ACTIVE_DATA(x,y,z) \
  181. if (active_count++ < wscount) \
  182. { \
  183. next_active_state->offset = (x); \
  184. next_active_state->count = (y); \
  185. next_active_state->ims = ims; \
  186. next_active_state->data = (z); \
  187. next_active_state++; \
  188. DPRINTF(("%.*sADD_ACTIVE_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \
  189. } \
  190. else return PCRE_ERROR_DFA_WSSIZE
  191. #define ADD_NEW(x,y) \
  192. if (new_count++ < wscount) \
  193. { \
  194. next_new_state->offset = (x); \
  195. next_new_state->count = (y); \
  196. next_new_state->ims = ims; \
  197. next_new_state++; \
  198. DPRINTF(("%.*sADD_NEW(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \
  199. } \
  200. else return PCRE_ERROR_DFA_WSSIZE
  201. #define ADD_NEW_DATA(x,y,z) \
  202. if (new_count++ < wscount) \
  203. { \
  204. next_new_state->offset = (x); \
  205. next_new_state->count = (y); \
  206. next_new_state->ims = ims; \
  207. next_new_state->data = (z); \
  208. next_new_state++; \
  209. DPRINTF(("%.*sADD_NEW_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \
  210. } \
  211. else return PCRE_ERROR_DFA_WSSIZE
  212. /* And now, here is the code */
  213. static int
  214. internal_dfa_exec(
  215. dfa_match_data *md,
  216. const uschar *this_start_code,
  217. const uschar *current_subject,
  218. int start_offset,
  219. int *offsets,
  220. int offsetcount,
  221. int *workspace,
  222. int wscount,
  223. int ims,
  224. int rlevel,
  225. int recursing)
  226. {
  227. stateblock *active_states, *new_states, *temp_states;
  228. stateblock *next_active_state, *next_new_state;
  229. const uschar *ctypes, *lcc, *fcc;
  230. const uschar *ptr;
  231. const uschar *end_code;
  232. int active_count, new_count, match_count;
  233. /* Some fields in the md block are frequently referenced, so we load them into
  234. independent variables in the hope that this will perform better. */
  235. const uschar *start_subject = md->start_subject;
  236. const uschar *end_subject = md->end_subject;
  237. const uschar *start_code = md->start_code;
  238. BOOL utf8 = (md->poptions & PCRE_UTF8) != 0;
  239. rlevel++;
  240. offsetcount &= (-2);
  241. wscount -= 2;
  242. wscount = (wscount - (wscount % (INTS_PER_STATEBLOCK * 2))) /
  243. (2 * INTS_PER_STATEBLOCK);
  244. DPRINTF(("\n%.*s---------------------\n"
  245. "%.*sCall to internal_dfa_exec f=%d r=%d\n",
  246. rlevel*2-2, SP, rlevel*2-2, SP, rlevel, recursing));
  247. ctypes = md->tables + ctypes_offset;
  248. lcc = md->tables + lcc_offset;
  249. fcc = md->tables + fcc_offset;
  250. match_count = PCRE_ERROR_NOMATCH; /* A negative number */
  251. active_states = (stateblock *)(workspace + 2);
  252. next_new_state = new_states = active_states + wscount;
  253. new_count = 0;
  254. /* The first thing in any (sub) pattern is a bracket of some sort. Push all
  255. the alternative states onto the list, and find out where the end is. This
  256. makes is possible to use this function recursively, when we want to stop at a
  257. matching internal ket rather than at the end.
  258. If the first opcode in the first alternative is OP_REVERSE, we are dealing with
  259. a backward assertion. In that case, we have to find out the maximum amount to
  260. move back, and set up each alternative appropriately. */
  261. if (this_start_code[1+LINK_SIZE] == OP_REVERSE)
  262. {
  263. int max_back = 0;
  264. int gone_back;
  265. end_code = this_start_code;
  266. do
  267. {
  268. int back = GET(end_code, 2+LINK_SIZE);
  269. if (back > max_back) max_back = back;
  270. end_code += GET(end_code, 1);
  271. }
  272. while (*end_code == OP_ALT);
  273. /* If we can't go back the amount required for the longest lookbehind
  274. pattern, go back as far as we can; some alternatives may still be viable. */
  275. #ifdef SUPPORT_UTF8
  276. /* In character mode we have to step back character by character */
  277. if (utf8)
  278. {
  279. for (gone_back = 0; gone_back < max_back; gone_back++)
  280. {
  281. if (current_subject <= start_subject) break;
  282. current_subject--;
  283. while (current_subject > start_subject &&
  284. (*current_subject & 0xc0) == 0x80)
  285. current_subject--;
  286. }
  287. }
  288. else
  289. #endif
  290. /* In byte-mode we can do this quickly. */
  291. {
  292. gone_back = (current_subject - max_back < start_subject)?
  293. current_subject - start_subject : max_back;
  294. current_subject -= gone_back;
  295. }
  296. /* Now we can process the individual branches. */
  297. end_code = this_start_code;
  298. do
  299. {
  300. int back = GET(end_code, 2+LINK_SIZE);
  301. if (back <= gone_back)
  302. {
  303. int bstate = end_code - start_code + 2 + 2*LINK_SIZE;
  304. ADD_NEW_DATA(-bstate, 0, gone_back - back);
  305. }
  306. end_code += GET(end_code, 1);
  307. }
  308. while (*end_code == OP_ALT);
  309. }
  310. /* This is the code for a "normal" subpattern (not a backward assertion). The
  311. start of a whole pattern is always one of these. If we are at the top level,
  312. we may be asked to restart matching from the same point that we reached for a
  313. previous partial match. We still have to scan through the top-level branches to
  314. find the end state. */
  315. else
  316. {
  317. end_code = this_start_code;
  318. /* Restarting */
  319. if (rlevel == 1 && (md->moptions & PCRE_DFA_RESTART) != 0)
  320. {
  321. do { end_code += GET(end_code, 1); } while (*end_code == OP_ALT);
  322. new_count = workspace[1];
  323. if (!workspace[0])
  324. memcpy(new_states, active_states, new_count * sizeof(stateblock));
  325. }
  326. /* Not restarting */
  327. else
  328. {
  329. do
  330. {
  331. ADD_NEW(end_code - start_code + 1 + LINK_SIZE, 0);
  332. end_code += GET(end_code, 1);
  333. }
  334. while (*end_code == OP_ALT);
  335. }
  336. }
  337. workspace[0] = 0; /* Bit indicating which vector is current */
  338. DPRINTF(("%.*sEnd state = %d\n", rlevel*2-2, SP, end_code - start_code));
  339. /* Loop for scanning the subject */
  340. ptr = current_subject;
  341. for (;;)
  342. {
  343. int i, j;
  344. int c, d, clen, dlen;
  345. /* Make the new state list into the active state list and empty the
  346. new state list. */
  347. temp_states = active_states;
  348. active_states = new_states;
  349. new_states = temp_states;
  350. active_count = new_count;
  351. new_count = 0;
  352. workspace[0] ^= 1; /* Remember for the restarting feature */
  353. workspace[1] = active_count;
  354. #ifdef DEBUG
  355. printf("%.*sNext character: rest of subject = \"", rlevel*2-2, SP);
  356. pchars((uschar *)ptr, strlen((char *)ptr), stdout);
  357. printf("\"\n");
  358. printf("%.*sActive states: ", rlevel*2-2, SP);
  359. for (i = 0; i < active_count; i++)
  360. printf("%d/%d ", active_states[i].offset, active_states[i].count);
  361. printf("\n");
  362. #endif
  363. /* Set the pointers for adding new states */
  364. next_active_state = active_states + active_count;
  365. next_new_state = new_states;
  366. /* Load the current character from the subject outside the loop, as many
  367. different states may want to look at it, and we assume that at least one
  368. will. */
  369. if (ptr < end_subject)
  370. {
  371. clen = 1;
  372. #ifdef SUPPORT_UTF8
  373. if (utf8) { GETCHARLEN(c, ptr, clen); } else
  374. #endif /* SUPPORT_UTF8 */
  375. c = *ptr;
  376. }
  377. else
  378. {
  379. clen = 0; /* At end subject */
  380. c = -1;
  381. }
  382. /* Scan up the active states and act on each one. The result of an action
  383. may be to add more states to the currently active list (e.g. on hitting a
  384. parenthesis) or it may be to put states on the new list, for considering
  385. when we move the character pointer on. */
  386. for (i = 0; i < active_count; i++)
  387. {
  388. stateblock *current_state = active_states + i;
  389. const uschar *code;
  390. int state_offset = current_state->offset;
  391. int count, codevalue;
  392. int chartype, othercase;
  393. #ifdef DEBUG
  394. printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset);
  395. if (c < 0) printf("-1\n");
  396. else if (c > 32 && c < 127) printf("'%c'\n", c);
  397. else printf("0x%02x\n", c);
  398. #endif
  399. /* This variable is referred to implicity in the ADD_xxx macros. */
  400. ims = current_state->ims;
  401. /* A negative offset is a special case meaning "hold off going to this
  402. (negated) state until the number of characters in the data field have
  403. been skipped". */
  404. if (state_offset < 0)
  405. {
  406. if (current_state->data > 0)
  407. {
  408. DPRINTF(("%.*sSkipping this character\n", rlevel*2-2, SP));
  409. ADD_NEW_DATA(state_offset, current_state->count,
  410. current_state->data - 1);
  411. continue;
  412. }
  413. else
  414. {
  415. current_state->offset = state_offset = -state_offset;
  416. }
  417. }
  418. /* Check for a duplicate state with the same count, and skip if found. */
  419. for (j = 0; j < i; j++)
  420. {
  421. if (active_states[j].offset == state_offset &&
  422. active_states[j].count == current_state->count)
  423. {
  424. DPRINTF(("%.*sDuplicate state: skipped\n", rlevel*2-2, SP));
  425. goto NEXT_ACTIVE_STATE;
  426. }
  427. }
  428. /* The state offset is the offset to the opcode */
  429. code = start_code + state_offset;
  430. codevalue = *code;
  431. if (codevalue >= OP_BRA) codevalue = OP_BRA; /* All brackets are equal */
  432. /* If this opcode is followed by an inline character, load it. It is
  433. tempting to test for the presence of a subject character here, but that
  434. is wrong, because sometimes zero repetitions of the subject are
  435. permitted.
  436. We also use this mechanism for opcodes such as OP_TYPEPLUS that take an
  437. argument that is not a data character - but is always one byte long.
  438. Unfortunately, we have to take special action to deal with \P, \p, and
  439. \X in this case. To keep the other cases fast, convert these ones to new
  440. opcodes. */
  441. if (coptable[codevalue] > 0)
  442. {
  443. dlen = 1;
  444. #ifdef SUPPORT_UTF8
  445. if (utf8) { GETCHARLEN(d, (code + coptable[codevalue]), dlen); } else
  446. #endif /* SUPPORT_UTF8 */
  447. d = code[coptable[codevalue]];
  448. if (codevalue >= OP_TYPESTAR)
  449. {
  450. if (d == OP_ANYBYTE) return PCRE_ERROR_DFA_UITEM;
  451. if (d >= OP_NOTPROP)
  452. codevalue += (d == OP_EXTUNI)? OP_EXTUNI_EXTRA : OP_PROP_EXTRA;
  453. }
  454. }
  455. else
  456. {
  457. dlen = 0; /* Not strictly necessary, but compilers moan */
  458. d = -1; /* if these variables are not set. */
  459. }
  460. /* Now process the individual opcodes */
  461. switch (codevalue)
  462. {
  463. /* ========================================================================== */
  464. /* Reached a closing bracket. If not at the end of the pattern, carry
  465. on with the next opcode. Otherwise, unless we have an empty string and
  466. PCRE_NOTEMPTY is set, save the match data, shifting up all previous
  467. matches so we always have the longest first. */
  468. case OP_KET:
  469. case OP_KETRMIN:
  470. case OP_KETRMAX:
  471. if (code != end_code)
  472. {
  473. ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0);
  474. if (codevalue != OP_KET)
  475. {
  476. ADD_ACTIVE(state_offset - GET(code, 1), 0);
  477. }
  478. }
  479. else if (ptr > current_subject || (md->moptions & PCRE_NOTEMPTY) == 0)
  480. {
  481. if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0;
  482. else if (match_count > 0 && ++match_count * 2 >= offsetcount)
  483. match_count = 0;
  484. count = ((match_count == 0)? offsetcount : match_count * 2) - 2;
  485. if (count > 0) memmove(offsets + 2, offsets, count * sizeof(int));
  486. if (offsetcount >= 2)
  487. {
  488. offsets[0] = current_subject - start_subject;
  489. offsets[1] = ptr - start_subject;
  490. DPRINTF(("%.*sSet matched string = \"%.*s\"\n", rlevel*2-2, SP,
  491. offsets[1] - offsets[0], current_subject));
  492. }
  493. if ((md->moptions & PCRE_DFA_SHORTEST) != 0)
  494. {
  495. DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n"
  496. "%.*s---------------------\n\n", rlevel*2-2, SP, rlevel,
  497. match_count, rlevel*2-2, SP));
  498. return match_count;
  499. }
  500. }
  501. break;
  502. /* ========================================================================== */
  503. /* These opcodes add to the current list of states without looking
  504. at the current character. */
  505. /*-----------------------------------------------------------------*/
  506. case OP_ALT:
  507. do { code += GET(code, 1); } while (*code == OP_ALT);
  508. ADD_ACTIVE(code - start_code, 0);
  509. break;
  510. /*-----------------------------------------------------------------*/
  511. case OP_BRA:
  512. do
  513. {
  514. ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0);
  515. code += GET(code, 1);
  516. }
  517. while (*code == OP_ALT);
  518. break;
  519. /*-----------------------------------------------------------------*/
  520. case OP_BRAZERO:
  521. case OP_BRAMINZERO:
  522. ADD_ACTIVE(state_offset + 1, 0);
  523. code += 1 + GET(code, 2);
  524. while (*code == OP_ALT) code += GET(code, 1);
  525. ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0);
  526. break;
  527. /*-----------------------------------------------------------------*/
  528. case OP_BRANUMBER:
  529. ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0);
  530. break;
  531. /*-----------------------------------------------------------------*/
  532. case OP_CIRC:
  533. if ((ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0) ||
  534. ((ims & PCRE_MULTILINE) != 0 && ptr[-1] == NEWLINE))
  535. { ADD_ACTIVE(state_offset + 1, 0); }
  536. break;
  537. /*-----------------------------------------------------------------*/
  538. case OP_EOD:
  539. if (ptr >= end_subject) { ADD_ACTIVE(state_offset + 1, 0); }
  540. break;
  541. /*-----------------------------------------------------------------*/
  542. case OP_OPT:
  543. ims = code[1];
  544. ADD_ACTIVE(state_offset + 2, 0);
  545. break;
  546. /*-----------------------------------------------------------------*/
  547. case OP_SOD:
  548. if (ptr == start_subject) { ADD_ACTIVE(state_offset + 1, 0); }
  549. break;
  550. /*-----------------------------------------------------------------*/
  551. case OP_SOM:
  552. if (ptr == start_subject + start_offset) { ADD_ACTIVE(state_offset + 1, 0); }
  553. break;
  554. /* ========================================================================== */
  555. /* These opcodes inspect the next subject character, and sometimes
  556. the previous one as well, but do not have an argument. The variable
  557. clen contains the length of the current character and is zero if we are
  558. at the end of the subject. */
  559. /*-----------------------------------------------------------------*/
  560. case OP_ANY:
  561. if (clen > 0 && (c != NEWLINE || (ims & PCRE_DOTALL) != 0))
  562. { ADD_NEW(state_offset + 1, 0); }
  563. break;
  564. /*-----------------------------------------------------------------*/
  565. case OP_EODN:
  566. if (clen == 0 || (c == NEWLINE && ptr + 1 == end_subject))
  567. { ADD_ACTIVE(state_offset + 1, 0); }
  568. break;
  569. /*-----------------------------------------------------------------*/
  570. case OP_DOLL:
  571. if ((md->moptions & PCRE_NOTEOL) == 0)
  572. {
  573. if (clen == 0 || (c == NEWLINE && (ptr + 1 == end_subject ||
  574. (ims & PCRE_MULTILINE) != 0)))
  575. { ADD_ACTIVE(state_offset + 1, 0); }
  576. }
  577. else if (c == NEWLINE && (ims & PCRE_MULTILINE) != 0)
  578. { ADD_ACTIVE(state_offset + 1, 0); }
  579. break;
  580. /*-----------------------------------------------------------------*/
  581. case OP_DIGIT:
  582. case OP_WHITESPACE:
  583. case OP_WORDCHAR:
  584. if (clen > 0 && c < 256 &&
  585. ((ctypes[c] & toptable1[codevalue]) ^ toptable2[codevalue]) != 0)
  586. { ADD_NEW(state_offset + 1, 0); }
  587. break;
  588. /*-----------------------------------------------------------------*/
  589. case OP_NOT_DIGIT:
  590. case OP_NOT_WHITESPACE:
  591. case OP_NOT_WORDCHAR:
  592. if (clen > 0 && (c >= 256 ||
  593. ((ctypes[c] & toptable1[codevalue]) ^ toptable2[codevalue]) != 0))
  594. { ADD_NEW(state_offset + 1, 0); }
  595. break;
  596. /*-----------------------------------------------------------------*/
  597. case OP_WORD_BOUNDARY:
  598. case OP_NOT_WORD_BOUNDARY:
  599. {
  600. int left_word, right_word;
  601. if (ptr > start_subject)
  602. {
  603. const uschar *temp = ptr - 1;
  604. #ifdef SUPPORT_UTF8
  605. if (utf8) BACKCHAR(temp);
  606. #endif
  607. GETCHARTEST(d, temp);
  608. left_word = d < 256 && (ctypes[d] & ctype_word) != 0;
  609. }
  610. else left_word = 0;
  611. if (clen > 0) right_word = c < 256 && (ctypes[c] & ctype_word) != 0;
  612. else right_word = 0;
  613. if ((left_word == right_word) == (codevalue == OP_NOT_WORD_BOUNDARY))
  614. { ADD_ACTIVE(state_offset + 1, 0); }
  615. }
  616. break;
  617. #ifdef SUPPORT_UCP
  618. /*-----------------------------------------------------------------*/
  619. /* Check the next character by Unicode property. We will get here only
  620. if the support is in the binary; otherwise a compile-time error occurs.
  621. */
  622. case OP_PROP:
  623. case OP_NOTPROP:
  624. if (clen > 0)
  625. {
  626. int rqdtype, category;
  627. category = ucp_findchar(c, &chartype, &othercase);
  628. rqdtype = code[1];
  629. if (rqdtype >= 128)
  630. {
  631. if ((rqdtype - 128 == category) == (codevalue == OP_PROP))
  632. { ADD_NEW(state_offset + 2, 0); }
  633. }
  634. else
  635. {
  636. if ((rqdtype == chartype) == (codevalue == OP_PROP))
  637. { ADD_NEW(state_offset + 2, 0); }
  638. }
  639. }
  640. break;
  641. #endif
  642. /* ========================================================================== */
  643. /* These opcodes likewise inspect the subject character, but have an
  644. argument that is not a data character. It is one of these opcodes:
  645. OP_ANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE, OP_WORDCHAR,
  646. OP_NOT_WORDCHAR. The value is loaded into d. */
  647. case OP_TYPEPLUS:
  648. case OP_TYPEMINPLUS:
  649. count = current_state->count; /* Already matched */
  650. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  651. if (clen > 0)
  652. {
  653. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  654. (c < 256 &&
  655. (d != OP_ANY || c != '\n' || (ims & PCRE_DOTALL) != 0) &&
  656. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  657. {
  658. count++;
  659. ADD_NEW(state_offset, count);
  660. }
  661. }
  662. break;
  663. /*-----------------------------------------------------------------*/
  664. case OP_TYPEQUERY:
  665. case OP_TYPEMINQUERY:
  666. ADD_ACTIVE(state_offset + 2, 0);
  667. if (clen > 0)
  668. {
  669. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  670. (c < 256 &&
  671. (d != OP_ANY || c != '\n' || (ims & PCRE_DOTALL) != 0) &&
  672. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  673. {
  674. ADD_NEW(state_offset + 2, 0);
  675. }
  676. }
  677. break;
  678. /*-----------------------------------------------------------------*/
  679. case OP_TYPESTAR:
  680. case OP_TYPEMINSTAR:
  681. ADD_ACTIVE(state_offset + 2, 0);
  682. if (clen > 0)
  683. {
  684. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  685. (c < 256 &&
  686. (d != OP_ANY || c != '\n' || (ims & PCRE_DOTALL) != 0) &&
  687. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  688. {
  689. ADD_NEW(state_offset, 0);
  690. }
  691. }
  692. break;
  693. /*-----------------------------------------------------------------*/
  694. case OP_TYPEEXACT:
  695. case OP_TYPEUPTO:
  696. case OP_TYPEMINUPTO:
  697. if (codevalue != OP_TYPEEXACT)
  698. { ADD_ACTIVE(state_offset + 4, 0); }
  699. count = current_state->count; /* Number already matched */
  700. if (clen > 0)
  701. {
  702. if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
  703. (c < 256 &&
  704. (d != OP_ANY || c != '\n' || (ims & PCRE_DOTALL) != 0) &&
  705. ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
  706. {
  707. if (++count >= GET2(code, 1))
  708. { ADD_NEW(state_offset + 4, 0); }
  709. else
  710. { ADD_NEW(state_offset, count); }
  711. }
  712. }
  713. break;
  714. /* ========================================================================== */
  715. /* These are virtual opcodes that are used when something like
  716. OP_TYPEPLUS has OP_PROP, OP_NOTPROP, or OP_EXTUNI as its argument. It
  717. keeps the code above fast for the other cases. The argument is in the
  718. d variable. */
  719. case OP_PROP_EXTRA + OP_TYPEPLUS:
  720. case OP_PROP_EXTRA + OP_TYPEMINPLUS:
  721. count = current_state->count; /* Already matched */
  722. if (count > 0) { ADD_ACTIVE(state_offset + 3, 0); }
  723. if (clen > 0)
  724. {
  725. int category = ucp_findchar(c, &chartype, &othercase);
  726. int rqdtype = code[2];
  727. if ((d == OP_PROP) ==
  728. (rqdtype == ((rqdtype >= 128)? (category + 128) : chartype)))
  729. { count++; ADD_NEW(state_offset, count); }
  730. }
  731. break;
  732. /*-----------------------------------------------------------------*/
  733. case OP_EXTUNI_EXTRA + OP_TYPEPLUS:
  734. case OP_EXTUNI_EXTRA + OP_TYPEMINPLUS:
  735. count = current_state->count; /* Already matched */
  736. if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
  737. if (clen > 0 && ucp_findchar(c, &chartype, &othercase) != ucp_M)
  738. {
  739. const uschar *nptr = ptr + clen;
  740. int ncount = 0;
  741. while (nptr < end_subject)
  742. {
  743. int nd;
  744. int ndlen = 1;
  745. GETCHARLEN(nd, nptr, ndlen);
  746. if (ucp_findchar(nd, &chartype, &othercase) != ucp_M) break;
  747. ncount++;
  748. nptr += ndlen;
  749. }
  750. count++;
  751. ADD_NEW_DATA(-state_offset, count, ncount);
  752. }
  753. break;
  754. /*-----------------------------------------------------------------*/
  755. case OP_PROP_EXTRA + OP_TYPEQUERY:
  756. case OP_PROP_EXTRA + OP_TYPEMINQUERY:
  757. count = 3;
  758. goto QS1;
  759. case OP_PROP_EXTRA + OP_TYPESTAR:
  760. case OP_PROP_EXTRA + OP_TYPEMINSTAR:
  761. count = 0;
  762. QS1:
  763. ADD_ACTIVE(state_offset + 3, 0);
  764. if (clen > 0)
  765. {
  766. int category = ucp_findchar(c, &chartype, &othercase);
  767. int rqdtype = code[2];
  768. if ((d == OP_PROP) ==
  769. (rqdtype == ((rqdtype >= 128)? (category + 128) : chartype)))
  770. { ADD_NEW(state_offset + count, 0); }
  771. }
  772. break;
  773. /*-----------------------------------------------------------------*/
  774. case OP_EXTUNI_EXTRA + OP_TYPEQUERY:
  775. case OP_EXTUNI_EXTRA + OP_TYPEMINQUERY:
  776. count = 2;
  777. goto QS2;
  778. case OP_EXTUNI_EXTRA + OP_TYPESTAR:
  779. case OP_EXTUNI_EXTRA + OP_TYPEMINSTAR:
  780. count = 0;
  781. QS2:
  782. ADD_ACTIVE(state_offset + 2, 0);
  783. if (clen > 0 && ucp_findchar(c, &chartype, &othercase) != ucp_M)
  784. {
  785. const uschar *nptr = ptr + clen;
  786. int ncount = 0;
  787. while (nptr < end_subject)
  788. {
  789. int nd;
  790. int ndlen = 1;
  791. GETCHARLEN(nd, nptr, ndlen);
  792. if (ucp_findchar(nd, &chartype, &othercase) != ucp_M) break;
  793. ncount++;
  794. nptr += ndlen;
  795. }
  796. ADD_NEW_DATA(-(state_offset + count), 0, ncount);
  797. }
  798. break;
  799. /*-----------------------------------------------------------------*/
  800. case OP_PROP_EXTRA + OP_TYPEEXACT:
  801. case OP_PROP_EXTRA + OP_TYPEUPTO:
  802. case OP_PROP_EXTRA + OP_TYPEMINUPTO:
  803. if (codevalue != OP_PROP_EXTRA + OP_TYPEEXACT)
  804. { ADD_ACTIVE(state_offset + 5, 0); }
  805. count = current_state->count; /* Number already matched */
  806. if (clen > 0)
  807. {
  808. int category = ucp_findchar(c, &chartype, &othercase);
  809. int rqdtype = code[4];
  810. if ((d == OP_PROP) ==
  811. (rqdtype == ((rqdtype >= 128)? (category + 128) : chartype)))
  812. {
  813. if (++count >= GET2(code, 1))
  814. { ADD_NEW(state_offset + 5, 0); }
  815. else
  816. { ADD_NEW(state_offset, count); }
  817. }
  818. }
  819. break;
  820. /*-----------------------------------------------------------------*/
  821. case OP_EXTUNI_EXTRA + OP_TYPEEXACT:
  822. case OP_EXTUNI_EXTRA + OP_TYPEUPTO:
  823. case OP_EXTUNI_EXTRA + OP_TYPEMINUPTO:
  824. if (codevalue != OP_EXTUNI_EXTRA + OP_TYPEEXACT)
  825. { ADD_ACTIVE(state_offset + 4, 0); }
  826. count = current_state->count; /* Number already matched */
  827. if (clen > 0 && ucp_findchar(c, &chartype, &othercase) != ucp_M)
  828. {
  829. const uschar *nptr = ptr + clen;
  830. int ncount = 0;
  831. while (nptr < end_subject)
  832. {
  833. int nd;
  834. int ndlen = 1;
  835. GETCHARLEN(nd, nptr, ndlen);
  836. if (ucp_findchar(nd, &chartype, &othercase) != ucp_M) break;
  837. ncount++;
  838. nptr += ndlen;
  839. }
  840. if (++count >= GET2(code, 1))
  841. { ADD_NEW_DATA(-(state_offset + 4), 0, ncount); }
  842. else
  843. { ADD_NEW_DATA(-state_offset, count, ncount); }
  844. }
  845. break;
  846. /* ========================================================================== */
  847. /* These opcodes are followed by a character that is usually compared
  848. to the current subject character; it is loaded into d. We still get
  849. here even if there is no subject character, because in some cases zero
  850. repetitions are permitted. */
  851. /*-----------------------------------------------------------------*/
  852. case OP_CHAR:
  853. if (clen > 0 && c == d) { ADD_NEW(state_offset + dlen + 1, 0); }
  854. break;
  855. /*-----------------------------------------------------------------*/
  856. case OP_CHARNC:
  857. if (clen == 0) break;
  858. #ifdef SUPPORT_UTF8
  859. if (utf8)
  860. {
  861. if (c == d) { ADD_NEW(state_offset + dlen + 1, 0); } else
  862. {
  863. if (c < 128) othercase = fcc[c]; else
  864. /* If we have Unicode property support, we can use it to test the
  865. other case of the character, if there is one. The result of
  866. ucp_findchar() is < 0 if the char isn't found, and othercase is
  867. returned as zero if there isn't another case. */
  868. #ifdef SUPPORT_UCP
  869. if (ucp_findchar(c, &chartype, &othercase) < 0)
  870. #endif
  871. othercase = -1;
  872. if (d == othercase) { ADD_NEW(state_offset + dlen + 1, 0); }
  873. }
  874. }
  875. else
  876. #endif /* SUPPORT_UTF8 */
  877. /* Non-UTF-8 mode */
  878. {
  879. if (lcc[c] == lcc[d]) { ADD_NEW(state_offset + 2, 0); }
  880. }
  881. break;
  882. #ifdef SUPPORT_UCP
  883. /*-----------------------------------------------------------------*/
  884. /* This is a tricky one because it can match more than one character.
  885. Find out how many characters to skip, and then set up a negative state
  886. to wait for them to pass before continuing. */
  887. case OP_EXTUNI:
  888. if (clen > 0 && ucp_findchar(c, &chartype, &othercase) != ucp_M)
  889. {
  890. const uschar *nptr = ptr + clen;
  891. int ncount = 0;
  892. while (nptr < end_subject)
  893. {
  894. int nclen = 1;
  895. GETCHARLEN(c, nptr, nclen);
  896. if (ucp_findchar(c, &chartype, &othercase) != ucp_M) break;
  897. ncount++;
  898. nptr += nclen;
  899. }
  900. ADD_NEW_DATA(-(state_offset + 1), 0, ncount);
  901. }
  902. break;
  903. #endif
  904. /*-----------------------------------------------------------------*/
  905. /* Match a negated single character. This is only used for one-byte
  906. characters, that is, we know that d < 256. The character we are
  907. checking (c) can be multibyte. */
  908. case OP_NOT:
  909. if (clen > 0)
  910. {
  911. int otherd = ((ims & PCRE_CASELESS) != 0)? fcc[d] : d;
  912. if (c != d && c != otherd) { ADD_NEW(state_offset + dlen + 1, 0); }
  913. }
  914. break;
  915. /*-----------------------------------------------------------------*/
  916. case OP_PLUS:
  917. case OP_MINPLUS:
  918. case OP_NOTPLUS:
  919. case OP_NOTMINPLUS:
  920. count = current_state->count; /* Already matched */
  921. if (count > 0) { ADD_ACTIVE(state_offset + dlen + 1, 0); }
  922. if (clen > 0)
  923. {
  924. int otherd = -1;
  925. if ((ims & PCRE_CASELESS) != 0)
  926. {
  927. #ifdef SUPPORT_UTF8
  928. if (utf8 && c >= 128)
  929. {
  930. #ifdef SUPPORT_UCP
  931. if (ucp_findchar(d, &chartype, &otherd) < 0) otherd = -1;
  932. #endif /* SUPPORT_UCP */
  933. }
  934. else
  935. #endif /* SUPPORT_UTF8 */
  936. otherd = fcc[d];
  937. }
  938. if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR))
  939. { count++; ADD_NEW(state_offset, count); }
  940. }
  941. break;
  942. /*-----------------------------------------------------------------*/
  943. case OP_QUERY:
  944. case OP_MINQUERY:
  945. case OP_NOTQUERY:
  946. case OP_NOTMINQUERY:
  947. ADD_ACTIVE(state_offset + dlen + 1, 0);
  948. if (clen > 0)
  949. {
  950. int otherd = -1;
  951. if ((ims && PCRE_CASELESS) != 0)
  952. {
  953. #ifdef SUPPORT_UTF8
  954. if (utf8 && c >= 128)
  955. {
  956. #ifdef SUPPORT_UCP
  957. if (ucp_findchar(c, &chartype, &otherd) < 0) otherd = -1;
  958. #endif /* SUPPORT_UCP */
  959. }
  960. else
  961. #endif /* SUPPORT_UTF8 */
  962. otherd = fcc[d];
  963. }
  964. if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR))
  965. { ADD_NEW(state_offset + dlen + 1, 0); }
  966. }
  967. break;
  968. /*-----------------------------------------------------------------*/
  969. case OP_STAR:
  970. case OP_MINSTAR:
  971. case OP_NOTSTAR:
  972. case OP_NOTMINSTAR:
  973. ADD_ACTIVE(state_offset + dlen + 1, 0);
  974. if (clen > 0)
  975. {
  976. int otherd = -1;
  977. if ((ims && PCRE_CASELESS) != 0)
  978. {
  979. #ifdef SUPPORT_UTF8
  980. if (utf8 && c >= 128)
  981. {
  982. #ifdef SUPPORT_UCP
  983. if (ucp_findchar(c, &chartype, &otherd) < 0) otherd = -1;
  984. #endif /* SUPPORT_UCP */
  985. }
  986. else
  987. #endif /* SUPPORT_UTF8 */
  988. otherd = fcc[d];
  989. }
  990. if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR))
  991. { ADD_NEW(state_offset, 0); }
  992. }
  993. break;
  994. /*-----------------------------------------------------------------*/
  995. case OP_EXACT:
  996. case OP_UPTO:
  997. case OP_MINUPTO:
  998. case OP_NOTEXACT:
  999. case OP_NOTUPTO:
  1000. case OP_NOTMINUPTO:
  1001. if (codevalue != OP_EXACT && codevalue != OP_NOTEXACT)
  1002. { ADD_ACTIVE(state_offset + dlen + 3, 0); }
  1003. count = current_state->count; /* Number already matched */
  1004. if (clen > 0)
  1005. {
  1006. int otherd = -1;
  1007. if ((ims & PCRE_CASELESS) != 0)
  1008. {
  1009. #ifdef SUPPORT_UTF8
  1010. if (utf8 && c >= 128)
  1011. {
  1012. #ifdef SUPPORT_UCP
  1013. if (ucp_findchar(d, &chartype, &otherd) < 0) otherd = -1;
  1014. #endif /* SUPPORT_UCP */
  1015. }
  1016. else
  1017. #endif /* SUPPORT_UTF8 */
  1018. otherd = fcc[d];
  1019. }
  1020. if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR))
  1021. {
  1022. if (++count >= GET2(code, 1))
  1023. { ADD_NEW(state_offset + dlen + 3, 0); }
  1024. else
  1025. { ADD_NEW(state_offset, count); }
  1026. }
  1027. }
  1028. break;
  1029. /* ========================================================================== */
  1030. /* These are the class-handling opcodes */
  1031. case OP_CLASS:
  1032. case OP_NCLASS:
  1033. case OP_XCLASS:
  1034. {
  1035. BOOL isinclass = FALSE;
  1036. int next_state_offset;
  1037. const uschar *ecode;
  1038. /* For a simple class, there is always just a 32-byte table, and we
  1039. can set isinclass from it. */
  1040. if (codevalue != OP_XCLASS)
  1041. {
  1042. ecode = code + 33;
  1043. if (clen > 0)
  1044. {
  1045. isinclass = (c > 255)? (codevalue == OP_NCLASS) :
  1046. ((code[1 + c/8] & (1 << (c&7))) != 0);
  1047. }
  1048. }
  1049. /* An extended class may have a table or a list of single characters,
  1050. ranges, or both, and it may be positive or negative. There's a
  1051. function that sorts all this out. */
  1052. else
  1053. {
  1054. ecode = code + GET(code, 1);
  1055. if (clen > 0) isinclass = _pcre_xclass(c, code + 1 + LINK_SIZE);
  1056. }
  1057. /* At this point, isinclass is set for all kinds of class, and ecode
  1058. points to the byte after the end of the class. If there is a
  1059. quantifier, this is where it will be. */
  1060. next_state_offset = ecode - start_code;
  1061. switch (*ecode)
  1062. {
  1063. case OP_CRSTAR:
  1064. case OP_CRMINSTAR:
  1065. ADD_ACTIVE(next_state_offset + 1, 0);
  1066. if (isinclass) { ADD_NEW(state_offset, 0); }
  1067. break;
  1068. case OP_CRPLUS:
  1069. case OP_CRMINPLUS:
  1070. count = current_state->count; /* Already matched */
  1071. if (count > 0) { ADD_ACTIVE(next_state_offset + 1, 0); }
  1072. if (isinclass) { count++; ADD_NEW(state_offset, count); }
  1073. break;
  1074. case OP_CRQUERY:
  1075. case OP_CRMINQUERY:
  1076. ADD_ACTIVE(next_state_offset + 1, 0);
  1077. if (isinclass) { ADD_NEW(next_state_offset + 1, 0); }
  1078. break;
  1079. case OP_CRRANGE:
  1080. case OP_CRMINRANGE:
  1081. count = current_state->count; /* Already matched */
  1082. if (count >= GET2(ecode, 1))
  1083. { ADD_ACTIVE(next_state_offset + 5, 0); }
  1084. if (isinclass)
  1085. {
  1086. if (++count >= GET2(ecode, 3))
  1087. { ADD_NEW(next_state_offset + 5, 0); }
  1088. else
  1089. { ADD_NEW(state_offset, count); }
  1090. }
  1091. break;
  1092. default:
  1093. if (isinclass) { ADD_NEW(next_state_offset, 0); }
  1094. break;
  1095. }
  1096. }
  1097. break;
  1098. /* ========================================================================== */
  1099. /* These are the opcodes for fancy brackets of various kinds. We have
  1100. to use recursion in order to handle them. */
  1101. case OP_ASSERT:
  1102. case OP_ASSERT_NOT:
  1103. case OP_ASSERTBACK:
  1104. case OP_ASSERTBACK_NOT:
  1105. {
  1106. int rc;
  1107. int local_offsets[2];
  1108. int local_workspace[1000];
  1109. const uschar *endasscode = code + GET(code, 1);
  1110. while (*endasscode == OP_ALT) endasscode += GET(endasscode, 1);
  1111. rc = internal_dfa_exec(
  1112. md, /* static match data */
  1113. code, /* this subexpression's code */
  1114. ptr, /* where we currently are */
  1115. ptr - start_subject, /* start offset */
  1116. local_offsets, /* offset vector */
  1117. sizeof(local_offsets)/sizeof(int), /* size of same */
  1118. local_workspace, /* workspace vector */
  1119. sizeof(local_workspace)/sizeof(int), /* size of same */
  1120. ims, /* the current ims flags */
  1121. rlevel, /* function recursion level */
  1122. recursing); /* pass on regex recursion */
  1123. if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK))
  1124. { ADD_ACTIVE(endasscode + LINK_SIZE + 1 - start_code, 0); }
  1125. }
  1126. break;
  1127. /*-----------------------------------------------------------------*/
  1128. case OP_COND:
  1129. {
  1130. int local_offsets[1000];
  1131. int local_workspace[1000];
  1132. int condcode = code[LINK_SIZE+1];
  1133. /* The only supported version of OP_CREF is for the value 0xffff, which
  1134. means "test if in a recursion". */
  1135. if (condcode == OP_CREF)
  1136. {
  1137. int value = GET2(code, LINK_SIZE+2);
  1138. if (value != 0xffff) return PCRE_ERROR_DFA_UCOND;
  1139. if (recursing > 0) { ADD_ACTIVE(state_offset + LINK_SIZE + 4, 0); }
  1140. else { ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); }
  1141. }
  1142. /* Otherwise, the condition is an assertion */
  1143. else
  1144. {
  1145. int rc;
  1146. const uschar *asscode = code + LINK_SIZE + 1;
  1147. const uschar *endasscode = asscode + GET(asscode, 1);
  1148. while (*endasscode == OP_ALT) endasscode += GET(endasscode, 1);
  1149. rc = internal_dfa_exec(
  1150. md, /* fixed match data */
  1151. asscode, /* this subexpression's code */
  1152. ptr, /* where we currently are */
  1153. ptr - start_subject, /* start offset */
  1154. local_offsets, /* offset vector */
  1155. sizeof(local_offsets)/sizeof(int), /* size of same */
  1156. local_workspace, /* workspace vector */
  1157. sizeof(local_workspace)/sizeof(int), /* size of same */
  1158. ims, /* the current ims flags */
  1159. rlevel, /* function recursion level */
  1160. recursing); /* pass on regex recursion */
  1161. if ((rc >= 0) ==
  1162. (condcode == OP_ASSERT || condcode == OP_ASSERTBACK))
  1163. { ADD_ACTIVE(endasscode + LINK_SIZE + 1 - start_code, 0); }
  1164. else
  1165. { ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); }
  1166. }
  1167. }
  1168. break;
  1169. /*-----------------------------------------------------------------*/
  1170. case OP_RECURSE:
  1171. {
  1172. int local_offsets[1000];
  1173. int local_workspace[1000];
  1174. int rc;
  1175. DPRINTF(("%.*sStarting regex recursion %d\n", rlevel*2-2, SP,
  1176. recursing + 1));
  1177. rc = internal_dfa_exec(
  1178. md, /* fixed match data */
  1179. start_code + GET(code, 1), /* this subexpression's code */
  1180. ptr, /* where we currently are */
  1181. ptr - start_subject, /* start offset */
  1182. local_offsets, /* offset vector */
  1183. sizeof(local_offsets)/sizeof(int), /* size of same */
  1184. local_workspace, /* workspace vector */
  1185. sizeof(local_workspace)/sizeof(int), /* size of same */
  1186. ims, /* the current ims flags */
  1187. rlevel, /* function recursion level */
  1188. recursing + 1); /* regex recurse level */
  1189. DPRINTF(("%.*sReturn from regex recursion %d: rc=%d\n", rlevel*2-2, SP,
  1190. recursing + 1, rc));
  1191. /* Ran out of internal offsets */
  1192. if (rc == 0) return PCRE_ERROR_DFA_RECURSE;
  1193. /* For each successful matched substring, set up the next state with a
  1194. count of characters to skip before trying it. Note that the count is in
  1195. characters, not bytes. */
  1196. if (rc > 0)
  1197. {
  1198. for (rc = rc*2 - 2; rc >= 0; rc -= 2)
  1199. {
  1200. const uschar *p = start_subject + local_offsets[rc];
  1201. const uschar *pp = start_subject + local_offsets[rc+1];
  1202. int charcount = local_offsets[rc+1] - local_offsets[rc];
  1203. while (p < pp) if ((*p++ & 0xc0) == 0x80) charcount--;
  1204. if (charcount > 0)
  1205. {
  1206. ADD_NEW_DATA(-(state_offset + LINK_SIZE + 1), 0, (charcount - 1));
  1207. }
  1208. else
  1209. {
  1210. ADD_ACTIVE(state_offset + LINK_SIZE + 1, 0);
  1211. }
  1212. }
  1213. }
  1214. else if (rc != PCRE_ERROR_NOMATCH) return rc;
  1215. }
  1216. break;
  1217. /*-----------------------------------------------------------------*/
  1218. case OP_ONCE:
  1219. {
  1220. /* commented unused variable, Druzus */
  1221. /* const uschar *endcode; */
  1222. int local_offsets[2];
  1223. int local_workspace[1000];
  1224. int rc = internal_dfa_exec(
  1225. md, /* fixed match data */
  1226. code, /* this subexpression's code */
  1227. ptr, /* where we currently are */
  1228. ptr - start_subject, /* start offset */
  1229. local_offsets, /* offset vector */
  1230. sizeof(local_offsets)/sizeof(int), /* size of same */
  1231. local_workspace, /* workspace vector */
  1232. sizeof(local_workspace)/sizeof(int), /* size of same */
  1233. ims, /* the current ims flags */
  1234. rlevel, /* function recursion level */
  1235. recursing); /* pass on regex recursion */
  1236. if (rc >= 0)
  1237. {
  1238. const uschar *end_subpattern = code;
  1239. int charcount = local_offsets[1] - local_offsets[0];
  1240. int next_state_offset, repeat_state_offset;
  1241. /* commented unused variable, Druzus…

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