Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12683) move tileset name into the tileset struct
Home

[Freeciv-Dev] (PR#12683) move tileset name into the tileset struct

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12683) move tileset name into the tileset struct
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 28 Mar 2005 15:14:55 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12683 >

This patch moves the tileset name (currently the current tileset's name 
is in current_tileset) into the tileset struct as t->name.

It is pretty straightforward.  I believe this should also fix the 
"overlapping mystrlcpy" (PR#10670) buglet, thought I haven't tested that.

-jason

Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.279
diff -u -r1.279 tilespec.c
--- client/tilespec.c   28 Mar 2005 16:59:14 -0000      1.279
+++ client/tilespec.c   28 Mar 2005 23:12:04 -0000
@@ -250,10 +250,6 @@
   struct terrain_drawing_data *terrain[MAX_NUM_TERRAINS];
 };
 
-/* Stores the currently loaded tileset.  This differs from the value in
- * options.h since that variable is changed by the GUI code. */
-char current_tileset[512];
-
 static const int DIR4_TO_DIR8[4] =
     { DIR8_NORTH, DIR8_SOUTH, DIR8_EAST, DIR8_WEST };
 
@@ -330,6 +326,8 @@
 #define small_sprite_list_iterate_end  LIST_ITERATE_END
 
 struct tileset {
+  char name[512];
+
   bool is_isometric;
   int hex_width, hex_height;
 
@@ -766,15 +764,17 @@
 
   It will also call the necessary functions to redraw the graphics.
 ***********************************************************************/
-void tilespec_reread(const char *tileset_name)
+void tilespec_reread(const char *new_tileset_name)
 {
   int id;
   struct tile *center_tile;
   enum client_states state = get_client_state();
+  const char *name = new_tileset_name ? new_tileset_name : tileset->name;
+  char tileset_name[strlen(name) + 1], old_name[strlen(tileset->name) + 1];
 
-  if (!tileset_name) {
-    tileset_name = current_tileset;
-  }
+  /* Make local copies since these values may be freed down below */
+  sz_strlcpy(tileset_name, name);
+  sz_strlcpy(old_name, tileset->name);
 
   freelog(LOG_NORMAL, "Loading tileset %s.", tileset_name);
 
@@ -797,7 +797,7 @@
    * We read in the new tileset.  This should be pretty straightforward.
    */
   if (!(tileset = tileset_read_toplevel(tileset_name))) {
-    if (!(tileset = tileset_read_toplevel(current_tileset))) {
+    if (!(tileset = tileset_read_toplevel(old_name))) {
       die("Failed to re-read the currently loaded tileset.");
     }
   }
@@ -1158,6 +1158,8 @@
 
   (void) section_file_lookup(file, "tilespec.name"); /* currently unused */
 
+  sz_strlcpy(t->name, tileset_name);
+
   t->is_isometric = secfile_lookup_bool_default(file, FALSE,
                                                "tilespec.is_isometric");
 
@@ -1455,8 +1457,6 @@
   freelog(LOG_VERBOSE, "finished reading %s", fname);
   free(fname);
 
-  sz_strlcpy(current_tileset, tileset_name);
-
   return t;
 }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12683) move tileset name into the tileset struct, Jason Short <=