2006-05-26 Nicolas Trangez <eikke@eikke.com>

* src/NetworkManager.c: use GOptions instead of getopt
	* configure.in: bump glib required version to >= 2.6 for GOption
	  support


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1771 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Nicolas Trangez
2006-05-28 02:55:44 +00:00
committed by Dan Williams
parent 291bfd7993
commit 4202ba0ea1
3 changed files with 26 additions and 43 deletions

View File

@@ -1,3 +1,9 @@
2006-05-26 Nicolas Trangez <eikke@eikke.com>
* src/NetworkManager.c: use GOptions instead of getopt
* configure.in: bump glib required version to >= 2.6 for GOption
support
2006-05-25 Robert Love <rml@novell.com> 2006-05-25 Robert Love <rml@novell.com>
* src/nm-device.h: Introduce nm_ioctl_info(), which defines to * src/nm-device.h: Introduce nm_ioctl_info(), which defines to

View File

@@ -139,7 +139,7 @@ PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
AC_SUBST(GTHREAD_CFLAGS) AC_SUBST(GTHREAD_CFLAGS)
AC_SUBST(GTHREAD_LIBS) AC_SUBST(GTHREAD_LIBS)
PKG_CHECK_MODULES(GLIB, glib-2.0) PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.6)
AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS) AC_SUBST(GLIB_LIBS)

View File

@@ -655,13 +655,7 @@ write_pidfile (const char *pidfile)
*/ */
static void nm_print_usage (void) static void nm_print_usage (void)
{ {
fprintf (stderr, "\n" "usage : NetworkManager [--no-daemon] [--pid-file=<file>] [--help]\n");
fprintf (stderr, fprintf (stderr,
"\n"
" --no-daemon Don't become a daemon\n"
" --pid-file=<path> Specify the location of a PID file\n"
" --enable-test-devices Allow dummy devices to be created via DBUS methods [DEBUG]\n"
" --help Show this information and exit\n"
"\n" "\n"
"NetworkManager monitors all network connections and automatically\n" "NetworkManager monitors all network connections and automatically\n"
"chooses the best connection to use. It also allows the user to\n" "chooses the best connection to use. It also allows the user to\n"
@@ -677,8 +671,9 @@ static void nm_print_usage (void)
*/ */
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
gboolean become_daemon = TRUE; gboolean become_daemon = FALSE;
gboolean enable_test_devices = FALSE; gboolean enable_test_devices = FALSE;
gboolean show_usage = FALSE;
char * owner; char * owner;
char * pidfile = NULL; char * pidfile = NULL;
char * user_pidfile = NULL; char * user_pidfile = NULL;
@@ -694,47 +689,29 @@ int main( int argc, char *argv[] )
textdomain (GETTEXT_PACKAGE); textdomain (GETTEXT_PACKAGE);
/* Parse options */ /* Parse options */
while (1)
{ {
int c; GOptionContext *opt_ctx = NULL;
int option_index = 0; GOptionEntry options[] = {
const char *opt; {"no-daemon", 0, 0, G_OPTION_ARG_NONE, &become_daemon, "Don't become a daemon", NULL},
{"pid-file", 0, 0, G_OPTION_ARG_STRING, &user_pidfile, "Specify the location of a PID file", NULL},
static struct option options[] = { {"enable-test-devices", 0, 0, G_OPTION_ARG_NONE, &enable_test_devices, "Allow dummy devices to be created via DBUS methods [DEBUG]", NULL},
{"no-daemon", 0, NULL, 0}, {"info", 0, 0, G_OPTION_ARG_NONE, &show_usage, "Show application information", NULL},
{"enable-test-devices", 0, NULL, 0}, {NULL}
{"pid-file", 1, NULL, 0},
{"help", 0, NULL, 0},
{NULL, 0, NULL, 0}
}; };
opt_ctx = g_option_context_new("");
g_option_context_add_main_entries(opt_ctx, options, NULL);
g_option_context_parse(opt_ctx, &argc, &argv, NULL);
g_option_context_free(opt_ctx);
}
c = getopt_long (argc, argv, "", options, &option_index); /* Tricky: become_daemon is FALSE by default, so unless it's TRUE because of a CLI
if (c == -1) * option, it'll become TRUE after this */
break; become_daemon = !become_daemon;
if (show_usage == TRUE)
switch (c)
{
case 0:
opt = options[option_index].name;
if (strcmp (opt, "help") == 0)
{ {
nm_print_usage(); nm_print_usage();
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }
else if (strcmp (opt, "no-daemon") == 0)
become_daemon = FALSE;
else if (strcmp (opt, "enable-test-devices") == 0)
enable_test_devices = TRUE;
else if (strcmp (opt, "pid-file") == 0)
user_pidfile = g_strdup (optarg);
break;
default:
nm_print_usage ();
exit (EXIT_FAILURE);
break;
}
}
if (become_daemon) if (become_daemon)
{ {