Commit 97fb4785 97fb4785661350ab0ff8ae5605d1bdf7f6566386 by Sergey Poznyakoff

Provide extended interface to mu_cli.

* include/mailutils/cfg.h (MU_CFG_APPEND_TREE): New flag.
* include/mailutils/cli.h (mu_version_copyright): New extern.
(mu_cli_ext): New proto.
* libmailutils/cfg/parser.y (mu_cfg_parse_config): Check for
MU_CFG_APPEND_TREE bit set before accessing hints->append_tree.
* libmailutils/cli/cli.c (param_set): Likewise.
(mu_cli_ext): New function.
(mu_cli): Rewrite as an entry point to mu_cli_ext.

* comsat/comsat.c: Remove inclusion of obsolete headers.
* mu/help.c: Likewise.
* pop3d/extra.c: Likewise.
1 parent 68566697
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
17 17
18 #include "comsat.h" 18 #include "comsat.h"
19 #define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */ 19 #include "mailutils/syslog.h"
20 #include "mailutils/libcfg.h"
21 #include "mailutils/cli.h" 20 #include "mailutils/cli.h"
22 21
23 #ifndef PATH_DEV 22 #ifndef PATH_DEV
......
...@@ -241,6 +241,7 @@ int mu_config_register_plain_section (const char *parent_path, ...@@ -241,6 +241,7 @@ int mu_config_register_plain_section (const char *parent_path,
241 #define MU_CFG_FMT_VALUE_ONLY 0x100 241 #define MU_CFG_FMT_VALUE_ONLY 0x100
242 #define MU_CFG_FMT_PARAM_PATH 0x200 242 #define MU_CFG_FMT_PARAM_PATH 0x200
243 #define MU_PARSE_CONFIG_LINT 0x400 243 #define MU_PARSE_CONFIG_LINT 0x400
244 #define MU_CFG_APPEND_TREE 0x800
244 245
245 #ifdef MU_CFG_COMPATIBILITY 246 #ifdef MU_CFG_COMPATIBILITY
246 # define MU_CFG_DEPRECATED 247 # define MU_CFG_DEPRECATED
......
...@@ -54,10 +54,19 @@ struct mu_cli_setup ...@@ -54,10 +54,19 @@ struct mu_cli_setup
54 void (*prog_doc_hook) (mu_stream_t); 54 void (*prog_doc_hook) (mu_stream_t);
55 }; 55 };
56 56
57 extern const char mu_version_copyright[];
58
57 void mu_version_hook (struct mu_parseopt *po, mu_stream_t stream); 59 void mu_version_hook (struct mu_parseopt *po, mu_stream_t stream);
58 void mu_cli (int argc, char **argv, struct mu_cli_setup *setup, 60 void mu_cli (int argc, char **argv, struct mu_cli_setup *setup,
59 char **capa, void *data, 61 char **capa, void *data,
60 int *ret_argc, char ***ret_argv); 62 int *ret_argc, char ***ret_argv);
63 void mu_cli_ext (int argc, char **argv,
64 struct mu_cli_setup *setup,
65 struct mu_parseopt *pohint,
66 struct mu_cfg_parse_hints *cfhint,
67 char **capa,
68 void *data,
69 int *ret_argc, char ***ret_argv);
61 70
62 char *mu_site_config_file (void); 71 char *mu_site_config_file (void);
63 72
......
...@@ -1590,7 +1590,7 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints) ...@@ -1590,7 +1590,7 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints)
1590 } 1590 }
1591 } 1591 }
1592 1592
1593 if (hints->append_tree) 1593 if (hints->flags & MU_CFG_APPEND_TREE)
1594 mu_cfg_tree_union (&tree, &hints->append_tree); 1594 mu_cfg_tree_union (&tree, &hints->append_tree);
1595 1595
1596 *ptree = tree; 1596 *ptree = tree;
......
...@@ -155,8 +155,11 @@ param_set (struct mu_parseopt *po, struct mu_option *opt, char const *arg) ...@@ -155,8 +155,11 @@ param_set (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
155 if (rc) 155 if (rc)
156 mu_parseopt_error (po, "%s: cannot create node: %s", 156 mu_parseopt_error (po, "%s: cannot create node: %s",
157 arg, mu_strerror (rc)); 157 arg, mu_strerror (rc));
158 if (!hints->append_tree) 158 if (!(hints->flags & MU_CFG_APPEND_TREE))
159 {
159 mu_cfg_tree_create (&hints->append_tree); 160 mu_cfg_tree_create (&hints->append_tree);
161 hints->flags |= MU_CFG_APPEND_TREE;
162 }
160 mu_cfg_tree_add_node (hints->append_tree, node); 163 mu_cfg_tree_add_node (hints->append_tree, node);
161 } 164 }
162 165
...@@ -335,8 +338,22 @@ run_commit (void *item, void *data) ...@@ -335,8 +338,22 @@ run_commit (void *item, void *data)
335 return 0; 338 return 0;
336 } 339 }
337 340
341 #define PRESERVE_FLAGS \
342 ( MU_PARSEOPT_NO_SORT \
343 | MU_PARSEOPT_SINGLE_DASH \
344 | MU_PARSEOPT_PACKAGE_NAME \
345 | MU_PARSEOPT_PACKAGE_URL \
346 | MU_PARSEOPT_BUG_ADDRESS \
347 | MU_PARSEOPT_EXTRA_INFO \
348 | MU_PARSEOPT_VERSION_HOOK \
349 | MU_PARSEOPT_NEGATION)
350
338 void 351 void
339 mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, 352 mu_cli_ext (int argc, char **argv,
353 struct mu_cli_setup *setup,
354 struct mu_parseopt *pohint,
355 struct mu_cfg_parse_hints *cfhint,
356 char **capa,
340 void *data, 357 void *data,
341 int *ret_argc, char ***ret_argv) 358 int *ret_argc, char ***ret_argv)
342 { 359 {
...@@ -356,14 +373,22 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, ...@@ -356,14 +373,22 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
356 setup->ex_usage = EX_USAGE; 373 setup->ex_usage = EX_USAGE;
357 if (setup->ex_config == 0) 374 if (setup->ex_config == 0)
358 setup->ex_config = EX_CONFIG; 375 setup->ex_config = EX_CONFIG;
359 if (setup->inorder)
360 flags |= MU_PARSEOPT_IN_ORDER;
361 376
377 hints = *cfhint;
362 /* Set program name */ 378 /* Set program name */
379 if (hints.flags & MU_CFG_PARSE_PROGRAM)
380 {
381 if (!mu_log_tag)
382 mu_log_tag = (char*)hints.program;
383 }
384 else
385 {
363 mu_set_program_name (argv[0]); 386 mu_set_program_name (argv[0]);
364
365 if (!mu_log_tag) 387 if (!mu_log_tag)
366 mu_log_tag = (char*)mu_program_name; 388 mu_log_tag = (char*)mu_program_name;
389 hints.program = (char*) mu_program_name;
390 hints.flags |= MU_CFG_PARSE_PROGRAM;
391 }
367 392
368 /* Initialize standard streams */ 393 /* Initialize standard streams */
369 mu_stdstream_setup (MU_STDSTREAM_RESET_NONE); 394 mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
...@@ -371,16 +396,6 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, ...@@ -371,16 +396,6 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
371 /* Initialize standard capabilities */ 396 /* Initialize standard capabilities */
372 mu_cli_capa_init (); 397 mu_cli_capa_init ();
373 398
374 /* Initialize hints */
375 memset (&hints, 0, sizeof (hints));
376 hints.flags |= MU_CFG_PARSE_SITE_RCFILE;
377 hints.site_rcfile = mu_site_config_file ();
378
379 hints.flags |= MU_CFG_PARSE_PROGRAM;
380 hints.program = (char*) mu_program_name;
381
382 hints.data = setup;
383
384 /* Initialize po */ 399 /* Initialize po */
385 400
386 if (setup->prog_doc) 401 if (setup->prog_doc)
...@@ -388,6 +403,11 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, ...@@ -388,6 +403,11 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
388 po.po_prog_doc = setup->prog_doc; 403 po.po_prog_doc = setup->prog_doc;
389 flags |= MU_PARSEOPT_PROG_DOC; 404 flags |= MU_PARSEOPT_PROG_DOC;
390 } 405 }
406 else if (pohint->po_flags & MU_PARSEOPT_PROG_DOC)
407 {
408 po.po_prog_doc = pohint->po_prog_doc;
409 flags |= MU_PARSEOPT_PROG_DOC;
410 }
391 411
392 if (setup->prog_args) 412 if (setup->prog_args)
393 { 413 {
...@@ -415,21 +435,11 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, ...@@ -415,21 +435,11 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
415 435
416 flags |= MU_PARSEOPT_PROG_ARGS; 436 flags |= MU_PARSEOPT_PROG_ARGS;
417 } 437 }
418 438 else if (pohint->po_flags & MU_PARSEOPT_PROG_ARGS)
419 po.po_package_name = PACKAGE_NAME; 439 {
420 flags |= MU_PARSEOPT_PACKAGE_NAME; 440 po.po_prog_args = pohint->po_prog_args;
421 441 flags |= MU_PARSEOPT_PROG_ARGS;
422 po.po_package_url = PACKAGE_URL; 442 }
423 flags |= MU_PARSEOPT_PACKAGE_URL;
424
425 po.po_bug_address = PACKAGE_BUGREPORT;
426 flags |= MU_PARSEOPT_BUG_ADDRESS;
427
428 po.po_extra_info = gnu_general_help_url;
429 flags |= MU_PARSEOPT_EXTRA_INFO;
430
431 po.po_version_hook = mu_version_hook;
432 flags |= MU_PARSEOPT_VERSION_HOOK;
433 443
434 if (setup->prog_extra_doc) 444 if (setup->prog_extra_doc)
435 { 445 {
...@@ -442,6 +452,29 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, ...@@ -442,6 +452,29 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
442 po.po_prog_doc_hook = prog_doc_hook; 452 po.po_prog_doc_hook = prog_doc_hook;
443 flags |= MU_PARSEOPT_PROG_DOC_HOOK; 453 flags |= MU_PARSEOPT_PROG_DOC_HOOK;
444 } 454 }
455 else if (pohint->po_flags & MU_PARSEOPT_PROG_DOC_HOOK)
456 {
457 po.po_prog_doc_hook = pohint->po_prog_doc_hook;
458 flags |= MU_PARSEOPT_PROG_DOC_HOOK;
459 }
460
461 if (setup->inorder)
462 flags |= MU_PARSEOPT_IN_ORDER;
463
464 flags |= pohint->po_flags & PRESERVE_FLAGS;
465
466 if (flags & MU_PARSEOPT_PACKAGE_NAME)
467 po.po_package_name = pohint->po_package_name;
468 if (flags & MU_PARSEOPT_PACKAGE_URL)
469 po.po_package_url = pohint->po_package_url;
470 if (flags & MU_PARSEOPT_BUG_ADDRESS)
471 po.po_bug_address = pohint->po_bug_address;
472 if (flags & MU_PARSEOPT_EXTRA_INFO)
473 po.po_extra_info = pohint->po_extra_info;
474 if (flags & MU_PARSEOPT_VERSION_HOOK)
475 po.po_version_hook = pohint->po_version_hook;
476 if (flags & MU_PARSEOPT_NEGATION)
477 po.po_negation = pohint->po_negation;
445 478
446 po.po_data = &hints; 479 po.po_data = &hints;
447 flags |= MU_PARSEOPT_DATA; 480 flags |= MU_PARSEOPT_DATA;
...@@ -488,3 +521,33 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa, ...@@ -488,3 +521,33 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
488 521
489 mu_parseopt_free (&po); 522 mu_parseopt_free (&po);
490 } 523 }
524
525 void
526 mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
527 void *data,
528 int *ret_argc, char ***ret_argv)
529 {
530 struct mu_parseopt pohint;
531 struct mu_cfg_parse_hints cfhint;
532
533 pohint.po_package_name = PACKAGE_NAME;
534 pohint.po_flags |= MU_PARSEOPT_PACKAGE_NAME;
535
536 pohint.po_package_url = PACKAGE_URL;
537 pohint.po_flags |= MU_PARSEOPT_PACKAGE_URL;
538
539 pohint.po_bug_address = PACKAGE_BUGREPORT;
540 pohint.po_flags |= MU_PARSEOPT_BUG_ADDRESS;
541
542 pohint.po_extra_info = gnu_general_help_url;
543 pohint.po_flags |= MU_PARSEOPT_EXTRA_INFO;
544
545 pohint.po_version_hook = mu_version_hook;
546 pohint.po_flags |= MU_PARSEOPT_VERSION_HOOK;
547
548 cfhint.site_rcfile = mu_site_config_file ();
549 cfhint.flags = MU_CFG_PARSE_SITE_RCFILE;
550
551 mu_cli_ext (argc, argv, setup, &pohint, &cfhint, capa, data,
552 ret_argc, ret_argv);
553 }
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
22 #include <stdlib.h> 22 #include <stdlib.h>
23 #include <mailutils/nls.h> 23 #include <mailutils/nls.h>
24 #include <mailutils/io.h> 24 #include <mailutils/io.h>
25 #include "mailutils/libargp.h"
26 #include "mu.h" 25 #include "mu.h"
27 26
28 static char help_doc[] = N_("mu help - display a terse help summary"); 27 static char help_doc[] = N_("mu help - display a terse help summary");
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ 16 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
17 17
18 #include "pop3d.h" 18 #include "pop3d.h"
19 #include "mailutils/libargp.h"
20 #include "mailutils/property.h" 19 #include "mailutils/property.h"
21 20
22 mu_stream_t iostream; 21 mu_stream_t iostream;
......