[Toybox] toybox - expand

Rob Landley rob at landley.net
Tue Nov 27 11:55:28 PST 2012


Top posting, fun for the whole family!

Ok, I've merged your commit. (I note I slightly prefer hg import/export  
because it's more easily human readable before I apply it, but the  
bundle was only two commits.)

Cleanups:

In the main() function, single line comments explaining what a single  
line does probably aren't necessary. We can assume that readers are  
familiar with common infrastructure like "loopfiles", and if they're  
not there's a main docs page covering the infrastructure. So  
loopfiles(expand_file) is pretty much going to expand the files in a  
3-line main.

Make the freeing code right before exit depend on CFG_TOYBOX_FREE. In  
theory we don't have to waste space on resource freeing if the OS is  
going to do it for us when the process exits. In practice, people like  
to run things like valgrind against code to find memory leaks so being  
able to free it says "we know about this one". The interesting memory  
leaks are the ones that depend on size of input, so if we leak 100  
bytes per line processed and get a million line input file, that's bad.  
Note that command line arguments have to fit in 128k on linux:

   http://landley.net/notes-2011.html#17-12-2011

so there's built-in size limitations on the amount of input you can get  
from the command line even with something like xargs, so being lax  
about freeing stuff source from there is less likely to bite you. But  
input from stdin or a file can go on forever.

Jumping up to the top: the help text is very long. It winds up in the  
binary _and_ may be read by people who don't have english as their  
first language, so trimming it down serves multiple purposes.

Also, the URL to the standard is wrong, the correct one is...

What the heck happened to the open group's server? Ah, I see,  
pubs.opengroup.org/onlinepubs goes to www3.opengroup.org and just  
opengroup.org/onlinepubs goes to www5.opengroup.org and the www5 one is  
being retired and they've got different contents. Beautiful  
sysadminning, guys...

Anyway, changing it to:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/expand.html

And I'll figure out if I need to change the rest of the URLs after the  
30th, I guess?

More to come,

Rob

On 11/26/2012 03:32:28 AM, Jonathan Clairembault wrote:
> Hi,
> 
> Here is the complete version. That's basically a hundred lines + the  
> tests.
> 
> Jonathan
> 
> On Fri, Nov 23, 2012 at 12:19 AM, Jonathan Clairembault
> <jonathan at clairembault.fr> wrote:
> > Hi Rob,
> >
> > I find ToyBox cool. I've started to hack. As an "hello world", I've
> > coded expand. It is not completely finished as it does not handle
> > backspace yet. Though I'll let you review my code and merge it if  
> you
> > want to.
> >
> > Some performance tests run on rhel5:
> >
> > jclairem at naboo - 21:18:02 -~/src/toybox
> > $sudo time -p find /etc -type f -exec ./toybox expand {} + >  
> /dev/null
> > real 1.87
> > user 1.01
> > sys 0.60
> > jclairem at naboo - 21:18:12 -~/src/toybox
> > $sudo time -p find /etc -type f -exec expand {} + > /dev/null
> > real 6.30
> > user 6.14
> > sys 0.11
> >
> > --
> > wbr, Jonathan
> 


 1354046128.0


More information about the Toybox mailing list