| 935 |
to find all possible matches. |
to find all possible matches. |
| 936 |
|
|
| 937 |
Arguments: |
Arguments: |
| 938 |
matchptr the start of the subject |
matchptr the start of the subject |
| 939 |
length the length of the subject to match |
length the length of the subject to match |
| 940 |
offsets the offets vector to fill in |
startoffset where to start matching |
| 941 |
mrc address of where to put the result of pcre_exec() |
offsets the offets vector to fill in |
| 942 |
|
mrc address of where to put the result of pcre_exec() |
| 943 |
|
|
| 944 |
Returns: TRUE if there was a match |
Returns: TRUE if there was a match |
| 945 |
FALSE if there was no match |
FALSE if there was no match |
| 947 |
*/ |
*/ |
| 948 |
|
|
| 949 |
static BOOL |
static BOOL |
| 950 |
match_patterns(char *matchptr, size_t length, int *offsets, int *mrc) |
match_patterns(char *matchptr, size_t length, int startoffset, int *offsets, |
| 951 |
|
int *mrc) |
| 952 |
{ |
{ |
| 953 |
int i; |
int i; |
| 954 |
size_t slen = length; |
size_t slen = length; |
| 960 |
} |
} |
| 961 |
for (i = 0; i < pattern_count; i++) |
for (i = 0; i < pattern_count; i++) |
| 962 |
{ |
{ |
| 963 |
*mrc = pcre_exec(pattern_list[i], hints_list[i], matchptr, (int)length, 0, |
*mrc = pcre_exec(pattern_list[i], hints_list[i], matchptr, (int)length, |
| 964 |
PCRE_NOTEMPTY, offsets, OFFSET_SIZE); |
startoffset, PCRE_NOTEMPTY, offsets, OFFSET_SIZE); |
| 965 |
if (*mrc >= 0) return TRUE; |
if (*mrc >= 0) return TRUE; |
| 966 |
if (*mrc == PCRE_ERROR_NOMATCH) continue; |
if (*mrc == PCRE_ERROR_NOMATCH) continue; |
| 967 |
fprintf(stderr, "pcregrep: pcre_exec() gave error %d while matching ", *mrc); |
fprintf(stderr, "pcregrep: pcre_exec() gave error %d while matching ", *mrc); |
| 1079 |
{ |
{ |
| 1080 |
int endlinelength; |
int endlinelength; |
| 1081 |
int mrc = 0; |
int mrc = 0; |
| 1082 |
|
int startoffset = 0; |
| 1083 |
BOOL match; |
BOOL match; |
| 1084 |
char *matchptr = ptr; |
char *matchptr = ptr; |
| 1085 |
char *t = ptr; |
char *t = ptr; |
| 1156 |
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 |
| 1157 |
finding subsequent matches when colouring matched lines. */ |
finding subsequent matches when colouring matched lines. */ |
| 1158 |
|
|
| 1159 |
match = match_patterns(matchptr, length, offsets, &mrc); |
match = match_patterns(matchptr, length, startoffset, offsets, &mrc); |
| 1160 |
|
|
| 1161 |
/* 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. */ |
| 1162 |
|
|
| 1219 |
} |
} |
| 1220 |
} |
} |
| 1221 |
else if (printname != NULL || number) fprintf(stdout, "\n"); |
else if (printname != NULL || number) fprintf(stdout, "\n"); |
| 1222 |
|
/* |
| 1223 |
matchptr += offsets[1]; |
matchptr += offsets[1]; |
| 1224 |
length -= offsets[1]; |
length -= offsets[1]; |
| 1225 |
|
*/ |
| 1226 |
match = FALSE; |
match = FALSE; |
| 1227 |
if (line_buffered) fflush(stdout); |
if (line_buffered) fflush(stdout); |
| 1228 |
rc = 0; /* Had some success */ |
rc = 0; /* Had some success */ |
| 1229 |
|
startoffset = offsets[1]; |
| 1230 |
goto ONLY_MATCHING_RESTART; |
goto ONLY_MATCHING_RESTART; |
| 1231 |
} |
} |
| 1232 |
} |
} |
| 1366 |
fprintf(stdout, "%c[00m", 0x1b); |
fprintf(stdout, "%c[00m", 0x1b); |
| 1367 |
for (;;) |
for (;;) |
| 1368 |
{ |
{ |
| 1369 |
|
/* |
| 1370 |
last_offset += offsets[1]; |
last_offset += offsets[1]; |
| 1371 |
matchptr += offsets[1]; |
matchptr += offsets[1]; |
| 1372 |
length -= offsets[1]; |
length -= offsets[1]; |
| 1373 |
|
*/ |
| 1374 |
|
|
| 1375 |
|
startoffset = offsets[1]; |
| 1376 |
|
last_offset = startoffset; |
| 1377 |
if (last_offset >= linelength + endlinelength || |
if (last_offset >= linelength + endlinelength || |
| 1378 |
!match_patterns(matchptr, length, offsets, &mrc)) break; |
!match_patterns(matchptr, length, startoffset, offsets, &mrc)) |
| 1379 |
FWRITE(matchptr, 1, offsets[0], stdout); |
break; |
| 1380 |
|
FWRITE(matchptr + startoffset, 1, offsets[0] - startoffset, stdout); |
| 1381 |
fprintf(stdout, "%c[%sm", 0x1b, colour_string); |
fprintf(stdout, "%c[%sm", 0x1b, colour_string); |
| 1382 |
FWRITE(matchptr + offsets[0], 1, offsets[1] - offsets[0], stdout); |
FWRITE(matchptr + offsets[0], 1, offsets[1] - offsets[0], stdout); |
| 1383 |
fprintf(stdout, "%c[00m", 0x1b); |
fprintf(stdout, "%c[00m", 0x1b); |