Toybox's design goals require simpler, tighter, and more explicit code
than most other implementations, among other reasons to allow better security
auditing. Writing "another" implementation of standard command line tools
isn't very interesting, they should be _better_ implementations.
Unfortunately, this means existing, working commands often take more effort to
clean up to Toybox's standards than writing a new one from scratch, not
because they don't work, but because we aim for an unusual level of polish.
In hopes of teaching more people how to do this
cleanup work, I've started breaking cleanup changes into smaller chunks and
posting explanations of each change to the mailing list.
Below are indexes of such cleanup series. Each commit and post are meant to
be read together: each description explains what the corresponding patch
was trying to accomplish.
Line/byte totals of completed series are given for scale, but the point
of this work is simplicity and compactness, not size per se.
(Note: mercurial's web viewer doesn't follow renames, so although each
command name links to a commit list with the bulk of the changes, it may
not include the final version of each file moved from the "pending"
directory to its final location. The summaries link the initial and cleaned
versions of each file when giving line counts.)
This series describes a thorough cleanup that took a while to do.
When ifconfig was submitted, it touched a half-dozen files. I glued it
together into a single self-contained file, which needed a lot of
cleanup. The final version is about 1/3 the size of the original.
This was the first command I started cleaning up with the intent of
describing the process, and especially the first few entries in this
series describe many of the low hanging fruit techniques used to clean
up a codebase.
- commit: 843, description: Infrastructure in search of a user, code proximity,
unnecessary #defines, shorter code is easier to read.
- commit: 844,
description: Headers, replacing repeated code with loops,
logical operators guaranteed to return 0 or 1, math on string constants,
removing unnecessary variables and tests.
- commit: 852,
description: hg commit numbers, documenting the obvious, ordering
to avoid prototypes, returning void, collate local declarations,
use error_exit(), unnecessary parentheses, inline to remove variables/functions
used only once, using *var instead of var[0], unnecessary typecasts,
xprintf("\n") vs xputc('\n')
- commit: 856,
description: one line portability fix from Isaac Dunham
- commit: 861
and 863,
description:
Help
infrastructure cleanup from Isaac Dunham
(which I mis-applied and then fixed plus some whitespace changes)
- commit: 862, description:
remove unused headers and function, replace local buffer with toybuf, perror_exit(), avoid unnecessary assignment.
- commit: 864, description:
use common linked list functions, inline set_data, add xioctl, clean up error messages, whitespace and comment tweaks, remove NOP return statements
- commit: 866, description:
move standalone globals into GLOBALS() block, collate structs into
iface_list. Inline/rewrite/remove field_format, iface_flags_str,
omit_whitespace(), print_iface_flags(), print_media(), get_ifconfig_info(),
and clear_list(). Merge duplicate function
calls. Show get_proc_info() version field can't matter in 2.6 or newer kernel,
and that SIOCGIFMAP has been there since 1994 so doesn't need an #ifdef.
Loop simplification in readconf() and show_iface().
- commit: 869 and 870,
description: 869:
reorder to eliminate prototypes, put command_main() at end of file,
870: long repeated variable prefixes, replacing struct+sscanf()+printf with a
loop and a table (from iface_list, get_proc_info(), display_ifconfig()),
use lib/xwrap.c functions to return void, why xstrcpy() fails closed,
(functional comment: why multicast failed, CSLIP obsolecense), not being
_too_ clever.
- commit: 878 and 879:
description: 878: add xsocket(), free(NULL) is a safe NOP (posix!).
879: inline three functions and simplify, some simplifications only show up
after repeated inlining
- commit: 883,
description: move some common code to lib/ and posix headers to toys.h.
- commit: 898,
description: Argument parsing. (Replace ifconfig_main() if/else staircase with a loop over
an array, genericize minus prefix logic, inline a use of set_flags().)
- commit: 905,
description: remove unnecessary wrapper function, inlining more functions,
relying on the values of constants that don't change across architectures
(binary backwards compatability), more ifconfig_main table work,
man ioctl_list.
- commit: 906,
description: More ifconfig_main() table work, remove vestigial arguments
to functions, "a frenzy of inlining", slightly better error reporting,
don't reinvent libc functions.
- commit: 907,
inlining show_ip_addr() with a loop and a table, inlining hex_to_binary()
and set_hw_address(), stop validating data we supplied, remove a table
that's overkill (two entries, we don't even loop over it), when you don't need a
NULL terminator for array, remove unnecessary memcpy(offsetof()) with
assignment, trusting -funsigned-char.
- commit: 919,
todo whitespace damage, introduce IFREQ_OFFSZ() and poke() to
ifconfig_main() table logic to fold more if/else parts into the table
- Status update: Entering the home stretch on ifconfig (and a note about infiniband)
- commit: 921, description: Inline a couple more functions and make sockfd a global.
- commit: 957, description: Remove unused socklen and addr_to_len(), cleanup so we can merge get_device_info()/display_ifconfig().
- commit: 958, description: This commit removes struct if_list by unifying get_device_info() and display_ifconfig().
- commit: 1104, description: Merge toynet into toys.h: musl supports it and micromanaging uClibc config options isn't very interesting anymore.
- commit: 1127, description: Start tacling ipv6 issues, beginning with display_ifconfig().
- commit: 1128, description: More ipv6, make struct sockaddr_with_len go away, merge more arguments into the table in main().
- commit: 1132, description: promotion from pending to other
- commit: 1133, description: cleanup help text, remove obsolete/NOP commands
Status: COMPLETE.
814 Initial version by Gurang Shastri.
815
816
847 Felix Janda
848 Whitespace (reindent from tabs -> 2 spaces)
849 More cleanup
867 Felix Janda Improve operator processing.
874 Felix Janda
875 Felix Janda
887 Felix Janda fix -mtime
Status: in progress.
A lot of the stat cleanup was done by Felix Janda.
- commit 747: initial submission
Status: COMPLETE.