Options handler for userspace programs
Andrea Di Pasquale
spikey.it at gmail.com
Tue Nov 25 12:03:50 PST 2008
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[] = {
{"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° optional
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
>> options with arguments.
>> I wanna to propose new options handler that handle name or alias
>> for options and
>> option's argument, example no argument, required one or two
>> arguments, required
>> argument with 2° option argument and one or two optional arguments.
>> Can it useful for freebsd?
>> Regards,
>> Andrea_______________________________________________
>> freebsd-current at freebsd.org mailing list
>> http://lists.freebsd.org/mailman/listinfo/freebsd-current
>> To unsubscribe, send any mail to "freebsd-current-unsubscribe at freebsd.org
>> "
>
More information about the freebsd-current
mailing list