53 |
#endif |
#endif |
54 |
|
|
55 |
/* PCRE is compiled as an 8 bit library if it is not requested otherwise. */ |
/* PCRE is compiled as an 8 bit library if it is not requested otherwise. */ |
56 |
|
|
57 |
#if !defined COMPILE_PCRE16 && !defined COMPILE_PCRE32 |
#if !defined COMPILE_PCRE16 && !defined COMPILE_PCRE32 |
58 |
#define COMPILE_PCRE8 |
#define COMPILE_PCRE8 |
59 |
#endif |
#endif |
112 |
#include <stdlib.h> |
#include <stdlib.h> |
113 |
#include <string.h> |
#include <string.h> |
114 |
|
|
115 |
|
/* Valgrind (memcheck) support */ |
116 |
|
|
117 |
|
#ifdef SUPPORT_VALGRIND |
118 |
|
#include <valgrind/memcheck.h> |
119 |
|
#endif |
120 |
|
|
121 |
/* When compiling a DLL for Windows, the exported symbols have to be declared |
/* When compiling a DLL for Windows, the exported symbols have to be declared |
122 |
using some MS magic. I found some useful information on this web page: |
using some MS magic. I found some useful information on this web page: |
123 |
http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the |
http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the |
221 |
have stdint.h (e.g. Solaris) may have inttypes.h. The macro int64_t may be set |
have stdint.h (e.g. Solaris) may have inttypes.h. The macro int64_t may be set |
222 |
by "configure". */ |
by "configure". */ |
223 |
|
|
224 |
#if HAVE_STDINT_H |
#if defined HAVE_STDINT_H |
225 |
#include <stdint.h> |
#include <stdint.h> |
226 |
#elif HAVE_INTTYPES_H |
#elif defined HAVE_INTTYPES_H |
227 |
#include <inttypes.h> |
#include <inttypes.h> |
228 |
#endif |
#endif |
229 |
|
|
529 |
#define PUT2(a,n,d) \ |
#define PUT2(a,n,d) \ |
530 |
a[n] = (d) >> 8; \ |
a[n] = (d) >> 8; \ |
531 |
a[(n)+1] = (d) & 255 |
a[(n)+1] = (d) & 255 |
532 |
|
|
533 |
|
/* For reasons that I do not understand, the expression in this GET2 macro is |
534 |
|
treated by gcc as a signed expression, even when a is declared as unsigned. It |
535 |
|
seems that any kind of arithmetic results in a signed value. */ |
536 |
|
|
537 |
#define GET2(a,n) \ |
#define GET2(a,n) \ |
538 |
(((a)[n] << 8) | (a)[(n)+1]) |
(unsigned int)(((a)[n] << 8) | (a)[(n)+1]) |
539 |
|
|
540 |
#elif defined COMPILE_PCRE16 |
#elif defined COMPILE_PCRE16 |
541 |
|
|
776 |
we know we are in UTF mode. */ |
we know we are in UTF mode. */ |
777 |
|
|
778 |
#define RAWUCHARINC(eptr) \ |
#define RAWUCHARINC(eptr) \ |
779 |
(*(eptr)++) |
(*((eptr)++)) |
780 |
|
|
781 |
/* Returns the next uchar, testing for UTF mode, and not advancing the |
/* Returns the next uchar, testing for UTF mode, and not advancing the |
782 |
pointer. */ |
pointer. */ |
788 |
pointer. */ |
pointer. */ |
789 |
|
|
790 |
#define RAWUCHARINCTEST(eptr) \ |
#define RAWUCHARINCTEST(eptr) \ |
791 |
(*(eptr)++) |
(*((eptr)++)) |
792 |
|
|
793 |
/* 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 |
794 |
it is. This is called only in UTF-8 mode - we don't put a test within the macro |
it is. This is called only in UTF-8 mode - we don't put a test within the macro |
895 |
we know we are in UTF mode. */ |
we know we are in UTF mode. */ |
896 |
|
|
897 |
#define RAWUCHARINC(eptr) \ |
#define RAWUCHARINC(eptr) \ |
898 |
(*(eptr)++) |
(*((eptr)++)) |
899 |
|
|
900 |
/* Returns the next uchar, testing for UTF mode, and not advancing the |
/* Returns the next uchar, testing for UTF mode, and not advancing the |
901 |
pointer. */ |
pointer. */ |
907 |
pointer. */ |
pointer. */ |
908 |
|
|
909 |
#define RAWUCHARINCTEST(eptr) \ |
#define RAWUCHARINCTEST(eptr) \ |
910 |
(*(eptr)++) |
(*((eptr)++)) |
911 |
|
|
912 |
/* 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 |
913 |
it is. This is called only in UTF-16 mode - we don't put a test within the |
it is. This is called only in UTF-16 mode - we don't put a test within the |
934 |
|
|
935 |
#define UTF32_MASK (0x1fffffu) |
#define UTF32_MASK (0x1fffffu) |
936 |
|
|
937 |
|
/* Base macro to pick up an UTF-32 character out of a uint32 */ |
938 |
|
|
939 |
|
#define MASKHIGHBITS(c) ((c) & UTF32_MASK) |
940 |
|
|
941 |
|
/* Base macro to pick up an UTF-32 character, not advancing the pointer */ |
942 |
|
|
943 |
|
#define GETUTF32(eptr) (MASKHIGHBITS(*(eptr))) |
944 |
|
|
945 |
|
/* Base macro to pick up an UTF-32 character, advancing the pointer */ |
946 |
|
|
947 |
|
#define GETUTF32INC(eptr) (MASKHIGHBITS(*((eptr)++))) |
948 |
|
|
949 |
/* Get the next UTF-32 character, not advancing the pointer. This is called when |
/* Get the next UTF-32 character, not advancing the pointer. This is called when |
950 |
we know we are in UTF-32 mode. */ |
we know we are in UTF-32 mode. */ |
951 |
|
|
952 |
#define GETCHAR(c, eptr) \ |
#define GETCHAR(c, eptr) \ |
953 |
c = (*eptr) & UTF32_MASK; |
c = GETUTF32(eptr); |
954 |
|
|
955 |
/* Get the next UTF-32 character, testing for UTF-32 mode, and not advancing the |
/* Get the next UTF-32 character, testing for UTF-32 mode, and not advancing the |
956 |
pointer. */ |
pointer. */ |
957 |
|
|
958 |
#define GETCHARTEST(c, eptr) \ |
#define GETCHARTEST(c, eptr) \ |
959 |
c = *eptr; \ |
c = (utf ? GETUTF32(eptr) : *(eptr)); |
|
if (utf) c &= UTF32_MASK; |
|
960 |
|
|
961 |
/* Get the next UTF-32 character, advancing the pointer. This is called when we |
/* Get the next UTF-32 character, advancing the pointer. This is called when we |
962 |
know we are in UTF-32 mode. */ |
know we are in UTF-32 mode. */ |
963 |
|
|
964 |
#define GETCHARINC(c, eptr) \ |
#define GETCHARINC(c, eptr) \ |
965 |
c = (*eptr++) & UTF32_MASK; |
c = GETUTF32INC(eptr); |
966 |
|
|
967 |
/* Get the next character, testing for UTF-32 mode, and advancing the pointer. |
/* Get the next character, testing for UTF-32 mode, and advancing the pointer. |
968 |
This is called when we don't know if we are in UTF-32 mode. */ |
This is called when we don't know if we are in UTF-32 mode. */ |
969 |
|
|
970 |
#define GETCHARINCTEST(c, eptr) \ |
#define GETCHARINCTEST(c, eptr) \ |
971 |
c = *eptr++; \ |
c = (utf ? GETUTF32INC(eptr) : *((eptr)++)); |
|
if (utf) c &= UTF32_MASK; |
|
972 |
|
|
973 |
/* Get the next UTF-32 character, not advancing the pointer, not incrementing |
/* Get the next UTF-32 character, not advancing the pointer, not incrementing |
974 |
length (since all UTF-32 is of length 1). This is called when we know we are in |
length (since all UTF-32 is of length 1). This is called when we know we are in |
988 |
we know we are in UTF mode. */ |
we know we are in UTF mode. */ |
989 |
|
|
990 |
#define RAWUCHAR(eptr) \ |
#define RAWUCHAR(eptr) \ |
991 |
(*(eptr) & UTF32_MASK) |
(MASKHIGHBITS(*(eptr))) |
992 |
|
|
993 |
/* Returns the next uchar, advancing the pointer. This is called when |
/* Returns the next uchar, advancing the pointer. This is called when |
994 |
we know we are in UTF mode. */ |
we know we are in UTF mode. */ |
995 |
|
|
996 |
#define RAWUCHARINC(eptr) \ |
#define RAWUCHARINC(eptr) \ |
997 |
(*(eptr)++ & UTF32_MASK) |
(MASKHIGHBITS(*((eptr)++))) |
998 |
|
|
999 |
/* Returns the next uchar, testing for UTF mode, and not advancing the |
/* Returns the next uchar, testing for UTF mode, and not advancing the |
1000 |
pointer. */ |
pointer. */ |
1001 |
|
|
1002 |
#define RAWUCHARTEST(eptr) \ |
#define RAWUCHARTEST(eptr) \ |
1003 |
(utf ? (*(eptr) & UTF32_MASK) : *(eptr)) |
(utf ? (MASKHIGHBITS(*(eptr))) : *(eptr)) |
1004 |
|
|
1005 |
/* Returns the next uchar, testing for UTF mode, advancing the |
/* Returns the next uchar, testing for UTF mode, advancing the |
1006 |
pointer. */ |
pointer. */ |
1007 |
|
|
1008 |
#define RAWUCHARINCTEST(eptr) \ |
#define RAWUCHARINCTEST(eptr) \ |
1009 |
(utf ? (*(eptr)++ & UTF32_MASK) : *(eptr)++) |
(utf ? (MASKHIGHBITS(*((eptr)++))) : *((eptr)++)) |
1010 |
|
|
1011 |
/* 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 |
1012 |
it is. This is called only in UTF-32 mode - we don't put a test within the |
it is. This is called only in UTF-32 mode - we don't put a test within the |
1193 |
(PCRE_STUDY_JIT_COMPILE|PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE| \ |
(PCRE_STUDY_JIT_COMPILE|PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE| \ |
1194 |
PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE|PCRE_STUDY_EXTRA_NEEDED) |
PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE|PCRE_STUDY_EXTRA_NEEDED) |
1195 |
|
|
1196 |
|
#define PUBLIC_JIT_EXEC_OPTIONS \ |
1197 |
|
(PCRE_NO_UTF8_CHECK|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|\ |
1198 |
|
PCRE_NOTEMPTY_ATSTART|PCRE_PARTIAL_SOFT|PCRE_PARTIAL_HARD) |
1199 |
|
|
1200 |
/* Magic number to provide a small check against being handed junk. */ |
/* Magic number to provide a small check against being handed junk. */ |
1201 |
|
|
1202 |
#define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */ |
#define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */ |
1300 |
|
|
1301 |
/* The remaining definitions work in both environments. */ |
/* The remaining definitions work in both environments. */ |
1302 |
|
|
1303 |
|
#define CHAR_NULL '\0' |
1304 |
#define CHAR_HT '\t' |
#define CHAR_HT '\t' |
1305 |
#define CHAR_VT '\v' |
#define CHAR_VT '\v' |
1306 |
#define CHAR_FF '\f' |
#define CHAR_FF '\f' |
1570 |
#define CHAR_ESC '\033' |
#define CHAR_ESC '\033' |
1571 |
#define CHAR_DEL '\177' |
#define CHAR_DEL '\177' |
1572 |
|
|
1573 |
|
#define CHAR_NULL '\0' |
1574 |
#define CHAR_SPACE '\040' |
#define CHAR_SPACE '\040' |
1575 |
#define CHAR_EXCLAMATION_MARK '\041' |
#define CHAR_EXCLAMATION_MARK '\041' |
1576 |
#define CHAR_QUOTATION_MARK '\042' |
#define CHAR_QUOTATION_MARK '\042' |
2420 |
int names_found; /* Number of entries so far */ |
int names_found; /* Number of entries so far */ |
2421 |
int name_entry_size; /* Size of each entry */ |
int name_entry_size; /* Size of each entry */ |
2422 |
int workspace_size; /* Size of workspace */ |
int workspace_size; /* Size of workspace */ |
2423 |
int bracount; /* Count of capturing parens as we compile */ |
unsigned int bracount; /* Count of capturing parens as we compile */ |
2424 |
int final_bracount; /* Saved value after first pass */ |
int final_bracount; /* Saved value after first pass */ |
2425 |
int max_lookbehind; /* Maximum lookbehind (characters) */ |
int max_lookbehind; /* Maximum lookbehind (characters) */ |
2426 |
int top_backref; /* Maximum back reference */ |
int top_backref; /* Maximum back reference */ |
2450 |
|
|
2451 |
typedef struct recursion_info { |
typedef struct recursion_info { |
2452 |
struct recursion_info *prevrec; /* Previous recursion record (or NULL) */ |
struct recursion_info *prevrec; /* Previous recursion record (or NULL) */ |
2453 |
int group_num; /* Number of group that was called */ |
unsigned int group_num; /* Number of group that was called */ |
2454 |
int *offset_save; /* Pointer to start of saved offsets */ |
int *offset_save; /* Pointer to start of saved offsets */ |
2455 |
int saved_max; /* Number of saved offsets */ |
int saved_max; /* Number of saved offsets */ |
2456 |
PCRE_PUCHAR subject_position; /* Position at start of recursion */ |
PCRE_PUCHAR subject_position; /* Position at start of recursion */ |
2708 |
extern const pcre_uchar *PRIV(find_bracket)(const pcre_uchar *, BOOL, int); |
extern const pcre_uchar *PRIV(find_bracket)(const pcre_uchar *, BOOL, int); |
2709 |
extern BOOL PRIV(is_newline)(PCRE_PUCHAR, int, PCRE_PUCHAR, |
extern BOOL PRIV(is_newline)(PCRE_PUCHAR, int, PCRE_PUCHAR, |
2710 |
int *, BOOL); |
int *, BOOL); |
2711 |
extern int PRIV(ord2utf)(pcre_uint32, pcre_uchar *); |
extern unsigned int PRIV(ord2utf)(pcre_uint32, pcre_uchar *); |
2712 |
extern int PRIV(valid_utf)(PCRE_PUCHAR, int, int *); |
extern int PRIV(valid_utf)(PCRE_PUCHAR, int, int *); |
2713 |
extern BOOL PRIV(was_newline)(PCRE_PUCHAR, int, PCRE_PUCHAR, |
extern BOOL PRIV(was_newline)(PCRE_PUCHAR, int, PCRE_PUCHAR, |
2714 |
int *, BOOL); |
int *, BOOL); |
2717 |
#ifdef SUPPORT_JIT |
#ifdef SUPPORT_JIT |
2718 |
extern void PRIV(jit_compile)(const REAL_PCRE *, |
extern void PRIV(jit_compile)(const REAL_PCRE *, |
2719 |
PUBL(extra) *, int); |
PUBL(extra) *, int); |
2720 |
extern int PRIV(jit_exec)(const REAL_PCRE *, const PUBL(extra) *, |
extern int PRIV(jit_exec)(const PUBL(extra) *, |
2721 |
const pcre_uchar *, int, int, int, int *, int); |
const pcre_uchar *, int, int, int, int *, int); |
2722 |
extern void PRIV(jit_free)(void *); |
extern void PRIV(jit_free)(void *); |
2723 |
extern int PRIV(jit_get_size)(void *); |
extern int PRIV(jit_get_size)(void *); |