168 |
static int filenames = FN_DEFAULT; |
static int filenames = FN_DEFAULT; |
169 |
static int only_matching = -1; |
static int only_matching = -1; |
170 |
static int process_options = 0; |
static int process_options = 0; |
171 |
|
|
172 |
|
#ifdef SUPPORT_PCREGREP_JIT |
173 |
|
static int study_options = PCRE_STUDY_JIT_COMPILE; |
174 |
|
#else |
175 |
static int study_options = 0; |
static int study_options = 0; |
176 |
|
#endif |
177 |
|
|
178 |
static unsigned long int match_limit = 0; |
static unsigned long int match_limit = 0; |
179 |
static unsigned long int match_limit_recursion = 0; |
static unsigned long int match_limit_recursion = 0; |
224 |
#define N_M_LIMIT (-13) |
#define N_M_LIMIT (-13) |
225 |
#define N_M_LIMIT_REC (-14) |
#define N_M_LIMIT_REC (-14) |
226 |
#define N_BUFSIZE (-15) |
#define N_BUFSIZE (-15) |
227 |
|
#define N_NOJIT (-16) |
228 |
|
|
229 |
static option_item optionlist[] = { |
static option_item optionlist[] = { |
230 |
{ OP_NODATA, N_NULL, NULL, "", " terminate options" }, |
{ OP_NODATA, N_NULL, NULL, "", " terminate options" }, |
245 |
{ OP_NODATA, 'H', NULL, "with-filename", "force the prefixing filename on output" }, |
{ OP_NODATA, 'H', NULL, "with-filename", "force the prefixing filename on output" }, |
246 |
{ OP_NODATA, 'h', NULL, "no-filename", "suppress the prefixing filename on output" }, |
{ OP_NODATA, 'h', NULL, "no-filename", "suppress the prefixing filename on output" }, |
247 |
{ OP_NODATA, 'i', NULL, "ignore-case", "ignore case distinctions" }, |
{ OP_NODATA, 'i', NULL, "ignore-case", "ignore case distinctions" }, |
248 |
{ OP_NODATA, 'j', NULL, "jit", "use JIT compiler if available" }, |
#ifdef SUPPORT_PCREGREP_JIT |
249 |
|
{ OP_NODATA, N_NOJIT, NULL, "no-jit", "do not use just-in-time compiler optimization" }, |
250 |
|
#else |
251 |
|
{ OP_NODATA, N_NOJIT, NULL, "no-jit", "ignored: this pcregrep does not support JIT" }, |
252 |
|
#endif |
253 |
{ OP_NODATA, 'l', NULL, "files-with-matches", "print only FILE names containing matches" }, |
{ OP_NODATA, 'l', NULL, "files-with-matches", "print only FILE names containing matches" }, |
254 |
{ OP_NODATA, 'L', NULL, "files-without-match","print only FILE names not containing matches" }, |
{ OP_NODATA, 'L', NULL, "files-without-match","print only FILE names not containing matches" }, |
255 |
{ OP_STRING, N_LABEL, &stdin_name, "label=name", "set name for standard input" }, |
{ OP_STRING, N_LABEL, &stdin_name, "label=name", "set name for standard input" }, |
327 |
{ |
{ |
328 |
if (resource_error) |
if (resource_error) |
329 |
{ |
{ |
330 |
fprintf(stderr, "pcregrep: Error %d or %d means that a resource limit " |
fprintf(stderr, "pcregrep: Error %d, %d or %d means that a resource limit " |
331 |
"was exceeded.\n", PCRE_ERROR_MATCHLIMIT, PCRE_ERROR_RECURSIONLIMIT); |
"was exceeded.\n", PCRE_ERROR_MATCHLIMIT, PCRE_ERROR_RECURSIONLIMIT, |
332 |
|
PCRE_ERROR_JIT_STACKLIMIT); |
333 |
fprintf(stderr, "pcregrep: Check your regex for nested unlimited loops.\n"); |
fprintf(stderr, "pcregrep: Check your regex for nested unlimited loops.\n"); |
334 |
} |
} |
335 |
|
|
988 |
fprintf(stderr, "%s", msg); |
fprintf(stderr, "%s", msg); |
989 |
FWRITE(matchptr, 1, slen, stderr); /* In case binary zero included */ |
FWRITE(matchptr, 1, slen, stderr); /* In case binary zero included */ |
990 |
fprintf(stderr, "\n\n"); |
fprintf(stderr, "\n\n"); |
991 |
if (*mrc == PCRE_ERROR_MATCHLIMIT || *mrc == PCRE_ERROR_RECURSIONLIMIT) |
if (*mrc == PCRE_ERROR_MATCHLIMIT || *mrc == PCRE_ERROR_RECURSIONLIMIT || |
992 |
|
*mrc == PCRE_ERROR_JIT_STACKLIMIT) |
993 |
resource_error = TRUE; |
resource_error = TRUE; |
994 |
if (error_count++ > 20) |
if (error_count++ > 20) |
995 |
{ |
{ |
1397 |
for (;;) |
for (;;) |
1398 |
{ |
{ |
1399 |
startoffset = offsets[1]; |
startoffset = offsets[1]; |
1400 |
if (startoffset >= linelength + endlinelength || |
if (startoffset >= (int)linelength + endlinelength || |
1401 |
!match_patterns(matchptr, length, startoffset, offsets, &mrc)) |
!match_patterns(matchptr, length, startoffset, offsets, &mrc)) |
1402 |
break; |
break; |
1403 |
FWRITE(matchptr + startoffset, 1, offsets[0] - startoffset, stdout); |
FWRITE(matchptr + startoffset, 1, offsets[0] - startoffset, stdout); |
1460 |
/* If input is line buffered, and the buffer is not yet full, read another |
/* If input is line buffered, and the buffer is not yet full, read another |
1461 |
line and add it into the buffer. */ |
line and add it into the buffer. */ |
1462 |
|
|
1463 |
if (input_line_buffered && bufflength < bufsize) |
if (input_line_buffered && bufflength < (size_t)bufsize) |
1464 |
{ |
{ |
1465 |
int add = read_one_line(ptr, bufsize - (ptr - main_buffer), in); |
int add = read_one_line(ptr, bufsize - (ptr - main_buffer), in); |
1466 |
bufflength += add; |
bufflength += add; |
1472 |
1/3 and refill it. Before we do this, if some unprinted "after" lines are |
1/3 and refill it. Before we do this, if some unprinted "after" lines are |
1473 |
about to be lost, print them. */ |
about to be lost, print them. */ |
1474 |
|
|
1475 |
if (bufflength >= bufsize && ptr > main_buffer + 2*bufthird) |
if (bufflength >= (size_t)bufsize && ptr > main_buffer + 2*bufthird) |
1476 |
{ |
{ |
1477 |
if (after_context > 0 && |
if (after_context > 0 && |
1478 |
lastmatchnumber > 0 && |
lastmatchnumber > 0 && |
1869 |
{ |
{ |
1870 |
case N_FOFFSETS: file_offsets = TRUE; break; |
case N_FOFFSETS: file_offsets = TRUE; break; |
1871 |
case N_HELP: help(); pcregrep_exit(0); |
case N_HELP: help(); pcregrep_exit(0); |
|
case N_LOFFSETS: line_offsets = number = TRUE; break; |
|
1872 |
case N_LBUFFER: line_buffered = TRUE; break; |
case N_LBUFFER: line_buffered = TRUE; break; |
1873 |
|
case N_LOFFSETS: line_offsets = number = TRUE; break; |
1874 |
|
case N_NOJIT: study_options &= ~PCRE_STUDY_JIT_COMPILE; break; |
1875 |
case 'c': count_only = TRUE; break; |
case 'c': count_only = TRUE; break; |
1876 |
case 'F': process_options |= PO_FIXED_STRINGS; break; |
case 'F': process_options |= PO_FIXED_STRINGS; break; |
1877 |
case 'H': filenames = FN_FORCE; break; |
case 'H': filenames = FN_FORCE; break; |
1878 |
case 'h': filenames = FN_NONE; break; |
case 'h': filenames = FN_NONE; break; |
1879 |
case 'i': options |= PCRE_CASELESS; break; |
case 'i': options |= PCRE_CASELESS; break; |
|
case 'j': study_options |= PCRE_STUDY_JIT_COMPILE; break; |
|
1880 |
case 'l': omit_zero_count = TRUE; filenames = FN_MATCH_ONLY; break; |
case 'l': omit_zero_count = TRUE; filenames = FN_MATCH_ONLY; break; |
1881 |
case 'L': filenames = FN_NOMATCH_ONLY; break; |
case 'L': filenames = FN_NOMATCH_ONLY; break; |
1882 |
case 'M': multiline = TRUE; options |= PCRE_MULTILINE|PCRE_FIRSTLINE; break; |
case 'M': multiline = TRUE; options |= PCRE_MULTILINE|PCRE_FIRSTLINE; break; |
2060 |
const char *locale_from = "--locale"; |
const char *locale_from = "--locale"; |
2061 |
const char *error; |
const char *error; |
2062 |
|
|
2063 |
|
#ifdef SUPPORT_PCREGREP_JIT |
2064 |
|
pcre_jit_stack *jit_stack = NULL; |
2065 |
|
#endif |
2066 |
|
|
2067 |
/* 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; |
2068 |
"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". |
2069 |
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 |
2586 |
if (f != stdin) fclose(f); |
if (f != stdin) fclose(f); |
2587 |
} |
} |
2588 |
|
|
2589 |
/* Study the regular expressions, as we will be running them many times */ |
/* Study the regular expressions, as we will be running them many times. Unless |
2590 |
|
JIT has been explicitly disabled, arrange a stack for it to use. */ |
2591 |
|
|
2592 |
|
#ifdef SUPPORT_PCREGREP_JIT |
2593 |
|
if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0) |
2594 |
|
jit_stack = pcre_jit_stack_alloc(32*1024, 1024*1024); |
2595 |
|
#endif |
2596 |
|
|
2597 |
for (j = 0; j < pattern_count; j++) |
for (j = 0; j < pattern_count; j++) |
2598 |
{ |
{ |
2605 |
goto EXIT2; |
goto EXIT2; |
2606 |
} |
} |
2607 |
hint_count++; |
hint_count++; |
2608 |
|
#ifdef SUPPORT_PCREGREP_JIT |
2609 |
|
if (jit_stack != NULL && hints_list[j] != NULL) |
2610 |
|
pcre_assign_jit_stack(hints_list[j], NULL, jit_stack); |
2611 |
|
#endif |
2612 |
} |
} |
2613 |
|
|
2614 |
/* If --match-limit or --recursion-limit was set, put the value(s) into the |
/* If --match-limit or --recursion-limit was set, put the value(s) into the |
2715 |
} |
} |
2716 |
|
|
2717 |
EXIT: |
EXIT: |
2718 |
|
#ifdef SUPPORT_PCREGREP_JIT |
2719 |
|
if (jit_stack != NULL) pcre_jit_stack_free(jit_stack); |
2720 |
|
#endif |
2721 |
if (main_buffer != NULL) free(main_buffer); |
if (main_buffer != NULL) free(main_buffer); |
2722 |
if (pattern_list != NULL) |
if (pattern_list != NULL) |
2723 |
{ |
{ |