diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2003-01-16 13:43:05 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2003-01-16 13:43:05 +0000 |
commit | cd9a5361ab0416c7be112c84758745120a8fc014 (patch) | |
tree | 498c97019a5c975ce4c339dd28ca84288f9d839d /mh/mh_getopt.c | |
parent | 8e10585386d7e33eb62e2f1e0c708350798cb261 (diff) | |
download | mailutils-cd9a5361ab0416c7be112c84758745120a8fc014.tar.gz mailutils-cd9a5361ab0416c7be112c84758745120a8fc014.tar.bz2 |
(mh_getopt): Rewritten. The main purpose is
to expand old-style options to their double-dash equivalents.
(mh_argv_preproc): New function. Preprocess the argv array.
Diffstat (limited to 'mh/mh_getopt.c')
-rw-r--r-- | mh/mh_getopt.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c index b1a745a4f..71183bc09 100644 --- a/mh/mh_getopt.c +++ b/mh/mh_getopt.c @@ -25,9 +25,9 @@ #include <stdlib.h> #include <mh_getopt.h> -int mh_optind = 1; -char *mh_optarg; -char *mh_optptr; +static int mh_optind = 1; +static char *mh_optarg; +static char *mh_optptr; int mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc) @@ -46,8 +46,11 @@ mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc) return '+'; } - if (mh_optptr[0] != '-') - return EOF; + if (mh_optptr[0] != '-' || mh_optptr[1] == '-') + { + mh_optind++; + return 0; + } optlen = strlen (mh_optptr+1); for (p = mh_opt; p->opt; p++) @@ -64,6 +67,7 @@ mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc) if (p->opt) { + char *longopt = p->longopt ? p->longopt : p->opt; switch (p->flags) { case MH_OPT_BOOL: @@ -71,17 +75,20 @@ mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc) mh_optarg = "no"; else mh_optarg = "yes"; + asprintf (&argv[mh_optind], "--%s=%s", longopt, mh_optarg); break; case MH_OPT_ARG: + asprintf (&argv[mh_optind], "--%s", longopt); mh_optarg = argv[++mh_optind]; break; default: + asprintf (&argv[mh_optind], "--%s", longopt); mh_optarg = NULL; } mh_optind++; - return p->key; + return 1; } else if (!strcmp (mh_optptr+1, "help")) { @@ -92,6 +99,14 @@ mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc) } void +mh_argv_preproc (int argc, char **argv, struct mh_argp_data *data) +{ + mh_optind = 1; + while (mh_getopt (argc, argv, data->mh_option, data->doc) != EOF) + ; +} + +void mh_help (struct mh_option *mh_opt, const char *doc) { struct mh_option *p; |