summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2011-03-04 03:11:22 +0000
committertedu <tedu@openbsd.org>2011-03-04 03:11:22 +0000
commit34fecf261ac0b7d9ad15f906b64cf859dbed945e (patch)
treed7b3ce076f0095177a7c55ed7803c140257c92db
parentrepair arguments passed to pfctl; PR 6142, ok beck (diff)
downloadwireguard-openbsd-34fecf261ac0b7d9ad15f906b64cf859dbed945e.tar.xz
wireguard-openbsd-34fecf261ac0b7d9ad15f906b64cf859dbed945e.zip
add -H (opposite of -h) to always print name. ok deraadt millert
-rw-r--r--usr.bin/grep/grep.112
-rw-r--r--usr.bin/grep/grep.c17
-rw-r--r--usr.bin/grep/grep.h4
3 files changed, 21 insertions, 12 deletions
diff --git a/usr.bin/grep/grep.1 b/usr.bin/grep/grep.1
index 7ba98185257..a818c95c272 100644
--- a/usr.bin/grep/grep.1
+++ b/usr.bin/grep/grep.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: grep.1,v 1.39 2010/09/03 11:09:28 jmc Exp $
+.\" $OpenBSD: grep.1,v 1.40 2011/03/04 03:11:22 tedu Exp $
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -28,7 +28,7 @@
.\"
.\" @(#)grep.1 8.3 (Berkeley) 4/18/94
.\"
-.Dd $Mdocdate: September 3 2010 $
+.Dd $Mdocdate: March 4 2011 $
.Dt GREP 1
.Os
.Sh NAME
@@ -38,7 +38,7 @@
.Sh SYNOPSIS
.Nm grep
.Bk -words
-.Op Fl abcEFGhIiLlnqRsUVvwxZ
+.Op Fl abcEFGHhIiLlnqRsUVvwxZ
.Op Fl A Ar num
.Op Fl B Ar num
.Op Fl C Ns Op Ar num
@@ -184,6 +184,10 @@ as a basic regular expression
.Nm grep
to behave as traditional
.Nm grep ) .
+.It Fl H
+Always print filename headers
+.Pq i.e. filenames
+with output lines.
.It Fl h
Never print filename headers
.Pq i.e. filenames
@@ -349,7 +353,7 @@ utility is compliant with the
specification.
.Pp
The flags
-.Op Fl AaBbCGhILRUVwZ
+.Op Fl AaBbCGHhILRUVwZ
are extensions to that specification, and the behaviour of the
.Fl f
flag when used with an empty pattern file is left undefined.
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index d34fd959750..e477cf97e3a 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */
+/* $OpenBSD: grep.c,v 1.43 2011/03/04 03:11:23 tedu Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -62,6 +62,7 @@ int Bflag; /* -B x: print x lines leading each match */
int Eflag; /* -E: interpret pattern as extended regexp */
int Fflag; /* -F: interpret pattern as list of fixed strings */
int Gflag; /* -G: interpret pattern as basic regexp */
+int Hflag; /* -H: always print filename header */
int Lflag; /* -L: only show names of files with no matches */
int Rflag; /* -R: recursively search directory trees */
#ifndef NOZ
@@ -106,9 +107,9 @@ usage(void)
{
fprintf(stderr,
#ifdef NOZ
- "usage: %s [-abcEFGhIiLlnqRsUVvwx] [-A num] [-B num] [-C[num]]\n"
+ "usage: %s [-abcEFGHhIiLlnqRsUVvwx] [-A num] [-B num] [-C[num]]\n"
#else
- "usage: %s [-abcEFGhIiLlnqRsUVvwxZ] [-A num] [-B num] [-C[num]]\n"
+ "usage: %s [-abcEFGHhIiLlnqRsUVvwxZ] [-A num] [-B num] [-C[num]]\n"
#endif
"\t[-e pattern] [-f file] [--binary-files=value] [--context[=num]]\n"
"\t[--line-buffered] [pattern] [file ...]\n", __progname);
@@ -116,9 +117,9 @@ usage(void)
}
#ifdef NOZ
-static char *optstr = "0123456789A:B:CEFGILRUVabce:f:hilnqrsuvwxy";
+static char *optstr = "0123456789A:B:CEFGHILRUVabce:f:hilnqrsuvwxy";
#else
-static char *optstr = "0123456789A:B:CEFGILRUVZabce:f:hilnqrsuvwxy";
+static char *optstr = "0123456789A:B:CEFGHILRUVZabce:f:hilnqrsuvwxy";
#endif
struct option long_options[] =
@@ -134,6 +135,7 @@ struct option long_options[] =
{"extended-regexp", no_argument, NULL, 'E'},
{"fixed-strings", no_argument, NULL, 'F'},
{"basic-regexp", no_argument, NULL, 'G'},
+ {"with-filename", no_argument, NULL, 'H'},
{"binary", no_argument, NULL, 'U'},
{"version", no_argument, NULL, 'V'},
{"text", no_argument, NULL, 'a'},
@@ -315,6 +317,9 @@ main(int argc, char *argv[])
Eflag = Fflag = 0;
Gflag++;
break;
+ case 'H':
+ Hflag++;
+ break;
case 'I':
binbehave = BIN_FILE_SKIP;
break;
@@ -476,7 +481,7 @@ main(int argc, char *argv[])
if (lbflag)
setlinebuf(stdout);
- if ((argc == 0 || argc == 1) && !Rflag)
+ if ((argc == 0 || argc == 1) && !Rflag && !Hflag)
hflag = 1;
if (argc == 0)
diff --git a/usr.bin/grep/grep.h b/usr.bin/grep/grep.h
index 7bfbe9a50d8..7d584d40727 100644
--- a/usr.bin/grep/grep.h
+++ b/usr.bin/grep/grep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $ */
+/* $OpenBSD: grep.h,v 1.16 2011/03/04 03:11:23 tedu Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -63,7 +63,7 @@ typedef struct {
extern int cflags, eflags;
/* Command line flags */
-extern int Aflag, Bflag, Eflag, Fflag, Gflag, Lflag,
+extern int Aflag, Bflag, Eflag, Fflag, Gflag, Hflag, Lflag,
Rflag, Zflag,
bflag, cflag, hflag, iflag, lflag, nflag, qflag, sflag,
vflag, wflag, xflag;