1 /* GNU Mailutils -- a suite of utilities for electronic mail
2    Copyright (C) 2010-2021 Free Software Foundation, Inc.
3 
4    GNU Mailutils is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3, or (at your option)
7    any later version.
8 
9    GNU Mailutils 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
12    GNU 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 #include <config.h>
18 #include <mailutils/mailutils.h>
19 #include <mailutils/nls.h>
20 
21 static void
describe(struct mu_parseopt * po,struct mu_option * opt,char const * unused)22 describe (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
23 {
24   int len = strcspn (po->po_prog_doc, "\n");
25   mu_printf ("%.*s\n", len, po->po_prog_doc);
26   exit (0);
27 }
28 
29 struct mu_option common_options[] = {
30   { "describe", 0, NULL, MU_OPTION_HIDDEN,
31     "describe the program",
32     mu_c_string, NULL, describe },
33   MU_OPTION_END
34 };
35 
36 void
mu_action_getopt(int * pargc,char *** pargv,struct mu_option * opt,char const * docstring,char const * argdoc)37 mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
38 		  char const *docstring, char const *argdoc)
39 {
40   static struct mu_parseopt pohint = {
41     .po_flags = MU_PARSEOPT_PACKAGE_NAME
42               | MU_PARSEOPT_PACKAGE_URL
43               | MU_PARSEOPT_BUG_ADDRESS
44               | MU_PARSEOPT_VERSION_HOOK,
45     .po_package_name = PACKAGE_NAME,
46     .po_package_url = PACKAGE_URL,
47     .po_bug_address = PACKAGE_BUGREPORT,
48     .po_version_hook = mu_version_hook
49   };
50   static char *defcapa[] = { "debug", NULL };
51   struct mu_cfg_parse_hints cfhint = { .flags = 0 };
52   struct mu_option *options[3] = { common_options, opt, NULL };
53   struct mu_cli_setup cli = {
54     .prog_doc = (char*) docstring,
55     .prog_args = (char*) argdoc,
56     .optv = options
57   };
58   char *p;
59 
60   p = getenv ("MAILUTILS_PROGNAME");
61   if (p)
62     {
63       pohint.po_flags |= MU_PARSEOPT_PROG_NAME;
64       pohint.po_prog_name = p;
65     }
66 
67   MU_APP_INIT_NLS ();
68   mu_cli_ext (*pargc, *pargv, &cli, &pohint, &cfhint, defcapa, NULL,
69 	      pargc, pargv);
70 }
71 
72 
73