Commit b198d0ff b198d0ffc0823589a511529bc0b7c6c64e702115 by Sergey Poznyakoff

Added mhparam

1 parent a3b89af8
...@@ -10,6 +10,7 @@ inc ...@@ -10,6 +10,7 @@ inc
10 rmm 10 rmm
11 rmf 11 rmf
12 refile 12 refile
13 mhparam
13 mhpath 14 mhpath
14 folder 15 folder
15 forw 16 forw
......
...@@ -28,6 +28,7 @@ PROGRAMS_MH = \ ...@@ -28,6 +28,7 @@ PROGRAMS_MH = \
28 mark\ 28 mark\
29 mhl\ 29 mhl\
30 mhn\ 30 mhn\
31 mhparam\
31 mhpath\ 32 mhpath\
32 pick\ 33 pick\
33 refile\ 34 refile\
...@@ -51,6 +52,7 @@ EXTRA_PROGRAMS = \ ...@@ -51,6 +52,7 @@ EXTRA_PROGRAMS = \
51 mark\ 52 mark\
52 mhl\ 53 mhl\
53 mhn\ 54 mhn\
55 mhparam\
54 mhpath\ 56 mhpath\
55 pick\ 57 pick\
56 refile\ 58 refile\
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2002 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 2, 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, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18 /* MH mhpath command */
19
20 #include <mh.h>
21
22 const char *program_version = "mhparam (" PACKAGE_STRING ")";
23 static char doc[] = N_("GNU MH mhparam\v"
24 "Use -help to obtain the list of traditional MH options.");
25 static char args_doc[] = N_("[components]");
26
27 /* GNU options */
28 static struct argp_option options[] = {
29 {"all", ARG_ALL, NULL, 0,
30 N_("Display all components from the MH profile. All other arguments are ignored")},
31 {"component", ARG_COMPONENT, N_("BOOL"), OPTION_ARG_OPTIONAL,
32 N_("Always display the component name") },
33 {"license", ARG_LICENSE, 0, 0,
34 N_("Display software license"), -1},
35 { 0 }
36 };
37
38 /* Traditional MH options */
39 struct mh_option mh_option[] = {
40 { "all", 1, 0 },
41 { "component", 1, MH_OPT_BOOL},
42 { 0 }
43 };
44
45 static int display_all;
46 static int display_comp_name = -1;
47
48 static int
49 opt_handler (int key, char *arg, void *unused, struct argp_state *state)
50 {
51 switch (key)
52 {
53 case ARG_ALL:
54 display_all = 1;
55 break;
56
57 case ARG_COMPONENT:
58 display_comp_name = is_true (arg);
59 break;
60
61 case ARG_LICENSE:
62 mh_license (argp_program_version);
63 break;
64
65 default:
66 return 1;
67 }
68 return 0;
69 }
70
71 static struct {
72 char *comp;
73 char *val;
74 } defvaltab[] = {
75 { "etcdir", MHLIBDIR },
76 { "libdir", MHLIBDIR },
77 { "bindir", MHBINDIR },
78 };
79
80 char *
81 mhparam_defval (char *comp)
82 {
83 int i;
84 for (i = 0; i < sizeof(defvaltab)/sizeof(defvaltab[0]); i++)
85 if (strcasecmp(defvaltab[i].comp, comp) == 0)
86 return defvaltab[i].val;
87 return NULL;
88 }
89
90 int
91 mhparam_iterator (char *comp, char *value, char *data ARG_UNUSED)
92 {
93 if (display_comp_name)
94 printf("%s:\t", comp);
95 printf("%s\n", value);
96 return 0;
97 }
98
99 void
100 mhparam (char *comp)
101 {
102 if (comp)
103 {
104 char *val = mh_global_profile_get (comp, NULL);
105 if (!val)
106 val = mhparam_defval (comp);
107 if (!val)
108 return;
109 if (display_comp_name)
110 printf("%s:\t", comp);
111 printf("%s\n", val);
112 }
113 else
114 {
115 mh_global_profile_iterate (mhparam_iterator, NULL);
116 }
117 }
118
119 int
120 main (int argc, char **argv)
121 {
122 int index;
123
124 /* Native Language Support */
125 mu_init_nls ();
126
127 mu_argp_init (program_version, NULL);
128 mh_argp_parse (argc, argv, 0, options, mh_option, args_doc, doc,
129 opt_handler, NULL, &index);
130
131 if (display_all)
132 {
133 if (display_comp_name == -1)
134 display_comp_name = 1;
135 mhparam (NULL);
136 }
137 else
138 {
139 if (display_comp_name == -1)
140 display_comp_name = argc - index > 1;
141
142 for (; index < argc; index++)
143 mhparam (argv[index]);
144 }
145 return 0;
146 }
147