diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-10-21 17:48:26 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-10-21 17:57:59 +0300 |
commit | f434857b8318b05b7036025605ab18cdf3e7c238 (patch) | |
tree | 28223e6cc500a5f82f561ce0677d30a266ad8f8d | |
parent | 53eb68133eeede20c49445cd4ff58ad6e4becc07 (diff) | |
download | mailutils-f434857b8318b05b7036025605ab18cdf3e7c238.tar.gz mailutils-f434857b8318b05b7036025605ab18cdf3e7c238.tar.bz2 |
Begin rewriting MH to get rid of argp stuff.
MH utilities will use only single-dash long options.
* include/mailutils/opt.h (mu_option) <opt_default>: New member.
* libmailutils/opt/opt.c (find_long_option): Improve detection
of ambiguous options.
(mu_option_set_value): Use default value (opt_default), if
supplied.
* mh/mh_argp.c: Delete.
* mh/Makefile.am (libmh_a_SOURCES): Remove mh_argp.c
* mh/mh_getopt.c: Rewrite from scratch using mailutils/opt
* mh/mh_getopt.h: Likewise.
* mh/mh.h: Add missing includes
(mh_read_formfile, mh_alias_read): Change signatures.
* mh/mh_alias.l (mh_alias_read): Name is const
* mh/mh_init.c (mh_read_formfile): Name is const.
* mh/ali.c: Convert to mh_getopt.
* mh/anno.c: Likewise.
* mh/burst.c: Likewise.
* mh/comp.c: Likewise.
* mh/fmtcheck.c: Likewise.
* mh/folder.c: Likewise.
* mh/forw.c: Likewise.
* mh/inc.c: Likewise.
* mh/install-mh.c: Likewise.
* mh/mark.c: Likewise.
* mh/mhl.c: Likewise.
* mh/scan.c: Likewise.
* mh/tests/burst.at: Don't use double-dash options
* mh/tests/folder.at: Likewise.
-rw-r--r-- | include/mailutils/opt.h | 1 | ||||
-rw-r--r-- | libmailutils/opt/opt.c | 57 | ||||
-rw-r--r-- | mh/Makefile.am | 1 | ||||
-rw-r--r-- | mh/ali.c | 89 | ||||
-rw-r--r-- | mh/anno.c | 103 | ||||
-rw-r--r-- | mh/burst.c | 118 | ||||
-rw-r--r-- | mh/comp.c | 202 | ||||
-rw-r--r-- | mh/fmtcheck.c | 85 | ||||
-rw-r--r-- | mh/folder.c | 261 | ||||
-rw-r--r-- | mh/forw.c | 282 | ||||
-rw-r--r-- | mh/inc.c | 239 | ||||
-rw-r--r-- | mh/install-mh.c | 44 | ||||
-rw-r--r-- | mh/mark.c | 186 | ||||
-rw-r--r-- | mh/mh.h | 5 | ||||
-rw-r--r-- | mh/mh_alias.l | 2 | ||||
-rw-r--r-- | mh/mh_argp.c | 298 | ||||
-rw-r--r-- | mh/mh_format.c | 5 | ||||
-rw-r--r-- | mh/mh_getopt.c | 335 | ||||
-rw-r--r-- | mh/mh_getopt.h | 204 | ||||
-rw-r--r-- | mh/mh_init.c | 2 | ||||
-rw-r--r-- | mh/mhl.c | 155 | ||||
-rw-r--r-- | mh/scan.c | 136 | ||||
-rw-r--r-- | mh/tests/burst.at | 4 | ||||
-rw-r--r-- | mh/tests/folder.at | 4 |
24 files changed, 871 insertions, 1947 deletions
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h index 972e3efb0..efecd8fe7 100644 --- a/include/mailutils/opt.h +++ b/include/mailutils/opt.h @@ -47,6 +47,7 @@ struct mu_option void *opt_ptr; /* Data pointer */ void (*opt_set) (struct mu_parseopt *, struct mu_option *, char const *); /* Function to set the option */ + char const *opt_default;/* Default value */ }; #define MU_OPTION_GROUP(text) { NULL, 0, NULL, 0, text } diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c index b7dc8d000..fbe28681b 100644 --- a/libmailutils/opt/opt.c +++ b/libmailutils/opt/opt.c @@ -189,6 +189,31 @@ find_short_option (struct mu_parseopt *po, int chr) return NULL; } +enum neg_match + { + neg_nomatch, + neg_match_inexact, + neg_match_exact + }; + +static enum neg_match +negmatch (struct mu_parseopt *po, size_t i, char const *optstr, size_t optlen) +{ + if (mu_option_possible_negation (po, po->po_optv[i])) + { + size_t neglen = strlen (po->po_negation); + size_t len = strlen (po->po_optv[i]->opt_long); + if (optlen <= neglen + len + && memcmp (optstr, po->po_negation, neglen) == 0 + && memcmp (optstr + neglen, po->po_optv[i]->opt_long, + optlen - neglen) == 0) + { + return (optlen == neglen + len) ? neg_match_exact : neg_match_inexact; + } + } + return neg_nomatch; +} + /* Find a descriptor of long option OPTSTR. If it has argument, return it in *ARGPTR. */ struct mu_option * @@ -200,14 +225,11 @@ find_long_option (struct mu_parseopt *po, char const *optstr, size_t i; size_t optlen; /* Length of the option in optstr */ int found = 0; /* 1 if the match was found, 2 if option is ambiguous */ - int neglen; /* Length of the negation prefix, if any */ - int neg = 0; /* 1 if a boolean option is negated */ + enum neg_match neg; /* 1 if a boolean option is negated */ struct mu_option *ret_opt = NULL; struct mu_option *used_opt; optlen = strcspn (optstr, "="); - if (po->po_negation) - neglen = strlen (po->po_negation); for (i = 0; i < po->po_optc; i++) { @@ -215,14 +237,10 @@ find_long_option (struct mu_parseopt *po, char const *optstr, { size_t len = strlen (po->po_optv[i]->opt_long); struct mu_option *opt = option_unalias (po, i); - + neg = neg_nomatch; if ((optlen <= len && memcmp (po->po_optv[i]->opt_long, optstr, optlen) == 0) - || (neg = (mu_option_possible_negation (po, opt) - && optlen <= neglen + len - && memcmp (optstr, po->po_negation, neglen) == 0 - && memcmp (optstr + neglen, po->po_optv[i]->opt_long, - optlen - neglen) == 0))) + || (neg = negmatch (po, i, optstr, optlen))) { switch (found) { @@ -230,7 +248,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr, used_opt = po->po_optv[i]; ret_opt = opt; found++; - if (optlen == len || (neg && optlen == neglen + len)) + if (optlen == len || neg == neg_match_exact) i = po->po_optc - 1; /* exact match: break the loop */ break; @@ -247,6 +265,11 @@ find_long_option (struct mu_parseopt *po, char const *optstr, po->po_long_opt_start, neg ? po->po_negation : "", used_opt->opt_long); + if (neg == neg_nomatch && negmatch (po, i, optstr, optlen)) + fprintf (stderr, "%s%s%s\n", + po->po_long_opt_start, + po->po_negation, + po->po_optv[i]->opt_long); found++; case 2: @@ -254,6 +277,11 @@ find_long_option (struct mu_parseopt *po, char const *optstr, po->po_long_opt_start, neg ? po->po_negation : "", po->po_optv[i]->opt_long); + if (neg == neg_nomatch && negmatch (po, i, optstr, optlen)) + fprintf (stderr, "%s%s%s\n", + po->po_long_opt_start, + po->po_negation, + po->po_optv[i]->opt_long); } } } @@ -719,7 +747,9 @@ mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt, if (arg == NULL) { - if (opt->opt_arg == NULL) + if (opt->opt_default) + arg = opt->opt_default; + else if (opt->opt_arg == NULL) arg = "1"; else { @@ -737,7 +767,8 @@ mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt, errtext = mu_strerror (rc); if (opt->opt_long) - mu_parseopt_error (po, "--%s: %s", opt->opt_long, errtext); + mu_parseopt_error (po, "%s%s: %s", po->po_long_opt_start, + opt->opt_long, errtext); else mu_parseopt_error (po, "-%c: %s", opt->opt_short, errtext); free (errmsg); diff --git a/mh/Makefile.am b/mh/Makefile.am index 3cca33469..91c4985a6 100644 --- a/mh/Makefile.am +++ b/mh/Makefile.am @@ -70,7 +70,6 @@ libmh_a_SOURCES= \ mboxprop.c\ mh_alias_gram.c\ mh_alias_lex.c\ - mh_argp.c\ mh_getopt.c\ mh_global.c\ mh_format.c\ @@ -23,73 +23,41 @@ #include <sys/ioctl.h> #include <sys/stat.h> -static char doc[] = N_("GNU MH ali")"\v" -N_("Use -help to obtain the list of traditional MH options."); +static char prog_doc[] = N_("GNU MH ali"); static char args_doc[] = N_("ALIAS [ALIAS...]"); -/* GNU options */ -static struct argp_option options[] = { - {"alias", ARG_ALIAS, N_("FILE"), 0, - N_("use the additional alias FILE")}, - {"noalias", ARG_NOALIAS, NULL, 0, - N_("do not read the system alias file") }, - {"list", ARG_LIST, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("list each address on a separate line") }, - {"normalize", ARG_NORMALIZE, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("try to determine the official hostname for each address") }, - {"user", ARG_USER, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("list the aliases that expand to given addresses") }, - { 0 } -}; - -/* Traditional MH options */ -struct mh_option mh_option[] = { - { "alias", MH_OPT_ARG, "aliasfile" }, - { "noalias", }, - { "list", MH_OPT_BOOL }, - { "normalize", MH_OPT_BOOL }, - { "user", MH_OPT_BOOL }, - { NULL } -}; - static int list_mode; static int user_mode; static int normalize_mode; static int nolist_mode; -static error_t -opt_handler (int key, char *arg, struct argp_state *state) +static void +alias_handler (struct mu_parseopt *po, struct mu_option *opt, char const *arg) { - switch (key) - { - case ARG_ALIAS: - mh_alias_read (arg, 1); - break; - - case ARG_NOALIAS: - nolist_mode = 1; - break; - - case ARG_LIST: - list_mode = is_true (arg); - break; - - case ARG_NORMALIZE: - normalize_mode = is_true (arg); - break; - - case ARG_USER: - user_mode = is_true (arg); - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; + mh_alias_read (arg, 1); } +static struct mu_option options[] = { + { "alias", 0, N_("FILE"), MU_OPTION_DEFAULT, + N_("use the additional alias FILE"), + mu_c_string, NULL, alias_handler }, + { "noalias", 0, NULL, 0, + N_("do not read the system alias file"), + mu_c_int, &nolist_mode, NULL, "1" }, + { "list", 0, NULL, MU_OPTION_DEFAULT, + N_("list each address on a separate line"), + mu_c_bool, &list_mode }, + { "normalize", 0, NULL, MU_OPTION_DEFAULT, + N_("try to determine the official hostname for each address"), + mu_c_bool, &normalize_mode }, + { "user", 0, NULL, MU_OPTION_DEFAULT, + N_("list the aliases that expand to given addresses"), + mu_c_bool, &user_mode }, + MU_OPTION_END +}; + static int -getcols () +getcols (void) { struct winsize ws; @@ -174,17 +142,10 @@ ali_print_name (char *name) int main (int argc, char **argv) { - int index; - /* Native Language Support */ MU_APP_INIT_NLS (); - mh_argp_init (); - mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc, - opt_handler, NULL, &index); - - argc -= index; - argv += index; + mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL); if (!nolist_mode) mh_read_aliases (); @@ -19,81 +19,29 @@ #include <mh.h> -static char doc[] = N_("GNU MH anno")"\v" -N_("Options marked with `*' are not yet implemented.\n\ -Use -help to obtain the list of traditional MH options."); +static char prog_doc[] = N_("GNU MH anno"); static char args_doc[] = N_("[MSGLIST]"); -/* GNU options */ -static struct argp_option options[] = { - {"folder", ARG_FOLDER, N_("FOLDER"), 0, - N_("specify folder to operate upon")}, - {"inplace", ARG_INPLACE, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("* annotate the message in place")}, - {"noinplace", ARG_NOINPLACE, NULL, OPTION_HIDDEN, "" }, - {"date", ARG_DATE, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("add FIELD: date header") }, - {"nodate", ARG_NODATE, NULL, OPTION_HIDDEN, "" }, - {"component", ARG_COMPONENT, N_("FIELD"), 0, - N_("add this FIELD to the message header") }, - {"text", ARG_TEXT, N_("STRING"), 0, - N_("field value for the component") }, - { NULL } -}; - -struct mh_option mh_option[] = { - { "inplace", MH_OPT_BOOL }, - { "date", MH_OPT_BOOL }, - { "component", MH_OPT_ARG, "field" }, - { "text", MH_OPT_ARG, "body" }, - { NULL } -}; - -static int inplace; /* Annotate the message in place */ +//static int inplace; /* Annotate the message in place */ static int anno_date = 1; /* Add date to the annotation */ static char *component; /* header field */ static char *anno_text; /* header field value */ -static error_t -opt_handler (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case ARG_FOLDER: - mh_set_current_folder (arg); - break; - - case ARG_INPLACE: - mh_opt_notimpl_warning ("-inplace"); - inplace = is_true (arg); - break; - - case ARG_NOINPLACE: - mh_opt_notimpl_warning ("-noinplace"); - inplace = 0; - break; - - case ARG_DATE: - anno_date = is_true (arg); - break; - - case ARG_NODATE: - anno_date = 0; - break; - - case ARG_COMPONENT: - component = arg; - break; - - case ARG_TEXT: - mh_quote (arg, &anno_text); - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} +static struct mu_option options[] = { + { "inplace", 0, NULL, MU_OPTION_HIDDEN, + N_("annotate the message in place"), + mu_c_string, NULL, mh_opt_notimpl_warning }, + { "date", 0, NULL, MU_OPTION_DEFAULT, + N_("add FIELD: date header"), + mu_c_bool, &anno_date }, + { "component", 0, N_("FIELD"), MU_OPTION_DEFAULT, + N_("add this FIELD to the message header"), + mu_c_string, &component }, + { "text", 0, N_("STRING"), MU_OPTION_DEFAULT, + N_("field value for the component"), + mu_c_string, &anno_text }, + MU_OPTION_END +}; int anno (size_t n, mu_message_t msg, void *call_data) @@ -106,17 +54,21 @@ int main (int argc, char **argv) { int rc; - int index; mu_mailbox_t mbox; mu_msgset_t msgset; size_t len; MU_APP_INIT_NLS (); - mh_argp_init (); - mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc, - opt_handler, NULL, &index); - + mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, + args_doc, prog_doc, NULL); + if (anno_text) + { + char *arg = anno_text; + mh_quote (arg, &anno_text); + free (arg); + } + mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR); if (!component) @@ -152,9 +104,6 @@ main (int argc, char **argv) if (len > 0 && component[len-1] == ':') component[len-1] = 0; - argc -= index; - argv += index; - mh_msgset_parse (&msgset, mbox, argc, argv, "cur"); rc = mu_msgset_foreach_message (msgset, anno, NULL); if (rc) diff --git a/mh/burst.c b/mh/burst.c index 28ad2dd50..87b067c88 100644 --- a/mh/burst.c +++ b/mh/burst.c @@ -18,40 +18,9 @@ #include <mh.h> -static char doc[] = N_("GNU MH burst")"\v" -N_("Options marked with `*' are not yet implemented.\n\ -Use -help to obtain the list of traditional MH options."); +static char prog_doc[] = N_("GNU MH burst"); static char args_doc[] = N_("[MSGLIST]"); -/* GNU options */ -static struct argp_option options[] = { - {"folder", ARG_FOLDER, N_("FOLDER"), 0, - N_("specify folder to operate upon")}, - {"inplace", ARG_INPLACE, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("replace the source message with the table of contents, insert extracted messages after it") }, - {"noinplace", ARG_NOINPLACE, 0, OPTION_HIDDEN, ""}, - {"quiet", ARG_QUIET, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("be quiet about the messages that are not in digest format") }, - {"noquiet", ARG_NOQUIET, 0, OPTION_HIDDEN, ""}, - {"verbose", ARG_VERBOSE, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("verbosely list the actions taken") }, - {"noverbose", ARG_NOVERBOSE, 0, OPTION_HIDDEN, ""}, - {"recursive", ARG_RECURSIVE, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("recursively expand MIME messages") }, - {"norecursive", ARG_NORECURSIVE, 0, OPTION_HIDDEN, ""}, - {"length", ARG_LENGTH, N_("NUMBER"), 0, - N_("set minimal length of digest encapsulation boundary (default 1)") }, - { NULL } -}; - -/* Traditional MH options */ -struct mh_option mh_option[] = { - { "inplace", MH_OPT_BOOL }, - { "quiet", MH_OPT_BOOL }, - { "verbose", MH_OPT_BOOL }, - { NULL } -}; - /* Command line switches */ int inplace; int quiet; @@ -61,59 +30,24 @@ int eb_min_length = 1; /* Minimal length of encapsulation boundary */ #define VERBOSE(c) do { if (verbose) { printf c; putchar ('\n'); } } while (0) -static error_t -opt_handler (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case ARG_FOLDER: - mh_set_current_folder (arg); - break; - - case ARG_INPLACE: - inplace = is_true (arg); - break; - - case ARG_NOINPLACE: - inplace = 0; - break; - - case ARG_LENGTH: - eb_min_length = strtoul (arg, NULL, 0); - if (eb_min_length == 0) - eb_min_length = 1; - break; - - case ARG_VERBOSE: - verbose = is_true (arg); - break; - - case ARG_NOVERBOSE: - verbose = 0; - break; - - case ARG_RECURSIVE: - recursive = is_true (arg); - break; - - case ARG_NORECURSIVE: - recursive = 0; - break; - - case ARG_QUIET: - quiet = is_true (arg); - break; - - case ARG_NOQUIET: - quiet = 0; - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - +static struct mu_option options[] = { + { "inplace", 0, NULL, MU_OPTION_DEFAULT, + N_("replace the source message with the table of contents, insert extracted messages after it"), + mu_c_bool, &inplace }, + { "quiet", 0, NULL, MU_OPTION_DEFAULT, + N_("be quiet about the messages that are not in digest format"), + mu_c_bool, &quiet }, + { "verbose", 0, NULL, MU_OPTION_DEFAULT, + N_("verbosely list the actions taken"), + mu_c_bool, &verbose }, + { "recursive", 0, NULL, MU_OPTION_DEFAULT, + N_("recursively expand MIME messages"), + mu_c_bool, &recursive }, + { "length", 0, N_("NUM"), MU_OPTION_DEFAULT, + N_("set minimal length of digest encapsulation boundary (default 1)"), + mu_c_int, &eb_min_length }, + MU_OPTION_END +}; /* General-purpose data structures */ struct burst_map @@ -713,7 +647,7 @@ finalize_inplace (size_t lastuid) int main (int argc, char **argv) { - int index, rc; + int rc; mu_mailbox_t mbox; mu_msgset_t msgset; const char *tempfolder = mh_global_profile_get ("Temp-Folder", ".temp"); @@ -721,13 +655,11 @@ main (int argc, char **argv) /* Native Language Support */ MU_APP_INIT_NLS (); - mh_argp_init (); - mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc, - opt_handler, NULL, &index); - - argc -= index; - argv += index; - + mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, + args_doc, prog_doc, NULL); + if (eb_min_length == 0) + eb_min_length = 1; + VERBOSE ((_("Opening folder `%s'"), mh_current_folder ())); mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR); mh_msgset_parse (&msgset, mbox, argc, argv, "cur"); @@ -21,143 +21,73 @@ #include <sys/types.h> #include <sys/stat.h> -static char doc[] = N_("GNU MH comp")"\v" -N_("Options marked with `*' are not yet implemented.\n" -"Use -help to obtain the list of traditional MH options."); +static char prog_doc[] = N_("GNU MH comp"); static char args_doc[] = N_("[MSG]"); -/* GNU options */ -static struct argp_option options[] = { - {"build", ARG_BUILD, 0, 0, - N_("build the draft and quit immediately.")}, - {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0, - N_("specify the folder for message drafts")}, - {"nodraftfolder", ARG_NODRAFTFOLDER, 0, 0, - N_("undo the effect of the last --draftfolder option")}, - {"draftmessage" , ARG_DRAFTMESSAGE, N_("MSG"), 0, - N_("invoke the draftmessage facility")}, - {"folder", ARG_FOLDER, N_("FOLDER"), 0, - N_("specify folder to operate upon")}, - {"file", ARG_FILE, N_("FILE"), 0, - N_("use FILE as the message draft")}, - {"editor", ARG_EDITOR, N_("PROG"), 0, - N_("set the editor program to use")}, - {"noedit", ARG_NOEDIT, 0, 0, - N_("suppress the initial edit")}, - {"form", ARG_FORM, N_("FILE"), 0, - N_("read format from given file")}, - {"whatnowproc", ARG_WHATNOWPROC, N_("PROG"), 0, - N_("set the replacement for whatnow program")}, - {"nowhatnowproc", ARG_NOWHATNOWPROC, NULL, 0, - N_("don't run whatnowproc")}, - {"use", ARG_USE, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("use draft file preserved after the last session") }, - {"nouse", ARG_NOUSE, NULL, OPTION_HIDDEN, ""}, - { 0 } -}; - -/* Traditional MH options */ -struct mh_option mh_option[] = { - { "build" }, - { "file", MH_OPT_ARG, "draftfile" }, - { "form", MH_OPT_ARG, "formatfile" }, - { "draftfolder", MH_OPT_ARG, "folder" }, - { "nodraftfolder" }, - { "draftmessage" }, - { "editor", MH_OPT_ARG, "program" }, - { "noedit" }, - { "whatnowproc", MH_OPT_ARG, "program" }, - { "nowhatnowproc" }, - { "use" }, - { NULL } -}; - struct mh_whatnow_env wh_env = { 0 }; static int initial_edit = 1; static const char *whatnowproc; static int nowhatnowproc; char *formfile; -static int build_only = 0; /* --build flag */ -static int use_draft = 0; /* --use flag */ +static int build_only = 0; /* -build flag */ +static int use_draft = 0; /* -use flag */ static char *draftmessage = "new"; static const char *draftfolder = NULL; static int folder_set; /* Folder is set on the command line */ -static error_t -opt_handler (int key, char *arg, struct argp_state *state) +static void +set_folder (struct mu_parseopt *po, struct mu_option *opt, char const *arg) { - switch (key) - { - case ARGP_KEY_INIT: - draftfolder = mh_global_profile_get ("Draft-Folder", NULL); - whatnowproc = mh_global_profile_get ("whatnowproc", NULL); - break; - - case ARG_BUILD: - build_only = 1; - break; - - case ARG_DRAFTFOLDER: - draftfolder = arg; - break; - - case ARG_EDITOR: - wh_env.editor = arg; - break; - - case ARG_FOLDER: - mh_set_current_folder (arg); - folder_set = 1; - break; - - case ARG_FORM: - mh_find_file (arg, &formfile); - break; - - case ARG_DRAFTMESSAGE: - draftmessage = arg; - break; - - case ARG_USE: - use_draft = is_true (arg); - draftmessage = "cur"; - break; - - case ARG_NOUSE: - use_draft = 0; - break; - - case ARG_FILE: - wh_env.file = mh_expand_name (NULL, arg, NAME_ANY); - break; - - case ARG_NODRAFTFOLDER: - draftfolder = NULL; - break; - - case ARG_NOEDIT: - initial_edit = 0; - break; - - case ARG_WHATNOWPROC: - whatnowproc = arg; - break; - - case ARG_NOWHATNOWPROC: - nowhatnowproc = 1; - break; + mh_set_current_folder (arg); + folder_set = 1; +} - case ARGP_KEY_FINI: - if (!formfile) - mh_find_file ("components", &formfile); - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; +static void +set_file (struct mu_parseopt *po, struct mu_option *opt, char const *arg) +{ + wh_env.file = mh_expand_name (NULL, arg, NAME_ANY); } +static struct mu_option options[] = { + { "build", 0, NULL, MU_OPTION_DEFAULT, + N_("build the draft and quit immediately."), + mu_c_bool, &build_only }, + { "draftfolder", 0, N_("FOLDER"), MU_OPTION_DEFAULT, + N_("specify the folder for message drafts"), + mu_c_string, &draftfolder }, + { "nodraftfolder", 0, NULL, MU_OPTION_DEFAULT, + N_("undo the effect of the last --draftfolder option"), + mu_c_string, &draftfolder, mh_opt_clear_string }, + { "draftmessage" , 0, N_("MSG"), MU_OPTION_DEFAULT, + N_("invoke the draftmessage facility"), + mu_c_string, &draftmessage }, + { "folder", 0, N_("FOLDER"), MU_OPTION_DEFAULT, + N_("specify folder to operate upon"), + mu_c_string, NULL, set_folder }, + { "file", 0, N_("FILE"), MU_OPTION_DEFAULT, + N_("use FILE as the message draft"), + mu_c_string, NULL, set_file }, + { "editor", 0, N_("PROG"), MU_OPTION_DEFAULT, + N_("set the editor program to use"), + mu_c_string, &wh_env.editor }, + { "noedit", 0, NULL, MU_OPTION_DEFAULT, + N_("suppress the initial edit"), + mu_c_int, &initial_edit, NULL, "0" }, + { "form", 0, N_("FILE"), MU_OPTION_DEFAULT, + N_("read format from given file"), + mu_c_string, &formfile, mh_opt_find_file }, + { "whatnowproc", 0, N_("PROG"), MU_OPTION_DEFAULT, + N_("set the replacement for whatnow program"), + mu_c_string, &whatnowproc }, + { "nowhatnowproc", 0, NULL, MU_OPTION_DEFAULT, + N_("don't run whatnowproc"), + mu_c_string, &nowhatnowproc, NULL, "1" }, + { "use", 0, NULL, MU_OPTION_DEFAULT, + N_("use draft file preserved after the last session"), + mu_c_bool, &use_draft }, + MU_OPTION_END +}; + /* Copy Nth message from mailbox MBOX to FILE. */ int copy_message (mu_mailbox_t mbox, size_t n, const char *file) @@ -201,14 +131,18 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file) int main (int argc, char **argv) { - int index; - /* Native Language Support */ MU_APP_INIT_NLS (); - mh_argp_init (); - mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc, - opt_handler, NULL, &index); + draftfolder = mh_global_profile_get ("Draft-Folder", NULL); + whatnowproc = mh_global_profile_get ("whatnowproc", NULL); + + mh_getopt (&argc, &argv, options, 0, + args_doc, prog_doc, NULL); + if (use_draft) + draftmessage = "cur"; + if (!formfile) + mh_find_file ("components", &formfile); if (wh_env.file) { @@ -226,14 +160,14 @@ main (int argc, char **argv) { if (build_only || !draftfolder) { - switch (argc - index) + switch (argc) { case 0: wh_env.file = mh_expand_name (NULL, "draft", 0); break; case 1: - wh_env.file = mh_expand_name (NULL, argv[index], 0); + wh_env.file = mh_expand_name (NULL, argv[0], 0); break; default: @@ -245,7 +179,7 @@ main (int argc, char **argv) { /* Comp accepts a `file', and it will, if given `-draftfolder +folder' treat this arguments as `msg'. */ - if (use_draft || index < argc) + if (use_draft || argc) { mu_msgset_t msgset; mu_mailbox_t mbox; @@ -253,7 +187,7 @@ main (int argc, char **argv) mbox = mh_open_folder (draftfolder, MU_STREAM_RDWR|MU_STREAM_CREAT); mh_msgset_parse (&msgset, mbox, - argc - index, argv + index, + argc, argv, use_draft ? "cur" : "new"); if (!mh_msgset_single_message (msgset)) { @@ -271,13 +205,13 @@ main (int argc, char **argv) } wh_env.draftfile = wh_env.file; - if (folder_set && index < argc) + if (folder_set && argc) { mu_msgset_t msgset; mu_mailbox_t mbox; mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ); - mh_msgset_parse (&msgset, mbox, argc - index, argv + index, "cur"); + mh_msgset_parse (&msgset, mbox, argc, argv, "cur"); if (!mh_msgset_single_message (msgset)) { mu_error (_("only one message at a time!")); @@ -304,7 +238,7 @@ main (int argc, char **argv) } } - /* Exit immediately if --build is given */ + /* Exit immediately if -build is given */ if (build_only || nowhatnowproc) return 0; diff --git a/mh/fmtcheck.c b/mh/fmtcheck.c index e938a9a23..c3a2b468d 100644 --- a/mh/fmtcheck.c +++ b/mh/fmtcheck.c @@ -19,37 +19,33 @@ #include <mh.h> -static char doc[] = N_("GNU MH fmtcheck")"\v" -N_("Use -help to obtain the list of traditional MH options."); - -/* GNU options */ -static struct argp_option options[] = { - {"form", ARG_FORM, N_("FILE"), 0, - N_("read format from given file")}, - {"format", ARG_FORMAT, N_("FORMAT"), 0, - N_("use this format string")}, - {"dump", ARG_DUMP, NULL, 0, - N_("dump the listing of compiled format code")}, - { "debug", ARG_DEBUG, NULL, 0, - N_("enable parser debugging output"),}, - - { NULL } -}; - -/* Traditional MH options */ -struct mh_option mh_option[] = { - { "form", MH_OPT_ARG, "formatfile" }, - { "format", MH_OPT_ARG, "string" }, - { NULL } -}; +static char prog_doc[] = N_("GNU MH fmtcheck"); char *format_str; static mh_format_t format; - -typedef int (*action_fp) (void); +int dump_option; +int debug_option; + +static struct mu_option options[] = { + { "form", 0, N_("FILE"), MU_OPTION_DEFAULT, + N_("read format from given file"), + mu_c_string, &format_str, mh_opt_read_formfile }, + + { "format", 0, N_("FORMAT"), MU_OPTION_DEFAULT, + N_("use this format string"), + mu_c_string, &format_str }, + { "dump", 0, NULL, MU_OPTION_HIDDEN, + N_("dump the listing of compiled format code"), + mu_c_bool, &dump_option }, + { "debug", 0, NULL, MU_O |