Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F159203028
D32073.id95545.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D32073.id95545.diff
View Options
Index: usr.bin/cmp/cmp.1
===================================================================
--- usr.bin/cmp/cmp.1
+++ 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 @@
.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 @@
compatible.
The
.Fl h ,
+.Fl i ,
.Fl n ,
.Fl x ,
and
Index: usr.bin/cmp/cmp.c
===================================================================
--- usr.bin/cmp/cmp.c
+++ usr.bin/cmp/cmp.c
@@ -67,6 +67,7 @@
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'},
@@ -76,6 +77,28 @@
static void usage(void);
+static bool
+parse_iskipspec(char *spec, off_t *skip1, off_t *skip2)
+{
+ char *colon;
+
+ if (*spec == '\0')
+ return (false);
+
+ 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[])
{
@@ -87,8 +110,16 @@
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 'i':
+ if (!parse_iskipspec(optarg, &skip1, &skip2)) {
+ fprintf(stderr,
+ "Invalid --ignore-initial: '%s'\n",
+ optarg);
+ usage();
+ }
+ break;
case 'n': /* Limit */
if (expand_number(optarg, &limit) < 0 || limit < 0) {
fprintf(stderr, "Invalid --bytes: '%s'\n",
Index: usr.bin/cmp/tests/cmp_test2.sh
===================================================================
--- usr.bin/cmp/tests/cmp_test2.sh
+++ usr.bin/cmp/tests/cmp_test2.sh
@@ -71,8 +71,13 @@
{
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
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jun 12, 7:11 AM (2 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33901998
Default Alt Text
D32073.id95545.diff (2 KB)
Attached To
Mode
D32073: cmp: add -i, --ignore-initial, an alternative to skip1/skip2 args
Attached
Detach File
Event Timeline
Log In to Comment