2 args.c : small frontend to libPopt command line argument parser
4 Copyright (C) 1999-2001 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (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 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 GArray *iopt_tables = NULL;
26 void args_register(struct poptOption *options)
28 if (iopt_tables == NULL) {
29 iopt_tables = g_array_new(TRUE, TRUE,
30 sizeof(struct poptOption));
33 while (options->longName != NULL || options->shortName != '\0' ||
34 options->arg != NULL) {
35 g_array_append_val(iopt_tables, *options);
40 void args_execute(int argc, char *argv[])
45 if (iopt_tables == NULL)
48 con = poptGetContext(PACKAGE, argc, argv,
49 (struct poptOption *) (iopt_tables->data), 0);
50 poptReadDefaultConfig(con, TRUE);
52 while ((nextopt = poptGetNextOpt(con)) > 0) ;
55 printf("Error on option %s: %s.\n"
56 "Run '%s --help' to see a full list of "
57 "available command line options.\n",
58 poptBadOption(con, 0), poptStrerror(nextopt), argv[0]);
62 g_array_free(iopt_tables, TRUE);