[BusyBox] bb_opt_complementaly request

Tito farmatito at tiscali.it
Thu Dec 9 19:56:12 UTC 2004


On Thursday 09 December 2004 OO:07, Vladimir N. Oleynik wrote:
> Tito,
> 
> Thanks.
> Small corrections:
> 
> 1) This paragraph describes absolutely not that idea:
> 
> > Format:
Are this the erroneus statements?
 one char : one option to check for;
 chars    : set of options to check for.
> > ":"      : is used in bb_opt_complementaly as separator between two chars
> >            or groups of chars and special characters (stating some conditions to
> >            be checked).
> >            
> >            If one of the given options is found  a flag value is added to
> >            unsigned long bb_getopt_ulflags.
> >            
> >            The value of this flag is given by the position of the char in
> >            const char *applet_opts so for example in this case:
> >  
> >            flags = bb_getopt_ulflags(argc, argv, "rnug");
> >  
> >            "r" will add 1
> >            "n" will add 2
> >            "u  will add 4
> >            "g" will add 8
> >    
> >            and so on.
> >            If an argument is required by one of the switches add a ":"
> >            after the char in const char *applet_opts:
> > 
> >            flags = bb_getopt_ulflags(argc, argv, "a:b:c:d:");
> 
> Really idea is:
> if
> bb_opt_complementaly = "abc";
> and getopt() find "-a", then bb_getopt_ulflags return as it were
> "-a -b -c" found.
Hi, vodz,
Ok, i think that i've understood, i will modify the text and resend it.

What is when
 bb_opt_complementaly = "a";  ?
> > Special characters:
> > 
> > "-"      : a dash between two options cause the second of the two
> >            to be unset (ignored ) if it is given on the command line.
> >            For example:
> >            the du applet can have the options "-s" and "-d size"
> >            If bb_getopt_ulflags finds -s then -d is unset or if it
> >            finds -d then -s is unset.
> >            In this case the return value has no error flag set (0x80000000UL).
> >            To achieve this result you must set bb_opt_complementaly = "s-d:d-s".
> >            Only one flag value is added to unsigned long bb_getopt_ulflags
> >            depending on the position of the switches on the command line.
> >            If one of the two switches requires an argument pointer 
> >            (":" in const char *applet_opts as in "d:") optarg is
> >            set accordingly.
> >    
> >           char *smax_print_depth;
> >   
> >           bb_opt_complementaly = "s-d:d-s";
> >           opt = bb_getopt_ulflags(argc, argv, "s" "d:" , &smax_print_depth);
> > 
> >          if((opt & (1 << 6))) {
Just  copied the code from du .

    		if((opt & (1))) {    or     if((opt & (1 << 1))) {
> Why "6"? Must "1".
> 
> > "~"      : a tilde between two options or between an option and a group
> >            of options means that they are mutually exclusive.
> >            For example:
> >            the cut applet must have only one type of list specified,
> >            so -b, -c and -f are mutally exclusive and should raise an error
> >            if specified together ( this means that they could not 
> >            be simply ignored using the "-" dash char).
> >            In this case you must set bb_opt_complementaly = "b~cf:c~bf:f~bc".
> >            If one of the mutually exclusive options is found the return value
> >            will have the error flag set (0x80000000UL) so that we can check for it:
> >    
> >            if ((flags & 0x80000000UL)
> >                    bb_show_usage();
> >    
> > "*"      : a star after a char in bb_opt_complementaly means that the option
> >            can have one or more arguments.
> >            For example:
> >            the grep applet can have one or more "-e pattern" arguments.
> >            In this case you should use bb_getopt_ulflags() as follows:
> > 
> >            llist_t *patterns;  as returned by *llist_add_to(llist_t *old_head, char *new_item)
> 
> Time we bring changes I would like to concentrate attention here on a typical 
> mistake on which I and itself came across.
> 
ok. I will specify in the text.
> llist_t *patterns = NULL;	/* must initialized */
> 
> 
> 
> --w
> vodz
> 



More information about the busybox mailing list