2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of quvi <http://quvi.sourceforge.net/>.
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
24 #include <glib/gi18n.h>
28 static gint
_cmdline_parse(const lopts_t lopts
)
34 if (lopts
->argv
== NULL
)
35 return (EXIT_SUCCESS
);
37 c
= g_option_context_new(NULL
);
41 g_option_context_add_main_entries(c
, lopts
->entries
, GETTEXT_PACKAGE
);
42 g_option_context_set_translation_domain(c
, GETTEXT_PACKAGE
);
43 g_option_context_set_help_enabled(c
, FALSE
);
45 if (g_option_context_parse(c
, &lopts
->argc
, &lopts
->argv
, &e
) == FALSE
)
47 g_printerr(_("error: while parsing options: %s\n"), e
->message
);
52 g_option_context_free(c
);
56 extern void keyfile_read(lopts_t
);
60 gint
lopts_new(lopts_t lopts
)
62 g_assert(lopts
!= NULL
);
63 g_assert(lopts
->entries
!= NULL
);
67 /* read config files. */
71 /* cmdline values override config values. */
73 if (_cmdline_parse(lopts
) != EXIT_SUCCESS
)
74 return (EXIT_FAILURE
);
76 if (lopts
->cb
.cmdline_validate_values
!= NULL
)
78 if (lopts
->cb
.cmdline_validate_values() != EXIT_SUCCESS
)
79 return (EXIT_FAILURE
);
82 if (lopts
->cb
.set_post_parse_defaults
!= NULL
)
83 lopts
->cb
.set_post_parse_defaults();
85 return (EXIT_SUCCESS
);
88 /* vim: set ts=2 sw=2 tw=72 expandtab: */