On Saturday 23 February 2008 17:17:57 walter harms wrote:
>
> Tito wrote:
> > On Saturday 23 February 2008 13:33:44 walter harms wrote:
> >> Tito wrote:
> >>> 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.
> >>>
> >> i tried and failed:
> >> opt_complementary = "-1:n+";
> >> opt = getopt32(argv, "+dtn:", &period);
> >>
> >> the '+' option is not mentioned in the libbb/getopt32.c of 1.9.1
> >> did i miss something ?
> >
> > It is in svn now....but OTOH maybe it is better to use a different solution
> > for period checking min and max values as procps 3.2.7
> >
> > /* maximum as in procps 3.2.7 */
> > period = xatou_range(str, 1, 999999999);
> > argv += optind;
> >
>
> -1 causes an error 'invalid number'
And 0?
> and 999999999/(3600*24*365)=31 but 2036 (when time() ends :) - 2008 = 28 so
> no need to worry about
> if someone likes to type long number he likes to wait long time also.
Maybe reducing the limit could be an idea?
period = xatou_range(str, 1, 3600*24*365);
>
>
> >>> int param; // "unsigned param;" will also work
> >>> opt_complementary = "p+";
> >>> getopt32(argv, "p:", ¶m);
> >>>
> >>>> 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...
> >>>
> >
> > Also one more optimization:
> >
> > cmd = *argv++;
> > while (*argv)
> > str = xasprintf("%s %s", cmd, *argv++);
> >
>
> that looks good.
>
>
> >>>> asprintf(&cmd,"%s",*argv );
> >>>> while (*++argv)
> >>>> asprintf(&cmd,"%s %s",cmd,*argv );
> >>>> while (1) {
> >> done, actualy this was already an older version of my watch.c seems i
> >> mixed something up :)
> >>
> >
> > One more optimization could be to move
> >
> > get_terminal_width_height(STDIN_FILENO, &width, 0);
> > header=xasprintf("Every %ds: %-*s", period, width, cmd);
> >
>
> i tought that also but any window resize will cause problems. These days i
> often use minicom/xterm to monitor and discover i have
> a much to small window .....
I see...in that case it would be better to free header every time as it leaks
memory.
> I was thinking about making the timefmt a comandline option, since most time
> you do not need year and friends. but how
> many strftime() return the required size when used with size=0 ? so i dropped
> the idea.
>
Ciao,
Tito
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox