GOption patch
- From: Ikke <eikke eikke com>
- To: networkmanager-list <networkmanager-list gnome org>
- Subject: GOption patch
- Date: Fri, 26 May 2006 18:54:39 +0200
Hija,
As NM is still using getopt* to do command line parsing, I decided to
write a small patch to replace this with glib's GOption command line
parsing feature (one of the GNOME Goals, by vuntz iirc).
Attached is a patch that does this in NetworkManager.c, and bumps the
glib required version to >= 2.6 in configure.in
Please let me know if it's ok to commit this.
Regards,
Ikke
http://www.eikke.com
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/NetworkManager/ChangeLog,v
retrieving revision 1.956
diff -u -b -B -r1.956 ChangeLog
--- ChangeLog 25 May 2006 22:37:40 -0000 1.956
+++ ChangeLog 26 May 2006 16:48:47 -0000
@@ -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>
* src/nm-device.h: Introduce nm_ioctl_info(), which defines to
Index: configure.in
===================================================================
RCS file: /cvs/gnome/NetworkManager/configure.in,v
retrieving revision 1.133
diff -u -b -B -r1.133 configure.in
--- configure.in 25 May 2006 20:28:48 -0000 1.133
+++ configure.in 26 May 2006 16:48:48 -0000
@@ -139,7 +139,7 @@
AC_SUBST(GTHREAD_CFLAGS)
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_LIBS)
Index: src/NetworkManager.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManager.c,v
retrieving revision 1.108
diff -u -b -B -r1.108 NetworkManager.c
--- src/NetworkManager.c 24 May 2006 15:53:07 -0000 1.108
+++ src/NetworkManager.c 26 May 2006 16:48:49 -0000
@@ -655,14 +655,8 @@
*/
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"
"specify wireless access points which wireless cards in the computer\n"
@@ -677,8 +671,9 @@
*/
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 @@
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)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]