diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2019-10-07 17:47:33 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2019-10-07 17:47:33 +0000 |
commit | 92dd18f01ef8dafa7147b2522f223b2263950571 (patch) | |
tree | 03f8ffb2d10ae43e8909b3f7717f5d1b11a819ef /usr.bin/grep/grep.c | |
parent | dc3342e4c1c1c21ca67d9e58c17c18251b460b51 (diff) |
two compat features to allow the zstdgrep script to work.
add --label option to prefix the output instead of filename.
allow using - to mean stdin.
ok deraadt
Diffstat (limited to 'usr.bin/grep/grep.c')
-rw-r--r-- | usr.bin/grep/grep.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 651a3b15002..3b2cf80b8e7 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.60 2019/07/18 15:32:50 schwarze Exp $ */ +/* $OpenBSD: grep.c,v 1.61 2019/10/07 17:47:32 tedu Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -80,6 +80,7 @@ int vflag; /* -v: only show non-matching lines */ int wflag; /* -w: pattern must start and end on word boundaries */ int xflag; /* -x: pattern must match entire line */ int lbflag; /* --line-buffered */ +const char *labelname; /* --label=name */ int binbehave = BIN_FILE_BIN; @@ -87,7 +88,8 @@ enum { BIN_OPT = CHAR_MAX + 1, HELP_OPT, MMAP_OPT, - LINEBUF_OPT + LINEBUF_OPT, + LABEL_OPT, }; /* Housekeeping */ @@ -130,6 +132,7 @@ static const struct option long_options[] = {"binary-files", required_argument, NULL, BIN_OPT}, {"help", no_argument, NULL, HELP_OPT}, {"mmap", no_argument, NULL, MMAP_OPT}, + {"label", required_argument, NULL, LABEL_OPT}, {"line-buffered", no_argument, NULL, LINEBUF_OPT}, {"after-context", required_argument, NULL, 'A'}, {"before-context", required_argument, NULL, 'B'}, @@ -427,6 +430,9 @@ main(int argc, char *argv[]) case MMAP_OPT: /* default, compatibility */ break; + case LABEL_OPT: + labelname = optarg; + break; case LINEBUF_OPT: lbflag = 1; break; @@ -461,6 +467,11 @@ main(int argc, char *argv[]) --argc; ++argv; } + if (argc == 1 && strcmp(*argv, "-") == 0) { + /* stdin */ + --argc; + ++argv; + } if (Rflag && argc == 0) warnx("warning: recursive search of stdin"); |