summaryrefslogtreecommitdiff
path: root/include/mailutils
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-10-11 17:20:38 +0300
committerSergey Poznyakoff <gray@gnu.org>2016-10-11 17:36:10 +0300
commitbc73fc65600b6021dfe7a9fa1fba7e9b823993e2 (patch)
tree934b239ddd68b1bc91a42b66ddccfe3bcf01accf /include/mailutils
parent6e8147334cf9ffe36367760c06002a1e5b7ae0d5 (diff)
downloadmailutils-bc73fc65600b6021dfe7a9fa1fba7e9b823993e2.tar.gz
mailutils-bc73fc65600b6021dfe7a9fa1fba7e9b823993e2.tar.bz2
Introduce new CLI/configuration code for mailutils applications.
The new API is to replace libmu_cfg and libmu_argp. A smooth transition is scheduled, during which the two APIs will coexist, * configure.ac: Build libmailutils/cli/Makefile * include/mailutils/cli.h: New file. * include/mailutils/Makefile.am: Add cli.h * libmailutils/cli/Makefile.am: New file. * libmailutils/cli/capa.c: New file. * libmailutils/cli/cli.c: New file. * libmailutils/cli/stdcapa.c: New file. * libmailutils/Makefile.am (SUBDIRS): Add cli. * include/mailutils/cfg.h (mu_cfg_parse_hints): New members: append_tree and data. (MU_PARSE_CONFIG_LINT): New flag. * include/mailutils/diag.h (mu_program_name) (mu_full_program_name): Remove const qualifier. * include/mailutils/locker.h (mu_locker_set_default_external_program): Argument is const. * libmailutils/base/locker.c: Likewise. * include/mailutils/opt.h (mu_progname, mu_absprogname): Replace with mu_program_name and mu_full_program_name. (mu_set_progname): Rename to mu_set_program_name. (mu_parseopt) <po_data>: Change type to void *. (po_help_hook, po_version_hook): Change signatures. (mu_parseopt_error): New function. * libmailutils/opt/progname.c (mu_progname, mu_absprogname): Replace with mu_program_name and mu_full_program_name. (mu_set_progname): Rename to mu_set_program_name. * libmailutils/opt/help.c: Minor changes * libmailutils/opt/opt.c (parse_error): Rename to mu_parse_error (extern). (next_opt): Fix permutations. * libmailutils/tests/parseopt.c: Reflect changes. * libmailutils/tests/parseopt17.at: Improve test case * libmailutils/tests/parseopt_help05.at: Reflect changes. * libmailutils/tests/parseopt_help07.at: Reflect changes. * include/mailutils/stdstream.h (mu_program_name): Remove qualifier. * libmailutils/cfg/driver.c (mu_cfg_tree_reduce): Remove useless condition * libmailutils/cfg/lexer.l (mu_cfg_parse_file): Additional info messages. * libmailutils/cfg/parser.y (mu_cfg_parse_config): Join in the append_tree. * libmailutils/diag/diag.c (mu_program_name, mu_full_program_name) (mu_set_program_name): Remove. Declared elsewhere. * libmu_sieve/conf.c: Add new configuration code. Mark old text for removal. * libmailutils/tests/tcli.c: New program. * libmailutils/tests/Makefile.am: Add tcli.c
Diffstat (limited to 'include/mailutils')
-rw-r--r--include/mailutils/Makefile.am1
-rw-r--r--include/mailutils/cfg.h5
-rw-r--r--include/mailutils/cli.h55
-rw-r--r--include/mailutils/diag.h4
-rw-r--r--include/mailutils/locker.h2
-rw-r--r--include/mailutils/opt.h16
-rw-r--r--include/mailutils/stdstream.h2
7 files changed, 73 insertions, 12 deletions
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am
index ba87486ce..9ae3929af 100644
--- a/include/mailutils/Makefile.am
+++ b/include/mailutils/Makefile.am
@@ -36,6 +36,7 @@ pkginclude_HEADERS = \
cctype.h\
cfg.h\
cidr.h\
+ cli.h\
cstr.h\
datetime.h\
daemon.h\
diff --git a/include/mailutils/cfg.h b/include/mailutils/cfg.h
index 7ea8e080b..e9f3587ef 100644
--- a/include/mailutils/cfg.h
+++ b/include/mailutils/cfg.h
@@ -79,6 +79,8 @@ struct mu_cfg_parse_hints
char *site_rcfile;
char *custom_rcfile;
char *program;
+ struct mu_cfg_tree *append_tree;
+ void *data;
};
struct mu_cfg_tree
@@ -238,7 +240,8 @@ int mu_config_register_plain_section (const char *parent_path,
#define MU_CFG_FMT_LOCUS 0x080
#define MU_CFG_FMT_VALUE_ONLY 0x100
#define MU_CFG_FMT_PARAM_PATH 0x200
-
+#define MU_PARSE_CONFIG_LINT 0x400
+
#ifdef MU_CFG_COMPATIBILITY
# define MU_CFG_DEPRECATED
#else
diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
new file mode 100644
index 000000000..2943bc469
--- /dev/null
+++ b/include/mailutils/cli.h
@@ -0,0 +1,55 @@
+/* opt.h -- general-purpose command line option parser
+ Copyright (C) 2016 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/>.
+*/
+
+#ifndef _MAILUTILS_CLI_H
+#define _MAILUTILS_CLI_H
+#include <stdio.h>
+#include <mailutils/types.h>
+#include <mailutils/cfg.h>
+#include <mailutils/opt.h>
+
+typedef void (*mu_cli_capa_commit_fp) (void *);
+
+struct mu_cli_capa
+{
+ char *name;
+ struct mu_option *opt;
+ struct mu_cfg_param *cfg;
+ mu_cfg_section_fp parser;
+ mu_cli_capa_commit_fp commit;
+};
+
+void mu_cli_capa_init (void);
+void mu_cli_capa_register (struct mu_cli_capa *capa);
+void mu_cli_capa_apply (char const *name, mu_list_t opts, mu_list_t commits);
+
+struct mu_cli_setup
+{
+ struct mu_option **optv;
+ struct mu_cfg_param *cfg;
+ char *prog_doc;
+ char *prog_args;
+};
+
+void mu_version_func (struct mu_parseopt *po, FILE *stream);
+void mu_cli (int argc, char **argv, struct mu_cli_setup *setup,
+ char **capa, void *data,
+ int *ret_argc, char ***ret_argv);
+
+char *mu_site_config_file (void);
+
+#endif
diff --git a/include/mailutils/diag.h b/include/mailutils/diag.h
index 3e2bc5188..0a5ebd2de 100644
--- a/include/mailutils/diag.h
+++ b/include/mailutils/diag.h
@@ -29,8 +29,8 @@
extern "C" {
#endif
-extern const char *mu_program_name;
-extern const char *mu_full_program_name;
+extern char *mu_program_name;
+extern char *mu_full_program_name;
#define MU_DIAG_EMERG MU_LOG_EMERG
#define MU_DIAG_ALERT MU_LOG_ALERT
diff --git a/include/mailutils/locker.h b/include/mailutils/locker.h
index b8c4a93c5..718338f72 100644
--- a/include/mailutils/locker.h
+++ b/include/mailutils/locker.h
@@ -103,7 +103,7 @@ extern int mu_locker_set_default_flags (int flags, enum mu_locker_set_mode mode)
extern void mu_locker_set_default_retry_timeout (time_t to);
extern void mu_locker_set_default_retry_count (size_t n);
extern void mu_locker_set_default_expire_timeout (time_t t);
-extern int mu_locker_set_default_external_program (char *path);
+extern int mu_locker_set_default_external_program (char const *path);
/* A flags of 0 means that the default will be used. */
extern int mu_locker_create (mu_locker_t *, const char *filename, int flags);
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index 8e3b03b5d..cc5634211 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -23,10 +23,10 @@
#include <mailutils/util.h>
#include <mailutils/cctype.h>
-extern char *mu_progname;
-extern char *mu_absprogname;
+extern char *mu_program_name;
+extern char *mu_full_program_name;
-void mu_set_progname (char const *arg);
+void mu_set_program_name (char const *arg);
#define MU_OPTION_DEFAULT 0
#define MU_OPTION_ARG_OPTIONAL 0x01
@@ -118,7 +118,7 @@ struct mu_parseopt
struct mu_option **po_optv; /* Array of ptrs to option structures */
int po_flags;
- char *po_data; /* Call-specific data */
+ void *po_data; /* Call-specific data */
int po_exit_error; /* Exit on error with this code */
@@ -130,9 +130,10 @@ struct mu_parseopt
char const *po_package_name;
char const *po_package_url;
char const *po_extra_info;
-
- void (*po_help_hook) (FILE *stream); /* FIXME: should take mu_stream_t ?*/
- void (*po_version_hook) (FILE *stream);
+
+ /* FIXME: should these take mu_stream_t ?*/
+ void (*po_help_hook) (struct mu_parseopt *po, FILE *stream);
+ void (*po_version_hook) (struct mu_parseopt *po, FILE *stream);
/* Output data */
int po_ind; /* Index of the next option */
@@ -162,6 +163,7 @@ struct mu_parseopt
int mu_parseopt (struct mu_parseopt *p,
int argc, char **argv, struct mu_option **optv,
int flags);
+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);
diff --git a/include/mailutils/stdstream.h b/include/mailutils/stdstream.h
index ac35ff78d..97718811d 100644
--- a/include/mailutils/stdstream.h
+++ b/include/mailutils/stdstream.h
@@ -28,7 +28,7 @@ extern mu_stream_t mu_strin;
extern mu_stream_t mu_strout;
extern mu_stream_t mu_strerr;
-extern const char *mu_program_name;
+extern char *mu_program_name;
#define MU_STRERR_STDERR 0
#define MU_STRERR_SYSLOG 1

Return to:

Send suggestions and report system problems to the System administrator.