Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] (PR#7079) Remove unneeded options from clients
Home

[Freeciv-Dev] (PR#7079) Remove unneeded options from clients

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jordi@xxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#7079) Remove unneeded options from clients
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Jan 2004 15:17:07 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7079 >

> [jdorje - Fri Jan 16 02:34:32 2004]:

> I would rather do it a different way:
> 
> Have a separate array gui_options declared by each GUI.  At runtime this
> array is appended to the options[] array.

And the patch.

jason

Index: client/options.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.89
diff -u -r1.89 options.c
--- client/options.c    2004/01/11 17:45:03     1.89
+++ client/options.c    2004/01/19 23:16:53
@@ -77,20 +77,7 @@
 /* This option is currently set by the client - not by the user. */
 bool update_city_text_in_refresh_tile = TRUE;
 
-#define GEN_INT_OPTION(oname, desc) { #oname, desc, COT_INT, \
-                                      &oname, NULL, NULL, 0, NULL, \
-                                       NULL, NULL }
-#define GEN_BOOL_OPTION(oname, desc) { #oname, desc, COT_BOOL, \
-                                       NULL, &oname, NULL, 0, NULL, \
-                                       NULL, NULL }
-#define GEN_STR_OPTION(oname, desc, str_defaults, callback) \
-                                    { #oname, desc, COT_STR, \
-                                      NULL, NULL, oname, sizeof(oname), \
-                                      callback, str_defaults, NULL }
-#define GEN_OPTION_TERMINATOR { NULL, NULL, COT_BOOL, \
-                                NULL, NULL, NULL, 0, NULL, NULL, NULL }
-
-client_option options[] = {
+static client_option common_options[] = {
   GEN_STR_OPTION(default_user_name,        N_("Default player's login name"),
                 NULL, NULL), 
   GEN_STR_OPTION(default_server_host,       N_("Default server"),
@@ -119,18 +106,15 @@
   GEN_BOOL_OPTION(center_when_popup_city,   N_("Center map when Popup city")),
   GEN_BOOL_OPTION(concise_city_production,  N_("Concise City Production")),
   GEN_BOOL_OPTION(auto_turn_done,           N_("End Turn when done moving")),
-  GEN_BOOL_OPTION(meta_accelerators,        N_("Use Alt/Meta for accelerators 
(GTK+ only)")),
-  GEN_BOOL_OPTION(map_scrollbars,          N_("Show Map Scrollbars (GTK+ 
only)")),
-  GEN_BOOL_OPTION(keyboardless_goto,        N_("Keyboardless goto (GTK+ 
only)")),
-  GEN_BOOL_OPTION(dialogs_on_top,          N_("Keep dialogs on top (GTK+ 2.0 
only)")),
   GEN_BOOL_OPTION(ask_city_name,            N_("Prompt for city names")),
   GEN_BOOL_OPTION(popup_new_cities,         N_("Pop up city dialog for new 
cities")),
-  GEN_OPTION_TERMINATOR
 };
 #undef GEN_INT_OPTION
 #undef GEN_BOOL_OPTION
 #undef GEN_STR_OPTION
-#undef GEN_OPTION_TERMINATOR
+
+static int num_options;
+client_option *options;
 
 /** View Options: **/
 
@@ -434,9 +418,15 @@
   const char * const prefix = "client";
   char *name;
   int i, num;
-  client_option *o;
   view_option *v;
 
+  assert(options == NULL);
+  num_options = ARRAY_SIZE(common_options) + num_gui_options;
+  options = fc_malloc(num_options * sizeof(*options));
+  memcpy(options, common_options, sizeof(common_options));
+  memcpy(options + ARRAY_SIZE(common_options), gui_options,
+        num_gui_options * sizeof(*options));
+
   name = option_file_name();
   if (!name) {
     /* fail silently */
@@ -449,7 +439,9 @@
   sz_strlcpy(password, 
              secfile_lookup_str_default(&sf, "", "%s.password", prefix));
 
-  for (o = options; o->name; o++) {
+  for (i = 0; i < num_options; i++) {
+    client_option *o = options + i;
+
     switch (o->type) {
     case COT_BOOL:
       *(o->p_bool_value) =
@@ -534,7 +526,6 @@
 void save_options(void)
 {
   struct section_file sf;
-  client_option *o;
   char *name = option_file_name();
   char output_buffer[256];
   view_option *v;
@@ -547,8 +538,10 @@
 
   section_file_init(&sf);
   secfile_insert_str(&sf, VERSION_STRING, "client.version");
+
+  for (i = 0; i < num_options; i++) {
+    client_option *o = options + i;
 
-  for (o = options; o->name; o++) {
     switch (o->type) {
     case COT_BOOL:
       secfile_insert_bool(&sf, *(o->p_bool_value), "client.%s", o->name);
Index: client/options.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.h,v
retrieving revision 1.33
diff -u -r1.33 options.h
--- client/options.h    2003/12/16 15:07:52     1.33
+++ client/options.h    2004/01/19 23:16:53
@@ -73,7 +73,21 @@
   /* volatile */
   void *p_gui_data;
 } client_option;
-extern client_option options[];
+extern client_option *options;
+
+#define GEN_INT_OPTION(oname, desc) { #oname, desc, COT_INT, \
+                                      &oname, NULL, NULL, 0, NULL, \
+                                       NULL, NULL }
+#define GEN_BOOL_OPTION(oname, desc) { #oname, desc, COT_BOOL, \
+                                       NULL, &oname, NULL, 0, NULL, \
+                                       NULL, NULL }
+#define GEN_STR_OPTION(oname, desc, str_defaults, callback) \
+                                    { #oname, desc, COT_STR, \
+                                      NULL, NULL, oname, sizeof(oname), \
+                                      callback, str_defaults, NULL }
+/* GUI-specific options declared in gui-xxx but handled by common code. */
+extern const int num_gui_options;
+extern client_option gui_options[];
 
 /** View Options: **/
 
Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.141
diff -u -r1.141 gui_main.c
--- client/gui-gtk/gui_main.c   2003/12/16 15:07:52     1.141
+++ client/gui-gtk/gui_main.c   2004/01/19 23:16:54
@@ -132,6 +132,12 @@
 static gint timer_id;                               /*       ditto        */
 static gint gdk_input_id;
 
+client_option gui_options[] = {
+  GEN_BOOL_OPTION(meta_accelerators, N_("Use Alt/Meta for accelerators")),
+  GEN_BOOL_OPTION(map_scrollbars, N_("Show Map Scrollbars")),
+  GEN_BOOL_OPTION(keyboardless_goto, N_("Keyboardless goto")),
+};
+const int num_gui_options = ARRAY_SIZE(gui_options);
 
 static gint show_info_button_release(GtkWidget *w, GdkEventButton *ev);
 static gint show_info_popup(GtkWidget *w, GdkEventButton *ev);
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.63
diff -u -r1.63 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       2003/12/16 15:07:52     1.63
+++ client/gui-gtk-2.0/gui_main.c       2004/01/19 23:16:54
@@ -128,6 +128,14 @@
 GtkWidget *flake_ebox;
 GtkWidget *government_ebox;
 
+client_option gui_options[] = {
+  GEN_BOOL_OPTION(meta_accelerators, N_("Use Alt/Meta for accelerators")),
+  GEN_BOOL_OPTION(map_scrollbars, N_("Show Map Scrollbars")),
+  GEN_BOOL_OPTION(keyboardless_goto, N_("Keyboardless goto")),
+  GEN_BOOL_OPTION(dialogs_on_top, N_("Keep dialogs on top")),
+};
+const int num_gui_options = ARRAY_SIZE(gui_options);
+
 static GtkWidget *unit_pixmap_table;
 static GtkWidget *unit_pixmap;
 static GtkWidget *unit_pixmap_button;
Index: client/gui-mui/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/gui_main.c,v
retrieving revision 1.79
diff -u -r1.79 gui_main.c
--- client/gui-mui/gui_main.c   2003/11/19 17:30:51     1.79
+++ client/gui-mui/gui_main.c   2004/01/19 23:16:54
@@ -92,6 +92,11 @@
 
 const char *client_string = "gui-mui";
 
+client_option gui_options[] = {
+  /* None. */
+};
+const int num_gui_options = ARRAY_SIZE(gui_options);
+
 /**************************************************************************
   Print extra usage information, including one line help on each option,
   to stderr.
Index: client/gui-sdl/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/gui_main.c,v
retrieving revision 1.43
diff -u -r1.43 gui_main.c
--- client/gui-sdl/gui_main.c   2003/10/02 21:37:44     1.43
+++ client/gui-sdl/gui_main.c   2004/01/19 23:17:01
@@ -136,6 +136,11 @@
   EXIT_FROM_EVENT_LOOP = 7
 };
 
+client_option gui_options[] = {
+  /* None. */
+};
+const int num_gui_options = ARRAY_SIZE(gui_options);
+
 /* =========================================================== */
 
 /**************************************************************************
Index: client/gui-win32/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/gui_main.c,v
retrieving revision 1.23
diff -u -r1.23 gui_main.c
--- client/gui-win32/gui_main.c 2003/05/03 20:20:16     1.23
+++ client/gui-win32/gui_main.c 2004/01/19 23:17:01
@@ -92,6 +92,11 @@
 struct fcwin_box *main_win_box;
 struct fcwin_box *output_box;
 
+client_option gui_options[] = {
+  /* None. */
+};
+const int num_gui_options = ARRAY_SIZE(gui_options);
+
 /**************************************************************************
 
 **************************************************************************/
Index: client/gui-xaw/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v
retrieving revision 1.84
diff -u -r1.84 gui_main.c
--- client/gui-xaw/gui_main.c   2003/12/01 19:32:04     1.84
+++ client/gui-xaw/gui_main.c   2004/01/19 23:17:01
@@ -68,6 +68,11 @@
 
 const char *client_string = "gui-xaw";
 
+client_option gui_options[] = {
+  /* None. */
+};
+const int num_gui_options = ARRAY_SIZE(gui_options);
+
 static AppResources appResources;
 
 /* ids of the units icons in information display: (or 0) */

[Prev in Thread] Current Thread [Next in Thread]