On Friday 22 February 2008 19:13:51 walter harms wrote:
> hi list,
> this simplifies the coding of the watch utility.
> I does not save much bytes but it thing it is easier to read
> now. I have changed the date time display as the old one eat
> to much space.
> 
> Note:
> perhaps it even make sense to make the time display dynamic
> if someone is bored ,,,
> 
> 
> re,
>  wh
> 
> 
> 

Hi,

>int watch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
>int watch_main(int argc, char **argv)
>{
>        unsigned opt;
>        unsigned period = 2;
>        char *header = NULL;
>        char *cmd;
>
>        opt_complementary = "-1"; // at least one param please
>        opt = getopt32(argv, "+dtn:", &cmd);
>
>      if (opt & 0x4) period = xatou(cmd);

        getopt32 can do this for us:
"a+:"  A plus after a char in opt_complementary means that the parameter
        for this option is a nonnegative integer. It will be processed
        with xatoi_u() - allowed range is 0..INT_MAX.

        int param;  // "unsigned param;" will also work
        opt_complementary = "p+";
        getopt32(argv, "p:", &param);  

>        argv += optind;
>        cmd=NULL;
   
Maybe char *xasprintf(const char *format, ...) because it checks 
for malloc errors and is portable on systems that don't have asprintf...
     
>        asprintf(&cmd,"%s",*argv );
>        while (*++argv)
>            asprintf(&cmd,"%s %s",cmd,*argv );

>        while (1) {

Just my 2 cents. ;-)

Ciao,
Tito


BTW, coding style in some places is bad:
strftime(header + width - len,len,"%Y-%m-%d %H:%M:%S",localtime(&t));
no spaces between args.
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to