[PATCH] one more hdparm patch with command line parsing bug fix

Tito farmatito at tiscali.it
Sun May 14 14:55:02 UTC 2006


On Saturday 13 May 2006 23:01, Tito wrote:
> On Saturday 13 May 2006 22:04, you wrote:
> > On Sat, May 13, 2006 at 09:24:48PM +0200, Tito wrote:
> > >On Saturday 13 May 2006 18:43, Bernhard Fischer wrote:
> > >> 
> 
> BTW:
> 
> +#define opt_noisy                      (1<<0)
> +#define opt_verbose                    (1<<1)
> +#define opt_get_identity       (1<<2)
> +#define opt_get_geom           (1<<3)
> +#define opt_quiet                      (1<<4)
> +#define opt_do_flush           (1<<5)
> +#define opt_do_ctimings                (1<<6)
> +#define opt_do_timings         (1<<7)
> 
> by doing this for all the options don't we risk to overflow static unsigned int opts = 1; /* noisy is on */
> as this was the problem that made impossible to use bb_getoptulflags without additonal patches from
> vodz and even with them it was very problematic.
> 
> Think that we have to manage 38 options
> 
> #define opt_38th      (1<<37)  ??? is this ok
> 
> Ciao,
> Tito
> 

Maybe something like this would resolve the problem of overflowing the var holding opts.

char opt[n]; /* initialize all to '\0' ? maybe memset or the compiler does it for us ? */

#define opt_noisy                     opt[0]
#define opt_verbose                opt[1]
#define opt_get_identity          opt[2]
#define opt_get_geom             opt[3]
#define opt_quiet                      opt[4]
#define opt_do_flush                opt[5]
#define opt_do_ctimings          opt[6]
#define opt_do_timings            opt[8]
#define set_*		                     opt[x]
#define get_*                             opt[y]

and so on.

to turn an option on 
opt[0] ='1';

to test

if (opt_verbose)                         /* if (opt[1])

So we could handle whatever number of flags (and/or commandline opts) with one char string
and remove about 60 long or int vars.

What do you think about it?

Ciao,
Tito



> > 
> > The set_* get_* should be treated the same way, i.e just mask the bits
> > which are set and use one unsigned long flgs or something like this.
> > 
> > Feel free to incooperate any of these changes into your patch.
> > 
> > Cheers and sorry for being grumpy
> > 



More information about the busybox mailing list