[Toybox] Looking at nl

Rob Landley rob at landley.net
Sun May 26 19:14:16 PDT 2013


On 05/25/2013 06:36:49 PM, idunham at lavabit.com wrote:
> Would initializing GLOBALS to the defaults be something sane to allow,
> or would it complicate the build system too much?

Actually, now that I look at it, you can initialize the numerical ones  
in the option strings. (Boundary checking was fairly common, and  
setting a default is pretty much the same infrastructure.)

> Example:
> USE_NL(NEWTOY(wc, "1b:d:f:h:i#l#n:ps:v#w#", TOYBOX_USR | TOYBOX_BIN))

USE_NL(NEWTOY(wc, "1b:d:f:h:i#=1l#=1n:ps:v#=1w#=6"));

> ..
> GLOBALS(
> char *btype = "t";
> char *delim = "\:";
> char *ftype = "n";
> char *htype = "n";
> long incr = 1;
> long maxblank = 1;
> char *fmt = "rn";
> char *sep = "\t";
> long startnum = 1;
> long width = 6;
> )

If you stick the numerical defaults in the options string, you only  
have to initialize the string variables.

I didn't implement similar initialization logic for strings because A)  
there's no existing bounds checking logic to leverage, B) how do you  
know where the end of the string is, C) it complicates the "#define  
FLAG_x" generation logic because ordinarily "next letter" means start  
of new option. The signaling is done entirely with punctuation and  
digits.

Rob
 1369620856.0


More information about the Toybox mailing list