| 7 |
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. |
| 8 |
|
|
| 9 |
Written by Philip Hazel |
Written by Philip Hazel |
| 10 |
Copyright (c) 1997-2007 University of Cambridge |
Copyright (c) 1997-2008 University of Cambridge |
| 11 |
|
|
| 12 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
| 13 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
| 67 |
#endif |
#endif |
| 68 |
|
|
| 69 |
|
|
|
/* Get the definitions provided by running "configure" */ |
|
|
|
|
|
#include "config.h" |
|
|
|
|
| 70 |
/* Standard C headers plus the external interface definition. The only time |
/* Standard C headers plus the external interface definition. The only time |
| 71 |
setjmp and stdarg are used is when NO_RECURSE is set. */ |
setjmp and stdarg are used is when NO_RECURSE is set. */ |
| 72 |
|
|
| 108 |
|
|
| 109 |
#ifndef PCRE_EXP_DECL |
#ifndef PCRE_EXP_DECL |
| 110 |
# ifdef _WIN32 |
# ifdef _WIN32 |
| 111 |
# ifdef DLL_EXPORT |
# ifndef PCRE_STATIC |
| 112 |
# define PCRE_EXP_DECL extern __declspec(dllexport) |
# define PCRE_EXP_DECL extern __declspec(dllexport) |
| 113 |
# define PCRE_EXP_DEFN __declspec(dllexport) |
# define PCRE_EXP_DEFN __declspec(dllexport) |
| 114 |
# define PCRE_EXP_DATA_DEFN __declspec(dllexport) |
# define PCRE_EXP_DATA_DEFN __declspec(dllexport) |
| 117 |
# define PCRE_EXP_DEFN |
# define PCRE_EXP_DEFN |
| 118 |
# define PCRE_EXP_DATA_DEFN |
# define PCRE_EXP_DATA_DEFN |
| 119 |
# endif |
# endif |
|
# |
|
| 120 |
# else |
# else |
| 121 |
# ifdef __cplusplus |
# ifdef __cplusplus |
| 122 |
# define PCRE_EXP_DECL extern "C" |
# define PCRE_EXP_DECL extern "C" |
| 358 |
|
|
| 359 |
/* When UTF-8 encoding is being used, a character is no longer just a single |
/* When UTF-8 encoding is being used, a character is no longer just a single |
| 360 |
byte. The macros for character handling generate simple sequences when used in |
byte. The macros for character handling generate simple sequences when used in |
| 361 |
byte-mode, and more complicated ones for UTF-8 characters. */ |
byte-mode, and more complicated ones for UTF-8 characters. BACKCHAR should |
| 362 |
|
never be called in byte mode. To make sure it can never even appear when UTF-8 |
| 363 |
|
support is omitted, we don't even define it. */ |
| 364 |
|
|
| 365 |
#ifndef SUPPORT_UTF8 |
#ifndef SUPPORT_UTF8 |
| 366 |
|
#define NEXTCHAR(p) p++; |
| 367 |
#define GETCHAR(c, eptr) c = *eptr; |
#define GETCHAR(c, eptr) c = *eptr; |
| 368 |
#define GETCHARTEST(c, eptr) c = *eptr; |
#define GETCHARTEST(c, eptr) c = *eptr; |
| 369 |
#define GETCHARINC(c, eptr) c = *eptr++; |
#define GETCHARINC(c, eptr) c = *eptr++; |
| 370 |
#define GETCHARINCTEST(c, eptr) c = *eptr++; |
#define GETCHARINCTEST(c, eptr) c = *eptr++; |
| 371 |
#define GETCHARLEN(c, eptr, len) c = *eptr; |
#define GETCHARLEN(c, eptr, len) c = *eptr; |
| 372 |
#define BACKCHAR(eptr) |
/* #define BACKCHAR(eptr) */ |
| 373 |
|
|
| 374 |
#else /* SUPPORT_UTF8 */ |
#else /* SUPPORT_UTF8 */ |
| 375 |
|
|
| 376 |
|
/* Advance a character pointer one byte in non-UTF-8 mode and by one character |
| 377 |
|
in UTF-8 mode. */ |
| 378 |
|
|
| 379 |
|
#define NEXTCHAR(p) \ |
| 380 |
|
p++; \ |
| 381 |
|
if (utf8) { while((*p & 0xc0) == 0x80) p++; } |
| 382 |
|
|
| 383 |
/* Get the next UTF-8 character, not advancing the pointer. This is called when |
/* Get the next UTF-8 character, not advancing the pointer. This is called when |
| 384 |
we know we are in UTF-8 mode. */ |
we know we are in UTF-8 mode. */ |
| 385 |
|
|
| 469 |
} |
} |
| 470 |
|
|
| 471 |
/* If the pointer is not at the start of a character, move it back until |
/* If the pointer is not at the start of a character, move it back until |
| 472 |
it is. Called only in UTF-8 mode. */ |
it is. This is called only in UTF-8 mode - we don't put a test within the macro |
| 473 |
|
because almost all calls are already within a block of UTF-8 only code. */ |
| 474 |
|
|
| 475 |
#define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr--; |
#define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr-- |
| 476 |
|
|
| 477 |
#endif |
#endif |
| 478 |
|
|
| 489 |
|
|
| 490 |
#define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL) |
#define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL) |
| 491 |
|
|
| 492 |
/* Private options flags start at the most significant end of the four bytes. |
/* Private flags containing information about the compiled regex. They used to |
| 493 |
The public options defined in pcre.h start at the least significant end. Make |
live at the top end of the options word, but that got almost full, so now they |
| 494 |
sure they don't overlap! The bits are getting a bit scarce now -- when we run |
are in a 16-bit flags word. */ |
| 495 |
out, there is a dummy word in the structure that could be used for the private |
|
| 496 |
bits. */ |
#define PCRE_NOPARTIAL 0x0001 /* can't use partial with this regex */ |
| 497 |
|
#define PCRE_FIRSTSET 0x0002 /* first_byte is set */ |
| 498 |
#define PCRE_NOPARTIAL 0x80000000 /* can't use partial with this regex */ |
#define PCRE_REQCHSET 0x0004 /* req_byte is set */ |
| 499 |
#define PCRE_FIRSTSET 0x40000000 /* first_byte is set */ |
#define PCRE_STARTLINE 0x0008 /* start after \n for multiline */ |
| 500 |
#define PCRE_REQCHSET 0x20000000 /* req_byte is set */ |
#define PCRE_JCHANGED 0x0010 /* j option used in regex */ |
| 501 |
#define PCRE_STARTLINE 0x10000000 /* start after \n for multiline */ |
#define PCRE_HASCRORLF 0x0020 /* explicit \r or \n in pattern */ |
|
#define PCRE_JCHANGED 0x08000000 /* j option changes within regex */ |
|
| 502 |
|
|
| 503 |
/* Options for the "extra" block produced by pcre_study(). */ |
/* Options for the "extra" block produced by pcre_study(). */ |
| 504 |
|
|
| 514 |
(PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \ |
(PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \ |
| 515 |
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \ |
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \ |
| 516 |
PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE| \ |
PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE| \ |
| 517 |
PCRE_DUPNAMES|PCRE_NEWLINE_BITS) |
PCRE_DUPNAMES|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) |
| 518 |
|
|
| 519 |
#define PUBLIC_EXEC_OPTIONS \ |
#define PUBLIC_EXEC_OPTIONS \ |
| 520 |
(PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ |
(PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ |
| 521 |
PCRE_PARTIAL|PCRE_NEWLINE_BITS) |
PCRE_PARTIAL|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) |
| 522 |
|
|
| 523 |
#define PUBLIC_DFA_EXEC_OPTIONS \ |
#define PUBLIC_DFA_EXEC_OPTIONS \ |
| 524 |
(PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ |
(PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ |
| 525 |
PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_BITS) |
PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_BITS| \ |
| 526 |
|
PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) |
| 527 |
|
|
| 528 |
#define PUBLIC_STUDY_OPTIONS 0 /* None defined */ |
#define PUBLIC_STUDY_OPTIONS 0 /* None defined */ |
| 529 |
|
|
| 616 |
ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z, ESC_E, ESC_Q, ESC_k, ESC_REF }; |
ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z, ESC_E, ESC_Q, ESC_k, ESC_REF }; |
| 617 |
|
|
| 618 |
|
|
| 619 |
/* Opcode table: OP_BRA must be last, as all values >= it are used for brackets |
/* Opcode table: Starting from 1 (i.e. after OP_END), the values up to |
|
that extract substrings. Starting from 1 (i.e. after OP_END), the values up to |
|
| 620 |
OP_EOD must correspond in order to the list of escapes immediately above. |
OP_EOD must correspond in order to the list of escapes immediately above. |
| 621 |
|
|
|
To keep stored, compiled patterns compatible, new opcodes should be added |
|
|
immediately before OP_BRA, where (since release 7.0) a gap is left for this |
|
|
purpose. |
|
|
|
|
| 622 |
*** NOTE NOTE NOTE *** Whenever this list is updated, the two macro definitions |
*** NOTE NOTE NOTE *** Whenever this list is updated, the two macro definitions |
| 623 |
that follow must also be updated to match. There is also a table called |
that follow must also be updated to match. There is also a table called |
| 624 |
"coptable" in pcre_dfa_exec.c that must be updated. */ |
"coptable" in pcre_dfa_exec.c that must be updated. */ |
| 761 |
OP_DEF, /* 101 The DEFINE condition */ |
OP_DEF, /* 101 The DEFINE condition */ |
| 762 |
|
|
| 763 |
OP_BRAZERO, /* 102 These two must remain together and in this */ |
OP_BRAZERO, /* 102 These two must remain together and in this */ |
| 764 |
OP_BRAMINZERO /* 103 order. */ |
OP_BRAMINZERO, /* 103 order. */ |
| 765 |
|
|
| 766 |
|
/* These are backtracking control verbs */ |
| 767 |
|
|
| 768 |
|
OP_PRUNE, /* 104 */ |
| 769 |
|
OP_SKIP, /* 105 */ |
| 770 |
|
OP_THEN, /* 106 */ |
| 771 |
|
OP_COMMIT, /* 107 */ |
| 772 |
|
|
| 773 |
|
/* These are forced failure and success verbs */ |
| 774 |
|
|
| 775 |
|
OP_FAIL, /* 108 */ |
| 776 |
|
OP_ACCEPT /* 109 */ |
| 777 |
}; |
}; |
| 778 |
|
|
| 779 |
|
|
| 796 |
"class", "nclass", "xclass", "Ref", "Recurse", "Callout", \ |
"class", "nclass", "xclass", "Ref", "Recurse", "Callout", \ |
| 797 |
"Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", \ |
"Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", \ |
| 798 |
"AssertB", "AssertB not", "Reverse", \ |
"AssertB", "AssertB not", "Reverse", \ |
| 799 |
"Once", "Bra 0", "Bra", "Cond", "SBra 0", "SBra", "SCond", \ |
"Once", "Bra", "CBra", "Cond", "SBra", "SCBra", "SCond", \ |
| 800 |
"Cond ref", "Cond rec", "Cond def", "Brazero", "Braminzero" |
"Cond ref", "Cond rec", "Cond def", "Brazero", "Braminzero", \ |
| 801 |
|
"*PRUNE", "*SKIP", "*THEN", "*COMMIT", "*FAIL", "*ACCEPT" |
| 802 |
|
|
| 803 |
|
|
| 804 |
/* This macro defines the length of fixed length operations in the compiled |
/* This macro defines the length of fixed length operations in the compiled |
| 862 |
3, /* RREF */ \ |
3, /* RREF */ \ |
| 863 |
1, /* DEF */ \ |
1, /* DEF */ \ |
| 864 |
1, 1, /* BRAZERO, BRAMINZERO */ \ |
1, 1, /* BRAZERO, BRAMINZERO */ \ |
| 865 |
|
1, 1, 1, 1, /* PRUNE, SKIP, THEN, COMMIT, */ \ |
| 866 |
|
1, 1 /* FAIL, ACCEPT */ |
| 867 |
|
|
| 868 |
|
|
| 869 |
/* A magic value for OP_RREF to indicate the "any recursion" condition. */ |
/* A magic value for OP_RREF to indicate the "any recursion" condition. */ |
| 878 |
ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, |
ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, |
| 879 |
ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, |
ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, |
| 880 |
ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, |
ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, |
| 881 |
ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58 }; |
ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, |
| 882 |
|
ERR60, ERR61, ERR62, ERR63 }; |
| 883 |
|
|
| 884 |
/* The real format of the start of the pcre block; the index of names and the |
/* The real format of the start of the pcre block; the index of names and the |
| 885 |
code vector run on as long as necessary after the end. We store an explicit |
code vector run on as long as necessary after the end. We store an explicit |
| 901 |
typedef struct real_pcre { |
typedef struct real_pcre { |
| 902 |
pcre_uint32 magic_number; |
pcre_uint32 magic_number; |
| 903 |
pcre_uint32 size; /* Total that was malloced */ |
pcre_uint32 size; /* Total that was malloced */ |
| 904 |
pcre_uint32 options; |
pcre_uint32 options; /* Public options */ |
| 905 |
pcre_uint32 dummy1; /* For future use, maybe */ |
pcre_uint16 flags; /* Private flags */ |
| 906 |
|
pcre_uint16 dummy1; /* For future use */ |
| 907 |
pcre_uint16 top_bracket; |
pcre_uint16 top_bracket; |
| 908 |
pcre_uint16 top_backref; |
pcre_uint16 top_backref; |
| 909 |
pcre_uint16 first_byte; |
pcre_uint16 first_byte; |
| 942 |
uschar *name_table; /* The name/number table */ |
uschar *name_table; /* The name/number table */ |
| 943 |
int names_found; /* Number of entries so far */ |
int names_found; /* Number of entries so far */ |
| 944 |
int name_entry_size; /* Size of each entry */ |
int name_entry_size; /* Size of each entry */ |
| 945 |
int bracount; /* Count of capturing parens */ |
int bracount; /* Count of capturing parens as we compile */ |
| 946 |
|
int final_bracount; /* Saved value after first pass */ |
| 947 |
int top_backref; /* Maximum back reference */ |
int top_backref; /* Maximum back reference */ |
| 948 |
unsigned int backref_map; /* Bitmap of low back refs */ |
unsigned int backref_map; /* Bitmap of low back refs */ |
| 949 |
int external_options; /* External (initial) options */ |
int external_options; /* External (initial) options */ |
| 950 |
|
int external_flags; /* External flag bits to be set */ |
| 951 |
int req_varyopt; /* "After variable item" flag for reqbyte */ |
int req_varyopt; /* "After variable item" flag for reqbyte */ |
| 952 |
BOOL nopartial; /* Set TRUE if partial won't work */ |
BOOL had_accept; /* (*ACCEPT) encountered */ |
| 953 |
int nltype; /* Newline type */ |
int nltype; /* Newline type */ |
| 954 |
int nllen; /* Newline string length */ |
int nllen; /* Newline string length */ |
| 955 |
uschar nl[4]; /* Newline string when fixed length */ |
uschar nl[4]; /* Newline string when fixed length */ |
| 1008 |
BOOL notempty; /* Empty string match not wanted */ |
BOOL notempty; /* Empty string match not wanted */ |
| 1009 |
BOOL partial; /* PARTIAL flag */ |
BOOL partial; /* PARTIAL flag */ |
| 1010 |
BOOL hitend; /* Hit the end of the subject at some point */ |
BOOL hitend; /* Hit the end of the subject at some point */ |
| 1011 |
|
BOOL bsr_anycrlf; /* \R is just any CRLF, not full Unicode */ |
| 1012 |
const uschar *start_code; /* For use when recursing */ |
const uschar *start_code; /* For use when recursing */ |
| 1013 |
USPTR start_subject; /* Start of the subject string */ |
USPTR start_subject; /* Start of the subject string */ |
| 1014 |
USPTR end_subject; /* End of the subject string */ |
USPTR end_subject; /* End of the subject string */ |
| 1045 |
#define ctype_letter 0x02 |
#define ctype_letter 0x02 |
| 1046 |
#define ctype_digit 0x04 |
#define ctype_digit 0x04 |
| 1047 |
#define ctype_xdigit 0x08 |
#define ctype_xdigit 0x08 |
| 1048 |
#define ctype_word 0x10 /* alphameric or '_' */ |
#define ctype_word 0x10 /* alphanumeric or '_' */ |
| 1049 |
#define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */ |
#define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */ |
| 1050 |
|
|
| 1051 |
/* Offsets for the bitmap tables in pcre_cbits. Each table contains a set |
/* Offsets for the bitmap tables in pcre_cbits. Each table contains a set |
| 1073 |
#define tables_length (ctypes_offset + 256) |
#define tables_length (ctypes_offset + 256) |
| 1074 |
|
|
| 1075 |
/* Layout of the UCP type table that translates property names into types and |
/* Layout of the UCP type table that translates property names into types and |
| 1076 |
codes. */ |
codes. Each entry used to point directly to a name, but to reduce the number of |
| 1077 |
|
relocations in shared libraries, it now has an offset into a single string |
| 1078 |
|
instead. */ |
| 1079 |
|
|
| 1080 |
typedef struct { |
typedef struct { |
| 1081 |
const char *name; |
pcre_uint16 name_offset; |
| 1082 |
pcre_uint16 type; |
pcre_uint16 type; |
| 1083 |
pcre_uint16 value; |
pcre_uint16 value; |
| 1084 |
} ucp_type_table; |
} ucp_type_table; |
| 1096 |
|
|
| 1097 |
extern const int _pcre_utf8_table1_size; |
extern const int _pcre_utf8_table1_size; |
| 1098 |
|
|
| 1099 |
|
extern const char _pcre_utt_names[]; |
| 1100 |
extern const ucp_type_table _pcre_utt[]; |
extern const ucp_type_table _pcre_utt[]; |
| 1101 |
extern const int _pcre_utt_size; |
extern const int _pcre_utt_size; |
| 1102 |
|
|