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 /mh | |
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.
Diffstat (limited to 'mh')
-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 |
22 files changed, 826 insertions, 1934 deletions
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_OPTION_DEFAULT, + N_("enable parser debugging output"), + mu_c_bool, &debug_option }, + + MU_OPTION_END +}; static int -action_dump () +action_dump (void) { if (!format_str) { @@ -60,49 +56,18 @@ action_dump () return 0; } -static action_fp action = action_dump; - -static error_t -opt_handler (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case ARG_FORM: - mh_read_formfile (arg, &format_str); - break; - - case ARG_FORMAT: - format_str = arg; - break; - - case ARG_DUMP: - action = action_dump; - break; - - case ARG_DEBUG: - mh_format_debug (1); - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - int main (int argc, char **argv) { /* Native Language Support */ MU_APP_INIT_NLS (); - mh_argp_init (); - mh_argp_parse (&argc, &argv, 0, options, mh_option, NULL, doc, - opt_handler, NULL, NULL); - + mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, NULL); + mh_format_debug (debug_option); if (format_str && mh_format_parse (format_str, &format)) { mu_error (_("Bad format string")); exit (1); } - return (*action) (); + return action_dump (); } diff --git a/mh/folder.c b/mh/folder.c index 59f6aa81b..e68a62492 100644 --- a/mh/folder.c +++ b/mh/folder.c @@ -28,78 +28,16 @@ #include <dirent.h> -static char doc[] = N_("GNU MH folder")"\v" -N_("Use -help to obtain the list of traditional MH options."); +static char prog_doc[] = N_("GNU MH folder"); static char args_doc[] = N_("[ACTION] [MSG]"); -static struct argp_option options[] = { - {N_("Actions are:"), 0, 0, OPTION_DOC, NULL, 0 }, - {"print", ARG_PRINT, NULL, 0, - N_("list the folders (default)"), 1 }, - {"list", ARG_LIST, NULL, 0, - N_("list the contents of the folder stack"), 1}, - {"pack", ARG_PACK, N_("NUMBER"), OPTION_ARG_OPTIONAL, - N_("remove holes in message numbering, begin numbering from NUMBER (default: first message number)"), 1}, - {"push", ARG_PUSH, N_("FOLDER"), OPTION_ARG_OPTIONAL, - N_("push the folder on the folder stack. If FOLDER is specified, it is pushed. " - "Otherwise, if a folder is given in the command line (via + or --folder), " - "it is pushed on stack. Otherwise, the current folder and the top of the folder " - "stack are exchanged"), 1}, - {"pop", ARG_POP, NULL, 0, - N_("pop the folder off the folder stack"), 1}, - - {N_("Options are:"), 0, 0, OPTION_DOC, NULL, 2 }, - - {"folder", ARG_FOLDER, N_("FOLDER"), 0, - N_("specify folder to operate upon"), 3}, - {"all", ARG_ALL, NULL, 0, - N_("list all folders"), 3}, - {"create", ARG_CREATE, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("create non-existing folders"), 3}, - {"nocreate", ARG_NOCREATE, NULL, OPTION_HIDDEN, ""}, - {"fast", ARG_FAST, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("list only the folder names"), 3}, - {"nofast", ARG_NOFAST, NULL, OPTION_HIDDEN, ""}, - {"header", ARG_HEADER, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("print the header line"), 3}, - {"noheader", ARG_NOHEADER, NULL, OPTION_HIDDEN, ""}, - {"recurse",ARG_RECURSIVE, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("scan folders recursively"), 3}, - {"norecurse", ARG_NORECURSIVE, NULL, OPTION_HIDDEN, ""}, - {"total", ARG_TOTAL, N_("BOOL"), OPTION_ARG_OPTIONAL, - N_("output the total statistics"), 3}, - {"nototal", ARG_NOTOTAL, NULL, OPTION_HIDDEN, ""}, - {"verbose", ARG_VERBOSE, NULL, 0, - N_("verbosely list actions taken"), 3}, - {"dry-run", ARG_DRY_RUN, NULL, 0, - N_("do nothing, print what would be done (with --pack)"), 3}, - - {NULL}, -}; - -/* Traditional MH options */ -struct mh_option mh_option[] = { - { "print" }, - { "list" }, - { "push" }, - { "pop" }, - { "all" }, - { "pack" }, - { "create", MH_OPT_BOOL }, - { "fast", MH_OPT_BOOL }, - { "header", MH_OPT_BOOL }, - { "recurse", MH_OPT_BOOL }, - { "total", MH_OPT_BOOL }, - { NULL } -}; - -typedef int (*folder_action) (); +typedef int (*folder_action) (void); -static int action_print (); -static int action_list (); -static int action_push (); -static int action_pop (); -static int action_pack (); +static int action_print (void); +static int action_list (void); +static int action_push (void); +static int action_pop (void); +static int action_pack (void); static folder_action action = action_print; int show_all = 0; /* List all folders. Raised by --all switch */ @@ -121,110 +59,105 @@ const char *push_folder; /* Folder name to push on stack */ const char *mh_seq_name; /* Name of the mh sequence file (defaults to .mh_sequences) */ int has_folder; /* Folder has been explicitely given */ +int recurse_option = 0; size_t max_depth = 1; /* Maximum recursion depth (0 means infinity) */ #define OPTION_IS_SET(opt) ((opt) == -1 ? show_all : opt) -static int -opt_handler (int key, char *arg, struct argp_state *state) +void +set_action (struct mu_parseopt *po, struct mu_option *opt, char const *arg) |