[Toybox] [CLEANUP] lspci first pass
Rob Landley
rob at landley.net
Sun May 18 17:58:49 PDT 2014
http://landley.net/hg/toybox/rev/1289
Headers info:
As long as we've got a config LSPCI_TEXT, have the -n option live there.
Add a USE() guard in the NEWTOY() line, and move the help text around to
take advantage of the build infrastructure's ability to collate it.
Remove unnecessary prototype of find_in_db(), which is now local.
Coding style tweaks:
Remove space between * and thing that's a pointer.
Move variable declartions to the start of each block. (I know c99 allows
them to live anywhere, but the lifetime's the same anyway, and it's
easiest to spot 'em at the start, with a blank line between variable
declarations and other code.)
Say ! instead of == NULL, *blah instead of blah[0] (unless we're
referring to multiple elements of the same array, in which case
consistency the _other_ way can win).
Remove unnecessary parentheses. I still leave them around (val & mask)
because Dennis Ritchie himself admitted the priority of that was wrong,
but if (a == b || c == d) should be fairly well understood.
I moved "succeeded in matching both" to its own line because I prefer
comments before a line rather than comments at the end of a line. It's
not an absolute prohibition, but comments are something to be used
sparingly because they so easily fall out of sync with the code and
become misleading. (And because comments are not a substitute for
readable code, sometimes the comment is a substitute for choosing a more
descriptive variable name or similar.) In ifconfig I used comments on
the same line when I inlined a magic value there was a macro for, but I
couldn't #include it in a portable manner, so there are times it makes
sense...
do_lspci():
Instead of strcmp the path (and thus having the path in two places), I
just checked if this node's parent was null or not. (Null parent means
top of tree, which is what we're checking for here.)
Haven't quite pulled apart the sequencing of this function yet: we
memset all of toybuf to zeroes, and then still need p[size] = 0. I
suspect we don't need _both_ of those, but have to read more to work out
why the memset...
The if (errno) block can turn into if (!errno) return and then the rest
gets unintended, but I haven't done that because I have to move variable
declarations around and haven't read this bit of the code too deeply yet...
Rob
1400461129.0
More information about the Toybox
mailing list