Regex: Update PCRE to v8.35.

I was über lazy at first, so took libs from SM.
But actually it's quite easy to compile, so let's update to latest version \o/.
This commit is contained in:
Arkshine
2014-07-05 13:53:30 +02:00
parent d1153b8049
commit d4de0e6f1e
241 changed files with 51074 additions and 15011 deletions

View File

@@ -3,10 +3,16 @@
*************************************************/
/* This is a grep program that uses the PCRE regular expression library to do
its pattern matching. On a Unix or Win32 system it can recurse into
directories.
its pattern matching. On Unix-like, Windows, and native z/OS systems it can
recurse into directories, and in z/OS it can handle PDS files.
Copyright (c) 1997-2012 University of Cambridge
Note that for native z/OS, in addition to defining the NATIVE_ZOS macro, an
additional header is required. That header is not included in the main PCRE
distribution because other apparatus is needed to compile pcregrep for z/OS.
The header can be found in the special z/OS distribution, which is available
from www.zaconsultants.net or from www.cbttape.org.
Copyright (c) 1997-2014 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -530,17 +536,29 @@ while (fn != NULL)
* OS-specific functions *
*************************************************/
/* These functions are defined so that they can be made system specific,
although at present the only ones are for Unix, Win32, and for "no support". */
/* These functions are defined so that they can be made system specific.
At present there are versions for Unix-style environments, Windows, native
z/OS, and "no support". */
/************* Directory scanning in Unix ***********/
/************* Directory scanning Unix-style and z/OS ***********/
#if defined HAVE_SYS_STAT_H && defined HAVE_DIRENT_H && defined HAVE_SYS_TYPES_H
#if (defined HAVE_SYS_STAT_H && defined HAVE_DIRENT_H && defined HAVE_SYS_TYPES_H) || defined NATIVE_ZOS
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#if defined NATIVE_ZOS
/************* Directory and PDS/E scanning for z/OS ***********/
/************* z/OS looks mostly like Unix with USS ************/
/* However, z/OS needs the #include statements in this header */
#include "pcrzosfs.h"
/* That header is not included in the main PCRE distribution because
other apparatus is needed to compile pcregrep for z/OS. The header
can be found in the special z/OS distribution, which is available
from www.zaconsultants.net or from www.cbttape.org. */
#endif
typedef DIR directory_type;
#define FILESEP '/'
@@ -579,7 +597,7 @@ closedir(dir);
}
/************* Test for regular file in Unix **********/
/************* Test for regular file, Unix-style **********/
static int
isregfile(char *filename)
@@ -591,8 +609,26 @@ return (statbuf.st_mode & S_IFMT) == S_IFREG;
}
/************* Test for a terminal in Unix **********/
#if defined NATIVE_ZOS
/************* Test for a terminal in z/OS **********/
/* isatty() does not work in a TSO environment, so always give FALSE.*/
static BOOL
is_stdout_tty(void)
{
return FALSE;
}
static BOOL
is_file_tty(FILE *f)
{
return FALSE;
}
/************* Test for a terminal, Unix-style **********/
#else
static BOOL
is_stdout_tty(void)
{
@@ -604,9 +640,12 @@ is_file_tty(FILE *f)
{
return isatty(fileno(f));
}
#endif
/* End of Unix-style or native z/OS environment functions. */
/************* Directory scanning in Win32 ***********/
/************* Directory scanning in Windows ***********/
/* I (Philip Hazel) have no means of testing this code. It was contributed by
Lionel Fourquaux. David Burgess added a patch to define INVALID_FILE_ATTRIBUTES
@@ -709,7 +748,7 @@ free(dir);
}
/************* Test for regular file in Win32 **********/
/************* Test for regular file in Windows **********/
/* I don't know how to do this, or if it can be done; assume all paths are
regular if they are not directories. */
@@ -720,7 +759,7 @@ return !isdirectory(filename);
}
/************* Test for a terminal in Win32 **********/
/************* Test for a terminal in Windows **********/
/* I don't know how to do this; assume never */
@@ -736,6 +775,8 @@ is_file_tty(FILE *f)
return FALSE;
}
/* End of Windows functions */
/************* Directory scanning when we can't do it ***********/
@@ -752,7 +793,7 @@ char *readdirectory(directory_type *dir) { return (char*)0;}
void closedirectory(directory_type *dir) {}
/************* Test for regular when we can't do it **********/
/************* Test for regular file when we can't do it **********/
/* Assume all files are regular. */
@@ -773,7 +814,7 @@ is_file_tty(FILE *f)
return FALSE;
}
#endif
#endif /* End of system-specific functions */
@@ -1257,7 +1298,7 @@ switch(endlinetype)
while (p > startptr && p[-1] != '\n') p--;
if (p <= startptr + 1 || p[-2] == '\r') return p;
}
return p; /* But control should never get here */
/* Control can never get here */
case EL_ANY:
case EL_ANYCRLF:
@@ -1378,6 +1419,7 @@ to find all possible matches.
Arguments:
matchptr the start of the subject
length the length of the subject to match
options options for pcre_exec
startoffset where to start matching
offsets the offets vector to fill in
mrc address of where to put the result of pcre_exec()
@@ -1388,8 +1430,8 @@ Returns: TRUE if there was a match
*/
static BOOL
match_patterns(char *matchptr, size_t length, int startoffset, int *offsets,
int *mrc)
match_patterns(char *matchptr, size_t length, unsigned int options,
int startoffset, int *offsets, int *mrc)
{
int i;
size_t slen = length;
@@ -1404,7 +1446,7 @@ if (slen > 200)
for (i = 1; p != NULL; p = p->next, i++)
{
*mrc = pcre_exec(p->compiled, p->hint, matchptr, (int)length,
startoffset, PCRE_NOTEMPTY, offsets, OFFSET_SIZE);
startoffset, options, offsets, OFFSET_SIZE);
if (*mrc >= 0) return TRUE;
if (*mrc == PCRE_ERROR_NOMATCH) continue;
fprintf(stderr, "pcregrep: pcre_exec() gave error %d while matching ", *mrc);
@@ -1539,6 +1581,7 @@ while (ptr < endptr)
int endlinelength;
int mrc = 0;
int startoffset = 0;
unsigned int options = 0;
BOOL match;
char *matchptr = ptr;
char *t = ptr;
@@ -1628,9 +1671,12 @@ while (ptr < endptr)
/* Run through all the patterns until one matches or there is an error other
than NOMATCH. This code is in a subroutine so that it can be re-used for
finding subsequent matches when colouring matched lines. */
finding subsequent matches when colouring matched lines. After finding one
match, set PCRE_NOTEMPTY to disable any further matches of null strings in
this line. */
match = match_patterns(matchptr, length, startoffset, offsets, &mrc);
match = match_patterns(matchptr, length, options, startoffset, offsets, &mrc);
options = PCRE_NOTEMPTY;
/* If it's a match or a not-match (as required), do what's wanted. */
@@ -1830,7 +1876,7 @@ while (ptr < endptr)
{
char *endmatch = ptr + offsets[1];
t = ptr;
while (t < endmatch)
while (t <= endmatch)
{
t = end_of_line(t, endptr, &endlinelength);
if (t < endmatch) linenumber++; else break;
@@ -1871,7 +1917,8 @@ while (ptr < endptr)
{
startoffset = offsets[1];
if (startoffset >= (int)linelength + endlinelength ||
!match_patterns(matchptr, length, startoffset, offsets, &mrc))
!match_patterns(matchptr, length, options, startoffset, offsets,
&mrc))
break;
FWRITE(matchptr + startoffset, 1, offsets[0] - startoffset, stdout);
fprintf(stdout, "%c[%sm", 0x1b, colour_string);
@@ -2062,6 +2109,11 @@ BZFILE *inbz2 = NULL;
int pathlen;
#endif
#if defined NATIVE_ZOS
int zos_type;
FILE *zos_test_file;
#endif
/* If the file name is "-" we scan stdin */
if (strcmp(pathname, "-") == 0)
@@ -2082,6 +2134,45 @@ lastcomp = (lastcomp == NULL)? pathname : lastcomp + 1;
Otherwise, scan the directory and recurse for each path within it. The scanning
code is localized so it can be made system-specific. */
/* For z/OS, determine the file type. */
#if defined NATIVE_ZOS
zos_test_file = fopen(pathname,"rb");
if (zos_test_file == NULL)
{
if (!silent) fprintf(stderr, "pcregrep: failed to test next file %s\n",
pathname, strerror(errno));
return -1;
}
zos_type = identifyzosfiletype (zos_test_file);
fclose (zos_test_file);
/* Handle a PDS in separate code */
if (zos_type == __ZOS_PDS || zos_type == __ZOS_PDSE)
{
return travelonpdsdir (pathname, only_one_at_top);
}
/* Deal with regular files in the normal way below. These types are:
zos_type == __ZOS_PDS_MEMBER
zos_type == __ZOS_PS
zos_type == __ZOS_VSAM_KSDS
zos_type == __ZOS_VSAM_ESDS
zos_type == __ZOS_VSAM_RRDS
*/
/* Handle a z/OS directory using common code. */
else if (zos_type == __ZOS_HFS)
{
#endif /* NATIVE_ZOS */
/* Handle directories: common code for all OS */
if (isdirectory(pathname))
{
if (dee_action == dee_SKIP ||
@@ -2116,12 +2207,22 @@ if (isdirectory(pathname))
}
}
/* If the file is not a directory and not a regular file, skip it if that's
been requested. Otherwise, check for explicit include/exclude. */
#if defined NATIVE_ZOS
}
#endif
else if ((!isregfile(pathname) && DEE_action == DEE_SKIP) ||
!test_incexc(lastcomp, include_patterns, exclude_patterns))
return -1;
/* If the file is not a directory, check for a regular file, and if it is not,
skip it if that's been requested. Otherwise, check for an explicit inclusion or
exclusion. */
else if (
#if defined NATIVE_ZOS
(zos_type == __ZOS_NOFILE && DEE_action == DEE_SKIP) ||
#else /* all other OS */
(!isregfile(pathname) && DEE_action == DEE_SKIP) ||
#endif
!test_incexc(lastcomp, include_patterns, exclude_patterns))
return -1; /* File skipped */
/* Control reaches here if we have a regular file, or if we have a directory
and recursion or skipping was not requested, or if we have anything else and