summaryrefslogtreecommitdiff
path: root/mh/mh_getopt.c
diff options
context:
space:
mode:
Diffstat (limited to 'mh/mh_getopt.c')
-rw-r--r--mh/mh_getopt.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index 65fe3e8c7..16a6e5c55 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -179,10 +179,39 @@ has_folder_option (struct mu_option *opt)
179 return 0; 179 return 0;
180} 180}
181 181
182static void
183opt_init (struct mu_parseopt *po,
184 struct mu_option **optv, struct mh_optinit *optinit)
185{
186 if (!optinit)
187 return;
188 for (; optinit->opt; optinit++)
189 {
190 size_t i;
191 for (i = 0; optv[i]; i++)
192 {
193 struct mu_option *opt;
194 for (opt = optv[i]; !MU_OPTION_IS_END (opt); opt++)
195 {
196 if (strcmp (opt->opt_long, optinit->opt) == 0)
197 {
198 char const *val = mh_global_profile_get (optinit->var, NULL);
199 if (val)
200 {
201 (opt->opt_set ?
202 opt->opt_set : mu_option_set_value) (po, opt, val);
203 }
204 break;
205 }
206 }
207 }
208 }
209}
210
182void 211void
183mh_getopt (int *pargc, char ***pargv, struct mu_option *options, 212mh_getopt_ext (int *pargc, char ***pargv, struct mu_option *options,
184 int mhflags, 213 int mhflags, struct mh_optinit *optinit,
185 char *argdoc, char *progdoc, char *extradoc) 214 char *argdoc, char *progdoc, char *extradoc)
186{ 215{
187 int argc = *pargc; 216 int argc = *pargc;
188 char **argv = *pargv; 217 char **argv = *pargv;
@@ -256,6 +285,7 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
256 if (options) 285 if (options)
257 optv[i++] = options; 286 optv[i++] = options;
258 optv[i] = NULL; 287 optv[i] = NULL;
288 opt_init (&po, optv, optinit);
259 289
260 if (mu_parseopt (&po, argc, argv, optv, flags)) 290 if (mu_parseopt (&po, argc, argv, optv, flags))
261 exit (po.po_exit_error); 291 exit (po.po_exit_error);
@@ -285,6 +315,14 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
285} 315}
286 316
287void 317void
318mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
319 int mhflags, char *argdoc, char *progdoc, char *extradoc)
320{
321 mh_getopt_ext (pargc, pargv, options, mhflags, NULL, argdoc, progdoc,
322 extradoc);
323}
324
325void
288mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, char const *arg) 326mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
289{ 327{
290 mu_error (_("option is not yet implemented: %s"), opt->opt_long); 328 mu_error (_("option is not yet implemented: %s"), opt->opt_long);

Return to:

Send suggestions and report system problems to the System administrator.