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.

Reviewed by:	eadler (earlier version)
MFC after:	3 days
This commit is contained in:
Kyle Evans 2018-04-10 14:27:27 +00:00
parent 87c1cb45cd
commit 53128fb488
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=332372
2 changed files with 15 additions and 5 deletions

View File

@ -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.

View File

@ -51,6 +51,7 @@ static const char sccsid[] = "@(#)tail.c 8.1 (Berkeley) 6/6/93";
#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -65,6 +66,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[])
{
@ -113,7 +122,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;