| 825 |
* Apply patterns to subject till one matches * |
* Apply patterns to subject till one matches * |
| 826 |
*************************************************/ |
*************************************************/ |
| 827 |
|
|
| 828 |
/* This function is called to run through all patterns, looking for a match. It |
/* This function is called to run through all patterns, looking for a match. It |
| 829 |
is used multiple times for the same subject when colouring is enabled, in order |
is used multiple times for the same subject when colouring is enabled, in order |
| 830 |
to find all possible matches. |
to find all possible matches. |
| 831 |
|
|
| 832 |
Arguments: |
Arguments: |
| 834 |
length the length of the subject to match |
length the length of the subject to match |
| 835 |
offsets the offets vector to fill in |
offsets the offets vector to fill in |
| 836 |
mrc address of where to put the result of pcre_exec() |
mrc address of where to put the result of pcre_exec() |
| 837 |
|
|
| 838 |
Returns: TRUE if there was a match |
Returns: TRUE if there was a match |
| 839 |
FALSE if there was no match |
FALSE if there was no match |
| 840 |
invert if there was a non-fatal error |
invert if there was a non-fatal error |
| 841 |
*/ |
*/ |
| 842 |
|
|
| 843 |
static BOOL |
static BOOL |
| 844 |
match_patterns(char *matchptr, size_t length, int *offsets, int *mrc) |
match_patterns(char *matchptr, size_t length, int *offsets, int *mrc) |
| 992 |
#include <time.h> |
#include <time.h> |
| 993 |
struct timeval start_time, end_time; |
struct timeval start_time, end_time; |
| 994 |
struct timezone dummy; |
struct timezone dummy; |
| 995 |
int i; |
int i; |
| 996 |
|
|
| 997 |
if (jfriedl_XT) |
if (jfriedl_XT) |
| 998 |
{ |
{ |
| 1018 |
|
|
| 1019 |
|
|
| 1020 |
for (i = 0; i < jfriedl_XR; i++) |
for (i = 0; i < jfriedl_XR; i++) |
| 1021 |
match = (pcre_exec(pattern_list[0], hints_list[0], ptr, length, 0, |
match = (pcre_exec(pattern_list[0], hints_list[0], ptr, length, 0, |
| 1022 |
PCRE_NOTEMPTY, offsets, OFFSET_SIZE) >= 0); |
PCRE_NOTEMPTY, offsets, OFFSET_SIZE) >= 0); |
| 1023 |
|
|
| 1024 |
if (gettimeofday(&end_time, &dummy) != 0) |
if (gettimeofday(&end_time, &dummy) != 0) |
| 1038 |
|
|
| 1039 |
ONLY_MATCHING_RESTART: |
ONLY_MATCHING_RESTART: |
| 1040 |
|
|
| 1041 |
/* Run through all the patterns until one matches or there is an error other |
/* Run through all the patterns until one matches or there is an error other |
| 1042 |
than NOMATCH. This code is in a subroutine so that it can be re-used for |
than NOMATCH. This code is in a subroutine so that it can be re-used for |
| 1043 |
finding subsequent matches when colouring matched lines. */ |
finding subsequent matches when colouring matched lines. */ |
| 1044 |
|
|
| 1045 |
match = match_patterns(matchptr, length, offsets, &mrc); |
match = match_patterns(matchptr, length, offsets, &mrc); |
| 1046 |
|
|
| 1047 |
/* If it's a match or a not-match (as required), do what's wanted. */ |
/* If it's a match or a not-match (as required), do what's wanted. */ |
| 1096 |
if (do_colour) fprintf(stdout, "%c[%sm", 0x1b, colour_string); |
if (do_colour) fprintf(stdout, "%c[%sm", 0x1b, colour_string); |
| 1097 |
fwrite(matchptr + offsets[0], 1, offsets[1] - offsets[0], stdout); |
fwrite(matchptr + offsets[0], 1, offsets[1] - offsets[0], stdout); |
| 1098 |
if (do_colour) fprintf(stdout, "%c[00m", 0x1b); |
if (do_colour) fprintf(stdout, "%c[00m", 0x1b); |
| 1099 |
} |
} |
| 1100 |
fprintf(stdout, "\n"); |
fprintf(stdout, "\n"); |
| 1101 |
matchptr += offsets[1]; |
matchptr += offsets[1]; |
| 1102 |
length -= offsets[1]; |
length -= offsets[1]; |
| 1233 |
else |
else |
| 1234 |
#endif |
#endif |
| 1235 |
|
|
| 1236 |
/* We have to split the line(s) up if colouring, and search for further |
/* We have to split the line(s) up if colouring, and search for further |
| 1237 |
matches. */ |
matches. */ |
| 1238 |
|
|
| 1239 |
if (do_colour) |
if (do_colour) |
| 1240 |
{ |
{ |
| 1241 |
int last_offset = 0; |
int last_offset = 0; |
| 1242 |
fwrite(ptr, 1, offsets[0], stdout); |
fwrite(ptr, 1, offsets[0], stdout); |
| 1243 |
fprintf(stdout, "%c[%sm", 0x1b, colour_string); |
fprintf(stdout, "%c[%sm", 0x1b, colour_string); |
| 1244 |
fwrite(ptr + offsets[0], 1, offsets[1] - offsets[0], stdout); |
fwrite(ptr + offsets[0], 1, offsets[1] - offsets[0], stdout); |
| 1245 |
fprintf(stdout, "%c[00m", 0x1b); |
fprintf(stdout, "%c[00m", 0x1b); |
| 1246 |
for (;;) |
for (;;) |
| 1247 |
{ |
{ |
| 1248 |
last_offset += offsets[1]; |
last_offset += offsets[1]; |
| 1249 |
matchptr += offsets[1]; |
matchptr += offsets[1]; |
| 1250 |
length -= offsets[1]; |
length -= offsets[1]; |
| 1251 |
if (!match_patterns(matchptr, length, offsets, &mrc)) break; |
if (!match_patterns(matchptr, length, offsets, &mrc)) break; |
| 1257 |
fwrite(ptr + last_offset, 1, (linelength + endlinelength) - last_offset, |
fwrite(ptr + last_offset, 1, (linelength + endlinelength) - last_offset, |
| 1258 |
stdout); |
stdout); |
| 1259 |
} |
} |
| 1260 |
|
|
| 1261 |
/* Not colouring; no need to search for further matches */ |
/* Not colouring; no need to search for further matches */ |
| 1262 |
|
|
| 1263 |
else fwrite(ptr, 1, linelength + endlinelength, stdout); |
else fwrite(ptr, 1, linelength + endlinelength, stdout); |
| 1264 |
} |
} |
| 1265 |
|
|
| 1872 |
/* Set the default line ending value from the default in the PCRE library; |
/* Set the default line ending value from the default in the PCRE library; |
| 1873 |
"lf", "cr", "crlf", and "any" are supported. Anything else is treated as "lf". |
"lf", "cr", "crlf", and "any" are supported. Anything else is treated as "lf". |
| 1874 |
Note that the return values from pcre_config(), though derived from the ASCII |
Note that the return values from pcre_config(), though derived from the ASCII |
| 1875 |
codes, are the same in EBCDIC environments, so we must use the actual values |
codes, are the same in EBCDIC environments, so we must use the actual values |
| 1876 |
rather than escapes such as as '\r'. */ |
rather than escapes such as as '\r'. */ |
| 1877 |
|
|
| 1878 |
(void)pcre_config(PCRE_CONFIG_NEWLINE, &i); |
(void)pcre_config(PCRE_CONFIG_NEWLINE, &i); |