Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Nov 2008 21:03:44 +0100
From:      Andrea Di Pasquale <spikey.it@gmail.com>
To:        freebsd-current@freebsd.org
Subject:   Re: Options handler for userspace programs
Message-ID:  <C529E93E-0463-4350-A4B9-39C731BD338E@gmail.com>
In-Reply-To: <492C360B.8080304@freebsd.org>
References:  <5D9F392B-97B5-4812-B5CB-047193715A94@gmail.com> <492C360B.8080304@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Yes but getopt() and getopt() are limited. They can to handle
only 2 options type, character and word. My idea is a main
type that handle all. For example,

Long options:			Short options:

interface					i
-interface				-i
--interface				--i

Both they can use one or two flag front the option. For example:

optarg_t opts[] =3D {
         {"interface",	"--i",		OPT_REQARG1},
         {"--filter",    	"f",    	OPT_REQARG2},
         {"-typed",      	"t",    	OPT_REQOPT},
         {"-status",     	NULL,  	OPT_OPTARG1},
         {"status",      	"-s",   	OPT_OPTARG2},
         {NULL,          	"--v",  	OPT_NOARG},
         {"help",        	"h",    	OPT_NOARG},
         {NULL,          	NULL,   	OPT_NULL}
};

and optarg_t is:

typedef enum optflag {
         OPT_NOARG,      	/* no arguments */
         OPT_REQARG1,    	/* required argument */
         OPT_REQARG2,    	/* required two arguments */
         OPT_REQOPT,     	/* required argument with 2=B0 optional =20=

argument */
         OPT_OPTARG1,    	/* optional argument */
         OPT_OPTARG2,    	/* optional two arguments */
         OPT_NULL
} optflag_t;

typedef struct optarg {
         const char   	*opt_name; 	/* option's name */
         const char  	*opt_alias;     /* option's alias */
         optflag_t		 opt_flag;
} optarg_t;

Thank you, regards
Andrea

Tim Kientzle wrote:

> Have you looked at getopt_long, which is in the standard
> FreeBSD C libraries?
>
> man 3 getopt_long
>
> The use of getopt() in most utilities instead of getopt_long()
> is a very deliberate choice.
>
> Tim Kientzle
>
>
> Andrea Di Pasquale wrote:
>> Hi! I seen that all freebsd' s programs use getopt() or sequence  =20
>> options with arguments.
>> I wanna to propose new options handler that handle name or alias =20
>> for  options and
>> option's argument, example no argument, required one or two =20
>> arguments,  required
>> argument with 2=B0 option argument and one or two optional arguments.
>> Can it useful for freebsd?
>> Regards,
>> Andrea_______________________________________________
>> freebsd-current@freebsd.org mailing list
>> http://lists.freebsd.org/mailman/listinfo/freebsd-current
>> To unsubscribe, send any mail to =
"freebsd-current-unsubscribe@freebsd.org=20
>> "
>




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?C529E93E-0463-4350-A4B9-39C731BD338E>