blob: b0a9164c24af385d498141ac8a5e14a467815535 [file] [log] [blame]
Rob Landley349ff522014-01-04 13:09:42 -06001<html><head><title>toybox cleanup</title></head>
Rob Landleyb7ca39c2013-09-05 23:58:35 -05002<!--#include file="header.html" -->
3
Rob Landley2b55d862014-01-01 15:00:44 -06004<h1>Index</h1>
5
6<ul>
7<li><a href=#intro>Introduction</a></li>
8<li><a href=#advice>Advice</a></li>
9<li>Commands:</li>
10<ul>
11<li><a href=#uuencode>uuencode</a></li>
12<li><a href=#uudecode>uudecode</a></li>
13<li><a href=#ifconfig>ifconfig</a></li>
14<li><a href=#find>find</a></li>
15</ul>
16</ul>
17
18<hr>
19
20<a name=intro />
Rob Landleyb7ca39c2013-09-05 23:58:35 -050021<h1>Cleaning up the toybox code.</h1>
22
Rob Landley2b55d862014-01-01 15:00:44 -060023<p>Toybox <a href=http://landley.net/notes.html#31-03-2013>hasn't always</a>
24taken proper advantage of external contributions</a>.
Rob Landleyb7ca39c2013-09-05 23:58:35 -050025Lots of people want to help, but their contributions languish out of tree
26or in the "pending" directory, awaiting cleanup.</p>
27
28<p>Toybox's design goals require simpler, tighter, and more explicit code
29than most other implementations, among other reasons to allow better security
30auditing. Writing "another" implementation of standard command line tools
31isn't very interesting, they should be _better_ implementations.
32Unfortunately, this means existing, working commands often take more effort to
33clean up to Toybox's standards than writing a new one from scratch, not
Rob Landley2b55d862014-01-01 15:00:44 -060034because they don't work, but because we aim for an unusual level of polish.</p>
Rob Landleyb7ca39c2013-09-05 23:58:35 -050035
36<p>In hopes of teaching more people how to do this
37cleanup work, I've started breaking cleanup changes into smaller chunks and
38posting explanations of each change to the mailing list.
Rob Landley2b55d862014-01-01 15:00:44 -060039Below are indexes of such cleanup series. Each commit and post are meant to
40be read together: each description explains what the corresponding patch
41was trying to accomplish.</p>
Rob Landleyb7ca39c2013-09-05 23:58:35 -050042
Rob Landley2b55d862014-01-01 15:00:44 -060043<p>Line/byte totals of completed series are given for scale, but the point
44of this work is simplicity and compactness, not size per se.</p>
45
46<p>(Note: mercurial's web viewer doesn't follow renames, so although each
47command name links to a commit list with the bulk of the changes, it may
48not include the final version of each file moved from the "pending"
Rob Landleyb7ca39c2013-09-05 23:58:35 -050049directory to its final location. The summaries link the initial and cleaned
50versions of each file when giving line counts.)</p>
51
52<hr>
53
Rob Landley2b55d862014-01-01 15:00:44 -060054<a name=advice />
55<h1>General advice and/or policy.</h1>
Rob Landleyb7ca39c2013-09-05 23:58:35 -050056
Rob Landley2b55d862014-01-01 15:00:44 -060057<p>The <a href=design.html>design of toybox</a> page and the coding
58style section at the start of the <a href=code.html>source code walkthrough</a>
59don't cover everything. Here are some
60links to mailing list messages that cover various programming topics
61not directly related to a specific cleanup series:</p>
Rob Landleyb7ca39c2013-09-05 23:58:35 -050062
Rob Landley2b55d862014-01-01 15:00:44 -060063<ul>
64<li><a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000850.html>Error messages and internationalization.</a></li>
65<li><a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000891.html>Why not "const"?</a></li>
66<li><a href=http://lkml.indiana.edu/hypermail/linux/kernel/1308.3/03890.html>Why not "bool"?</a> (explanation from Linus Torvalds)</li>
67<li><a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000893.html>Why not to check in debug code.</a></li>
68<li><a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-June/001044.html>Relationship between /proc and /sys</a> (/proc isn't obsolete and /sys is an ABI)</li>
69</ul>
Rob Landleyb7ca39c2013-09-05 23:58:35 -050070
71<hr>
72
Rob Landley2b55d862014-01-01 15:00:44 -060073<a name="uuencode"><h1><a href=/hg/toybox/log/900/toys/pending/uuencode.c>uuencode</a></h1>
Rob Landleyb7ca39c2013-09-05 23:58:35 -050074
Rob Landleya89f8aa2014-02-04 06:16:44 -060075<p>This is an example of cleaning up something most projects would be quite
76happy with. The initial submission of uuencode and uudecode was high
77quality code, written by a seasoned developer who did an excellent
78job, but it was still possible to shrink the result almost by half:</p>
Rob Landleyb7ca39c2013-09-05 23:58:35 -050079
80<ul>
81<li>old total: <a href=/hg/toybox/file/828/toys/pending/uuencode.c>116 lines (2743
82bytes) in 7 functions</a></li>
83<li>new total: <a href=/hg/toybox/file/841/toys/posix/uuencode.c>67 lines (1440
84bytes) in 1 function</a></li>
85</ul>
86
87<ul>
Rob Landleya89f8aa2014-02-04 06:16:44 -060088<li>commit: <a href=/hg/toybox/rev/830>830</a>: first pass, description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000904.html>part 1</a>,
Rob Landleyb7ca39c2013-09-05 23:58:35 -050089<a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000903.html>part 2</a></li>
90<li>commit: <a href=/hg/toybox/rev/831>831</a>,
Rob Landleya89f8aa2014-02-04 06:16:44 -060091second pass, description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000919.html>part 3</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -050092<li>commit: <a href=/hg/toybox/rev/837>837</a>,
Rob Landleya89f8aa2014-02-04 06:16:44 -060093description: fix test suite.</li>
94<li>commit: <a href=/hg/toybox/rev/853>853</a>, description: bugfix.</li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -050095</ul>
96
97<p>Status: COMPLETE</p>
98
Rob Landley2b55d862014-01-01 15:00:44 -060099<a name="uudecode"><h1><a href=/hg/toybox/log/900/toys/pending/uudecode.c>uudecode</a></h1>
100
Rob Landleya89f8aa2014-02-04 06:16:44 -0600101<p>The uudecode cleanup was my second "explain as I go along" cleanup,
102and I tried to do it in smaller stages so it was easier to see what
103changed from the diff:</p>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500104
105<ul>
106<li>old: <a href=/hg/toybox/file/828/toys/pending/uudecode.c>175
107lines (4534 bytes) in 9 functions</a></li>
108<li>new: <a href=/hg/toybox/file/840/toys/posix/uudecode.c>107 lines
109(2300 bytes) in 1 function</a></li>
110</ul>
111
112<ul>
113<li>commit: <a href=/hg/toybox/rev/833>833</a>,
114description: preparatory adjustments to test suite.</li>
115<li>commit: <a href=/hg/toybox/rev/835>835</a>,
116description: todo</a></li>
117<li>commit: <a href=/hg/toybox/rev/838>838</a>,
118description: todo</a></li>
119<li>commit: <a href=/hg/toybox/rev/839>839</a>,
120description: todo</a></li>
Rob Landleya89f8aa2014-02-04 06:16:44 -0600121<li>commit: <a href=/hg/toybox/rev/840>840</a>,
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500122description: todo (finish, move pending->posix, default y)</a></li>
123</ul>
124
125<p>Status: COMPLETE</p>
126
Rob Landley2b55d862014-01-01 15:00:44 -0600127<a name=ifconfig>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500128<h1><a href=/hg/toybox/log/tip/toys/pending/ifconfig.c>ifconfig</a></h1>
129
Rob Landleya89f8aa2014-02-04 06:16:44 -0600130<p>This series describes a thorough cleanup that took a while to do.</p>
131
Rob Landley2b55d862014-01-01 15:00:44 -0600132<p>When ifconfig was submitted, it touched a half-dozen files. I glued it
133together into a single self-contained file, which needed a lot of
134cleanup. The final version is about 1/3 the size of the original.</p>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500135
136<ul>
Rob Landley2b55d862014-01-01 15:00:44 -0600137<li>old total: <a href=/hg/toybox/file/841/toys/pending/ifconfig.c>1504 lines (44268 bytes) in 38 functions</a></li>
Rob Landleya89f8aa2014-02-04 06:16:44 -0600138<li>new total: <a href=/hg/toybox/file/1113/toys/other/ifconfig.c>521 lines (15963 bytes) in 4 functions</a></li>
Rob Landley2b55d862014-01-01 15:00:44 -0600139</ul>
140
141<p>This was the first command I started cleaning up with the intent of
142describing the process, and especially the first few entries in this
143series describe many of the low hanging fruit techniques used to clean
144up a codebase.</p>
145
146<ul>
147<li>commit: <a href=/hg/toybox/rev/843>843</a>, description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000882.html>Infrastructure in search of a user, code proximity,
148unnecessary #defines, shorter code is easier to read.</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500149<li>commit: <a href=/hg/toybox/rev/844>844</a>,
Rob Landley2b55d862014-01-01 15:00:44 -0600150description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000881.html>Headers, replacing repeated code with loops,
151logical operators guaranteed to return 0 or 1, math on string constants,
152removing unnecessary variables and tests.</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500153<li>commit: <a href=/hg/toybox/rev/852>852</a>,
Rob Landley2b55d862014-01-01 15:00:44 -0600154description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000921.html>hg commit numbers, documenting the obvious, ordering
155to avoid prototypes, returning void, collate local declarations,
156use error_exit(), unnecessary parentheses, inline to remove variables/functions
157used only once, using *var instead of var[0], unnecessary typecasts,
158xprintf("\n") vs xputc('\n')</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500159<li>commit: <a href=/hg/toybox/rev/856>856</a>,
Rob Landley2b55d862014-01-01 15:00:44 -0600160description: one line portability fix from Isaac Dunham</li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500161<li>commit: <a href=/hg/toybox/rev/861>861</a>
162and <a href=/hg/toybox/rev/863>863</a>,
163description:
164<a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000910.html>Help
165infrastructure cleanup from Isaac Dunham</a>
Rob Landley2b55d862014-01-01 15:00:44 -0600166(which I mis-applied and then <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000920.html>fixed plus some whitespace changes</a>)</li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500167
Rob Landleya89f8aa2014-02-04 06:16:44 -0600168<li>commit: <a href=/hg/toybox/rev/862>862</a>, description:
169<a href=http://lists.landley.net/pipermail/toybox-landley.net/2014-January/001525.html>remove unused headers and function, replace local buffer with toybuf, perror_exit(), avoid unnecessary assignment.</a></li>
170<li>commit: <a href=/hg/toybox/rev/864>864</a>, description:
171<a href=>blah</a></li>
172<li>commit: <a href=/hg/toybox/rev/866>866</a>, description:
173<a href=>blah</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500174
175<li>commit: <a href=/hg/toybox/rev/869>869</a> and <a href=/hg/toybox/rev/870>870</a>,
Rob Landley2b55d862014-01-01 15:00:44 -0600176description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000928.html>869:
177reorder to eliminate prototypes, put command_main() at end of file,
178870: long repeated variable prefixes, replacing struct+sscanf()+printf with a
179loop and a table (from iface_list, get_proc_info(), display_ifconfig()),
180use lib/xwrap.c functions to return void, why xstrcpy() fails closed,
181(functional comment: why multicast failed, CSLIP obsolecense), not being
182_too_ clever.</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500183<li>commit: <a href=/hg/toybox/rev/878>878</a> and <a href=/hg/toybox/rev/879>879</a>:
Rob Landley2b55d862014-01-01 15:00:44 -0600184description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000946.html>878: add xsocket(), free(NULL) is a safe NOP (posix!).
185879: inline three functions and simplify, some simplifications only show up
186after repeated inlining</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500187<li>commit: <a href=/hg/toybox/rev/883>883</a>,
Rob Landley2b55d862014-01-01 15:00:44 -0600188description: move some common code to lib/ and posix headers to toys.h.</li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500189<li>commit: <a href=/hg/toybox/rev/898>898</a>,
Rob Landleya89f8aa2014-02-04 06:16:44 -0600190description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-May/000974.html>Argument parsing. (Replace ifconfig_main() if/else staircase with a loop over
191an array, genericize minus prefix logic, inline a use of set_flags().)</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500192<li>commit: <a href=/hg/toybox/rev/905>905</a>,
Rob Landley2b55d862014-01-01 15:00:44 -0600193description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-May/000992.html>remove unnecessary wrapper function, inlining more functions,
194relying on the values of constants that don't change across architectures
195(binary backwards compatability), more ifconfig_main table work,
196man ioctl_list.</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500197<li>commit: <a href=/hg/toybox/rev/906>906</a>,
Rob Landley2b55d862014-01-01 15:00:44 -0600198description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-May/000994.html>More ifconfig_main() table work, remove vestigial arguments
199to functions, "a frenzy of inlining", slightly better error reporting,
200don't reinvent libc functions.</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500201<li>commit: <a href=/hg/toybox/rev/907>907</a>,
Rob Landley2b55d862014-01-01 15:00:44 -0600202<a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-May/000995.html>inlining show_ip_addr() with a loop and a table, inlining hex_to_binary()
203and set_hw_address(), stop validating data we supplied, remove a table
204that's overkill (two entries, we don't even loop over it), when you don't need a
205NULL terminator for array, remove unnecessary memcpy(offsetof()) with
206assignment, trusting -funsigned-char.</a></li>
207<li>commit: <a href=/hg/toybox/rev/919>919</a>,
208<a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-June/001027.html>todo whitespace damage, introduce IFREQ_OFFSZ() and poke() to
209ifconfig_main() table logic to fold more if/else parts into the table</a></li>
210<li>Status update: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-June/001033.html>Entering the home stretch on ifconfig</a> (and a <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-June/001043.html>note about infiniband</a>)</li>
211<li>commit: <a href=/hg/toybox/rev/921>921</a>, description: todo</li>
212<li>commit: <a href=/hg/toybox/rev/957>957</a>, description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-July/001121.html>here</a></li>
213<li>commit: <a href=/hg/toybox/rev/958>958</a>, description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-July/001131.html>here</a></li>
214<li>commit: <a href=/hg/toybox/rev/1104>1104</a>, description: todo</li>
215<li>commit: <a href=/hg/toybox/rev/1127>1127</a>, description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-November/001464.html>here</a></li>
216<li>commit: <a href=/hg/toybox/rev/1128>1128</a>, description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-November/001463.html>here</a></li>
217<li>commit: <a href=/hg/toybox/rev/1132>1132</a>, description: promotion from pending to other</li>
218<li>commit: <a href=/hg/toybox/rev/1132>1133</a>, description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-November/001462.html>cleanup help text, remove obsolete/NOP commands</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500219</ul>
220
Rob Landley2b55d862014-01-01 15:00:44 -0600221<p>Status: COMPLETE.</p>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500222
223<h1><a href=/hg/toybox/log/tip/toys/pending/find.c>find</a></h1>
224
225<pre>
226814 Initial version by Gurang Shastri.
227815
228816
229847 Felix Janda
230848 Whitespace (reindent from tabs -> 2 spaces)
231849 More cleanup
232867 Felix Janda Improve operator processing.
233874 Felix Janda
234875 Felix Janda
235887 Felix Janda fix -mtime
236</pre>
237
238<ul>
239<li>commit: <a href=/hg/toybox/rev/849>849</a>,
240description: <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000895.html>here</a></li>
241</ul>
242
243<p>Status: in progress.</p>
244
245<h1><a href=/hg/toybox/log/917/toys/pending/stat.c>stat</a></h1>
246
Rob Landleya89f8aa2014-02-04 06:16:44 -0600247<p>A lot of the stat cleanup was done by Felix Janda.</p>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500248
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500249<ul>
Rob Landleya89f8aa2014-02-04 06:16:44 -0600250<li>commit <a href=/hg/toybox/rev/747>747</a>: initial submission</a></li>
251<li>commit <a href=/hg/toybox/rev/810>810</a>: whitespace</li>
252<li>commit <a href=/hg/toybox/rev/811>811</a>: description in commit message.</li>
253<li>commit <a href=/hg/toybox/rev/871>871</a>: whitespace (reindent from 4 spaces to 2)</li>
254<li>commit <a href=/hg/toybox/rev/872>872</a>: Felix Janda - <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000923.html>cleanup</a> (with discussion thread)</li>
255<li>commit <a href=/hg/toybox/rev/875>885</a>: Felix Janda - <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000936.html>move permission formatting (777 -> -rwxrwxrwx) from ls to lib so stat can reuse it.</a></li>
256<li>commit <a href=/hg/toybox/rev/885>886</a>: Felix Janda - remove unimplemented options and clean up help text</li>
257<li>commit <a href=/hg/toybox/rev/910>910</a>: Felix Janda - <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-May/001013.html>Add support for stating multiple files</a>.</li>
258<li>commit <a href=/hg/toybox/rev/911>911</a>: Felix Janda - Separate stat and statfs, give stat_main() a ds[2] array to distinguish FLAG_f vs not cases, and some whitespace changes.</li>
259<li>commit <a href=/hg/toybox/rev/912>912</a>: description in commit message (also <a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-May/001019.html>here</a>)</li>
260<li><a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-May/001024.html>design pondering</a> (leading to peek() function in lib/)</li>
261
262<li>commit <a href=/hg/toybox/rev/914>914</a>: description in commit message.</li>
263<li>commit <a href=/hg/toybox/rev/916>916</a>: description in commit message.</li>
264<li>commit: <a href=/hg/toybox/rev/917>917</a>: description in commit message.</li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500265<li>commit: <a href=/hg/toybox/rev/918>918</a>,
Rob Landleya89f8aa2014-02-04 06:16:44 -0600266description: done: move pending to posix, default y, no other changes</a>.</li>
267<li><a href=http://lists.landley.net/pipermail/toybox-landley.net/2013-June/001026.html>summary</a></li>
Rob Landleyb7ca39c2013-09-05 23:58:35 -0500268</ul>
269
270<p>Status: COMPLETE.</p>
271
272<!--#include file="footer.html" -->