From nobody Thu Mar 10 16:18:12 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 9909D1A0E24D; Thu, 10 Mar 2022 16:18:12 +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 4KDvPJ3qFkz3r4R; Thu, 10 Mar 2022 16:18:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646929092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lxKPUDejok/djXozvm1sHU+NGWhqHQ/bSWOCEZDgTMA=; b=wpG7MGx3h27uKFwH3PS8b9EEexybDmrHP7jUuhK9UzO9XujA/662bEeqW7yNJJXspALRx3 qs7XShcL6y0yPlu3JBiuDru/W9Iu9blnEAaMVUA5ok9u1Q0eMUWUYOZniDK0oOI/yO+A8I QKje9UlnDHMgTNHXQ6ag65YC5bL8sUweYCTNh+LZ8GQDW61SpYICnXYRah0tb4z0u9sY57 yRgwrQSJ9h5pV8Sz4iiNpVxnYjU53n6b+ctaDo1ue++JJZzJo7b9Xw5PVSZyzsnnf62ZdM 2GUK1d87H3kH507lXp9ISMBE+EYLvT1QcwFulNfEAaqtghP3jcpm/PVQScTg7Q== 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 62E7C72; Thu, 10 Mar 2022 16:18:12 +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 22AGICkl021679; Thu, 10 Mar 2022 16:18:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22AGICmd021678; Thu, 10 Mar 2022 16:18:12 GMT (envelope-from git) Date: Thu, 10 Mar 2022 16:18:12 GMT Message-Id: <202203101618.22AGICmd021678@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Tom Jones Subject: git: 8cf449db88b2 - main - diff: add support for --help and --version List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: thj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8cf449db88b2c7a505bc241a78f9736b43f2ede5 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646929092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lxKPUDejok/djXozvm1sHU+NGWhqHQ/bSWOCEZDgTMA=; b=D2YYDEiEUaEy4omznrKadR4M1UpIXPYmAbZQ1U+VMJqRsY2yI0IL1QC5NnrbFgG4wwLCFJ nuX8EnOFpBERgQfTIBk4LjaIhzfQhPUNPXxadx0F2gkT0Pn0cRJK+PWevfDa/oJ7c1Zd0u W29uVKeZunoOfWHIuw8cUQXKfXtu+NaWoUz+xygyMwVBG7OhfgHxPlojXHmYi4ILDKLJPi QkBJZ+W7JOeGxUa0wtcJKS8pKs61VJCoG4gYlIMI5Nfm2qyahcSAqGEUrR+JbCoVP+wreH 5AnfXijDVYe/B7Y+wpKD+4RMrA9pk65EJHOumufG8Q9mIVDPQ+ye0ldpN7Ulpg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646929092; a=rsa-sha256; cv=none; b=QTEtQinRKteXPKN9kEBK2VjkZCe+LvE+mNf8nKLR5aCcVSNoEjcGhyxTwSwgtzhThPR/la J3TOjagi9MTxJBDhRDzgahM/34dP0twEzgxaH+riUCuD0Uf/d0rtUYWQYj8xDCZS4ty2tj 1+ejR5WGWYyYTwEeSATtcT4Z/JxKeBuiWzR655hLF/3tx/qy6eK7WX7tsUJay33IPUMghR vMaHpgMm4Xn971cL924UpFfCkfME1mx6w/mHqUI0GcqdnXHZ+NfSHwSFV533uaiWTSy+7J +yljnVyxrRUQQ9abj/W/Evo9C3YC50DT2Op9G/5mYygCz+ilfQq+d5DYumLiiQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by thj: URL: https://cgit.FreeBSD.org/src/commit/?id=8cf449db88b2c7a505bc241a78f9736b43f2ede5 commit 8cf449db88b2c7a505bc241a78f9736b43f2ede5 Author: Tom Jones AuthorDate: 2022-03-10 16:15:39 +0000 Commit: Tom Jones CommitDate: 2022-03-10 16:17:37 +0000 diff: add support for --help and --version Add support for --help and --version to be compatible with gnu diff. gnu diff --help writes to stdout, do the same to be compatible Reviewed by: bapt, pstef, debrup, Pau Amma Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34508 --- usr.bin/diff/diff.1 | 15 ++++++++++++++- usr.bin/diff/diff.c | 25 +++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/usr.bin/diff/diff.1 b/usr.bin/diff/diff.1 index b17ddb123fd5..8582db6c9c1c 100644 --- a/usr.bin/diff/diff.1 +++ b/usr.bin/diff/diff.1 @@ -30,7 +30,7 @@ .\" @(#)diff.1 8.1 (Berkeley) 6/30/93 .\" $FreeBSD$ .\" -.Dd June 19, 2020 +.Dd March 10, 2022 .Dt DIFF 1 .Os .Sh NAME @@ -207,6 +207,9 @@ .Op Fl -width .Fl y | Fl -side-by-side .Ar file1 file2 +.Nm diff +.Op Fl -help +.Op Fl -version .Sh DESCRIPTION The .Nm @@ -282,6 +285,8 @@ Identical output to that of the flag, but in reverse order. It cannot be digested by .Xr ed 1 . +.It Fl -help +This option prints a summary to stdout and exits with status 0. .It Fl n Produces a script similar to that of .Fl e , @@ -308,6 +313,8 @@ However, unlike with .Fl c , all lines to be changed (added and/or removed) are present in a single section. +.It Fl -version +This option prints a version string to stdout and exits with status 0. .It Fl y Fl -side-by-side Output in two columns with a marker between them. The marker can be one @@ -655,6 +662,12 @@ Differences were found. .It >1 An error occurred. .El +.Pp +The +.Fl -help +and +.Fl -version +options exit with a status of 0. .Sh EXAMPLES Compare .Pa old_dir diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index 34cdd0d846d9..ba6bc7c3a310 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -38,8 +38,10 @@ __FBSDID("$FreeBSD$"); #include "diff.h" #include "xmalloc.h" +static const char diff_version[] = "FreeBSD diff 20220309"; bool lflag, Nflag, Pflag, rflag, sflag, Tflag, cflag; bool ignore_file_case, suppress_common, color, noderef; +static bool help = false; int diff_format, diff_context, status; int tabsize = 8, width = 130; static int colorflag = COLORFLAG_NEVER; @@ -58,11 +60,13 @@ enum { OPT_IGN_FN_CASE, OPT_NO_IGN_FN_CASE, OPT_NORMAL, + OPT_HELP, OPT_HORIZON_LINES, OPT_CHANGED_GROUP_FORMAT, OPT_SUPPRESS_COMMON, OPT_COLOR, OPT_NO_DEREFERENCE, + OPT_VERSION, }; static struct option longopts[] = { @@ -97,6 +101,7 @@ static struct option longopts[] = { { "exclude-from", required_argument, 0, 'X' }, { "side-by-side", no_argument, NULL, 'y' }, { "ignore-file-name-case", no_argument, NULL, OPT_IGN_FN_CASE }, + { "help", no_argument, NULL, OPT_HELP}, { "horizon-lines", required_argument, NULL, OPT_HORIZON_LINES }, { "no-dereference", no_argument, NULL, OPT_NO_DEREFERENCE}, { "no-ignore-file-name-case", no_argument, NULL, OPT_NO_IGN_FN_CASE }, @@ -106,6 +111,7 @@ static struct option longopts[] = { { "changed-group-format", required_argument, NULL, OPT_CHANGED_GROUP_FORMAT}, { "suppress-common-lines", no_argument, NULL, OPT_SUPPRESS_COMMON }, { "color", optional_argument, NULL, OPT_COLOR }, + { "version", no_argument, NULL, OPT_VERSION}, { NULL, 0, 0, '\0'} }; @@ -294,6 +300,10 @@ main(int argc, char **argv) diff_format = D_GFORMAT; group_format = optarg; break; + case OPT_HELP: + help = true; + usage(); + break; case OPT_HORIZON_LINES: break; /* XXX TODO for compatibility with GNU diff3 */ case OPT_IGN_FN_CASE: @@ -335,6 +345,9 @@ main(int argc, char **argv) rflag = true; noderef = true; break; + case OPT_VERSION: + printf("%s\n", diff_version); + exit(0); default: usage(); break; @@ -569,9 +582,9 @@ print_status(int val, char *path1, char *path2, const char *entry) } static void -usage(void) +usage() { - (void)fprintf(stderr, + (void)fprintf(help ? stdout : stderr, "usage: diff [-aBbdilpTtw] [-c | -e | -f | -n | -q | -u] [--ignore-case]\n" " [--no-ignore-case] [--normal] [--strip-trailing-cr] [--tabsize]\n" " [-I pattern] [-F pattern] [-L label] file1 file2\n" @@ -590,9 +603,13 @@ usage(void) " [--ignore-blank-lines] [--ignore-case] [--minimal]\n" " [--no-ignore-file-name-case] [--strip-trailing-cr]\n" " [--suppress-common-lines] [--tabsize] [--text] [--width]\n" - " -y | --side-by-side file1 file2\n"); + " -y | --side-by-side file1 file2\n" + " diff [--help] [--version]\n"); - exit(2); + if (help) + exit(0); + else + exit(2); } static void