summaryrefslogtreecommitdiff
path: root/libmailutils
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 /libmailutils
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 'libmailutils')
-rw-r--r--libmailutils/Makefile.am3
-rw-r--r--libmailutils/base/locker.c2
-rw-r--r--libmailutils/cfg/driver.c12
-rw-r--r--libmailutils/cfg/lexer.l6
-rw-r--r--libmailutils/cfg/parser.y5
-rw-r--r--libmailutils/cli/Makefile.am26
-rw-r--r--libmailutils/cli/capa.c96
-rw-r--r--libmailutils/cli/cli.c420
-rw-r--r--libmailutils/cli/stdcapa.c466
-rw-r--r--libmailutils/diag/diag.c26
-rw-r--r--libmailutils/opt/help.c8
-rw-r--r--libmailutils/opt/opt.c24
-rw-r--r--libmailutils/opt/progname.c14
-rw-r--r--libmailutils/tests/.gitignore1
-rw-r--r--libmailutils/tests/Makefile.am1
-rw-r--r--libmailutils/tests/parseopt.c4
-rw-r--r--libmailutils/tests/parseopt17.at20
-rw-r--r--libmailutils/tests/parseopt_help05.at2
-rw-r--r--libmailutils/tests/parseopt_help07.at2
-rw-r--r--libmailutils/tests/tcli.c75
20 files changed, 1149 insertions, 64 deletions
diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am
index 7a5270c4c..82550c23f 100644
--- a/libmailutils/Makefile.am
+++ b/libmailutils/Makefile.am
@@ -17,7 +17,7 @@
17# <http://www.gnu.org/licenses/>. 17# <http://www.gnu.org/licenses/>.
18 18
19SUBDIRS = \ 19SUBDIRS = \
20 auth base address list sockaddr cidr cfg diag\ 20 auth base address list sockaddr cidr cfg cli diag\
21 filter mailbox mailer mime msgset opt server string stream stdstream\ 21 filter mailbox mailer mime msgset opt server string stream stdstream\
22 property url imapio datetime . tests 22 property url imapio datetime . tests
23 23
@@ -33,6 +33,7 @@ libmailutils_la_LIBADD = \
33 sockaddr/libsockaddr.la\ 33 sockaddr/libsockaddr.la\
34 cidr/libcidr.la\ 34 cidr/libcidr.la\
35 cfg/libcfg.la\ 35 cfg/libcfg.la\
36 cli/libcli.la\
36 datetime/libdatetime.la\ 37 datetime/libdatetime.la\
37 diag/libdiag.la\ 38 diag/libdiag.la\
38 filter/libfilter.la\ 39 filter/libfilter.la\
diff --git a/libmailutils/base/locker.c b/libmailutils/base/locker.c
index b4663b948..c4fe993bf 100644
--- a/libmailutils/base/locker.c
+++ b/libmailutils/base/locker.c
@@ -242,7 +242,7 @@ mu_locker_set_default_expire_timeout (time_t t)
242} 242}
243 243
244int 244int
245mu_locker_set_default_external_program (char *path) 245mu_locker_set_default_external_program (char const *path)
246{ 246{
247 char *p = strdup (path); 247 char *p = strdup (path);
248 if (!p) 248 if (!p)
diff --git a/libmailutils/cfg/driver.c b/libmailutils/cfg/driver.c
index c0cd2d5d9..f2a43a367 100644
--- a/libmailutils/cfg/driver.c
+++ b/libmailutils/cfg/driver.c
@@ -463,7 +463,7 @@ mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree,
463 void *target_ptr) 463 void *target_ptr)
464{ 464{
465 int rc = 0; 465 int rc = 0;
466 466 struct mu_cfg_cont *cont;
467 if (!parse_tree) 467 if (!parse_tree)
468 return 0; 468 return 0;
469 if (hints && (hints->flags & MU_PARSE_CONFIG_DUMP)) 469 if (hints && (hints->flags & MU_PARSE_CONFIG_DUMP))
@@ -477,13 +477,9 @@ mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree,
477 mu_stream_destroy (&stream); 477 mu_stream_destroy (&stream);
478 } 478 }
479 479
480 if (root_container) 480 cont = mu_build_container (progparam);
481 { 481 rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, target_ptr, NULL);
482 struct mu_cfg_cont *cont = mu_build_container (progparam); 482 mu_config_destroy_container (&cont);
483 rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, target_ptr,
484 NULL);
485 mu_config_destroy_container (&cont);
486 }
487 483
488 return rc; 484 return rc;
489} 485}
diff --git a/libmailutils/cfg/lexer.l b/libmailutils/cfg/lexer.l
index 40598a1a2..b6c49ecc1 100644
--- a/libmailutils/cfg/lexer.l
+++ b/libmailutils/cfg/lexer.l
@@ -330,10 +330,16 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
330 int rc; 330 int rc;
331 char *full_name = mu_tilde_expansion (file, MU_HIERARCHY_DELIMITER, NULL); 331 char *full_name = mu_tilde_expansion (file, MU_HIERARCHY_DELIMITER, NULL);
332 332
333 if (flags & MU_PARSE_CONFIG_VERBOSE)
334 mu_diag_output (MU_DIAG_INFO, _("opening configuration file %s"),
335 full_name);
333 if (stat (full_name, &st)) 336 if (stat (full_name, &st))
334 { 337 {
335 if (errno != ENOENT) 338 if (errno != ENOENT)
336 mu_error (_("cannot stat `%s': %s"), full_name, mu_strerror (errno)); 339 mu_error (_("cannot stat `%s': %s"), full_name, mu_strerror (errno));
340 else if (flags & MU_PARSE_CONFIG_VERBOSE)
341 mu_diag_output (MU_DIAG_INFO, _("configuration file %s doesn't exist"),
342 full_name);
337 free (full_name); 343 free (full_name);
338 return ENOENT; 344 return ENOENT;
339 } 345 }
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index e36b513b0..043f7e0c7 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -1589,7 +1589,10 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints)
1589 mu_cfg_tree_union (&tree, &tmp); 1589 mu_cfg_tree_union (&tree, &tmp);
1590 } 1590 }
1591 } 1591 }
1592 1592
1593 if (hints->append_tree)
1594 mu_cfg_tree_union (&tree, &hints->append_tree);
1595
1593 *ptree = tree; 1596 *ptree = tree;
1594 return rc; 1597 return rc;
1595} 1598}
diff --git a/libmailutils/cli/Makefile.am b/libmailutils/cli/Makefile.am
new file mode 100644
index 000000000..48770e844
--- /dev/null
+++ b/libmailutils/cli/Makefile.am
@@ -0,0 +1,26 @@
1# GNU Mailutils -- a suite of utilities for electronic mail
2# Copyright (C) 2016 Free Software Foundation, Inc.
3#
4# This library is free software; you can redistribute it and/or
5# modify it under the terms of the GNU Lesser General Public
6# License as published by the Free Software Foundation; either
7# version 3 of the License, or (at your option) any later version.
8#
9# This library is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12# Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General
15# Public License along with this library. If not, see
16# <http://www.gnu.org/licenses/>.
17
18noinst_LTLIBRARIES = libcli.la
19
20libcli_la_SOURCES = \
21 capa.c\
22 cli.c\
23 stdcapa.c
24
25AM_CPPFLAGS = \
26 @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/cli/capa.c b/libmailutils/cli/capa.c
new file mode 100644
index 000000000..bd5c557e9
--- /dev/null
+++ b/libmailutils/cli/capa.c
@@ -0,0 +1,96 @@
1/* capa.c -- CLI capabilities for GNU Mailutils
2 Copyright (C) 2016 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 3, or (at
7 your option) any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16*/
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20#include <stdlib.h>
21#include <string.h>
22#include <mailutils/cli.h>
23#include <mailutils/list.h>
24#include <mailutils/alloc.h>
25#include <mailutils/nls.h>
26
27static mu_list_t capa_list;
28
29static void
30capa_free (void *ptr)
31{
32 struct mu_cli_capa *cp = ptr;
33 free (cp->name);
34 free (cp);
35}
36
37void
38mu_cli_capa_register (struct mu_cli_capa *capa)
39{
40 struct mu_cli_capa *cp = mu_alloc (sizeof (*cp));
41 cp->name = mu_strdup (capa->name);
42 cp->opt = capa->opt;
43 cp->cfg = capa->cfg;
44 cp->parser = capa->parser;
45 cp->commit = capa->commit;
46 if (!capa_list)
47 {
48 mu_list_create (&capa_list);