[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [BusyBox] re: long args in bb_getopt_ulflags()
From:       Paul Fox <pgf () brightstareng ! com>
Date:       2005-01-31 20:54:53
Message-ID: 9442.1107204893 () brightstareng ! com
[Download RAW message or body]

> On Monday 31 January 2005 17:36, Paul Fox wrote:
 > >  > Paul,
 > >  > 
 > >  > > hi tito.  i'm sorry, i was unclear in my statement above.  yes,
 > >  > > your example works fine, but "--version" is just a flag option --
 > >  > > there's no optarg associated with it.  i should have said:  if a
 > >  > > long option needs to have an argument, and there's no short
 > >  > > option equivalent for that option, then you can't get the
 > >  > > argument using bb_getop_ulflags().
 > 
 > Hi to all, 
 > one more example.
 > I know that the code is rather ugly and bloated but it does
 > the work and is easy to understand.

tito -- didn't i say i had done this?  did you look at my
patch?  this is exactly what my patch does, except that i called
getopt_long() to loop through the options the second time,
instead of doing it by hand.

paul

 > 
 > int strings_main(int argc, char **argv)
 > {
 > 	int n, c, i = 0, status = EXIT_SUCCESS;
 > 	unsigned long opt;
 > 	unsigned long count;
 > 	FILE *file = stdin;
 > 	char *string;
 > 	const char *fmt = "%s: ";
 > 	char *n_arg = "4";
 > 	int color=0;
 > 	
 > 	struct option strings_long_options[] = {
 > 		{ "color", 0, &color, -1 },
 > 		{ 0,         0, 0, 0 }
 > 	};
 > 	
 > 	bb_applet_long_options = strings_long_options;
 > 		
 > 	opt = bb_getopt_ulflags (argc, argv, "afon:", &n_arg);
 > 	/* -a is our default behaviour */
 > 	
 > 	if(color == -1) {
 > 		for (i=0;i<argc;i++) {
 > 			printf("%d %s\n",i, argv[i]); /* debug */
 > 			if(strcmp(argv[i],"--color=never")==0) {
 > 				color=0;
 > 			}
 > 			if(strcmp(argv[i],"--color=always")==0) {
 > 				color=1;
 > 			}
 > 			if(strcmp(argv[i],"--color=auto")==0) {
 > 				color=2;
 > 			}
 > 		} 
 > 		printf("color %d\n", color); /* debug */
 > 		if(color == -1) /* no optarg, assume color=always */ 
 > 			color=1;
 > 	}
 > 	i=0; 
 > 	argc -= optind;
 > 	argv += optind;
 > 
 > and so on........ 
 > Just an idea.
 > 
 > Ciao,
 > Tito
 > _______________________________________________
 > busybox mailing list
 > busybox@mail.busybox.net
 > http://codepoet.org/mailman/listinfo/busybox

=---------------------
 paul fox, pgf@brightstareng.com


_______________________________________________
busybox mailing list
busybox@mail.busybox.net
http://codepoet.org/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic