version 1.32, 2005/04/03 19:12:40 |
version 1.33, 2005/04/03 19:18:33 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/limits.h> |
#include <sys/limits.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
#include <sys/queue.h> |
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <err.h> |
#include <err.h> |
|
|
int tail; /* lines left to print */ |
int tail; /* lines left to print */ |
int lead; /* number of lines in leading context queue */ |
int lead; /* number of lines in leading context queue */ |
|
|
|
struct patfile { |
|
const char *pf_file; |
|
SLIST_ENTRY(patfile) pf_next; |
|
}; |
|
SLIST_HEAD(, patfile) patfilelh; |
|
|
extern char *__progname; |
extern char *__progname; |
|
|
static void |
static void |
|
|
} |
} |
|
|
static void |
static void |
read_patterns(char *fn) |
read_patterns(const char *fn) |
{ |
{ |
FILE *f; |
FILE *f; |
char *line; |
char *line; |
|
|
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
int c, lastc, prevoptind, newarg, i; |
int c, lastc, prevoptind, newarg, i; |
|
struct patfile *patfile, *pf_next; |
long l; |
long l; |
char *ep; |
char *ep; |
|
|
|
SLIST_INIT(&patfilelh); |
switch (__progname[0]) { |
switch (__progname[0]) { |
case 'e': |
case 'e': |
Eflag++; |
Eflag++; |
|
|
add_pattern(optarg, strlen(optarg)); |
add_pattern(optarg, strlen(optarg)); |
break; |
break; |
case 'f': |
case 'f': |
read_patterns(optarg); |
patfile = grep_malloc(sizeof(*patfile)); |
|
patfile->pf_file = optarg; |
|
SLIST_INSERT_HEAD(&patfilelh, patfile, pf_next); |
break; |
break; |
case 'h': |
case 'h': |
oflag = 0; |
oflag = 0; |
|
|
} |
} |
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
|
for (patfile = SLIST_FIRST(&patfilelh); patfile != NULL; |
|
patfile = pf_next) { |
|
pf_next = SLIST_NEXT(patfile, pf_next); |
|
read_patterns(patfile->pf_file); |
|
free(patfile); |
|
} |
|
|
if (argc == 0 && patterns == 0) |
if (argc == 0 && patterns == 0) |
usage(); |
usage(); |