Was Re: Ping - pstree + minor patch

David Collier from_busybox_maillist at dexdyne.com
Mon Dec 6 10:12:00 UTC 2010


In article <201012051558.26388.farmatito at tiscali.it>,
farmatito at tiscali.it (Tito) wrote:

> *From:* Tito <farmatito at tiscali.it>
> *To:* busybox at busybox.net
> *Date:* Sun, 5 Dec 2010 15:58:26 +0100
> 
> On Sunday 05 December 2010 15:03:25 Denys Vlasenko wrote:
> > On Sunday 05 December 2010 10:00, Lauri Kasanen wrote:
> > > -		} else if (*here >= ' ' && *here <= '~') {
> > > +		} else if (*here >= ' ' && *here < 0x7f) {
> > > 
> > > This makes it less readable. Why replace the char with a hex 
> > value?
> > 
> > It is less obvious that '~' is the last ASCII character.
> Hi,
> maybe using 127 would be easier to understand for self-taught 
> people like me ;-)

maybe 
#define last_ascii 127

but I have to admit that if you are going to piddle around with this
stuff, you need to learn hex first. What pisses me off is having to learn
octal!

:-)




> a la char = int as in putchar(int c).
> 
> > 
> > > -	if (argc > 1) bb_show_usage();
> > > -	else if (argc == 1) {
> > > -		if (*argv[0] >= '0' && *argv[0] <= '9') {
> > > +	if (argv[0]) {
> > > 
> > > I've been meaning to ask you about this. When I try to do the 
> > same,
> > > I end up usually getting a segfault. That was before any getopt 
> > too, maybe that has an effect.
> > 
> > It should not segfault. Can you reproduce SEGV?
> > 
> > > -	G.output_width = 132;
> > > 
> > > By removing the default, what happens if 
> > get_terminal_width_height can't > get the real width?
> > 
> > get_terminal_width_height returns 80 for width if it fails to 
> > determine it.
> > 
> 
> 
> Attached also a minor optimization and cleanup patch that saves a 
> few bytes and a few lines.
> Please apply if you like it.
> 
> Ciao,
> Tito
> 
>  diff -uN procps/pstree.c.orig procps/pstree.c
> --- procps/pstree.c.orig        2010-12-05 15:17:48.000000000 +0100
> +++ procps/pstree.c     2010-12-05 15:52:26.000000000 +0100
> @@ -95,16 +95,6 @@
>         }
>  }
> 
> -#if ENABLE_FEATURE_CLEAN_UP
> -static void maybe_free_buffers(void)
> -{
> -       free(G.width);
> -       free(G.more);
> -}
> -#else
> -# define maybe_free_buffers() ((void)0)
> -#endif
> -
>  /* NB: this function is never called with "bad" chars
>   * (control chars or chars >= 0x7f)
>   */
> @@ -385,13 +375,11 @@
>         G.cur_x = 1;
> 
>  //     get_terminal_width_height(1, &G.output_width, NULL);
> -
> +       opt_complementary = "?1";
>         getopt32(argv, "p");
>         argv += optind;
> 
>         if (argv[0]) {
> -               if (argv[1])
> -                       bb_show_usage();
>                 if (argv[0][0] >= '0' && argv[0][0] <= '9') {
>                         pid = xatoi(argv[0]);
>                 } else {
> @@ -410,6 +398,9 @@
>                 }
>         }
> 
> -       maybe_free_buffers();
> +       if (ENABLE_FEATURE_CLEAN_UP) {
> +               free(G.width);
> +               free(G.more);
> +       }
>         return 0;
>  }
> 
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
> 
> --
> *Included Files:*
> am2file:001-pstree.patch


More information about the busybox mailing list