Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144333065
D43382.id132524.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
D43382.id132524.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D43382: uniq: Fix interactive use.
Attached
Detach File
Event Timeline
Log In to Comment