Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Apr 2018 17:57:00 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r332482 - in stable/11/usr.bin: head tail
Message-ID:  <201804131757.w3DHv0Fs074545@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Fri Apr 13 17:57:00 2018
New Revision: 332482
URL: https://svnweb.freebsd.org/changeset/base/332482

Log:
  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.

Modified:
  stable/11/usr.bin/head/head.1
  stable/11/usr.bin/head/head.c
  stable/11/usr.bin/tail/tail.1
  stable/11/usr.bin/tail/tail.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/head/head.1
==============================================================================
--- stable/11/usr.bin/head/head.1	Fri Apr 13 17:45:54 2018	(r332481)
+++ stable/11/usr.bin/head/head.1	Fri Apr 13 17:57:00 2018	(r332482)
@@ -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
@@ -48,6 +48,18 @@ files are specified.
 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

Modified: stable/11/usr.bin/head/head.c
==============================================================================
--- stable/11/usr.bin/head/head.c	Fri Apr 13 17:45:54 2018	(r332481)
+++ stable/11/usr.bin/head/head.c	Fri Apr 13 17:57:00 2018	(r332482)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 
 #include <ctype.h>
 #include <err.h>
+#include <getopt.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -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);

Modified: stable/11/usr.bin/tail/tail.1
==============================================================================
--- stable/11/usr.bin/tail/tail.1	Fri Apr 13 17:45:54 2018	(r332481)
+++ stable/11/usr.bin/tail/tail.1	Fri Apr 13 17:57:00 2018	(r332482)
@@ -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.

Modified: stable/11/usr.bin/tail/tail.c
==============================================================================
--- stable/11/usr.bin/tail/tail.c	Fri Apr 13 17:45:54 2018	(r332481)
+++ stable/11/usr.bin/tail/tail.c	Fri Apr 13 17:57:00 2018	(r332482)
@@ -49,6 +49,7 @@ static const char sccsid[] = "@(#)tail.c	8.1 (Berkeley
 
 #include <err.h>
 #include <errno.h>
+#include <getopt.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201804131757.w3DHv0Fs074545>