From owner-svn-src-head@freebsd.org Tue Apr 10 14:44:08 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5FA9DFA2046; Tue, 10 Apr 2018 14:44:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 13CAF7D7E3; Tue, 10 Apr 2018 14:44:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0E9C86F70; Tue, 10 Apr 2018 14:44:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3AEi71F098234; Tue, 10 Apr 2018 14:44:07 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3AEi79n098232; Tue, 10 Apr 2018 14:44:07 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201804101444.w3AEi79n098232@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 10 Apr 2018 14:44:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r332374 - head/usr.bin/head X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/usr.bin/head X-SVN-Commit-Revision: 332374 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Apr 2018 14:44:08 -0000 Author: kevans Date: Tue Apr 10 14:44:07 2018 New Revision: 332374 URL: https://svnweb.freebsd.org/changeset/base/332374 Log: 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 Modified: head/usr.bin/head/head.1 head/usr.bin/head/head.c Modified: head/usr.bin/head/head.1 ============================================================================== --- head/usr.bin/head/head.1 Tue Apr 10 14:42:24 2018 (r332373) +++ head/usr.bin/head/head.1 Tue Apr 10 14:44:07 2018 (r332374) @@ -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: head/usr.bin/head/head.c ============================================================================== --- head/usr.bin/head/head.c Tue Apr 10 14:42:24 2018 (r332373) +++ head/usr.bin/head/head.c Tue Apr 10 14:44:07 2018 (r332374) @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -64,6 +65,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[]) { @@ -74,7 +82,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);