Page MenuHomeFreeBSD

D43941.diff
No OneTemporary

D43941.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
@@ -71,6 +71,8 @@
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 */
+static int tabsize = 8; /* tab size */
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.",
@@ -246,7 +248,6 @@
case FCASE_IGNORE_OPT:
case FCASE_SENSITIVE_OPT:
case STRIPCR_OPT:
- case TSIZE_OPT:
case 'S':
break;
/* combine no-arg single switches */
@@ -256,7 +257,6 @@
case 'd':
case 'E':
case 'i':
- case 't':
case 'W':
flagc++;
flagv = realloc(flagv, flagc + 2);
@@ -286,6 +286,9 @@
case 's':
sflag = true;
break;
+ case 't':
+ tflag = true;
+ break;
case 'w':
wval = strtonum(optarg, WIDTH_MIN,
INT_MAX, &errstr);
@@ -297,6 +300,11 @@
printf("%s\n", help_msg[i]);
exit(0);
break;
+ case TSIZE_OPT:
+ tabsize = strtonum(optarg, 1, INT_MAX, &errstr);
+ if (errstr)
+ errx(2, "tabsize is %s: %s", errstr, optarg);
+ break;
default:
usage();
break;
@@ -511,11 +519,11 @@
* If rounding to next multiple of eight causes
* an integer overflow, just return.
*/
- if (*col > SIZE_MAX - 8)
+ if (*col > SIZE_MAX - tabsize)
return;
/* Round to next multiple of eight. */
- new_col = (*col / 8 + 1) * 8;
+ new_col = (*col / tabsize + 1) * tabsize;
/*
* If printing the tab goes past the column
@@ -523,12 +531,20 @@
*/
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,23 @@
$(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\tb' \
+ sdiff a b
+ atf_check -s exit:1 -o match:"a {7}b" \
+ sdiff -t a b
+ atf_check -s exit:1 -o match:"a {3}b" \
+ sdiff -t --tabsize 4 a b
+}
+
atf_init_test_cases()
{
atf_add_test_case flags
@@ -203,4 +220,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, Apr 30, 6:59 PM (20 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17862852
Default Alt Text
D43941.diff (3 KB)

Event Timeline