From 0bc4c8ea0c839ab9f7a8de6c908f78018efaf170 Mon Sep 17 00:00:00 2001 From: "Sergey V. Udaltsov" Date: Tue, 11 Dec 2007 23:15:14 +0000 Subject: using GOption, b.g.o#502993 svn path=/trunk/; revision=202 --- test/Makefile.am | 8 ++-- test/gkbd-keyboard-drawing-test.c | 97 ++++++++++++++++++--------------------- 2 files changed, 49 insertions(+), 56 deletions(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index cf543b9..0904ae2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -19,13 +19,13 @@ gkbd_indicator_test_LDFLAGS= \ $(top_builddir)/libgnomekbd/libgnomekbd.la \ $(top_builddir)/libgnomekbd/libgnomekbdui.la -gkbd_keyboard_drawing_test_CFLAGS= \ +gkbd_keyboard_drawing_test_CFLAGS= \ $(WARN_CFLAGS) -I$(top_srcdir) \ - $(GTK_CFLAGS) + $(GTK_CFLAGS) $(GLIB_CFLAGS) -gkbd_keyboard_drawing_test_LDFLAGS= \ +gkbd_keyboard_drawing_test_LDFLAGS= \ + $(GLIB_LIBS) \ $(GTK_LIBS) \ - -lpopt \ $(LIBXKLAVIER_LIBS) \ $(top_builddir)/libgnomekbd/libgnomekbd.la \ $(top_builddir)/libgnomekbd/libgnomekbdui.la diff --git a/test/gkbd-keyboard-drawing-test.c b/test/gkbd-keyboard-drawing-test.c index 1b0e6d8..f855ca3 100644 --- a/test/gkbd-keyboard-drawing-test.c +++ b/test/gkbd-keyboard-drawing-test.c @@ -22,9 +22,9 @@ #endif #include -#include #include #include +#include #include "libgnomekbd/gkbd-keyboard-drawing.h" @@ -33,31 +33,41 @@ static gchar *levels = NULL; static gchar *symbols = NULL; static gchar *keycodes = NULL; static gchar *geometry = NULL; -static struct poptOption options[] = { - {"groups", '\0', POPT_ARG_STRING, &groups, 0, - "Keyboard groups to display, from 1-4. Up to four groups only may be displayed. Examples: --groups=3 or --groups=1,2,1,2", - "group1[,group2[,group3[,group4]]]"}, - {"levels", '\0', POPT_ARG_STRING, &levels, 0, - "Keyboard shift levels to display, from 1-64. Up to four shift levels only may be displayed. Examples: --levels=3 or --levels=1,2,1,2", - "level1[,level2[,level3[,level4]]]"}, - {"symbols", '\0', POPT_ARG_STRING, &symbols, 0, - "Symbols component of the keyboard. If you omit this option, it is obtained from the X server; that is, the keyboard that is currently configured is drawn. Examples: --symbols=us or --symbols=us(pc104)+iso9995-3+group(switch)+ctrl(nocaps)", - NULL}, - {"keycodes", '\0', POPT_ARG_STRING, &keycodes, 0, - "Keycodes component of the keyboard. If you omit this option, it is obtained from the X server; that is, the keyboard that is currently configured is drawn. Examples: --keycodes=xfree86+aliases(qwerty)", - NULL}, - {"geometry", '\0', POPT_ARG_STRING, &geometry, 0, - "Geometry xkb component. If you omit this option, it is obtained from the X server; that is, the keyboard that is currently configured is drawn. Example: --geometry=kinesis", - NULL}, - {"track-modifiers", '\0', POPT_ARG_NONE, NULL, 3, - "Track the current modifiers", NULL}, - {"track-config", '\0', POPT_ARG_NONE, NULL, 4, - "Track the server XKB configuration", NULL}, - {"version", 'v', POPT_ARG_NONE, NULL, 1, "Show current version", - NULL}, - POPT_AUTOHELP {NULL, '\0', 0, NULL, 0} -}; +static gboolean track_config = FALSE; +static gboolean track_modifiers = FALSE; +static gboolean program_version = FALSE; + +static const GOptionEntry options[] = { + { "groups", '\0', 0, G_OPTION_ARG_STRING, &groups, + "Keyboard groups to display, from 1-4. Up to four groups only may be " + "displayed. Examples: --groups=3 or --groups=1,2,1,2", + "group1[,group2[,group3[,group4]]]" }, + { "levels", '\0', 0, G_OPTION_ARG_STRING, &levels, + "Keyboard shift levels to display, from 1-64. Up to four shift levels " + "only may be displayed. Examples: --levels=3 or --levels=1,2,1,2", + "level1[,level2[,level3[,level4]]]" }, + { "symbols", '\0', 0, G_OPTION_ARG_STRING, &symbols, + "Symbols component of the keyboard. If you omit this option, it is " + "obtained from the X server; that is, the keyboard that is currently " + "configured is drawn. Examples: --symbols=us or " + "--symbols=us(pc104)+iso9995-3+group(switch)+ctrl(nocaps)", NULL }, + { "keycodes", '\0', 0, G_OPTION_ARG_STRING, &keycodes, + "Keycodes component of the keyboard. If you omit this option, it is " + "obtained from the X server; that is, the keyboard that is currently" + " configured is drawn. Examples: --keycodes=xfree86+aliases(qwerty)", NULL }, + { "geometry", '\0', 0, G_OPTION_ARG_STRING, &geometry, + "Geometry xkb component. If you omit this option, it is obtained from the" + " X server; that is, the keyboard that is currently configured is drawn. " + "Example: --geometry=kinesis", NULL }, + { "track-modifiers", '\0', 0, G_OPTION_ARG_NONE, &track_modifiers, + "Track the current modifiers", NULL }, + { "track-config", '\0', 0, G_OPTION_ARG_NONE, &track_config, + "Track the server XKB configuration", NULL }, + { "version", '\0', 0, G_OPTION_ARG_NONE, &program_version, + "Show current version", NULL }, + { NULL }, +}; static gboolean set_groups (gchar * groups_option, @@ -152,7 +162,7 @@ main (gint argc, gchar ** argv) GdkScreen *screen; gint monitor; GdkRectangle rect; - poptContext popt_context; + GOptionContext *context; gint rc; GkbdKeyboardDrawingGroupLevel groupLevels[4] = { {0, 0}, {1, 0}, {0, 1}, {1, 1} }; @@ -160,36 +170,19 @@ main (gint argc, gchar ** argv) { &groupLevels[0], &groupLevels[1], &groupLevels[2], &groupLevels[3] }; - gboolean track_config = False, track_modifiers = False; - - gtk_init (&argc, &argv); - popt_context = - poptGetContext ("kbdraw", argc, (const gchar **) argv, options, - 0); - - for (rc = poptGetNextOpt (popt_context); rc > 0; - rc = poptGetNextOpt (popt_context)) - switch (rc) { - case 1: - g_print ("kbdraw %s\n", VERSION); - exit (0); - case 3: - track_modifiers = True; - break; - case 4: - track_config = True; - break; - } + context = g_option_context_new ("kbdraw"); + g_option_context_add_main_entries (context, options, NULL); + g_option_context_parse (context, &argc, &argv, NULL); + g_option_context_free (context); - if (rc != -1) { - g_printerr ("%s: %s\n", - poptBadOption (popt_context, - POPT_BADOPTION_NOALIAS), - poptStrerror (rc)); - exit (1); + if (program_version) { + g_print("kbdraw %s\n", VERSION); + exit (0); } + gtk_init (&argc, &argv); + if (!set_groups (groups, groupLevels)) { g_printerr ("--groups: invalid argument\n"); exit (1); -- cgit v1.2.1