| 147 |
static pcre **pattern_list = NULL; |
static pcre **pattern_list = NULL; |
| 148 |
static pcre_extra **hints_list = NULL; |
static pcre_extra **hints_list = NULL; |
| 149 |
|
|
| 150 |
|
static char *file_list = NULL; |
| 151 |
static char *include_pattern = NULL; |
static char *include_pattern = NULL; |
| 152 |
static char *exclude_pattern = NULL; |
static char *exclude_pattern = NULL; |
| 153 |
static char *include_dir_pattern = NULL; |
static char *include_dir_pattern = NULL; |
| 226 |
#define N_M_LIMIT_REC (-14) |
#define N_M_LIMIT_REC (-14) |
| 227 |
#define N_BUFSIZE (-15) |
#define N_BUFSIZE (-15) |
| 228 |
#define N_NOJIT (-16) |
#define N_NOJIT (-16) |
| 229 |
|
#define N_FILE_LIST (-17) |
| 230 |
|
|
| 231 |
static option_item optionlist[] = { |
static option_item optionlist[] = { |
| 232 |
{ OP_NODATA, N_NULL, NULL, "", " terminate options" }, |
{ OP_NODATA, N_NULL, NULL, "", " terminate options" }, |
| 243 |
{ OP_PATLIST, 'e', NULL, "regex(p)=pattern", "specify pattern (may be used more than once)" }, |
{ OP_PATLIST, 'e', NULL, "regex(p)=pattern", "specify pattern (may be used more than once)" }, |
| 244 |
{ OP_NODATA, 'F', NULL, "fixed-strings", "patterns are sets of newline-separated strings" }, |
{ OP_NODATA, 'F', NULL, "fixed-strings", "patterns are sets of newline-separated strings" }, |
| 245 |
{ OP_STRING, 'f', &pattern_filename, "file=path", "read patterns from file" }, |
{ OP_STRING, 'f', &pattern_filename, "file=path", "read patterns from file" }, |
| 246 |
|
{ OP_STRING, N_FILE_LIST, &file_list, "file-list=path","read files to search from file" }, |
| 247 |
{ OP_NODATA, N_FOFFSETS, NULL, "file-offsets", "output file offsets, not text" }, |
{ OP_NODATA, N_FOFFSETS, NULL, "file-offsets", "output file offsets, not text" }, |
| 248 |
{ OP_NODATA, 'H', NULL, "with-filename", "force the prefixing filename on output" }, |
{ OP_NODATA, 'H', NULL, "with-filename", "force the prefixing filename on output" }, |
| 249 |
{ OP_NODATA, 'h', NULL, "no-filename", "suppress the prefixing filename on output" }, |
{ OP_NODATA, 'h', NULL, "no-filename", "suppress the prefixing filename on output" }, |
| 1854 |
|
|
| 1855 |
printf("\nNumbers may be followed by K or M, e.g. --buffer-size=100K.\n"); |
printf("\nNumbers may be followed by K or M, e.g. --buffer-size=100K.\n"); |
| 1856 |
printf("The default value for --buffer-size is %d.\n", PCREGREP_BUFSIZE); |
printf("The default value for --buffer-size is %d.\n", PCREGREP_BUFSIZE); |
| 1857 |
printf("When reading patterns from a file instead of using a command line option,\n"); |
printf("When reading patterns or file names from a file, trailing white\n"); |
| 1858 |
printf("trailing white space is removed and blank lines are ignored.\n"); |
printf("space is removed and blank lines are ignored.\n"); |
| 1859 |
printf("There is a maximum of %d patterns, each of maximum size %d bytes.\n", |
printf("There is a maximum of %d patterns, each of maximum size %d bytes.\n", |
| 1860 |
MAX_PATTERN_COUNT, PATBUFSIZE); |
MAX_PATTERN_COUNT, PATBUFSIZE); |
| 1861 |
|
|
| 2697 |
goto EXIT2; |
goto EXIT2; |
| 2698 |
} |
} |
| 2699 |
} |
} |
| 2700 |
|
|
| 2701 |
|
/* If a file that contains a list of files to search has been specified, read |
| 2702 |
|
it line by line and search the given files. Otherwise, if there are no further |
| 2703 |
|
arguments, do the business on stdin and exit. */ |
| 2704 |
|
|
| 2705 |
/* If there are no further arguments, do the business on stdin and exit. */ |
if (file_list != NULL) |
| 2706 |
|
{ |
| 2707 |
|
char buffer[PATBUFSIZE]; |
| 2708 |
|
FILE *fl; |
| 2709 |
|
if (strcmp(file_list, "-") == 0) fl = stdin; else |
| 2710 |
|
{ |
| 2711 |
|
fl = fopen(file_list, "rb"); |
| 2712 |
|
if (fl == NULL) |
| 2713 |
|
{ |
| 2714 |
|
fprintf(stderr, "pcregrep: Failed to open %s: %s\n", file_list, |
| 2715 |
|
strerror(errno)); |
| 2716 |
|
goto EXIT2; |
| 2717 |
|
} |
| 2718 |
|
} |
| 2719 |
|
while (fgets(buffer, PATBUFSIZE, fl) != NULL) |
| 2720 |
|
{ |
| 2721 |
|
int frc; |
| 2722 |
|
char *end = buffer + (int)strlen(buffer); |
| 2723 |
|
while (end > buffer && isspace(end[-1])) end--; |
| 2724 |
|
*end = 0; |
| 2725 |
|
if (*buffer != 0) |
| 2726 |
|
{ |
| 2727 |
|
frc = grep_or_recurse(buffer, dee_action == dee_RECURSE, FALSE); |
| 2728 |
|
if (frc > 1) rc = frc; |
| 2729 |
|
else if (frc == 0 && rc == 1) rc = 0; |
| 2730 |
|
} |
| 2731 |
|
} |
| 2732 |
|
if (fl != stdin) fclose (fl); |
| 2733 |
|
} |
| 2734 |
|
|
| 2735 |
|
/* Do this only if there was no file list (and no file arguments). */ |
| 2736 |
|
|
| 2737 |
if (i >= argc) |
else if (i >= argc) |
| 2738 |
{ |
{ |
| 2739 |
rc = pcregrep(stdin, FR_PLAIN, stdin_name, |
rc = pcregrep(stdin, FR_PLAIN, stdin_name, |
| 2740 |
(filenames > FN_DEFAULT)? stdin_name : NULL); |
(filenames > FN_DEFAULT)? stdin_name : NULL); |
| 2741 |
goto EXIT; |
goto EXIT; |
| 2742 |
} |
} |
| 2743 |
|
|
| 2744 |
/* Otherwise, work through the remaining arguments as files or directories. |
/* After handling file-list or if there are remaining arguments, work through |
| 2745 |
Pass in the fact that there is only one argument at top level - this suppresses |
them as files or directories. Pass in the fact that there is only one argument |
| 2746 |
the file name if the argument is not a directory and filenames are not |
at top level - this suppresses the file name if the argument is not a directory |
| 2747 |
otherwise forced. */ |
and filenames are not otherwise forced. */ |
| 2748 |
|
|
| 2749 |
only_one_at_top = i == argc - 1; /* Catch initial value of i */ |
only_one_at_top = i == argc - 1 && file_list == NULL; |
| 2750 |
|
|
| 2751 |
for (; i < argc; i++) |
for (; i < argc; i++) |
| 2752 |
{ |
{ |