summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/grep/grep.c66
-rw-r--r--usr.bin/grep/grep.h5
-rw-r--r--usr.bin/grep/util.c11
3 files changed, 47 insertions, 35 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index 3fce875d9a5..c43d98f2c24 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.c,v 1.15 2003/06/23 22:32:48 tedu Exp $ */
+/* $OpenBSD: grep.c,v 1.16 2003/06/24 18:45:30 tedu Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -232,6 +232,34 @@ main(int argc, char *argv[])
char *tmp;
int c, i;
+ switch (__progname[0]) {
+ case 'e':
+ Eflag++;
+ break;
+ case 'f':
+ Fflag++;
+ break;
+ case 'g':
+ Gflag++;
+ break;
+#ifndef NOZ
+ case 'z':
+ Zflag++;
+ switch(__progname[1]) {
+ case 'e':
+ Eflag++;
+ break;
+ case 'f':
+ Fflag++;
+ break;
+ case 'g':
+ Gflag++;
+ break;
+ }
+ break;
+#endif
+ }
+
while ((c = getopt_long(argc, argv, optstr,
long_options, (int *)NULL)) != -1) {
switch (c) {
@@ -257,12 +285,15 @@ main(int argc, char *argv[])
Aflag = Bflag = strtol(optarg, (char **)NULL, 10);
break;
case 'E':
+ Fflag = Gflag = 0;
Eflag++;
break;
case 'F':
+ Eflag = Gflag = 0;
Fflag++;
break;
case 'G':
+ Eflag = Fflag = 0;
Gflag++;
break;
case 'H':
@@ -380,35 +411,10 @@ main(int argc, char *argv[])
++argv;
}
- switch (__progname[0]) {
- case 'e':
- Eflag++;
- break;
- case 'f':
- Fflag++;
- break;
- case 'g':
- Gflag++;
- break;
-#ifndef NOZ
- case 'z':
- Zflag++;
- switch(__progname[1]) {
- case 'e':
- Eflag++;
- break;
- case 'f':
- Fflag++;
- break;
- case 'g':
- Gflag++;
- break;
- }
- break;
-#endif
- }
-
- cflags |= Eflag ? REG_EXTENDED : REG_BASIC;
+ if (Eflag)
+ cflags |= REG_EXTENDED;
+ else if (Fflag)
+ cflags |= REG_NOSPEC;
fg_pattern = grep_malloc(patterns * sizeof(*fg_pattern));
r_pattern = grep_malloc(patterns * sizeof(regex_t));
for (i = 0; i < patterns; ++i) {
diff --git a/usr.bin/grep/grep.h b/usr.bin/grep/grep.h
index 782343ae066..afa1ad2577f 100644
--- a/usr.bin/grep/grep.h
+++ b/usr.bin/grep/grep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.h,v 1.4 2003/06/23 22:05:23 tedu Exp $ */
+/* $OpenBSD: grep.h,v 1.5 2003/06/24 18:45:30 tedu Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -62,7 +62,8 @@ typedef struct {
extern int cflags, eflags;
/* Command line flags */
-extern int Aflag, Bflag, Hflag, Lflag, Pflag, Sflag, Rflag, Zflag,
+extern int Aflag, Bflag, Eflag, Fflag, Gflag, Hflag, Lflag, Pflag,
+ Sflag, Rflag, Zflag,
bflag, cflag, hflag, iflag, lflag, nflag, qflag, sflag,
vflag, wflag, xflag;
extern int binbehave, boleol, maxPatternLen;
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 59bff4096d4..c6b887ce469 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.7 2003/06/24 17:32:10 tedu Exp $ */
+/* $OpenBSD: util.c,v 1.8 2003/06/24 18:45:30 tedu Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -246,6 +246,11 @@ fastcomp(fastgrep_t *fg, const char *pattern)
int firstLastHalfDot = -1;
int lastHalfDot = 0;
+ if (Fflag) {
+ fg->pattern = NULL;
+ return (-1);
+ }
+
/* Initialize. */
origPatternLen = fg->patternLen = strlen(pattern);
fg->bol = 0;
@@ -269,8 +274,8 @@ fastcomp(fastgrep_t *fg, const char *pattern)
}
/*
- * Copy pattern minus '^' and '$' characters at the beginning and ending of
- * the string respectively.
+ * Copy pattern minus '^' and '$' characters at the beginning and
+ * ending of the string respectively.
*/
fg->pattern = grep_strdup(pattern + bol);