From 7d068da5c00b4acff3473172f631dc78c6538a3f Mon Sep 17 00:00:00 2001 From: kevans Date: Fri, 13 Apr 2018 17:57:00 +0000 Subject: MFC r332372-r332374: tail(1)/head(1) compatibility long options r332372: tail(1): Add some long options Add --blocks, --bytes, and --lines long options for -b, -c, and -n respectively. This improves tail(1)'s compatibility with its GNU counterpart in a straightforward way. r332373: tail(1): Address mandoc concern (space before punctuation after macro) r332374: head(1): Provide long options Provide long options --bytes and --lines to match -c and -n respectively. This improves head(1)'s compatibility with its GNU counterpart in a sensible way. --- usr.bin/head/head.1 | 14 +++++++++++++- usr.bin/head/head.c | 10 +++++++++- usr.bin/tail/tail.1 | 8 ++++---- usr.bin/tail/tail.c | 12 +++++++++++- 4 files changed, 37 insertions(+), 7 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/head/head.1 b/usr.bin/head/head.1 index dd12485..75971a7 100644 --- a/usr.bin/head/head.1 +++ b/usr.bin/head/head.1 @@ -28,7 +28,7 @@ .\" @(#)head.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd March 16, 2013 +.Dd April 10, 2018 .Dt HEAD 1 .Os .Sh NAME @@ -49,6 +49,18 @@ If .Ar count is omitted it defaults to 10. .Pp +The following options are available: +.Bl -tag -width indent +.It Fl c Ar bytes , Fl -bytes Ns = Ns Ar bytes +Print +.Ar bytes +of each of the specified files. +.It Fl n Ar count , Fl -lines Ns = Ns Ar count +Print +.Ar count +lines of each of the specified files. +.El +.Pp If more than a single file is specified, each file is preceded by a header consisting of the string .Dq ==> XXX <== diff --git a/usr.bin/head/head.c b/usr.bin/head/head.c index e1caa1f..da3760e 100644 --- a/usr.bin/head/head.c +++ b/usr.bin/head/head.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -62,6 +63,13 @@ static void head_bytes(FILE *, off_t); static void obsolete(char *[]); static void usage(void); +static const struct option long_opts[] = +{ + {"bytes", required_argument, NULL, 'c'}, + {"lines", required_argument, NULL, 'n'}, + {NULL, no_argument, NULL, 0} +}; + int main(int argc, char *argv[]) { @@ -72,7 +80,7 @@ main(int argc, char *argv[]) char *ep; obsolete(argv); - while ((ch = getopt(argc, argv, "n:c:")) != -1) + while ((ch = getopt_long(argc, argv, "+n:c:", long_opts, NULL)) != -1) switch(ch) { case 'c': bytecnt = strtoimax(optarg, &ep, 10); diff --git a/usr.bin/tail/tail.1 b/usr.bin/tail/tail.1 index 35866f5..15ed2d6 100644 --- a/usr.bin/tail/tail.1 +++ b/usr.bin/tail/tail.1 @@ -31,7 +31,7 @@ .\" @(#)tail.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd March 16, 2013 +.Dd April 10, 2018 .Dt TAIL 1 .Os .Sh NAME @@ -73,11 +73,11 @@ or the last 10 lines of the input. .Pp The options are as follows: .Bl -tag -width indent -.It Fl b Ar number +.It Fl b Ar number , Fl -blocks Ns = Ns Ar number The location is .Ar number 512-byte blocks. -.It Fl c Ar number +.It Fl c Ar number , Fl -bytes Ns = Ns Ar number The location is .Ar number bytes. @@ -112,7 +112,7 @@ The option is the same as the .Fl f option if reading from standard input rather than a file. -.It Fl n Ar number +.It Fl n Ar number , Fl -lines Ns = Ns Ar number The location is .Ar number lines. diff --git a/usr.bin/tail/tail.c b/usr.bin/tail/tail.c index e5566cb..97f8371 100644 --- a/usr.bin/tail/tail.c +++ b/usr.bin/tail/tail.c @@ -49,6 +49,7 @@ static const char sccsid[] = "@(#)tail.c 8.1 (Berkeley) 6/6/93"; #include #include +#include #include #include #include @@ -63,6 +64,14 @@ static file_info_t *files; static void obsolete(char **); static void usage(void); +static const struct option long_opts[] = +{ + {"blocks", required_argument, NULL, 'b'}, + {"bytes", required_argument, NULL, 'c'}, + {"lines", required_argument, NULL, 'n'}, + {NULL, no_argument, NULL, 0} +}; + int main(int argc, char *argv[]) { @@ -111,7 +120,8 @@ main(int argc, char *argv[]) obsolete(argv); style = NOTSET; off = 0; - while ((ch = getopt(argc, argv, "Fb:c:fn:qr")) != -1) + while ((ch = getopt_long(argc, argv, "+Fb:c:fn:qr", long_opts, NULL)) != + -1) switch(ch) { case 'F': /* -F is superset of (and implies) -f */ Fflag = fflag = 1; -- cgit v1.1