Page MenuHomeFreeBSD

uniq: Fix interactive use.
ClosedPublic

Authored by des on Jan 9 2024, 8:29 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 7, 4:25 AM
Unknown Object (File)
Sat, Nov 2, 9:25 AM
Unknown Object (File)
Oct 4 2024, 2:58 PM
Unknown Object (File)
Oct 2 2024, 6:31 PM
Unknown Object (File)
Oct 1 2024, 1:00 PM
Unknown Object (File)
Oct 1 2024, 1:00 PM
Unknown Object (File)
Oct 1 2024, 12:30 PM
Unknown Object (File)
Sep 30 2024, 1:32 PM
Subscribers

Details

Summary

Output a line as soon as it is possible to determine that it will have
to be output. For the basic case, this means output each line as it is
read unless it is identical to the previous one. For the -d case, it
means output the first instance as soon as the second is read, unless
the -c option was also given. The -D and -u cases were already fine.

Add test cases for interactive use with no options and with -d.

Explicitly ignore -d when -D is also specified.

Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

des requested review of this revision.Jan 9 2024, 8:29 PM
This revision is now accepted and ready to land.Jan 10 2024, 6:55 PM
kevans added inline comments.
usr.bin/uniq/uniq.c
139

This is probably worth a small note in the manpage

205

This seems to break the -c -d case:

printf "A\nA\nB\n" | uniq -dc

I'd expect this to print, 2 A, but we don't have any provision in this to output prevline now that we have the final count.

239

The above example is also broken because we shouldn't print here for dflag && cflag unless repeats > 0

usr.bin/uniq/uniq.c
139

Because -D is a superset of -d this behaviour makes sense to me even absent a note in the man page, but I agree it wouldn't hurt to be explicit.

This revision now requires review to proceed.Jan 11 2024, 4:24 PM
des marked 4 inline comments as done.Jan 11 2024, 5:21 PM
kevans added inline comments.
usr.bin/uniq/uniq.c
239

The predicates for these are of course an exact match for the mismatch branch above (as well as the show() before the getline loop); might not be a bad idea to pull them out into a macro or inline function (show_every() and show_repeated(repeated) respectively, maybe? *shrug*), but I do not insist

This revision is now accepted and ready to land.Jan 12 2024, 12:52 AM
This revision was automatically updated to reflect the committed changes.