diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-04-11 15:04:38 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-04-11 17:32:19 +0300 |
commit | 444d20f3c7151c1d30fa6567cce35868c7ec38f3 (patch) | |
tree | e186f9a06833c9bc4c0bbe01c81dec9a1a7519dd | |
parent | 460fc33fd89c4789edfbcafda89cf32cba89e854 (diff) | |
download | mailutils-444d20f3c7151c1d30fa6567cce35868c7ec38f3.tar.gz mailutils-444d20f3c7151c1d30fa6567cce35868c7ec38f3.tar.bz2 |
Rewrite the mailutils tool
The subcommands are re-implemented as standalone binaries installed
to pkglibexecdir. The main binary acts as a dispatcher.
* configure.ac: Build mu/libexec/Makefile
* include/mailutils/.gitignore: Ignore gitinfo.h
* include/mailutils/opt.h (mu_parseopt_help_stream_create): New proto.
* libmailutils/cli/cli.c (mu_cli_ext): Honor MU_PARSEOPT_PROG_NAME
setting.
* libmailutils/opt/help.c (mu_parseopt_create_help_stream): New
function.
(mu_program_help,mu_program_usage)
(mu_program_version): Use it.
* mu/Makefile.am: Move commands to separate executables under libexec.
* mu/mu.c: Rewrite.
* mu/dispatch.c: Remove.
* mu/help.c: Remove.
* mu/libexec/.gitignore: New file.
* mu/libexec/Makefile.am: New file.
* mu/libexec/getopt.c: New file.
* mu/getans.c: Move to mu/libexec.
* mu/getarg.c: Likewise.
* mu/getyn.c: Likewise.
* mu/util.c: Likewise.
* mu/verbose.c: Likewise.
* mu/shell.c: Likewise.
* mu/mu.h: Remove.
* mu/libexec/mu.h: New file.
* mu/acl.c: Move to mu/libexec; Rewrite as a standalone program.
* mu/cflags.c: Likewise.
* mu/dbm.c: Likewise.
* mu/filter.c: Likewise.
* mu/flt2047.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/smtp.c: Likewise.
* mu/stat.c: Likewise.
* mu/wicket.c: Likewise.
* mu/mu-setup.awk: Remove.
* po/POTFILES.in: Update.
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | include/mailutils/.gitignore | 1 | ||||
-rw-r--r-- | include/mailutils/opt.h | 3 | ||||
-rw-r--r-- | libmailutils/cli/cli.c | 14 | ||||
-rw-r--r-- | libmailutils/opt/help.c | 39 | ||||
-rw-r--r-- | mu/Makefile.am | 98 | ||||
-rw-r--r-- | mu/dispatch.c | 82 | ||||
-rw-r--r-- | mu/help.c | 63 | ||||
-rw-r--r-- | mu/libexec/.gitignore | 1 | ||||
-rw-r--r-- | mu/libexec/Makefile.am | 131 | ||||
-rw-r--r-- | mu/libexec/acl.c (renamed from mu/acl.c) | 13 | ||||
-rw-r--r-- | mu/libexec/cflags.c (renamed from mu/cflags.c) | 13 | ||||
-rw-r--r-- | mu/libexec/dbm.c (renamed from mu/dbm.c) | 18 | ||||
-rw-r--r-- | mu/libexec/filter.c (renamed from mu/filter.c) | 9 | ||||
-rw-r--r-- | mu/libexec/flt2047.c (renamed from mu/flt2047.c) | 13 | ||||
-rw-r--r-- | mu/libexec/getans.c (renamed from mu/getans.c) | 0 | ||||
-rw-r--r-- | mu/libexec/getarg.c (renamed from mu/getarg.c) | 0 | ||||
-rw-r--r-- | mu/libexec/getopt.c | 72 | ||||
-rw-r--r-- | mu/libexec/getyn.c (renamed from mu/getyn.c) | 0 | ||||
-rw-r--r-- | mu/libexec/imap.c (renamed from mu/imap.c) | 10 | ||||
-rw-r--r-- | mu/libexec/info.c (renamed from mu/info.c) | 18 | ||||
-rw-r--r-- | mu/libexec/ldflags.c (renamed from mu/ldflags.c) | 13 | ||||
-rw-r--r-- | mu/libexec/logger.c (renamed from mu/logger.c) | 16 | ||||
-rw-r--r-- | mu/libexec/mu.h (renamed from mu/mu.h) | 33 | ||||
-rw-r--r-- | mu/libexec/pop.c (renamed from mu/pop.c) | 14 | ||||
-rw-r--r-- | mu/libexec/query.c (renamed from mu/query.c) | 15 | ||||
-rw-r--r-- | mu/libexec/send.c (renamed from mu/send.c) | 10 | ||||
-rw-r--r-- | mu/libexec/shell.c (renamed from mu/shell.c) | 0 | ||||
-rw-r--r-- | mu/libexec/smtp.c (renamed from mu/smtp.c) | 9 | ||||
-rw-r--r-- | mu/libexec/stat.c (renamed from mu/stat.c) | 24 | ||||
-rw-r--r-- | mu/libexec/util.c (renamed from mu/util.c) | 0 | ||||
-rw-r--r-- | mu/libexec/verbose.c (renamed from mu/verbose.c) | 0 | ||||
-rw-r--r-- | mu/libexec/wicket.c (renamed from mu/wicket.c) | 14 | ||||
-rw-r--r-- | mu/mu-setup.awk | 68 | ||||
-rw-r--r-- | mu/mu.c | 289 | ||||
-rw-r--r-- | po/POTFILES.in | 25 |
36 files changed, 540 insertions, 589 deletions
diff --git a/configure.ac b/configure.ac index 7ffba717b..949a04050 100644 --- a/configure.ac +++ b/configure.ac @@ -1541,6 +1541,7 @@ AC_CONFIG_FILES([ mu-aux/mailutils.spec sieve/Makefile mu/Makefile + mu/libexec/Makefile ]) AC_OUTPUT diff --git a/include/mailutils/.gitignore b/include/mailutils/.gitignore index cbd8ca5a1..23c5dff1e 100644 --- a/include/mailutils/.gitignore +++ b/include/mailutils/.gitignore @@ -2,3 +2,4 @@ Makefile Makefile.in errno.h types.h +gitinfo.h diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h index 66a3fc97c..866e00809 100644 --- a/include/mailutils/opt.h +++ b/include/mailutils/opt.h @@ -185,6 +185,9 @@ void mu_parseopt_error (struct mu_parseopt *po, char const *fmt, ...); int mu_parseopt_apply (struct mu_parseopt *p); void mu_parseopt_free (struct mu_parseopt *p); +int mu_parseopt_help_stream_create (mu_stream_t *retstr, + struct mu_parseopt *po, + mu_stream_t outstr); unsigned mu_parseopt_getcolumn (const char *name); void mu_option_describe_options (mu_stream_t str, struct mu_parseopt *p); diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c index a7a015780..0680a2f0e 100644 --- a/libmailutils/cli/cli.c +++ b/libmailutils/cli/cli.c @@ -483,6 +483,7 @@ run_commit (void *item, void *data) | MU_PARSEOPT_BUG_ADDRESS \ | MU_PARSEOPT_EXTRA_INFO \ | MU_PARSEOPT_VERSION_HOOK \ + | MU_PARSEOPT_PROG_NAME \ | MU_PARSEOPT_NEGATION) void @@ -520,8 +521,13 @@ mu_cli_ext (int argc, char **argv, /* Set program name */ if (!(hints.flags & MU_CFHINT_PROGRAM)) { - mu_set_program_name (argv[0]); - hints.program = (char*) mu_program_name; + if (pohint->po_flags & MU_PARSEOPT_PROG_NAME) + hints.program = (char *) pohint->po_prog_name; + else + { + mu_set_program_name (argv[0]); + hints.program = (char*) mu_program_name; + } hints.flags |= MU_CFHINT_PROGRAM; } @@ -610,7 +616,9 @@ mu_cli_ext (int argc, char **argv, po.po_version_hook = pohint->po_version_hook; if (flags & MU_PARSEOPT_NEGATION) po.po_negation = pohint->po_negation; - + if (flags & MU_PARSEOPT_PROG_NAME) + po.po_prog_name = pohint->po_prog_name; + appd.setup = setup; appd.hints = &hints; appd.append_tree = NULL; diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c index bfd99cf1e..8be732614 100644 --- a/libmailutils/opt/help.c +++ b/libmailutils/opt/help.c @@ -345,19 +345,21 @@ mu_option_describe_options (mu_stream_t str, struct mu_parseopt *po) static void print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str); +int +mu_parseopt_help_stream_create (mu_stream_t *retstr, + struct mu_parseopt *po, mu_stream_t outstr) +{ + init_usage_vars (po); + return mu_wordwrap_stream_create (retstr, outstr, 0, rmargin); +} + void mu_program_help (struct mu_parseopt *po, mu_stream_t outstr) { mu_stream_t str; - int rc; - init_usage_vars (po); - - rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin); - if (rc) - { - abort ();//FIXME - } + if (mu_parseopt_help_stream_create (&str, po, outstr)) + abort (); print_program_usage (po, 0, str); @@ -575,16 +577,10 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str) void mu_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t outstr) { - int rc; mu_stream_t str; - - init_usage_vars (po); - rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin); - if (rc) - { - abort ();//FIXME - } + if (mu_parseopt_help_stream_create (&str, po, outstr)) + abort (); print_program_usage (po, optsum, str); mu_stream_destroy (&str); } @@ -592,16 +588,11 @@ mu_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t outstr) void mu_program_version (struct mu_parseopt *po, mu_stream_t outstr) { - int rc; mu_stream_t str; - - init_usage_vars (po); - rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin); - if (rc) - { - abort ();//FIXME - } + if (mu_parseopt_help_stream_create (&str, po, outstr)) + abort (); + po->po_version_hook (po, str); mu_stream_destroy (&str); diff --git a/mu/Makefile.am b/mu/Makefile.am index 1c2ec00c9..0cf99cf93 100644 --- a/mu/Makefile.am +++ b/mu/Makefile.am @@ -15,99 +15,15 @@ ## You should have received a copy of the GNU General Public License ## along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. +SUBDIRS = libexec + bin_PROGRAMS = mailutils bin_SCRIPTS = mailutils-config +EXTRA_DIST = mailutils-config -IDLE_MODULES= - -if MU_COND_SUPPORT_POP - POP_C=pop.c -else - IDLE_MODULES+=pop.c -endif - -if MU_COND_SUPPORT_IMAP - IMAP_C=imap.c -else - IDLE_MODULES+=imap.c -endif - -if MU_COND_DBM - DBM_C=dbm.c - LIBMU_DBM=../libmu_dbm/libmu_dbm.la -else - IDLE_MODULES+=dbm.c -endif - -if MU_COND_SUPPORT_SMTP - SMTP_C=smtp.c -else - IDLE_MODULES+=smtp.c -endif - -MODULES = \ - acl.c\ - cflags.c\ - $(DBM_C)\ - $(IMAP_C)\ - filter.c\ - flt2047.c\ - help.c\ - info.c\ - ldflags.c\ - logger.c\ - $(POP_C)\ - query.c\ - send.c\ - stat.c\ - $(SMTP_C)\ - wicket.c - -mailutils_SOURCES = \ - dispatch.c\ - getans.c\ - getarg.c\ - getyn.c\ - mu.h\ - mu.c\ - shell.c\ - util.c\ - verbose.c\ - $(MODULES) - -mailutils_LDADD = \ - ${MU_APP_LIBRARIES}\ - ${MU_LIB_MBOX}\ - ${MU_LIB_IMAP}\ - ${MU_LIB_POP}\ - ${MU_LIB_NNTP}\ - ${MU_LIB_MH}\ - ${MU_LIB_MAILDIR}\ - ${MU_LIB_MAILER}\ - ${MU_LIB_AUTH}\ - @MU_AUTHLIBS@\ - ${MU_LIB_MAILUTILS}\ - ${LIBMU_DBM} @DBMLIBS@\ - @READLINE_LIBS@ @MU_COMMON_LIBRARIES@ - -AM_CPPFLAGS = \ - @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@\ - -DCOMPILE_FLAGS="\"-I$(includedir)\"" \ - -DLINK_FLAGS="\"-L$(libdir)\"" \ - -DLINK_POSTFLAGS="\"$(MU_LINK_POSTFLAGS)\"" \ - -DAUTHLIBS="\"$(MU_AUTHLIBS)\"" \ - -DGUILE_LIBS="\"$(GUILE_LIBS)\"" \ - -DPYTHON_LIBS="\"$(PYTHON_LIBS)\"" \ - -DI18NLIBS="\"$(LIBINTL)\"" \ - -DDBMLIBS="\"$(DBMLIBS)\"" - -BUILT_SOURCES=mu-setup.c mu-setup.h -EXTRA_DIST=mu-setup.awk mu-setup.c mu-setup.h template.c mailutils-config +mailutils_SOURCES = mu.c +mailutils_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ -DMAILUTILSDIR=\"$(pkglibexecdir)\" -mu-setup.h: Makefile.am $(MODULES) $(IDLE_MODULES) - $(AM_V_GEN)$(AWK) -f $(srcdir)/mu-setup.awk -v mode=h \ - $(MODULES) $(IDLE_MODULES) > mu-setup.h +LDADD = ${MU_APP_LIBRARIES} ${MU_LIB_MAILUTILS} -mu-setup.c: Makefile.am $(MODULES) $(IDLE_MODULES) - $(AM_V_GEN)$(AWK) -f $(srcdir)/mu-setup.awk -v mode=c \ - $(MODULES) $(IDLE_MODULES) > mu-setup.c +AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ diff --git a/mu/dispatch.c b/mu/dispatch.c deleted file mode 100644 index 3fd008b31..000000000 --- a/mu/dispatch.c +++ /dev/null @@ -1,82 +0,0 @@ -/* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 2010-2012, 2014-2017 Free Software Foundation, Inc. - - GNU Mailutils is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - GNU Mailutils is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - 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/alloc.h> -#include <mailutils/stream.h> -#include <mailutils/stdstream.h> -#include <mailutils/nls.h> -#include "mu.h" -#include "mu-setup.h" - -struct mutool_action_tab -{ - const char *name; - mutool_action_t action; - const char *docstring; -}; - -struct mutool_action_tab mutool_action_tab[] = { -#include "mu-setup.c" - { NULL } -}; - -mutool_action_t -dispatch_find_action (const char *name) -{ - struct mutool_action_tab *p; - - for (p = mutool_action_tab; p->name; p++) - if (strcmp (p->name, name) == 0) - return p->action; - return NULL; -} - -void -subcommand_help (mu_stream_t str) -{ - struct mutool_action_tab *p; - unsigned margin; - - mu_stream_printf (str, "%s\n\n", _("Commands are:")); - for (p = mutool_action_tab; p->name; p++) - { - 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:")); -} - diff --git a/mu/help.c b/mu/help.c deleted file mode 100644 index c0e306af2..000000000 --- a/mu/help.c +++ /dev/null @@ -1,63 +0,0 @@ -/* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 2010-2012, 2014-2017 Free Software Foundation, Inc. - - GNU Mailutils is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - GNU Mailutils is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ - -/* mu help - specjalnie dla Wojtka :) */ - -#if defined(HAVE_CONFIG_H) -# include <config.h> -#endif -#include <stdlib.h> -#include <mailutils/nls.h> -#include <mailutils/io.h> -#include "mu.h" - -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]"); - -int -mutool_help (int argc, char **argv) -{ - mu_action_getopt (&argc, &argv, NULL, help_doc, help_args_doc); - - if (argc == 1) - { - char *hargv[3]; - mutool_action_t action = dispatch_find_action (argv[0]); - if (!action) - { - mu_error (_("don't know what %s is"), argv[0]); - exit (1); - } - hargv[0] = argv[0]; - hargv[1] = "--help"; - hargv[2] = NULL; - return action (3, hargv); - } - else if (argc > 1) - { - mu_error (_("too many arguments")); - exit (1); - } - return mu_help (); -} - -/* - MU Setup: help - mu-handler: mutool_help - mu-docstring: help_docstring - End MU Setup: -*/ diff --git a/mu/libexec/.gitignore b/mu/libexec/.gitignore new file mode 100644 index 000000000..1fea78c06 --- /dev/null +++ b/mu/libexec/.gitignore @@ -0,0 +1 @@ +/mailutils-* diff --git a/mu/libexec/Makefile.am b/mu/libexec/Makefile.am new file mode 100644 index 000000000..b59dc1127 --- /dev/null +++ b/mu/libexec/Makefile.am @@ -0,0 +1,131 @@ +pkglibexec_PROGRAMS=\ + mailutils-acl\ + mailutils-cflags\ + mailutils-ldflags\ + mailutils-filter\ + mailutils-flt2047\ + mailutils-info\ + mailutils-logger\ + mailutils-query\ + mailutils-send\ + mailutils-smtp\ + mailutils-stat\ + mailutils-wicket + +noinst_HEADERS = mu.h +noinst_LIBRARIES = libmutool.a +libmutool_a_SOURCES = \ + getopt.c\ + getans.c\ + getarg.c\ + getyn.c\ + shell.c\ + util.c\ + verbose.c + +mailutils_acl_SOURCES = acl.c +mailutils_filter_SOURCES = filter.c +mailutils_flt2047_SOURCES = flt2047.c +mailutils_info_SOURCES = info.c +mailutils_logger_SOURCES = logger.c +mailutils_query_SOURCES = query.c +mailutils_wicket_SOURCES = wicket.c + +mailutils_cflags_SOURCES=cflags.c +mailutils_cflags_CPPFLAGS = $(AM_CPPFLAGS)\ + -DCOMPILE_FLAGS="\"-I$(includedir)\"" + +mailutils_ldflags_SOURCES=ldflags.c +mailutils_ldflags_CPPFLAGS = $(AM_CPPFLAGS)\ + -DLINK_FLAGS="\"-L$(libdir)\"" \ + -DLINK_POSTFLAGS="\"$(MU_LINK_POSTFLAGS)\"" \ + -DAUTHLIBS="\"$(MU_AUTHLIBS)\"" \ + -DGUILE_LIBS="\"$(GUILE_LIBS)\"" \ + -DPYTHON_LIBS="\"$(PYTHON_LIBS)\"" \ + -DI18NLIBS="\"$(LIBINTL)\"" \ + -DDBMLIBS="\"$(DBMLIBS)\"" + +if MU_COND_DBM + pkglibexec_PROGRAMS += mailutils-dbm + mailutils_dbm_SOURCES = dbm.c + mailutils_dbm_LDFLAGS = \ + ${MU_APP_LIBRARIES}\ + ../../libmu_dbm/libmu_dbm.la\ + @DBMLIBS@\ + $(MUTOOL_LIBRARIES_TAIL) +endif + +if MU_COND_SUPPORT_POP + pkglibexec_PROGRAMS += mailutils-pop + mailutils_pop_SOURCES = pop.c + mailutils_pop_CPPFLAGS = \ + $(AM_CPPFLAGS)\ + @MU_AUTHINCS@ + mailutils_pop_LDADD =\ + ${MU_APP_LIBRARIES}\ + ${MU_LIB_POP}\ + ${MU_LIB_AUTH}\ + @MU_AUTHLIBS@\ + $(MUTOOL_LIBRARIES_TAIL) +endif + +if MU_COND_SUPPORT_IMAP + pkglibexec_PROGRAMS += mailutils-imap + mailutils_imap_SOURCES = imap.c + mailutils_imap_CPPFLAGS = \ + $(AM_CPPFLAGS)\ + @MU_AUTHINCS@ + mailutils_imap_LDADD =\ + ${MU_APP_LIBRARIES}\ + ${MU_LIB_IMAP}\ + ${MU_LIB_AUTH}\ + @MU_AUTHLIBS@\ + $(MUTOOL_LIBRARIES_TAIL) +endif + +mailutils_send_SOURCES = send.c +mailutils_send_CPPFLAGS = \ + $(AM_CPPFLAGS)\ + @MU_AUTHINCS@ +mailutils_send_LDADD = \ + ${MU_APP_LIBRARIES}\ + ${MU_LIB_MAILER}\ + ${MU_LIB_AUTH}\ + @MU_AUTHLIBS@\ + $(MUTOOL_LIBRARIES_TAIL) + +mailutils_stat_SOURCES = stat.c +mailutils_stat_LDADD = \ + ${MU_APP_LIBRARIES}\ + ${MU_LIB_MBOX}\ + ${MU_LIB_IMAP}\ + ${MU_LIB_POP}\ + ${MU_LIB_NNTP}\ + ${MU_LIB_MH}\ + ${MU_LIB_MAILDIR}\ + ${MU_LIB_AUTH}\ + @MU_AUTHLIBS@\ + $(MUTOOL_LIBRARIES_TAIL) + +mailutils_smtp_SOURCES = smtp.c +mailutils_smtp_CPPFLAGS = \ + $(AM_CPPFLAGS)\ + @MU_AUTHINCS@ +mailutils_smtp_LDADD = \ + ${MU_APP_LIBRARIES}\ + ${MU_LIB_MAILER}\ + ${MU_LIB_AUTH}\ + @MU_AUTHLIBS@\ + $(MUTOOL_LIBRARIES_TAIL) + +MUTOOL_LIBRARIES_TAIL = \ + ${MU_APP_LIBRARIES}\ + ./libmutool.a\ + ${MU_LIB_MAILUTILS}\ + @READLINE_LIBS@\ + @MU_COMMON_LIBRARIES@ + +LDADD = ${MU_APP_LIBRARIES} $(MUTOOL_LIBRARIES_TAIL) + +AM_CPPFLAGS = \ + @MU_APP_COMMON_INCLUDES@ diff --git a/mu/acl.c b/mu/libexec/acl.c index 0c18483ce..9c5e732d3 100644 --- a/mu/acl.c +++ b/mu/libexec/acl.c @@ -14,6 +14,10 @@ You should have received a copy of the GNU General Public License along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ +#include <config.h> +#include <mailutils/mailutils.h> +#include <mailutils/nls.h> +#include <sysexits.h> #include "mu.h" char acl_docstring[] = N_("test access control lists"); @@ -41,7 +45,7 @@ static struct mu_cfg_param acl_cfg_param[] = { }; int -mutool_acl (int argc, char **argv) +main (int argc, char **argv) { int rc; mu_acl_result_t result; @@ -126,10 +130,3 @@ mutool_acl (int argc, char **argv) return 0; } - -/* - MU Setup: acl - mu-handler: mutool_acl - mu-docstring: acl_docstring - End MU Setup: -*/ diff --git a/mu/cflags.c b/mu/libexec/cflags.c index 233d5f96e..c63aa5e8c 100644 --- a/mu/cflags.c +++ b/mu/libexec/cflags.c @@ -14,12 +14,16 @@ You should have received a copy of the GNU General Public License along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ +#include <config.h> +#include <mailutils/mailutils.h> +#include <mailutils/nls.h> +#include <sysexits.h> #include "mu.h" char cflags_docstring[] = N_("show compiler options"); int -mutool_cflags (int argc, char **argv) +main (int argc, char **argv) { mu_action_getopt (&argc, &argv, NULL, cflags_docstring, NULL); if (argc) @@ -31,10 +35,3 @@ mutool_cflags (int argc, char **argv) return 0; } -/* - MU Setup: cflags - mu-handler: mutool_cflags - mu-docstring: cflags_docstring - End MU Setup: -*/ - diff --git a/mu/dbm.c b/mu/libexec/dbm.c index 56c75ebc9..50fe4ec87 100644 --- a/mu/dbm.c +++ b/mu/libexec/dbm.c @@ -14,14 +14,17 @@ You should have received a copy of the GNU General Public License along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ -#include "mu.h" +#include <config.h> +#include <mailutils/mailutils.h> #include <mailutils/dbm.h> #include <fnmatch.h> #include <regex.h> #include <sys/stat.h> #include <grp.h> +#include <sysexits.h> +#include "mu.h" -static char dbm_doc[] = N_("mu dbm - DBM management tool\n" +static char dbm_doc[] = N_("DBM management tool\n" "Valid COMMANDs are:\n" "\n" " create or load - create the database\n" @@ -1765,7 +1768,7 @@ struct mu_kwd mode_tab[] = }; int -mutool_dbm (int argc, char **argv) +main (int argc, char **argv) { int index; @@ -1852,12 +1855,3 @@ mutool_dbm (int argc, char **argv) return 0; } -/* - MU Setup: dbm - mu-handler: mutool_dbm - mu-docstring: dbm_docstring - mu-cond: ENABLE_DBM - End MU Setup: -*/ - - diff --git a/mu/filter.c b/mu/libexec/filter.c index c64ae5ca4..97800c487 100644 --- a/mu/filter.c +++ b/mu/libexec/filter.c @@ -92,7 +92,7 @@ negate_filter_mode (int mode) } int -mutool_filter (int argc, char **argv) +main (int argc, char **argv) { int rc; mu_stream_t flt, prev_stream; @@ -173,10 +173,3 @@ mutool_filter (int argc, char **argv) return 0; } - -/* - MU Setup: filter - mu-handler: mutool_filter - mu-docstring: filter_docstring - End MU Setup: -*/ diff --git a/mu/flt2047.c b/mu/libexec/flt2047.c index 0193ee124..efd1cdb41 100644 --- a/mu/flt2047.c +++ b/mu/libexec/flt2047.c @@ -14,6 +14,10 @@ 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 <mailutils/mailutils.h> #include "mu.h" char flt2047_docstring[] = N_("decode/encode email message headers"); @@ -51,7 +55,7 @@ static struct mu_option flt2047_options[] = { }; int -mutool_flt2047 (int argc, char **argv) +main (int argc, char **argv) { int rc; char *p; @@ -103,10 +107,3 @@ mutool_flt2047 (int argc, char **argv) return 0; } - -/* - MU Setup: 2047 - mu-handler: mutool_flt2047 - mu-docstring: flt2047_docstring - End MU Setup: -*/ diff --git a/mu/getans.c b/mu/libexec/getans.c index 9a090658c..9a090658c 100644 --- a/mu/getans.c +++ b/mu/libexec/getans.c diff --git a/mu/getarg.c b/mu/libexec/getarg.c index ad7be5654..ad7be5654 100644 --- a/mu/getarg.c +++ b/mu/libexec/getarg.c diff --git a/mu/libexec/getopt.c b/mu/libexec/getopt.c new file mode 100644 index 000000000..113687a4b --- /dev/null +++ b/mu/libexec/getopt.c @@ -0,0 +1,72 @@ +/* GNU Mailutils -- a suite of utilities for electronic mail + Copyright (C) 2010-2012, 2014-2017 Free Software Foundation, Inc. + + GNU Mailutils is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GNU Mailutils is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> +#include <mailutils/mailutils.h> +#include <mailutils/nls.h> + +static void +describe (struct mu_parseopt *po, struct mu_option *opt, char const *unused) +{ + int len = strcspn (po->po_prog_doc, "\n"); + mu_printf ("%.*s\n", len, po->po_prog_doc); + exit (0); +} + +struct mu_option common_options[] = { + { "describe", 0, NULL, MU_OPTION_HIDDEN, + "describe the program", + mu_c_string, NULL, describe }, + MU_OPTION_END +}; + +void +mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt, + char const *docstring, char const *argdoc) +{ + static struct mu_parseopt pohint = { + .po_flags = MU_PARSEOPT_PACKAGE_NAME + | MU_PARSEOPT_PACKAGE_URL + | MU_PARSEOPT_BUG_ADDRESS + | MU_PARSEOPT_VERSION_HOOK, + .po_package_name = PACKAGE_NAME, + .po_package_url = PACKAGE_URL, + .po_bug_address = PACKAGE_BUGREPORT, + .po_version_hook = mu_version_hook + }; + static char *defcapa[] = { "debug", NULL }; + struct mu_cfg_parse_hints cfhint = { .flags = 0 }; + struct mu_option *options[3] = { common_options, opt, NULL }; + struct mu_cli_setup cli = { + .prog_doc = (char*) docstring, + .prog_args = (char*) argdoc, + .optv = options + }; + char *p; + + p = getenv ("MAILUTILS_PROGNAME"); + if (p) + { + pohint.po_flags |= MU_PARSEOPT_PROG_NAME; + pohint.po_prog_name = p; + } + + MU_APP_INIT_NLS (); + mu_cli_ext (*pargc, *pargv, &cli, &pohint, &cfhint, defcapa, NULL, + pargc, pargv); +} + + diff --git a/mu/getyn.c b/mu/libexec/getyn.c index 4d293a732..4d293a732 100644 --- a/mu/getyn.c +++ b/mu/libexec/getyn.c diff --git a/mu/imap.c b/mu/li |