svn commit: r194789 - head/usr.bin/usbhidctl
brde at optusnet.com.au
Wed Jul 1 12:21:40 UTC 2009
On Tue, 30 Jun 2009, [utf-8] Dag-Erling SmÃ¸rgrav wrote:
> Bruce Evans <brde at optusnet.com.au> writes:
>> Actually, it is OK to use it in FreeBSD iff the system supports the
>> same program having different names, like reboot/halt/etc.
> I don't see the point - you would still need different usage messages
> for each version. Using your example:
> % reboot -h
> reboot: illegal option -- h
> usage: reboot [-dlnpq] [-k kernel]
> % halt -h
> halt: illegal option -- h
> usage: halt [-lnpq] [-k kernel]
> The code that implements this is needlessly complicated:
> static void
> (void)fprintf(stderr, "usage: %s [-%slnpq] [-k kernel]\n",
> getprogname(), dohalt ? "" : "d");
Yes, I missed that. I had only looked at an old version which was just
broken -- it always printed -[dnpq] (was also missing -l).
> The following is far more readable:
> static void
> (void)fprintf(stderr, dohalt ?
> "usage: halt [-lnpq] [-k kernel]\n" :
> "usage: reboot [-dlnpq] [-k kernel]\n");
However, this is broken since it doesn't handle the program being named
fasthalt or fastboot. The dohalt condition in the current version
barely works for these since fasthalt takes the same args as halt, etc.
I like using the `? :' operator in sub-expressions, but it only works
well for simpler statements than the above.
reboot in Lite2 uses it instead of getprogname(). reboot in Lite2
also has a home-made err() with another ?: instead of getprogname().
It uses "dohalt ? :", and this is actually correct since Lite2 doesn't
have fasthalt or fastboot, at least in reboot's own Makefile.
> BTW, there are numerous style issues in sbin/reboot/reboot.c.
Really? According to knfom, it is 94.772% knf (up from 94.520% in
~5.2 and 92.896% in Lite2). It is a small program so it is easy to
get right, but anything above 90% is a nice colour. (94.520% is due
to 7 lines fixed by indent(1) and 5 lines broken by indent(1)).
More information about the svn-src-head