Page MenuHomeFreeBSD

D43941.id134458.diff
No OneTemporary

D43941.id134458.diff

diff --git a/usr.bin/sdiff/sdiff.1 b/usr.bin/sdiff/sdiff.1
--- a/usr.bin/sdiff/sdiff.1
+++ b/usr.bin/sdiff/sdiff.1
@@ -3,7 +3,7 @@
.\" Written by Raymond Lai <ray@cyth.net>.
.\" Public domain.
.\"
-.Dd April 8, 2017
+.Dd February 16, 2024
.Dt SDIFF 1
.Os
.Sh NAME
@@ -117,8 +117,6 @@
Ignore blank lines.
.It Fl E -ignore-tab-expansion
Treat tabs and eight spaces as the same.
-.It Fl t -ignore-tabs
-Ignore tabs.
.It Fl H -speed-large-files
Assume scattered small changes in a large file.
.It Fl -ignore-file-name-case
diff --git a/usr.bin/sdiff/sdiff.c b/usr.bin/sdiff/sdiff.c
--- a/usr.bin/sdiff/sdiff.c
+++ b/usr.bin/sdiff/sdiff.c
@@ -18,6 +18,7 @@
#include <getopt.h>
#include <limits.h>
#include <paths.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -68,9 +69,10 @@
static size_t line_width; /* width of a line (two columns and divider) */
static size_t width; /* width of each column */
static size_t file1ln, file2ln; /* line number of file1 and file2 */
-static int Iflag = 0; /* ignore sets matching regexp */
-static int lflag; /* print only left column for identical lines */
-static int sflag; /* skip identical lines */
+static bool Iflag; /* ignore sets matching regexp */
+static bool lflag; /* print only left column for identical lines */
+static bool sflag; /* skip identical lines */
+static bool tflag; /* expand tabs */
FILE *outfp; /* file to save changes to */
const char *tmpdir; /* TMPDIR or /tmp */
@@ -126,7 +128,7 @@
"\t-d, --minimal: minimize diff size.",
"\t-I RE, --ignore-matching-lines=RE: ignore changes whose line matches RE.",
"\t-i, --ignore-case: do a case-insensitive comparison.",
- "\t-t, --expand-tabs: sxpand tabs to spaces.",
+ "\t-t, --expand-tabs: expand tabs to spaces.",
"\t-W, --ignore-all-spaces: ignore all spaces.",
"\t--speed-large-files: assume large file with scattered changes.",
"\t--strip-trailing-cr: strip trailing carriage return.",
@@ -256,7 +258,6 @@
case 'd':
case 'E':
case 'i':
- case 't':
case 'W':
diffargv[1] = realloc(diffargv[1], sizeof(char) * strlen(diffargv[1]) + 2);
/*
@@ -274,18 +275,21 @@
diffargv[0] = diffprog = optarg;
break;
case 'I':
- Iflag = 1;
+ Iflag = true;
diffargv[diffargc++] = I_arg;
diffargv[diffargc++] = optarg;
break;
case 'l':
- lflag = 1;
+ lflag = true;
break;
case 'o':
outfile = optarg;
break;
case 's':
- sflag = 1;
+ sflag = true;
+ break;
+ case 't':
+ tflag = true;
break;
case 'w':
wflag = strtonum(optarg, WIDTH_MIN,
@@ -525,12 +529,19 @@
*/
if (new_col > col_max)
return;
- *col = new_col;
+ if (tflag) {
+ do {
+ putchar(' ');
+ } while (++*col < new_col);
+ } else {
+ putchar(*s);
+ *col = new_col;
+ }
break;
default:
- ++(*col);
+ ++*col;
+ putchar(*s);
}
- putchar(*s);
}
}
diff --git a/usr.bin/sdiff/tests/sdiff_test.sh b/usr.bin/sdiff/tests/sdiff_test.sh
--- a/usr.bin/sdiff/tests/sdiff_test.sh
+++ b/usr.bin/sdiff/tests/sdiff_test.sh
@@ -191,6 +191,21 @@
$(atf_get_srcdir)/d_input2 >/dev/null ; cat merge.out"
}
+atf_test_case tflag
+tflag_head()
+{
+ atf_set "descr" "Checks tab expansion"
+}
+tflag_body()
+{
+ printf "a\tb\n" >a
+ printf "b\ta\n" >b
+ atf_check -s exit:1 -o match:"a b" \
+ sdiff a b
+ atf_check -s exit:1 -o match:"a b" \
+ sdiff -t a b
+}
+
atf_init_test_cases()
{
atf_add_test_case flags
@@ -203,4 +218,5 @@
atf_add_test_case dot
atf_add_test_case stdin
atf_add_test_case short
+ atf_add_test_case tflag
}

File Metadata

Mime Type
text/plain
Expires
Wed, Jan 21, 4:33 PM (2 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27813927
Default Alt Text
D43941.id134458.diff (3 KB)

Event Timeline