diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-10-19 17:20:42 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-10-19 19:20:31 +0300 |
commit | dc78d43ff77a65e3400af0401142aca2ebb6cd1e (patch) | |
tree | 61b7442d72109e743527a19e5e4ae575a749ed2d /mu | |
parent | d1339b3ffaa3d82e21c3a36e5bdfccee3246904d (diff) | |
download | mailutils-dc78d43ff77a65e3400af0401142aca2ebb6cd1e.tar.gz mailutils-dc78d43ff77a65e3400af0401142aca2ebb6cd1e.tar.bz2 |
Convert remaining utilities (except mh) to mu_cli.
* Makefile.am: Remove libmu_argp and libmu_cfg
* configure.ac: Likewise.
* libmu_argp/: Remove.
* libmu_cfg/: Remove.
* include/mailutils/Makefile.am (pkginclude_HEADERS): Remove gocs.h,
libargp.h, libcfg.h
* frm/frm.c: Register tls auth module
* frm/from.c: Likewise.
* maidag/maidag.c: Likewise.
* mail/mail.c: Likewise.
* messages/messages.c: Likewise.
* movemail/movemail.c: Likewise.
* readmsg/readmsg.c: Likewise.
* sieve/sieve.c: Likewise.
* frm/frm.h: Remove obsolete includes
* imap4d/Makefile.am: Update.
* imap4d/imap4d.c: Use mu_cli for command line and configuration
parsing.
* imap4d/imap4d.h: Update.
* include/mailutils/gocs.h: Remove.
* libmailutils/cfg/gocs.c: Remove.
* libmailutils/cfg/Makefile.am: Remove gocs.c
* include/mailutils/cli.h (mu_cli_capa_apply): Rename to
mu_cli_capa_extend_settings
(mu_cli_setup) <inorder, prog_doc_hook>: New fields.
* include/mailutils/daemon.h: Remove obsolete includes.
* include/mailutils/gsasl.h: Likewise.
* include/mailutils/mailutils.h: Update.
* include/mailutils/mu_auth.h (mu_auth_mode): New enum
(mu_auth_module): Redo structure.
* include/mailutils/opt.h (mu_parseopt) <po_prog_doc_hook>: New field.
* include/mailutils/sql.h (mu_sql_module_config): New extern.
(mu_sql_interface_index): Change proto.
* libmailutils/auth/mu_auth.c: Rewrite.
* libmailutils/auth/system.c (mu_auth_system_module): Update structure
* libmailutils/cli/capa.c (mu_cli_capa_apply): Rename to
mu_cli_capa_extend_settings
* libmailutils/cli/cli.c: Extend settings from auth modules as well.
* libmailutils/opt/help.c (mu_program_help): Invoke po_prog_doc_hook
if defined.
* libmailutils/opt/opt.c (parseopt_init): Check the
MU_PARSEOPT_PROG_DOC_HOOK flag.
(find_long_option): Fix recognition of ambiguous options in case
of exact match.
* libmu_auth/gsasl.c: Add configuration.
* libmu_auth/ldap.c: Likewise.
* libmu_auth/pam.c: Likewise.
* libmu_auth/radius.c: Likewise.
* libmu_auth/sql.c: Likewise.
* libmu_auth/tls.c: Likewise.
* libmu_auth/virtual.c: Likewise.
* mu/Makefile.am: Update.
* mu/mu.c: Rewrite using mu_cli
* mu/mu.h: Likewise.
* mu/acl.c: Likewise.
* mu/cflags.c: Likewise.
* mu/dbm.c: Likewise.
* mu/dispatch.c: Likewise.
* mu/filter.c: Likewise.
* mu/flt2047.c: Likewise.
* mu/getans.c: Likewise.
* mu/getarg.c: Likewise.
* mu/getyn.c: Likewise.
* mu/help.c: Likewise.
* mu/imap.c: Likewise.
* mu/info.c: Likewise.
* mu/ldflags.c: Likewise.
* mu/logger.c: Likewise.
* mu/pop.c: Likewise.
* mu/query.c: Likewise.
* mu/send.c: Likewise.
* mu/shell.c: Likewise.
* mu/smtp.c: Likewise.
* mu/util.c: Likewise.
* mu/verbose.c: Likewise.
* mu/wicket.c: Likewise.
* pop3d/Makefile.am: Update.
* pop3d/pop3d.c: Convert to mu_cli interface.
* pop3d/pop3d.h: Likewise.
* sql/sql.c (mu_sql_interface_index): Change argument qualifiers.
Diffstat (limited to 'mu')
-rw-r--r-- | mu/Makefile.am | 2 | ||||
-rw-r--r-- | mu/acl.c | 77 | ||||
-rw-r--r-- | mu/cflags.c | 29 | ||||
-rw-r--r-- | mu/dbm.c | 297 | ||||
-rw-r--r-- | mu/dispatch.c | 41 | ||||
-rw-r--r-- | mu/filter.c | 77 | ||||
-rw-r--r-- | mu/flt2047.c | 87 | ||||
-rw-r--r-- | mu/getans.c | 4 | ||||
-rw-r--r-- | mu/getarg.c | 10 | ||||
-rw-r--r-- | mu/getyn.c | 4 | ||||
-rw-r--r-- | mu/help.c | 25 | ||||
-rw-r--r-- | mu/imap.c | 36 | ||||
-rw-r--r-- | mu/info.c | 49 | ||||
-rw-r--r-- | mu/ldflags.c | 27 | ||||
-rw-r--r-- | mu/logger.c | 197 | ||||
-rw-r--r-- | mu/mu.c | 141 | ||||
-rw-r--r-- | mu/mu.h | 17 | ||||
-rw-r--r-- | mu/pop.c | 47 | ||||
-rw-r--r-- | mu/query.c | 113 | ||||
-rw-r--r-- | mu/send.c | 81 | ||||
-rw-r--r-- | mu/shell.c | 10 | ||||
-rw-r--r-- | mu/smtp.c | 35 | ||||
-rw-r--r-- | mu/util.c | 8 | ||||
-rw-r--r-- | mu/verbose.c | 6 | ||||
-rw-r--r-- | mu/wicket.c | 69 |
25 files changed, 513 insertions, 976 deletions
diff --git a/mu/Makefile.am b/mu/Makefile.am index d9355dff6..b01900427 100644 --- a/mu/Makefile.am +++ b/mu/Makefile.am @@ -75,7 +75,7 @@ mailutils_SOURCES = \ $(MODULES) mailutils_LDADD = \ - ${MU_APP_LIBRARIES}\ + ${MU_APP_NEW_LIBRARIES}\ ${MU_LIB_MBOX}\ ${MU_LIB_IMAP}\ ${MU_LIB_POP}\ @@ -14,63 +14,24 @@ You should have received a copy of the GNU General Public License along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ -#if defined(HAVE_CONFIG_H) -# include <config.h> -#endif -#include <stdlib.h> -#include <string.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <sys/un.h> -#include <arpa/inet.h> -#include <mailutils/mailutils.h> -#include <mailutils/libcfg.h> -#include "argp.h" #include "mu.h" -static char acl_doc[] = N_("mu acl - test access control lists."); char acl_docstring[] = N_("test access control lists"); static char acl_args_doc[] = N_("ADDRESS [ADDRESS...]"); -static struct argp_option acl_options[] = { - { "file", 'f', N_("FILE"), 0, N_("read ACLs from FILE") }, - { "path", 'p', N_("PATH"), 0, - N_("path to the ACL in the configuration tree") }, - { NULL } -}; - static char *input_file_name; static struct mu_sockaddr *target_sa; static mu_acl_t acl; static const char *path = "acl"; -static error_t -acl_parse_opt (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case 'f': - input_file_name = arg; - break; - - case 'p': - path = arg; - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp acl_argp = { - acl_options, - acl_parse_opt, - acl_args_doc, - acl_doc, - NULL, - NULL, - NULL +static struct mu_option acl_options[] = { + { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT, + N_("read ACLs from FILE"), + mu_c_string, &input_file_name }, + { "path", 'p', N_("PATH"), MU_OPTION_DEFAULT, + N_("path to the ACL in the configuration tree"), + mu_c_string, &path }, + { NULL } }; @@ -82,16 +43,13 @@ static struct mu_cfg_param acl_cfg_param[] = { int mutool_acl (int argc, char **argv) { - int rc, index; + int rc; mu_acl_result_t result; mu_cfg_tree_t *tree = NULL, *temp_tree = NULL; mu_cfg_node_t *node; - - if (argp_parse (&acl_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) - return 1; + struct mu_cfg_parse_hints hints; - argc -= index; - argv += index; + mu_action_getopt (&argc, &argv, acl_options, acl_docstring, acl_args_doc); if (argc == 0) { @@ -99,16 +57,13 @@ mutool_acl (int argc, char **argv) return 1; } - if (input_file_name) - { - mu_load_site_rcfile = 0; - mu_load_user_rcfile = 0; - mu_load_rcfile = input_file_name; - } + memset (&hints, 0, sizeof (hints)); + hints.flags = MU_CFG_PARSE_CUSTOM_RCFILE; + hints.custom_rcfile = input_file_name; mu_acl_cfg_init (); - if (mu_libcfg_parse_config (&tree)) - return 1; + if (mu_cfg_parse_config (&tree, &hints)) + exit (EX_CONFIG); if (!tree) return 0; diff --git a/mu/cflags.c b/mu/cflags.c index 1ecadb500..dd549e65a 100644 --- a/mu/cflags.c +++ b/mu/cflags.c @@ -14,32 +14,19 @@ You should have received a copy of the GNU General Public License along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ -#if defined(HAVE_CONFIG_H) -# include <config.h> -#endif -#include <stdlib.h> -#include <mailutils/mailutils.h> -#include <mailutils/libcfg.h> -#include <argp.h> - -static char cflags_doc[] = N_("mu cflags - show compiler options"); -char cflags_docstring[] = N_("show compiler options"); +#include "mu.h" -static struct argp cflags_argp = { - NULL, - NULL, - NULL, - cflags_doc, - NULL, - NULL, - NULL -}; +char cflags_docstring[] = N_("show compiler options"); int mutool_cflags (int argc, char **argv) { - if (argp_parse (&cflags_argp, argc, argv, ARGP_IN_ORDER, NULL, NULL)) - return 1; + mu_action_getopt (&argc, &argv, NULL, cflags_docstring, NULL); + if (argc) + { + mu_error (_("too many arguments")); + return EX_USAGE; + } mu_printf ("%s\n", COMPILE_FLAGS); return 0; } @@ -14,21 +14,12 @@ You should have received a copy of the GNU General Public License along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ -#if defined(HAVE_CONFIG_H) -# include <config.h> -#endif -#include <sys/types.h> -#include <sys/stat.h> -#include <stdlib.h> -#include <string.h> -#include <grp.h> -#include <sysexits.h> +#include "mu.h" +#include <mailutils/dbm.h> #include <fnmatch.h> #include <regex.h> -#include <mailutils/mailutils.h> -#include <mailutils/dbm.h> -#include "argp.h" -#include "mu.h" +#include <sys/stat.h> +#include <grp.h> static char dbm_doc[] = N_("mu dbm - DBM management tool\n" "Valid COMMANDs are:\n" @@ -39,6 +30,7 @@ static char dbm_doc[] = N_("mu dbm - DBM management tool\n" " delete - delete specified keys from the database\n" " add - add records to the database\n" " replace - add records replacing ones with matching keys\n"); + char dbm_docstring[] = N_("DBM management tool"); static char dbm_args_doc[] = N_("COMMAND FILE [KEY...]"); @@ -1603,154 +1595,161 @@ delete_database (int argc, char **argv) mu dbm --replace a.db < input */ -static struct argp_option dbm_options[] = { - { NULL, 0, NULL, 0, N_("Create Options"), 0}, - { "file", 'f', N_("FILE"), 0, - N_("read input from FILE (with create, delete, add and replace)") }, - { "permissions", 'p', N_("NUM"), 0, - N_("set permissions on the created database") }, - { "user", 'u', N_("USER"), 0, - N_("set database owner name") }, - { "group", 'g', N_("GROUP"), 0, - N_("set database owner group") }, - { "copy-permissions", 'P', NULL, 0, - N_("copy database permissions and ownership from the input file") }, - { "ignore-meta", 'm', NULL, 0, - N_("ignore meta-information from input file headers") }, - { "ignore-directives", 'I', N_("NAMES"), 0, - N_("ignore the listed directives") }, - { NULL, 0, NULL, 0, N_("List and Dump Options"), 0}, - { "format", 'H', N_("TYPE"), 0, - N_("select output format") }, - { "no-header", 'q', NULL, 0, - N_("suppress format header") }, - { NULL, 0, NULL, 0, N_("List, Dump and Delete Options"), 0}, - { "glob", 'G', NULL, 0, - N_("treat keys as globbing patterns") }, - { "regex", 'R', NULL, 0, - N_("treat keys as regular expressions") }, - { "ignore-case", 'i', NULL, 0, - N_("case-insensitive matches") }, - { NULL, 0, NULL, 0, N_("Options for Use with Format 0.0"), 0 }, - { "count-null", 'N', NULL, 0, - N_("data length accounts for terminating zero") }, - { "no-count-null", 'n', NULL, 0, - N_("data length does not account for terminating zero") }, - { NULL } -}; - -static error_t -dbm_parse_opt (int key, char *arg, struct argp_state *state) +static void +set_permissions (struct mu_parseopt *po, struct mu_option *opt, char const *arg) { - switch (key) + char *p; + unsigned long d = strtoul (arg, &p, 8); + if (*p || (d & ~0777)) { - case 'f': - input_file = arg; - break; - - case 'H': - select_format (arg); - break; - - case 'p': - { - char *p; - unsigned long d = strtoul (arg, &p, 8); - if (*p || (d & ~0777)) - argp_error (state, _("invalid file mode: %s"), arg); - file_mode = d; - known_meta_data |= META_FILE_MODE; - } - break; + mu_parseopt_error (po, _("invalid file mode: %s"), arg); + exit (po->po_exit_error); + } + file_mode = d; + known_meta_data |= META_FILE_MODE; +} - case 'P': - copy_permissions = 1; - break; +static void +set_user (struct mu_parseopt *po, struct mu_option *opt, char const *arg) +{ + auth = mu_get_auth_by_name (arg); + if (auth) + known_meta_data |= META_AUTH; + else + { + char *p; + unsigned long n = strtoul (arg, &p, 0); + if (*p == 0) + { + owner_uid = n; + known_meta_data |= META_UID; + } + else + { + mu_parseopt_error (po, _("no such user: %s"), arg); + exit (po->po_exit_error); + } + } + ignore_directives ("user,uid"); +} - case 'q': - suppress_header = 1; - break; - - case 'u': - auth = mu_get_auth_by_name (arg); - if (auth) - known_meta_data |= META_AUTH; +static void +set_group (struct mu_parseopt *po, struct mu_option *opt, char const *arg) +{ + struct group *gr = getgrnam (arg); + if (!gr) + { + char *p; + unsigned long n = strtoul (arg, &p, 0); + if (*p == 0) + owner_gid = n; else { - char *p; - unsigned long n = strtoul (arg, &p, 0); - if (*p == 0) - { - owner_uid = n; - known_meta_data |= META_UID; - } - else - argp_error (state, _("no such user: %s"), arg); + mu_parseopt_error (po, _("no such group: %s"), arg); + exit (po->po_exit_error); } - ignore_directives ("user,uid"); - break; + } + else + owner_gid = gr->gr_gid; + known_meta_data |= META_GID; + ignore_directives ("group,gid"); +} - case 'g': - { - struct group *gr = getgrnam (arg); - if (!gr) - { - char *p; - unsigned long n = strtoul (arg, &p, 0); - if (*p == 0) - owner_gid = n; - else - argp_error (state, _("no such group: %s"), arg); - } - else - owner_gid = gr->gr_gid; - known_meta_data |= META_GID; - ignore_directives ("group,gid"); - } - break; +static void +set_ignore_meta (struct mu_parseopt *po, struct mu_option *opt, char const *arg) +{ + ignore_flagged_directives (DF_META); +} - case 'G': - key_type = key_glob; - break; +static void +set_ignore_directives (struct mu_parseopt *po, struct mu_option *opt, + char const *arg) +{ + ignore_directives (arg); +} - case 'R': - key_type = key_regex; - break; +static void +set_format (struct mu_parseopt *po, struct mu_option *opt, char const *arg) +{ + select_format (arg); +} - case 'm':/* FIXME: Why m? */ - ignore_flagged_directives (DF_META); - break; +static void +set_glob (struct mu_parseopt *po, struct mu_option *opt, char const *arg) +{ + key_type = key_glob; +} - case 'I': - ignore_directives (arg); - break; - - case 'i': - case_sensitive = 0; - break; +static void +set_regex (struct mu_parseopt *po, struct mu_option *opt, char const *arg) +{ + key_type = key_regex; +} - case 'N': - include_zero = 1; - break; +static void +set_ignore_case (struct mu_parseopt *po, struct mu_option *opt, char const *arg) +{ + case_sensitive = 0; +} - case 'n': - include_zero = 0; - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; +static void +clear_include_zero (struct mu_parseopt *po, struct mu_option *opt, + char const *arg) +{ + include_zero = 0; } -static struct argp dbm_argp = { - dbm_options, - dbm_parse_opt, - dbm_args_doc, - dbm_doc, - NULL, - NULL, - NULL +static struct mu_option dbm_options[] = { + MU_OPTION_GROUP (N_("Create Options")), + { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT, + N_("read input from FILE (with create, delete, add and replace)"), + mu_c_string, &input_file }, + { "permissions", 'p', N_("NUM"), MU_OPTION_DEFAULT, + N_("set permissions on the created database"), + mu_c_string, NULL, set_permissions }, + { "user", 'u', N_("USER"), MU_OPTION_DEFAULT, + N_("set database owner name"), + mu_c_string, NULL, set_user }, + { "group", 'g', N_("GROUP"), MU_OPTION_DEFAULT, + N_("set database owner group"), + mu_c_string, NULL, set_group }, + { "copy-permissions", 'P', NULL, MU_OPTION_DEFAULT, + N_("copy database permissions and ownership from the input file"), + mu_c_bool, ©_permissions }, + { "ignore-meta", 'm', NULL, MU_OPTION_DEFAULT, + N_("ignore meta-information from input file headers"), + mu_c_string, NULL, set_ignore_meta }, + { "ignore-directives", 'I', N_("NAMES"), MU_OPTION_DEFAULT, + N_("ignore the listed directives"), + mu_c_string, NULL, set_ignore_directives }, + + MU_OPTION_GROUP (N_("List and Dump Options")), + { "format", 'H', N_("TYPE"), MU_OPTION_DEFAULT, + N_("select output format"), + mu_c_string, NULL, set_format }, + { "no-header", 'q', NULL, MU_OPTION_DEFAULT, + N_("suppress format header"), + mu_c_bool, &suppress_header }, + + MU_OPTION_GROUP (N_("List, Dump and Delete Options")), + { "glob", 'G', NULL, MU_OPTION_DEFAULT, + N_("treat keys as globbing patterns"), + mu_c_string, NULL, set_glob }, + { "regex", 'R', NULL, MU_OPTION_DEFAULT, + N_("treat keys as regular expressions"), + mu_c_string, NULL, set_regex }, + { "ignore-case", 'i', NULL, MU_OPTION_DEFAULT, + N_("case-insensitive matches"), + mu_c_string, NULL, set_ignore_case }, + + MU_OPTION_GROUP (N_("Options for Use with Format 0.0")), + { "count-null", 'N', NULL, MU_OPTION_DEFAULT, + N_("data length accounts for terminating zero"), + mu_c_bool, &include_zero }, + { "no-count-null", 'n', NULL, MU_OPTION_DEFAULT, + N_("data length does not account for terminating zero"), + mu_c_string, NULL, clear_include_zero }, + MU_OPTION_END }; struct mu_kwd mode_tab[] = @@ -1769,12 +1768,8 @@ int mutool_dbm (int argc, char **argv) { int index; - - if (argp_parse (&dbm_argp, argc, argv, 0, &index, NULL)) - return 1; - - argc -= index; - argv += index; + + mu_action_getopt (&argc, &argv, dbm_options, dbm_doc, dbm_args_doc); if (argc == 0) { diff --git a/mu/dispatch.c b/mu/dispatch.c index 05ffeec96..cd27a6629 100644 --- a/mu/dispatch.c +++ b/mu/dispatch.c @@ -49,33 +49,34 @@ dispatch_find_action (const char *name) return NULL; } -char * -dispatch_docstring (const char *text) +void +subcommand_help (mu_stream_t str) { - mu_stream_t str; struct mutool_action_tab *p; - mu_off_t size; - size_t n; - char *ret; + unsigned margin; - mu_memory_stream_create (&str, MU_STREAM_RDWR); - mu_stream_printf (str, "%s\n%s\n\n", text, _("Commands are:")); + mu_stream_printf (str, "%s\n\n", _("Commands are:")); for (p = mutool_action_tab; p->name; p++) - mu_stream_printf (str, " %s %-16s - %s\n", - mu_program_name, - p->name, gettext (p->docstring)); + { + margin = 2; + mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM, + MU_IOCTL_WORDWRAP_SET_MARGIN, + &margin); + mu_stream_printf (str, "%s %s", mu_program_name, p->name); + margin = 29; + mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM, + MU_IOCTL_WORDWRAP_SET_MARGIN, + &margin); + mu_stream_printf (str, "%s", gettext (p->docstring)); + } + margin = 0; + mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM, + MU_IOCTL_WORDWRAP_SET_MARGIN, + &margin); mu_stream_printf (str, _("\nTry `%s COMMAND --help' to get help on a particular " "COMMAND.\n\n"), mu_program_name); - mu_stream_printf (str, "%s\n", _("Options are:")); - mu_stream_flush (str); - mu_stream_size (str, &size); - ret = mu_alloc (size + 1); - mu_stream_seek (str, 0, MU_SEEK_SET, NULL); - mu_stream_read (str, ret, size, &n); - ret[n] = 0; - mu_stream_destroy (&str); - return ret; + mu_stream_printf (str, "%s\n", _("OPTIONs are:")); } diff --git a/mu/filter.c b/mu/filter.c index 33a5588cc..ea23979d2 100644 --- a/mu/filter.c +++ b/mu/filter.c @@ -23,57 +23,41 @@ #include "argp.h" #include "mu.h" -static char filter_doc[] = N_("mu filter - apply a chain of filters to the input"); char filter_docstring[] = N_("apply a chain of filters to the input"); static char filter_args_doc[] = N_("[~]NAME [ARGS] [+ [~]NAME [ARGS]...]"); -static struct argp_option filter_options[] = { - { "encode", 'e', NULL, 0, N_("encode the input (default)") }, - { "decode", 'd', NULL, 0, N_("decode the input") }, - { "newline", 'n', NULL, 0, N_("print additional newline") }, - { "list", 'L', NULL, 0, N_("list supported filters") }, - { NULL } -}; - static int filter_mode = MU_FILTER_ENCODE; static int newline_option = 0; static int list_option; -static error_t -filter_parse_opt (int key, char *arg, struct argp_state *state) +static void +set_encode_mode (struct mu_parseopt *po, struct mu_option *opt, + char const *arg) { - switch (key) - { - case 'e': - filter_mode = MU_FILTER_ENCODE; - break; - - case 'd': - filter_mode = MU_FILTER_DECODE; - break; - - case 'n': - newline_option = 1; - break; + filter_mode = MU_FILTER_ENCODE; +} - case 'L': - list_option = 1; - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; +static void +set_decode_mode (struct mu_parseopt *po, struct mu_option *opt, + char const *arg) +{ + filter_mode = MU_FILTER_DECODE; } -static struct argp filter_argp = { - filter_options, - filter_parse_opt, - filter_args_doc, - filter_doc, - NULL, - NULL, - NULL +static struct mu_option filter_options[] = { + { "encode", 'e', NULL, MU_OPTION_DEFAULT, + N_("encode the input (default)"), + mu_c_string, NULL, set_encode_mode }, + { "decode", 'd', NULL, MU_OPTION_DEFAULT, + N_("decode the input"), + mu_c_string, NULL, set_decode_mode }, + { "newline", 'n', NULL, MU_OPTION_DEFAULT, + N_("print additional newline"), + mu_c_bool, &newline_option }, + { "list", 'L', NULL, MU_OPTION_DEFAULT, + N_("list supported filters"), + mu_c_bool, &list_option }, + MU_OPTION_END }; static int @@ -85,7 +69,7 @@ filter_printer (void *item, void *data) } static int -list_filters () +list_filters (void) { mu_list_t list; int rc = mu_filter_get_list (&list); @@ -111,17 +95,14 @@ negate_filter_mode (int mode) int mutool_filter (int argc, char **argv) { - int rc, index; + int rc; mu_stream_t flt, prev_stream; const char *fltname; int mode; - - if (argp_parse (&filter_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) - return 1; - - argc -= index; - argv += index; + mu_action_getopt (&argc, &argv, filter_options, filter_docstring, + filter_args_doc); + if (list_option) { if (argc) diff --git a/mu/flt2047.c b/mu/flt2047.c index df02409ee..eb99b7b4a 100644 --- a/mu/flt2047.c +++ b/mu/flt2047.c @@ -14,87 +14,50 @@ You should have received a copy of the GNU General Public License along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ -#if defined(HAVE_CONFIG_H) -# include <config.h> -#endif -#include <stdlib.h> -#include <string.h> -#include <mailutils/mailutils.h> -#include "argp.h" #include "mu.h" -static char flt2047_doc[] = N_("mu 2047 - decode/encode message headers."); char flt2047_docstring[] = N_("decode/encode email message headers"); static char flt2047_args_doc[] = N_("[text]"); -static struct argp_option flt2047_options[] = { - { "encode", 'e', NULL, 0, N_("encode the input (default)") }, - { "decode", 'd', NULL, 0, N_("decode the input") }, - { "newline", 'n', NULL, 0, N_("print additional newline") }, - { "charset", 'c', N_("NAME"), 0, - N_("set charset (default: iso-8859-1)") }, - { "encoding", 'E', N_("NAME"), 0, - N_("set encoding (default: quoted-printable)") }, - { NULL } -}; - static int decode_mode = 0; static int newline_option = 0; static const char *charset = "iso-8859-1"; static const char *encoding = "quoted-printable"; -static error_t -flt2047_parse_opt (int key, char *arg, struct argp_state *state) +static void +set_encode_mode (struct mu_parseopt *po, struct mu_option *opt, + char const *arg) { - switch (key) - { - case 'c': - charset = arg; - break; - - case 'e': - decode_mode = 0; - break; - - case 'E': - encoding = arg; - break; - - case 'd': - decode_mode = 1; - break; - - case 'n': - newline_option = 0; - break; - - default: - return ARGP_ERR_UNKNOWN; - } - return 0; + decode_mode = 0; } -static struct argp flt2047_argp = { - flt2047_options, - flt2047_parse_opt, - flt2047_args_doc, - flt2047_doc, - NULL, - NULL, - NULL +static struct mu_option flt2047_options[] = { + { "encode", 'e', NULL, MU_OPTION_DEFAULT, + N_("encode the input (default)"), + mu_c_string, NULL, set_encode_mode }, + { "decode", 'd', NULL, MU_OPTION_DEFAULT, + N_("decode the input"), + mu_c_bool, &decode_mode }, + { "newline", 'n', NULL, MU_OPTION_DEFAULT, + N_("print additional newline"), + mu_c_bool, &newline_option }, + { "charset", 'c', N_("NAME"), MU_OPTION_DEFAULT, + N_("set charset (default: iso-8859-1)"), + mu_c_string, &charset }, + { "encoding", 'E', N_("NAME"), MU_OPTION_DEFAULT, + N_("set encoding (default: quoted-printable)"), + mu_c_string, &encoding }, + MU_OPTION_END }; - + int mutool_flt2047 (int argc, char **argv) { - int rc, index; + int rc; char *p; - - if (argp_parse (&flt2047_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) - return 1; - argc -= index; - argv += index; + mu_action_getopt (&argc, &argv, flt2047_options, flt2047_docstring, + flt2047_args_doc); if (argc) { diff --git a/mu/getans.c b/mu/getans.c index dc59401e5..529aca4db 100644 --- a/mu/getans.c +++ b/mu/getans.c @@ -14,10 +14,6 @@ You should have received a copy of the GNU General Public License along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif -#include <mailutils/mailutils.h> #include "mu.h" int diff --git a/mu/getarg.c b/mu/getarg.c index f7197df72..6a084edaa 100644 --- a/mu/getarg.c +++ b/mu/getarg.c @@ -14,16 +14,8 @@ You should have received a copy of the GNU General Public License along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ -#if defined(HAVE_CONFIG_H) -# include <config.h> -#endif -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <netdb.h> -#include <netinet/in.h> -#include <mailutils/mailutils.h> #include "mu.h" +#include <netdb.h> int get_bool (const char *str, int *pb) diff --git a/mu/getyn.c b/mu/getyn.c index eb364929a..d721f9623 100644 --- a/mu/getyn.c +++ b/mu/getyn.c @@ -14,10 +14,6 @@ You should have received a copy of the GNU General Public License along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif -#include <mailutils/mailutils.h> #include "mu.h" int @@ -29,37 +29,24 @@ static char help_doc[] = N_("mu help - display a terse help summary"); char help_docstring[] = N_("display a terse help summary"); static char help_args_doc[] = N_("[COMMAND]"); -static struct argp help_argp = { - NULL, - NULL, - help_args_doc, - help_doc, - NULL, - NULL, - NULL -}; - int mutool_help (int argc, char **argv) { - int index; - - if (argp_parse (&help_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) - return 1; + mu_action_getopt (&argc, &argv, NULL, help_doc, help_args_doc); - if (index == argc - 1) + if (argc == 1) { - mutool_action_t action = dispatc |