On Sun, Dec 24 2017, Theo Buehler <[email protected]> wrote:
>> Obviously, the relevant condition should have been
>>
>> if ((iflag ? strcasecmp : strcmp)(t1, t2) != 0)
>>
>> instead of awkwardly messing with logical AND and OR.
>
> Indeed, this is much better. I like your version, but perhaps others
> might like this one more:
>
> if ((iflag && strcasecmp(t1, t2)) || strcmp(t1, t2))
This would break -i mode. If people want to avoid the ternary operator
(I see no reason here) then please write a proper if / else pattern.
> Thanks for pointing it out.
ok jca@ for the diff below
> Index: uniq.c
> ===================================================================
> RCS file: /var/cvs/src/usr.bin/uniq/uniq.c,v
> retrieving revision 1.25
> diff -u -p -r1.25 uniq.c
> --- uniq.c 21 Dec 2017 10:05:59 -0000 1.25
> +++ uniq.c 23 Dec 2017 23:07:16 -0000
> @@ -152,7 +152,7 @@ main(int argc, char *argv[])
> }
>
> /* If different, print; set previous to new value. */
> - if ((!iflag && strcmp(t1, t2)) || strcasecmp(t1, t2)) {
> + if ((iflag ? strcasecmp : strcmp)(t1, t2)) {
> show(ofp, prevline);
> t1 = prevline;
> prevline = thisline;
>
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE