Page MenuHomeFreeBSD

D43382.id132524.diff
No OneTemporary

D43382.id132524.diff

diff --git a/usr.bin/uniq/tests/uniq_test.sh b/usr.bin/uniq/tests/uniq_test.sh
--- a/usr.bin/uniq/tests/uniq_test.sh
+++ b/usr.bin/uniq/tests/uniq_test.sh
@@ -119,6 +119,30 @@
atf_check_uniq --unique
}
+atf_test_case interactive
+interactive_head() {
+ atf_set descr "test interactive use"
+}
+interactive_body() {
+ sh -c 'yes | stdbuf -oL uniq >actual' &
+ pid=$!
+ sleep 1
+ kill $!
+ atf_check -o inline:"y\n" cat actual
+}
+
+atf_test_case interactive_repeated
+interactive_repeated_head() {
+ atf_set descr "test interactive use with -d"
+}
+interactive_repeated_body() {
+ sh -c 'yes | stdbuf -oL uniq -d >actual' &
+ pid=$!
+ sleep 1
+ kill $!
+ atf_check -o inline:"y\n" cat actual
+}
+
atf_init_test_cases()
{
atf_add_test_case basic
@@ -131,4 +155,6 @@
atf_add_test_case ignore_case
atf_add_test_case skip_chars
atf_add_test_case unique
+ atf_add_test_case interactive
+ atf_add_test_case interactive_repeated
}
diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c
--- a/usr.bin/uniq/uniq.c
+++ b/usr.bin/uniq/uniq.c
@@ -140,6 +140,9 @@
if (argc > 2)
usage();
+ if (Dflag && dflag)
+ dflag = 0;
+
ifp = stdin;
ifn = "stdin";
ofp = stdout;
@@ -180,6 +183,8 @@
err(1, "%s", ifn);
exit(0);
}
+ if (!cflag && !Dflag && !dflag && !uflag)
+ show(ofp, prevline);
tprev = convert(prevline);
tthis = NULL;
@@ -199,7 +204,9 @@
/* If different, print; set previous to new value. */
if (Dflag == DF_POSTSEP && repeats > 0)
fputc('\n', ofp);
- if (!Dflag)
+ if (!cflag && !Dflag && !dflag && !uflag)
+ show(ofp, thisline);
+ else if (!Dflag && !dflag)
show(ofp, prevline);
p = prevline;
b1 = prevbuflen;
@@ -220,13 +227,18 @@
show(ofp, prevline);
}
show(ofp, thisline);
+ } else if (dflag && !cflag) {
+ if (repeats == 0)
+ show(ofp, prevline);
}
++repeats;
}
}
if (ferror(ifp))
err(1, "%s", ifn);
- if (!Dflag)
+ if (!cflag && !Dflag && !dflag && !uflag)
+ /* already printed */ ;
+ else if (!Dflag && (!dflag || cflag))
show(ofp, prevline);
exit(0);
}
@@ -291,8 +303,7 @@
static void
show(FILE *ofp, const char *str)
{
-
- if ((!Dflag && dflag && repeats == 0) || (uflag && repeats > 0))
+ if (uflag && repeats > 0)
return;
if (cflag)
(void)fprintf(ofp, "%4d %s", repeats + 1, str);

File Metadata

Mime Type
text/plain
Expires
Sun, Feb 8, 9:44 PM (9 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28501643
Default Alt Text
D43382.id132524.diff (2 KB)

Event Timeline