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. Reviewed by: eadler (previous version) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D14139
This commit is contained in:
parent
6df8601ce6
commit
b75e4698e9
@ -28,7 +28,7 @@
|
|||||||
.\" @(#)head.1 8.1 (Berkeley) 6/6/93
|
.\" @(#)head.1 8.1 (Berkeley) 6/6/93
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd March 16, 2013
|
.Dd April 10, 2018
|
||||||
.Dt HEAD 1
|
.Dt HEAD 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -49,6 +49,18 @@ If
|
|||||||
.Ar count
|
.Ar count
|
||||||
is omitted it defaults to 10.
|
is omitted it defaults to 10.
|
||||||
.Pp
|
.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
|
If more than a single file is specified, each file is preceded by a
|
||||||
header consisting of the string
|
header consisting of the string
|
||||||
.Dq ==> XXX <==
|
.Dq ==> XXX <==
|
||||||
|
@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -64,6 +65,13 @@ static void head_bytes(FILE *, off_t);
|
|||||||
static void obsolete(char *[]);
|
static void obsolete(char *[]);
|
||||||
static void usage(void);
|
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
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -74,7 +82,7 @@ main(int argc, char *argv[])
|
|||||||
char *ep;
|
char *ep;
|
||||||
|
|
||||||
obsolete(argv);
|
obsolete(argv);
|
||||||
while ((ch = getopt(argc, argv, "n:c:")) != -1)
|
while ((ch = getopt_long(argc, argv, "+n:c:", long_opts, NULL)) != -1)
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'c':
|
case 'c':
|
||||||
bytecnt = strtoimax(optarg, &ep, 10);
|
bytecnt = strtoimax(optarg, &ep, 10);
|
||||||
|
Loading…
Reference in New Issue
Block a user