Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137484453
D34508.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D34508.id.diff
View Options
diff --git a/usr.bin/diff/diff.1 b/usr.bin/diff/diff.1
--- 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 @@
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 @@
.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 @@
.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
--- a/usr.bin/diff/diff.c
+++ b/usr.bin/diff/diff.c
@@ -38,8 +38,10 @@
#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 @@
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 @@
{ "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 @@
{ "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 @@
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 @@
rflag = true;
noderef = true;
break;
+ case OPT_VERSION:
+ printf("%s\n", diff_version);
+ exit(0);
default:
usage();
break;
@@ -569,9 +582,9 @@
}
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 @@
" [--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
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 24, 9:41 PM (2 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26076155
Default Alt Text
D34508.id.diff (3 KB)
Attached To
Mode
D34508: diff: add support for --help and --version
Attached
Detach File
Event Timeline
Log In to Comment