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:

committed by
Dan Williams

parent
291bfd7993
commit
4202ba0ea1
@@ -655,13 +655,7 @@ write_pidfile (const char *pidfile)
|
||||
*/
|
||||
static void nm_print_usage (void)
|
||||
{
|
||||
fprintf (stderr, "\n" "usage : NetworkManager [--no-daemon] [--pid-file=<file>] [--help]\n");
|
||||
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"
|
||||
"NetworkManager monitors all network connections and automatically\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[] )
|
||||
{
|
||||
gboolean become_daemon = TRUE;
|
||||
gboolean become_daemon = FALSE;
|
||||
gboolean enable_test_devices = FALSE;
|
||||
gboolean show_usage = FALSE;
|
||||
char * owner;
|
||||
char * pidfile = NULL;
|
||||
char * user_pidfile = NULL;
|
||||
@@ -694,47 +689,29 @@ int main( int argc, char *argv[] )
|
||||
textdomain (GETTEXT_PACKAGE);
|
||||
|
||||
/* Parse options */
|
||||
while (1)
|
||||
{
|
||||
int c;
|
||||
int option_index = 0;
|
||||
const char *opt;
|
||||
|
||||
static struct option options[] = {
|
||||
{"no-daemon", 0, NULL, 0},
|
||||
{"enable-test-devices", 0, NULL, 0},
|
||||
{"pid-file", 1, NULL, 0},
|
||||
{"help", 0, NULL, 0},
|
||||
{NULL, 0, NULL, 0}
|
||||
GOptionContext *opt_ctx = NULL;
|
||||
GOptionEntry options[] = {
|
||||
{"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},
|
||||
{"enable-test-devices", 0, 0, G_OPTION_ARG_NONE, &enable_test_devices, "Allow dummy devices to be created via DBUS methods [DEBUG]", NULL},
|
||||
{"info", 0, 0, G_OPTION_ARG_NONE, &show_usage, "Show application information", NULL},
|
||||
{NULL}
|
||||
};
|
||||
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);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
/* Tricky: become_daemon is FALSE by default, so unless it's TRUE because of a CLI
|
||||
* option, it'll become TRUE after this */
|
||||
become_daemon = !become_daemon;
|
||||
if (show_usage == TRUE)
|
||||
{
|
||||
case 0:
|
||||
opt = options[option_index].name;
|
||||
if (strcmp (opt, "help") == 0)
|
||||
{
|
||||
nm_print_usage ();
|
||||
nm_print_usage();
|
||||
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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user