From owner-dev-commits-src-all@freebsd.org Sun Oct 3 05:21:00 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2BFD06B1450; Sun, 3 Oct 2021 05:21:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HMXHv3yb6z4S1y; Sun, 3 Oct 2021 05:20:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3B6AF20630; Sun, 3 Oct 2021 05:20:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1935KxXA020978; Sun, 3 Oct 2021 05:20:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1935KxqC020977; Sun, 3 Oct 2021 05:20:59 GMT (envelope-from git) Date: Sun, 3 Oct 2021 05:20:59 GMT Message-Id: <202110030520.1935KxqC020977@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: b0f46c4b8409 - stable/12 - cmp: add -i, --ignore-initial, an alternative to skip1/skip2 args MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: b0f46c4b84093b23e8d40ffbc1f7f63659a0123c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Oct 2021 05:21:00 -0000 The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=b0f46c4b84093b23e8d40ffbc1f7f63659a0123c commit b0f46c4b84093b23e8d40ffbc1f7f63659a0123c Author: Kyle Evans AuthorDate: 2021-09-23 05:43:32 +0000 Commit: Kyle Evans CommitDate: 2021-10-03 05:19:56 +0000 cmp: add -i, --ignore-initial, an alternative to skip1/skip2 args This is compatible with GNU cmp. Reviewed by: markj Sponsored by: Klara, Inc. (cherry picked from commit 8d546b6832eea031f95f30eaec3232ec1256a281) --- usr.bin/cmp/cmp.1 | 19 +++++++++++++++++++ usr.bin/cmp/cmp.c | 30 +++++++++++++++++++++++++++++- usr.bin/cmp/tests/cmp_test2.sh | 5 +++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/usr.bin/cmp/cmp.1 b/usr.bin/cmp/cmp.1 index 511e09ac8628..5a56802bd22e 100644 --- a/usr.bin/cmp/cmp.1 +++ b/usr.bin/cmp/cmp.1 @@ -41,6 +41,7 @@ .Nm .Op Fl l | s | x .Op Fl hz +.Op Fl -ignore-initial Ns Cm = Ns Ar num1 Ns Op :num2 .Op Fl -bytes Ns Cm = Ns Ar num .Ar file1 file2 .Op Ar skip1 Op Ar skip2 @@ -60,6 +61,23 @@ The following options are available: .Bl -tag -width indent .It Fl h Do not follow symbolic links. +.It Fl i Ar num1 Ns Oo :num2 Oc , Fl -ignore-initial= Ns Ar num1 Ns Op :num2 +Skip +.Ar num1 +bytes from +.Ar file1 , +and optionally skip +.Ar num2 +bytes from +.Ar file2 . +If +.Ar num2 +is not specified, then +.Ar num1 +is applied for both +.Ar file1 +and +.Ar file2 . .It Fl l , Fl -verbose Print the byte number (decimal) and the differing byte values (octal) for each difference. @@ -170,6 +188,7 @@ utility is expected to be compatible. The .Fl h , +.Fl i , .Fl n , .Fl x , and diff --git a/usr.bin/cmp/cmp.c b/usr.bin/cmp/cmp.c index 384c273f4632..256cef8a0c31 100644 --- a/usr.bin/cmp/cmp.c +++ b/usr.bin/cmp/cmp.c @@ -66,6 +66,7 @@ bool lflag, sflag, xflag, zflag; static const struct option long_opts[] = { + {"ignore-initial", required_argument, NULL, 'i'}, {"verbose", no_argument, NULL, 'l'}, {"bytes", required_argument, NULL, 'n'}, {"silent", no_argument, NULL, 's'}, @@ -75,6 +76,25 @@ static const struct option long_opts[] = static void usage(void); +static bool +parse_iskipspec(char *spec, off_t *skip1, off_t *skip2) +{ + char *colon; + + colon = strchr(spec, ':'); + if (colon != NULL) + *colon++ = '\0'; + + if (expand_number(spec, skip1) < 0) + return (false); + + if (colon != NULL) + return (expand_number(colon, skip2) == 0); + + *skip2 = *skip1; + return (true); +} + int main(int argc, char *argv[]) { @@ -86,11 +106,19 @@ main(int argc, char *argv[]) skip1 = skip2 = 0; oflag = O_RDONLY; - while ((ch = getopt_long(argc, argv, "+hln:sxz", long_opts, NULL)) != -1) + while ((ch = getopt_long(argc, argv, "+hi:ln:sxz", long_opts, NULL)) != -1) switch (ch) { case 'h': /* Don't follow symlinks */ oflag |= O_NOFOLLOW; break; + case 'i': + if (!parse_iskipspec(optarg, &skip1, &skip2)) { + fprintf(stderr, + "Invalid --ignore-initial: %s\n", + optarg); + usage(); + } + break; case 'l': /* print all differences */ lflag = true; break; diff --git a/usr.bin/cmp/tests/cmp_test2.sh b/usr.bin/cmp/tests/cmp_test2.sh index c513984daf8b..893ee59076c3 100755 --- a/usr.bin/cmp/tests/cmp_test2.sh +++ b/usr.bin/cmp/tests/cmp_test2.sh @@ -71,8 +71,13 @@ pr252542_body() { echo -n '1234567890' > a echo -n 'abc567890' > b + echo -n 'xbc567890' > c atf_check -s exit:0 cmp -s a b 4 3 + atf_check -s exit:0 cmp -i 4:3 -s a b + atf_check -s exit:0 cmp -i 1 -s b c atf_check -s exit:1 -o ignore cmp -z a b 4 3 + atf_check -s exit:1 -o ignore cmp -i 4:3 -z a b + atf_check -s exit:1 -o ignore cmp -i 1 -z a b } atf_test_case skipsuff