| 119 |
static const unsigned char *pcretables = NULL; |
static const unsigned char *pcretables = NULL; |
| 120 |
|
|
| 121 |
static int pattern_count = 0; |
static int pattern_count = 0; |
| 122 |
static pcre **pattern_list; |
static pcre **pattern_list = NULL; |
| 123 |
static pcre_extra **hints_list; |
static pcre_extra **hints_list = NULL; |
| 124 |
|
|
| 125 |
static char *include_pattern = NULL; |
static char *include_pattern = NULL; |
| 126 |
static char *exclude_pattern = NULL; |
static char *exclude_pattern = NULL; |
| 1866 |
if (pattern_list == NULL || hints_list == NULL) |
if (pattern_list == NULL || hints_list == NULL) |
| 1867 |
{ |
{ |
| 1868 |
fprintf(stderr, "pcregrep: malloc failed\n"); |
fprintf(stderr, "pcregrep: malloc failed\n"); |
| 1869 |
return 2; |
goto EXIT2; |
| 1870 |
} |
} |
| 1871 |
|
|
| 1872 |
/* If no patterns were provided by -e, and there is no file provided by -f, |
/* If no patterns were provided by -e, and there is no file provided by -f, |
| 1885 |
{ |
{ |
| 1886 |
if (!compile_pattern(patterns[j], pcre_options, NULL, |
if (!compile_pattern(patterns[j], pcre_options, NULL, |
| 1887 |
(j == 0 && cmd_pattern_count == 1)? 0 : j + 1)) |
(j == 0 && cmd_pattern_count == 1)? 0 : j + 1)) |
| 1888 |
return 2; |
goto EXIT2; |
| 1889 |
} |
} |
| 1890 |
|
|
| 1891 |
/* Compile the regular expressions that are provided in a file. */ |
/* Compile the regular expressions that are provided in a file. */ |
| 1909 |
{ |
{ |
| 1910 |
fprintf(stderr, "pcregrep: Failed to open %s: %s\n", pattern_filename, |
fprintf(stderr, "pcregrep: Failed to open %s: %s\n", pattern_filename, |
| 1911 |
strerror(errno)); |
strerror(errno)); |
| 1912 |
return 2; |
goto EXIT2; |
| 1913 |
} |
} |
| 1914 |
filename = pattern_filename; |
filename = pattern_filename; |
| 1915 |
} |
} |
| 1922 |
linenumber++; |
linenumber++; |
| 1923 |
if (buffer[0] == 0) continue; /* Skip blank lines */ |
if (buffer[0] == 0) continue; /* Skip blank lines */ |
| 1924 |
if (!compile_pattern(buffer, pcre_options, filename, linenumber)) |
if (!compile_pattern(buffer, pcre_options, filename, linenumber)) |
| 1925 |
return 2; |
goto EXIT2; |
| 1926 |
} |
} |
| 1927 |
|
|
| 1928 |
if (f != stdin) fclose(f); |
if (f != stdin) fclose(f); |
| 1938 |
char s[16]; |
char s[16]; |
| 1939 |
if (pattern_count == 1) s[0] = 0; else sprintf(s, " number %d", j); |
if (pattern_count == 1) s[0] = 0; else sprintf(s, " number %d", j); |
| 1940 |
fprintf(stderr, "pcregrep: Error while studying regex%s: %s\n", s, error); |
fprintf(stderr, "pcregrep: Error while studying regex%s: %s\n", s, error); |
| 1941 |
return 2; |
goto EXIT2; |
| 1942 |
} |
} |
| 1943 |
} |
} |
| 1944 |
|
|
| 1952 |
{ |
{ |
| 1953 |
fprintf(stderr, "pcregrep: Error in 'exclude' regex at offset %d: %s\n", |
fprintf(stderr, "pcregrep: Error in 'exclude' regex at offset %d: %s\n", |
| 1954 |
errptr, error); |
errptr, error); |
| 1955 |
return 2; |
goto EXIT2; |
| 1956 |
} |
} |
| 1957 |
} |
} |
| 1958 |
|
|
| 1964 |
{ |
{ |
| 1965 |
fprintf(stderr, "pcregrep: Error in 'include' regex at offset %d: %s\n", |
fprintf(stderr, "pcregrep: Error in 'include' regex at offset %d: %s\n", |
| 1966 |
errptr, error); |
errptr, error); |
| 1967 |
return 2; |
goto EXIT2; |
| 1968 |
} |
} |
| 1969 |
} |
} |
| 1970 |
|
|
| 1971 |
/* If there are no further arguments, do the business on stdin and exit. */ |
/* If there are no further arguments, do the business on stdin and exit. */ |
| 1972 |
|
|
| 1973 |
if (i >= argc) |
if (i >= argc) |
| 1974 |
return pcregrep(stdin, (filenames > FN_DEFAULT)? stdin_name : NULL); |
{ |
| 1975 |
|
rc = pcregrep(stdin, (filenames > FN_DEFAULT)? stdin_name : NULL); |
| 1976 |
|
goto EXIT; |
| 1977 |
|
} |
| 1978 |
|
|
| 1979 |
/* Otherwise, work through the remaining arguments as files or directories. |
/* Otherwise, work through the remaining arguments as files or directories. |
| 1980 |
Pass in the fact that there is only one argument at top level - this suppresses |
Pass in the fact that there is only one argument at top level - this suppresses |
| 1991 |
else if (frc == 0 && rc == 1) rc = 0; |
else if (frc == 0 && rc == 1) rc = 0; |
| 1992 |
} |
} |
| 1993 |
|
|
| 1994 |
|
EXIT: |
| 1995 |
|
if (pattern_list != NULL) |
| 1996 |
|
{ |
| 1997 |
|
for (i = 0; i < pattern_count; i++) free(pattern_list[i]); |
| 1998 |
|
free(pattern_list); |
| 1999 |
|
} |
| 2000 |
|
if (hints_list != NULL) |
| 2001 |
|
{ |
| 2002 |
|
for (i = 0; i < pattern_count; i++) free(hints_list[i]); |
| 2003 |
|
free(hints_list); |
| 2004 |
|
} |
| 2005 |
return rc; |
return rc; |
| 2006 |
|
|
| 2007 |
|
EXIT2: |
| 2008 |
|
rc = 2; |
| 2009 |
|
goto EXIT; |
| 2010 |
} |
} |
| 2011 |
|
|
| 2012 |
/* End of pcregrep */ |
/* End of pcregrep */ |