On Tue, 30 Jun 2009, [utf-8] Dag-Erling Sm??rgrav wrote:
Bruce Evans <b...@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
usage()
{
(void)fprintf(stderr, "usage: %s [-%slnpq] [-k kernel]\n",
getprogname(), dohalt ? "" : "d");
exit(1);
}
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
usage(void)
{
(void)fprintf(stderr, dohalt ?
"usage: halt [-lnpq] [-k kernel]\n" :
"usage: reboot [-dlnpq] [-k kernel]\n");
exit(1);
}
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)).
Bruce
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"