Page MenuHomeFreeBSD

uniq: Fix interactive use.
ClosedPublic

Authored by des on Jan 9 2024, 8:29 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Sep 23, 3:06 PM
Unknown Object (File)
Sun, Sep 22, 10:29 AM
Unknown Object (File)
Sat, Sep 21, 5:04 AM
Unknown Object (File)
Sat, Sep 21, 4:53 AM
Unknown Object (File)
Sat, Sep 21, 4:52 AM
Unknown Object (File)
Fri, Sep 20, 7:36 AM
Unknown Object (File)
Thu, Sep 19, 5:16 PM
Unknown Object (File)
Wed, Sep 18, 7:23 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 Skipped
Unit
Tests Skipped
Build Status
Buildable 55337
Build 52226: arc lint + arc unit

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
143

This is probably worth a small note in the manpage

209

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.

241

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

usr.bin/uniq/uniq.c
143

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
241

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.