6 |
and semantics are as close as possible to those of the Perl 5 language. |
and semantics are as close as possible to those of the Perl 5 language. |
7 |
|
|
8 |
Written by Philip Hazel |
Written by Philip Hazel |
9 |
Copyright (c) 1997-2007 University of Cambridge |
Copyright (c) 1997-2008 University of Cambridge |
10 |
|
|
11 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
12 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
45 |
|
|
46 |
|
|
47 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
48 |
#include <config.h> |
#include "config.h" |
49 |
#endif |
#endif |
50 |
|
|
51 |
#define NLBLOCK md /* Block containing newline information */ |
#define NLBLOCK md /* Block containing newline information */ |
84 |
small value. ***NOTE*** If the start of this table is modified, the two tables |
small value. ***NOTE*** If the start of this table is modified, the two tables |
85 |
that follow must also be modified. */ |
that follow must also be modified. */ |
86 |
|
|
87 |
static uschar coptable[] = { |
static const uschar coptable[] = { |
88 |
0, /* End */ |
0, /* End */ |
89 |
0, 0, 0, 0, 0, /* \A, \G, \K, \B, \b */ |
0, 0, 0, 0, 0, /* \A, \G, \K, \B, \b */ |
90 |
0, 0, 0, 0, 0, 0, /* \D, \d, \S, \s, \W, \w */ |
0, 0, 0, 0, 0, 0, /* \D, \d, \S, \s, \W, \w */ |
91 |
0, 0, /* Any, Anybyte */ |
0, 0, 0, /* Any, AllAny, Anybyte */ |
92 |
0, 0, 0, /* NOTPROP, PROP, EXTUNI */ |
0, 0, 0, /* NOTPROP, PROP, EXTUNI */ |
93 |
0, 0, 0, 0, 0, /* \R, \H, \h, \V, \v */ |
0, 0, 0, 0, 0, /* \R, \H, \h, \V, \v */ |
94 |
0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */ |
0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */ |
132 |
0, /* DEF */ |
0, /* DEF */ |
133 |
0, 0, /* BRAZERO, BRAMINZERO */ |
0, 0, /* BRAZERO, BRAMINZERO */ |
134 |
0, 0, 0, 0, /* PRUNE, SKIP, THEN, COMMIT */ |
0, 0, 0, 0, /* PRUNE, SKIP, THEN, COMMIT */ |
135 |
0, 0 /* FAIL, ACCEPT */ |
0, 0, 0 /* FAIL, ACCEPT, SKIPZERO */ |
136 |
}; |
}; |
137 |
|
|
138 |
/* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W, |
/* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W, |
139 |
and \w */ |
and \w */ |
140 |
|
|
141 |
static uschar toptable1[] = { |
static const uschar toptable1[] = { |
142 |
0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, |
143 |
ctype_digit, ctype_digit, |
ctype_digit, ctype_digit, |
144 |
ctype_space, ctype_space, |
ctype_space, ctype_space, |
145 |
ctype_word, ctype_word, |
ctype_word, ctype_word, |
146 |
0 /* OP_ANY */ |
0, 0 /* OP_ANY, OP_ALLANY */ |
147 |
}; |
}; |
148 |
|
|
149 |
static uschar toptable2[] = { |
static const uschar toptable2[] = { |
150 |
0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, |
151 |
ctype_digit, 0, |
ctype_digit, 0, |
152 |
ctype_space, 0, |
ctype_space, 0, |
153 |
ctype_word, 0, |
ctype_word, 0, |
154 |
1 /* OP_ANY */ |
1, 1 /* OP_ANY, OP_ALLANY */ |
155 |
}; |
}; |
156 |
|
|
157 |
|
|
223 |
rlevel function call recursion level |
rlevel function call recursion level |
224 |
recursing regex recursive call level |
recursing regex recursive call level |
225 |
|
|
226 |
Returns: > 0 => |
Returns: > 0 => number of match offset pairs placed in offsets |
227 |
= 0 => |
= 0 => offsets overflowed; longest matches are present |
228 |
-1 => failed to match |
-1 => failed to match |
229 |
< -1 => some kind of unexpected problem |
< -1 => some kind of unexpected problem |
230 |
|
|
694 |
break; |
break; |
695 |
|
|
696 |
/*-----------------------------------------------------------------*/ |
/*-----------------------------------------------------------------*/ |
697 |
|
case OP_SKIPZERO: |
698 |
|
code += 1 + GET(code, 2); |
699 |
|
while (*code == OP_ALT) code += GET(code, 1); |
700 |
|
ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0); |
701 |
|
break; |
702 |
|
|
703 |
|
/*-----------------------------------------------------------------*/ |
704 |
case OP_CIRC: |
case OP_CIRC: |
705 |
if ((ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0) || |
if ((ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0) || |
706 |
((ims & PCRE_MULTILINE) != 0 && |
((ims & PCRE_MULTILINE) != 0 && |
739 |
|
|
740 |
/*-----------------------------------------------------------------*/ |
/*-----------------------------------------------------------------*/ |
741 |
case OP_ANY: |
case OP_ANY: |
742 |
if (clen > 0 && ((ims & PCRE_DOTALL) != 0 || !IS_NEWLINE(ptr))) |
if (clen > 0 && !IS_NEWLINE(ptr)) |
743 |
|
{ ADD_NEW(state_offset + 1, 0); } |
744 |
|
break; |
745 |
|
|
746 |
|
/*-----------------------------------------------------------------*/ |
747 |
|
case OP_ALLANY: |
748 |
|
if (clen > 0) |
749 |
{ ADD_NEW(state_offset + 1, 0); } |
{ ADD_NEW(state_offset + 1, 0); } |
750 |
break; |
break; |
751 |
|
|
865 |
/* ========================================================================== */ |
/* ========================================================================== */ |
866 |
/* These opcodes likewise inspect the subject character, but have an |
/* These opcodes likewise inspect the subject character, but have an |
867 |
argument that is not a data character. It is one of these opcodes: |
argument that is not a data character. It is one of these opcodes: |
868 |
OP_ANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE, OP_WORDCHAR, |
OP_ANY, OP_ALLANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE, |
869 |
OP_NOT_WORDCHAR. The value is loaded into d. */ |
OP_WORDCHAR, OP_NOT_WORDCHAR. The value is loaded into d. */ |
870 |
|
|
871 |
case OP_TYPEPLUS: |
case OP_TYPEPLUS: |
872 |
case OP_TYPEMINPLUS: |
case OP_TYPEMINPLUS: |
877 |
{ |
{ |
878 |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
879 |
(c < 256 && |
(c < 256 && |
880 |
(d != OP_ANY || |
(d != OP_ANY || !IS_NEWLINE(ptr)) && |
|
(ims & PCRE_DOTALL) != 0 || |
|
|
!IS_NEWLINE(ptr) |
|
|
) && |
|
881 |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
882 |
{ |
{ |
883 |
if (count > 0 && codevalue == OP_TYPEPOSPLUS) |
if (count > 0 && codevalue == OP_TYPEPOSPLUS) |
900 |
{ |
{ |
901 |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
902 |
(c < 256 && |
(c < 256 && |
903 |
(d != OP_ANY || |
(d != OP_ANY || !IS_NEWLINE(ptr)) && |
|
(ims & PCRE_DOTALL) != 0 || |
|
|
!IS_NEWLINE(ptr) |
|
|
) && |
|
904 |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
905 |
{ |
{ |
906 |
if (codevalue == OP_TYPEPOSQUERY) |
if (codevalue == OP_TYPEPOSQUERY) |
922 |
{ |
{ |
923 |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
924 |
(c < 256 && |
(c < 256 && |
925 |
(d != OP_ANY || |
(d != OP_ANY || !IS_NEWLINE(ptr)) && |
|
(ims & PCRE_DOTALL) != 0 || |
|
|
!IS_NEWLINE(ptr) |
|
|
) && |
|
926 |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
927 |
{ |
{ |
928 |
if (codevalue == OP_TYPEPOSSTAR) |
if (codevalue == OP_TYPEPOSSTAR) |
942 |
{ |
{ |
943 |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
944 |
(c < 256 && |
(c < 256 && |
945 |
(d != OP_ANY || |
(d != OP_ANY || !IS_NEWLINE(ptr)) && |
|
(ims & PCRE_DOTALL) != 0 || |
|
|
!IS_NEWLINE(ptr) |
|
|
) && |
|
946 |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
947 |
{ |
{ |
948 |
if (++count >= GET2(code, 1)) |
if (++count >= GET2(code, 1)) |
963 |
{ |
{ |
964 |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || |
965 |
(c < 256 && |
(c < 256 && |
966 |
(d != OP_ANY || |
(d != OP_ANY || !IS_NEWLINE(ptr)) && |
|
(ims & PCRE_DOTALL) != 0 || |
|
|
!IS_NEWLINE(ptr) |
|
|
) && |
|
967 |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) |
968 |
{ |
{ |
969 |
if (codevalue == OP_TYPEPOSUPTO) |
if (codevalue == OP_TYPEPOSUPTO) |
2160 |
|
|
2161 |
/* ========================================================================== */ |
/* ========================================================================== */ |
2162 |
/* These are the opcodes for fancy brackets of various kinds. We have |
/* These are the opcodes for fancy brackets of various kinds. We have |
2163 |
to use recursion in order to handle them. */ |
to use recursion in order to handle them. The "always failing" assersion |
2164 |
|
(?!) is optimised when compiling to OP_FAIL, so we have to support that, |
2165 |
|
though the other "backtracking verbs" are not supported. */ |
2166 |
|
|
2167 |
|
case OP_FAIL: |
2168 |
|
break; |
2169 |
|
|
2170 |
case OP_ASSERT: |
case OP_ASSERT: |
2171 |
case OP_ASSERT_NOT: |
case OP_ASSERT_NOT: |
2607 |
md->moptions |= re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE); |
md->moptions |= re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE); |
2608 |
#ifdef BSR_ANYCRLF |
#ifdef BSR_ANYCRLF |
2609 |
else md->moptions |= PCRE_BSR_ANYCRLF; |
else md->moptions |= PCRE_BSR_ANYCRLF; |
2610 |
#endif |
#endif |
2611 |
} |
} |
2612 |
|
|
2613 |
/* Handle different types of newline. The three bits give eight cases. If |
/* Handle different types of newline. The three bits give eight cases. If |
2614 |
nothing is set at run time, whatever was used at compile time applies. */ |
nothing is set at run time, whatever was used at compile time applies. */ |