2000-04-26 04:03:38 -04:00
|
|
|
/*
|
2008-02-03 11:48:02 -05:00
|
|
|
args.c : small frontend to GOption command line argument parser
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-05-17 12:50:52 -04:00
|
|
|
Copyright (C) 1999-2001 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2007-05-08 14:41:10 -04:00
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2000-04-26 04:03:38 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "args.h"
|
|
|
|
|
2008-02-03 11:48:02 -05:00
|
|
|
static GOptionContext *context = NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2008-02-03 11:48:02 -05:00
|
|
|
void args_register(GOptionEntry *options)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2008-02-03 11:48:02 -05:00
|
|
|
if (context == NULL)
|
|
|
|
context = g_option_context_new("");
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2008-02-03 11:48:02 -05:00
|
|
|
g_option_context_add_main_entries(context, options, PACKAGE_TARNAME);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void args_execute(int argc, char *argv[])
|
|
|
|
{
|
2008-02-03 11:48:02 -05:00
|
|
|
GError* error = NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2008-02-03 11:48:02 -05:00
|
|
|
if (context == NULL)
|
2000-04-26 04:03:38 -04:00
|
|
|
return;
|
|
|
|
|
2008-02-03 11:48:02 -05:00
|
|
|
g_option_context_parse(context, &argc, &argv, &error);
|
|
|
|
g_option_context_free(context);
|
|
|
|
context = NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2008-02-03 11:48:02 -05:00
|
|
|
if (error != NULL) {
|
|
|
|
printf("%s\n"
|
2001-05-17 16:13:59 -04:00
|
|
|
"Run '%s --help' to see a full list of "
|
|
|
|
"available command line options.\n",
|
2008-02-03 11:48:02 -05:00
|
|
|
error->message, argv[0]);
|
2000-04-26 04:03:38 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|