Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] Re: (PR#10930) i18n in ukrainian: "Translated name is too
Home

[Freeciv-Dev] Re: (PR#10930) i18n in ukrainian: "Translated name is too

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: ktocomp@xxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#10930) i18n in ukrainian: "Translated name is too long. Aborting."
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 8 Nov 2004 19:47:31 -0800
Reply-to: rt@xxxxxxxxxxx

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

Here's a patch that handles all translated strings (all those in the 
header files with _orig in the name).

It's a bit tedious because translated strings must be const so lots of 
other strings have to be turned const.

jason


Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.408.2.6
diff -u -r1.408.2.6 packhand.c
--- client/packhand.c   4 Nov 2004 20:57:49 -0000       1.408.2.6
+++ client/packhand.c   9 Nov 2004 03:46:46 -0000
@@ -2189,7 +2189,8 @@
   }
   u = get_unit_type(p->id);
 
-  sz_strlcpy(u->name, p->name);
+  sz_strlcpy(u->name_orig, p->name);
+  u->name = u->name_orig;
   sz_strlcpy(u->graphic_str, p->graphic_str);
   sz_strlcpy(u->graphic_alt, p->graphic_alt);
   sz_strlcpy(u->sound_move, p->sound_move);
@@ -2247,7 +2248,8 @@
   }
   a = &advances[p->id];
 
-  sz_strlcpy(a->name, p->name);
+  sz_strlcpy(a->name_orig, p->name);
+  a->name = a->name_orig;
   sz_strlcpy(a->graphic_str, p->graphic_str);
   sz_strlcpy(a->graphic_alt, p->graphic_alt);
   a->req[0] = p->req[0];
@@ -2277,7 +2279,8 @@
   }
   b = &improvement_types[p->id];
 
-  sz_strlcpy(b->name, p->name);
+  sz_strlcpy(b->name_orig, p->name);
+  b->name = b->name_orig;
   sz_strlcpy(b->graphic_str, p->graphic_str);
   sz_strlcpy(b->graphic_alt, p->graphic_alt);
   b->tech_req = p->tech_req;
@@ -2429,7 +2432,8 @@
   gov->flags               = p->flags;
   gov->num_ruler_titles    = p->num_ruler_titles;
     
-  sz_strlcpy(gov->name, p->name);
+  sz_strlcpy(gov->name_orig, p->name);
+  gov->name = gov->name_orig;
   sz_strlcpy(gov->graphic_str, p->graphic_str);
   sz_strlcpy(gov->graphic_alt, p->graphic_alt);
 
@@ -2457,8 +2461,12 @@
     return;
   }
   gov->ruler_titles[p->id].nation = p->nation;
-  sz_strlcpy(gov->ruler_titles[p->id].male_title, p->male_title);
-  sz_strlcpy(gov->ruler_titles[p->id].female_title, p->female_title);
+  sz_strlcpy(gov->ruler_titles[p->id].male_title_orig, p->male_title);
+  gov->ruler_titles[p->id].male_title
+    = gov->ruler_titles[p->id].male_title_orig;
+  sz_strlcpy(gov->ruler_titles[p->id].female_title_orig, p->female_title);
+  gov->ruler_titles[p->id].female_title
+    = gov->ruler_titles[p->id].female_title_orig;
 }
 
 /**************************************************************************
@@ -2476,7 +2484,8 @@
   }
   t = &(tile_types[p->id]);
 
-  sz_strlcpy(t->terrain_name, p->terrain_name);
+  sz_strlcpy(t->terrain_name_orig, p->terrain_name);
+  t->terrain_name = t->terrain_name_orig;
   sz_strlcpy(t->graphic_str, p->graphic_str);
   sz_strlcpy(t->graphic_alt, p->graphic_alt);
   t->movement_cost = p->movement_cost;
@@ -2484,11 +2493,13 @@
   t->food = p->food;
   t->shield = p->shield;
   t->trade = p->trade;
-  sz_strlcpy(t->special_1_name, p->special_1_name);
+  sz_strlcpy(t->special_1_name_orig, p->special_1_name);
+  t->special_1_name = t->special_1_name_orig;
   t->food_special_1 = p->food_special_1;
   t->shield_special_1 = p->shield_special_1;
   t->trade_special_1 = p->trade_special_1;
-  sz_strlcpy(t->special_2_name, p->special_2_name);
+  sz_strlcpy(t->special_2_name_orig, p->special_2_name);
+  t->special_2_name = t->special_2_name_orig;
   t->food_special_2 = p->food_special_2;
   t->shield_special_2 = p->shield_special_2;
   t->trade_special_2 = p->trade_special_2;
@@ -2547,8 +2558,10 @@
   }
   pl = get_nation_by_idx(p->id);
 
-  sz_strlcpy(pl->name, p->name);
-  sz_strlcpy(pl->name_plural, p->name_plural);
+  sz_strlcpy(pl->name_orig, p->name);
+  pl->name = pl->name_orig;
+  sz_strlcpy(pl->name_plural_orig, p->name_plural);
+  pl->name_plural = pl->name_plural_orig;
   sz_strlcpy(pl->flag_graphic_str, p->graphic_str);
   sz_strlcpy(pl->flag_graphic_alt, p->graphic_alt);
   pl->leader_count = p->leader_count;
@@ -2593,7 +2606,8 @@
   cs->techreq = packet->techreq;
   cs->replaced_by = packet->replaced_by;
 
-  sz_strlcpy(cs->name, packet->name);
+  sz_strlcpy(cs->name_orig, packet->name);
+  cs->name = cs->name_orig;
   sz_strlcpy(cs->graphic, packet->graphic);
   sz_strlcpy(cs->graphic_alt, packet->graphic_alt);
   sz_strlcpy(cs->citizens_graphic, packet->citizens_graphic);
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.204.2.4
diff -u -r1.204.2.4 tilespec.c
--- client/tilespec.c   23 Oct 2004 19:10:27 -0000      1.204.2.4
+++ client/tilespec.c   9 Nov 2004 03:46:47 -0000
@@ -1771,7 +1771,7 @@
   }
 
   for (i=0; i<2; i++) {
-    char *name = (i != 0) ? tt->special_2_name : tt->special_1_name;
+    const char *name = (i != 0) ? tt->special_2_name : tt->special_1_name;
     if (name[0] != '\0') {
       draw->special[i]
        = lookup_sprite_tag_alt(tt->special[i].graphic_str,
Index: client/gui-gtk/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/dialogs.c,v
retrieving revision 1.148
diff -u -r1.148 dialogs.c
--- client/gui-gtk/dialogs.c    29 Sep 2004 02:24:20 -0000      1.148
+++ client/gui-gtk/dialogs.c    9 Nov 2004 03:46:48 -0000
@@ -724,7 +724,7 @@
   advance_type[j] = -1;
 
   if (pvictim) { /* you don't want to know what lag can do -- Syela */
-    gchar *row[1];
+    const gchar *row[1];
 
     for(i=A_FIRST; i<game.num_tech_types; i++) {
       if(get_invention(pvictim, i)==TECH_KNOWN && 
@@ -732,14 +732,14 @@
          get_invention(pplayer, i)==TECH_REACHABLE)) {
 
        row[0] = advances[i].name;
-       gtk_clist_append(GTK_CLIST(spy_advances_list), row);
+       gtk_clist_append(GTK_CLIST(spy_advances_list), (gchar **)row);
         advance_type[j++] = i;
       }
     }
 
     if(j > 0) {
       row[0] = _("At Spy's Discretion");
-      gtk_clist_append(GTK_CLIST(spy_advances_list), row);
+      gtk_clist_append(GTK_CLIST(spy_advances_list), (gchar **)row);
       advance_type[j++] = game.num_tech_types;
     }
   }
@@ -1866,8 +1866,8 @@
     for (i = 0; i < nations_in_class; i++) {
       race_names =
          g_list_append(race_names,
-               get_nation_by_idx(GPOINTER_TO_INT(g_list_nth_data
-                                 (sorted_races_list[class_id], i)))->name);
+               (gchar *)get_nation_by_idx(GPOINTER_TO_INT(g_list_nth_data
+                       (sorted_races_list[class_id], i)))->name);
     }
 
     per_row = 8;
Index: client/gui-gtk/helpdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/helpdlg.c,v
retrieving revision 1.68
diff -u -r1.68 helpdlg.c
--- client/gui-gtk/helpdlg.c    4 Sep 2004 21:11:46 -0000       1.68
+++ client/gui-gtk/helpdlg.c    9 Nov 2004 03:46:48 -0000
@@ -395,7 +395,7 @@
   return button;
 }
 
-static GtkWidget *help_slink_new(gchar *txt, enum help_page_type type)
+static GtkWidget *help_slink_new(const gchar *txt, enum help_page_type type)
 {
   GtkWidget *button;
 
Index: client/gui-gtk/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/repodlgs.c,v
retrieving revision 1.83
diff -u -r1.83 repodlgs.c
--- client/gui-gtk/repodlgs.c   2 Aug 2004 23:44:57 -0000       1.83
+++ client/gui-gtk/repodlgs.c   9 Nov 2004 03:46:48 -0000
@@ -341,7 +341,7 @@
 *****************************************************************/
 static gint cmp_func(gconstpointer a_p, gconstpointer b_p)
 {
-  gchar *a_str, *b_str;
+  const gchar *a_str, *b_str;
   gchar text_a[512], text_b[512];
   gint a = GPOINTER_TO_INT(a_p), b = GPOINTER_TO_INT(b_p);
 
@@ -372,7 +372,7 @@
   if(science_dialog_shell) {
   char text[512];
   int i, j, hist;
-  static char *row     [1];
+  static const char *row[1];
   GtkWidget *item;
   GList *sorting_list = NULL;
   gfloat pct;
@@ -401,7 +401,7 @@
   for(i=0; i<g_list_length(sorting_list); i++) {
     j = GPOINTER_TO_INT(g_list_nth_data(sorting_list, i));
     row[0] = advances[j].name;
-    gtk_clist_append(GTK_CLIST(science_list[i%4]), row);
+    gtk_clist_append(GTK_CLIST(science_list[i%4]), (gchar **)row);
   }
   g_list_free(sorting_list);
   sorting_list = NULL;
@@ -451,7 +451,7 @@
   /* sort the list and build from it the menu */
   sorting_list = g_list_sort(sorting_list, cmp_func);
   for (i = 0; i < g_list_length(sorting_list); i++) {
-    gchar *data;
+    const gchar *data;
 
     if (GPOINTER_TO_INT(g_list_nth_data(sorting_list, i)) <
        game.num_tech_types) {
@@ -515,7 +515,7 @@
   /* sort the list and build from it the menu */
   sorting_list = g_list_sort(sorting_list, cmp_func);
   for (i = 0; i < g_list_length(sorting_list); i++) {
-    gchar *data =
+    const gchar *data =
        advances[GPOINTER_TO_INT(g_list_nth_data(sorting_list, i))].name;
 
     item = gtk_menu_item_new_with_label(data);
Index: client/gui-gtk-2.0/helpdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/helpdlg.c,v
retrieving revision 1.35
diff -u -r1.35 helpdlg.c
--- client/gui-gtk-2.0/helpdlg.c        4 Sep 2004 21:11:47 -0000       1.35
+++ client/gui-gtk-2.0/helpdlg.c        9 Nov 2004 03:46:48 -0000
@@ -315,7 +315,7 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static GtkWidget *help_slink_new(gchar *txt, enum help_page_type type)
+static GtkWidget *help_slink_new(const gchar *txt, enum help_page_type type)
 {
   GtkWidget *button, *label;
 
Index: client/gui-gtk-2.0/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/repodlgs.c,v
retrieving revision 1.60.2.4
diff -u -r1.60.2.4 repodlgs.c
--- client/gui-gtk-2.0/repodlgs.c       2 Nov 2004 18:04:39 -0000       1.60.2.4
+++ client/gui-gtk-2.0/repodlgs.c       9 Nov 2004 03:46:48 -0000
@@ -358,7 +358,7 @@
 *****************************************************************/
 static gint cmp_func(gconstpointer a_p, gconstpointer b_p)
 {
-  gchar *a_str, *b_str;
+  const gchar *a_str, *b_str;
   gchar text_a[512], text_b[512];
   gint a = GPOINTER_TO_INT(a_p), b = GPOINTER_TO_INT(b_p);
 
@@ -477,7 +477,7 @@
   /* sort the list and build from it the menu */
   sorting_list = g_list_sort(sorting_list, cmp_func);
   for (i = 0; i < g_list_length(sorting_list); i++) {
-    gchar *data;
+    const gchar *data;
 
     if (GPOINTER_TO_INT(g_list_nth_data(sorting_list, i)) <
        game.num_tech_types) {
Index: client/gui-xaw/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/dialogs.c,v
retrieving revision 1.104
diff -u -r1.104 dialogs.c
--- client/gui-xaw/dialogs.c    29 Sep 2004 02:24:22 -0000      1.104
+++ client/gui-xaw/dialogs.c    9 Nov 2004 03:46:49 -0000
@@ -688,7 +688,7 @@
   Dimension width1, width2; 
   int i, j;
 
-  static char *advances_can_steal[A_LAST+1]; 
+  static const char *advances_can_steal[A_LAST+1]; 
 
   spy_tech_shell =
     I_T(XtVaCreatePopupShell("spystealtechpopup", 
@@ -753,7 +753,7 @@
   
   XtSetSensitive(spy_steal_command, FALSE);
   
-  XawListChange(spy_advances_list, advances_can_steal, 0, 0, 1);
+  XawListChange(spy_advances_list, (char **)advances_can_steal, 0, 0, 1);
   XtVaGetValues(spy_advances_list, XtNwidth, &width1, NULL);
   XtVaGetValues(spy_advances_list_label, XtNwidth, &width2, NULL);
   XtVaSetValues(spy_advances_list, XtNwidth, MAX(width1,width2), NULL); 
Index: client/gui-xaw/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/menu.c,v
retrieving revision 1.69
diff -u -r1.69 menu.c
--- client/gui-xaw/menu.c       29 Sep 2004 02:24:22 -0000      1.69
+++ client/gui-xaw/menu.c       9 Nov 2004 03:46:49 -0000
@@ -254,8 +254,10 @@
                        void (*menucallback)(Widget, XtPointer, XtPointer),
                        Widget parent);
 static void menu_entry_sensitive(enum MenuIndex menu, enum MenuID id, Bool s);
-static void menu_entry_rename(enum MenuIndex menu, enum MenuID id, int var, 
char *terr);
-static char *menu_entry_text(enum MenuIndex menu, int ent, int var, char 
*terr);
+static void menu_entry_rename(enum MenuIndex menu, enum MenuID id, int var,
+                             const char *terr);
+static char *menu_entry_text(enum MenuIndex menu, int ent, int var,
+                            const char *terr);
 
 static void revolution_menu_callback(Widget w, XtPointer client_data,
                                     XtPointer garbage);
@@ -983,7 +985,8 @@
 /****************************************************************
 ...
 *****************************************************************/
-void menu_entry_rename(enum MenuIndex menu, enum MenuID id, int var, char 
*terr)
+void menu_entry_rename(enum MenuIndex menu, enum MenuID id, int var,
+                      const char *terr)
 {
   struct Menu *pmenu = menus[menu];
   int i;
@@ -1017,7 +1020,8 @@
 /****************************************************************
 ...
 *****************************************************************/
-char *menu_entry_text(enum MenuIndex menu, int ent, int var, char *terr)
+static char *menu_entry_text(enum MenuIndex menu, int ent, int var,
+                            const char *terr)
 {
   struct Menu *pmenu = menus[menu];
   static char retbuf[256];
Index: client/gui-xaw/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/repodlgs.c,v
retrieving revision 1.62
diff -u -r1.62 repodlgs.c
--- client/gui-xaw/repodlgs.c   21 Sep 2004 01:03:57 -0000      1.62
+++ client/gui-xaw/repodlgs.c   9 Nov 2004 03:46:49 -0000
@@ -195,7 +195,7 @@
 {
   Widget science_form;
   Widget  close_command;
-  static char *tech_list_names_ptrs[A_LAST+1];
+  const static char *tech_list_names_ptrs[A_LAST + 1];
   int j, flag, num_list;
   size_t i;
   Dimension width;
@@ -471,7 +471,7 @@
   if(is_report_dialogs_frozen()) return;
   if(science_dialog_shell) {
     char text[512];
-    static char *tech_list_names_ptrs[A_LAST+1];
+    static const char *tech_list_names_ptrs[A_LAST + 1];
     int j, flag;
     size_t i;
     const char *report_title;
@@ -520,7 +520,7 @@
     tech_list_names_ptrs[j]=0;
     qsort(tech_list_names_ptrs, j, sizeof(char *), compare_strings_ptrs);
 
-    XawListChange(science_list, tech_list_names_ptrs, 0/*j*/, 0, 1);
+    XawListChange(science_list, (char **)tech_list_names_ptrs, 0/*j*/, 0, 1);
 
     XtDestroyWidget(popupmenu);
     
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.249.2.3
diff -u -r1.249.2.3 city.c
--- common/city.c       19 Oct 2004 06:46:58 -0000      1.249.2.3
+++ common/city.c       9 Nov 2004 03:46:50 -0000
@@ -1287,7 +1287,7 @@
 /**************************************************************************
   Get name of given city style.
 **************************************************************************/
-char* get_city_style_name(int style)
+const char *get_city_style_name(int style)
 {
    return city_styles[style].name;
 }
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.163.2.1
diff -u -r1.163.2.1 city.h
--- common/city.h       19 Oct 2004 06:46:58 -0000      1.163.2.1
+++ common/city.h       9 Nov 2004 03:46:50 -0000
@@ -318,7 +318,7 @@
 #define MAX_CITY_TILES 8
 
 struct citystyle {
-  char name[MAX_LEN_NAME];
+  const char *name; /* Translated string - doesn't need freeing. */
   char name_orig[MAX_LEN_NAME];              /* untranslated */
   char graphic[MAX_LEN_NAME];
   char graphic_alt[MAX_LEN_NAME];
@@ -465,7 +465,7 @@
 int get_player_city_style(struct player *plr);
 int get_style_by_name(const char *);
 int get_style_by_name_orig(const char *);
-char* get_city_style_name(int style);
+const char *get_city_style_name(int style);
 char* get_city_style_name_orig(int style);
 
 struct city *is_enemy_city_tile(const struct tile *ptile,
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.187
diff -u -r1.187 game.c
--- common/game.c       29 Sep 2004 02:24:22 -0000      1.187
+++ common/game.c       9 Nov 2004 03:46:50 -0000
@@ -540,72 +540,59 @@
 void translate_data_names(void)
 {
   int i;
-  static const char too_long_msg[]
-    = "Translated name is too long, truncating: %s";
 
-#define name_strlcpy(dst, src) ((void) sz_loud_strlcpy(dst, src, too_long_msg))
-  
   tech_type_iterate(tech_id) {
     struct advance *tthis = &advances[tech_id];
-    sz_strlcpy(tthis->name_orig, tthis->name);
-    name_strlcpy(tthis->name, Q_(tthis->name_orig));
+
+    tthis->name = Q_(tthis->name_orig);
   } tech_type_iterate_end;
 
   unit_type_iterate(i) {
     struct unit_type *tthis = &unit_types[i];
-    sz_strlcpy(tthis->name_orig, tthis->name);
-    name_strlcpy(tthis->name, Q_(tthis->name_orig));
+
+    tthis->name = Q_(tthis->name_orig);
   } unit_type_iterate_end;
 
   impr_type_iterate(i) {
     struct impr_type *tthis = &improvement_types[i];
-    sz_strlcpy(tthis->name_orig, tthis->name);
-    name_strlcpy(tthis->name, Q_(tthis->name_orig));
+
+    tthis->name = Q_(tthis->name_orig);
   } impr_type_iterate_end;
 
   terrain_type_iterate(i) {
     struct tile_type *tthis = &tile_types[i];
-    sz_strlcpy(tthis->terrain_name_orig, tthis->terrain_name);
-    name_strlcpy(tthis->terrain_name,
-                (strcmp(tthis->terrain_name_orig, "") != 0) ?
-                       Q_(tthis->terrain_name_orig) : "");
-    sz_strlcpy(tthis->special_1_name_orig, tthis->special_1_name);
-    name_strlcpy(tthis->special_1_name,
-                (strcmp(tthis->special_1_name_orig, "") != 0) ?
-                       Q_(tthis->special_1_name_orig) : "");
-    sz_strlcpy(tthis->special_2_name_orig, tthis->special_2_name);
-    name_strlcpy(tthis->special_2_name,
-                (strcmp(tthis->special_2_name_orig, "") != 0) ?
-                       Q_(tthis->special_2_name_orig) : "");
+
+    tthis->terrain_name = ((strcmp(tthis->terrain_name_orig, "") != 0)
+                          ? Q_(tthis->terrain_name_orig) : "");
+
+    tthis->special_1_name = ((strcmp(tthis->special_1_name_orig, "") != 0)
+                            ? Q_(tthis->special_1_name_orig) : "");
+    tthis->special_2_name = ((strcmp(tthis->special_2_name_orig, "") != 0)
+                            ? Q_(tthis->special_2_name_orig) : "");
   } terrain_type_iterate_end;
 
   government_iterate(tthis) {
     int j;
 
-    sz_strlcpy(tthis->name_orig, tthis->name);
-    name_strlcpy(tthis->name, Q_(tthis->name_orig));
+    tthis->name = Q_(tthis->name_orig);
     for(j=0; j<tthis->num_ruler_titles; j++) {
       struct ruler_title *that = &tthis->ruler_titles[j];
-      sz_strlcpy(that->male_title_orig, that->male_title);
-      name_strlcpy(that->male_title, Q_(that->male_title_orig));
-      sz_strlcpy(that->female_title_orig, that->female_title);
-      name_strlcpy(that->female_title, Q_(that->female_title_orig));
+
+      that->male_title = Q_(that->male_title_orig);
+      that->female_title = Q_(that->female_title_orig);
     }
   } government_iterate_end;
   for (i=0; i<game.nation_count; i++) {
     struct nation_type *tthis = get_nation_by_idx(i);
-    sz_strlcpy(tthis->name_orig, tthis->name);
-    name_strlcpy(tthis->name, Q_(tthis->name_orig));
-    sz_strlcpy(tthis->name_plural_orig, tthis->name_plural);
-    name_strlcpy(tthis->name_plural, Q_(tthis->name_plural_orig));
+
+    tthis->name = Q_(tthis->name_orig);
+    tthis->name_plural = Q_(tthis->name_plural_orig);
   }
   for (i=0; i<game.styles_count; i++) {
     struct citystyle *tthis = &city_styles[i];
-    sz_strlcpy(tthis->name_orig, tthis->name);
-    name_strlcpy(tthis->name, Q_(tthis->name_orig));
-  }
 
-#undef name_strlcpy
+    tthis->name = Q_(tthis->name_orig);
+  }
 
 }
 
Index: common/government.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.c,v
retrieving revision 1.46
diff -u -r1.46 government.c
--- common/government.c 13 Sep 2004 15:54:51 -0000      1.46
+++ common/government.c 9 Nov 2004 03:46:50 -0000
@@ -251,13 +251,17 @@
 
   gov->num_ruler_titles++;
   gov->ruler_titles =
-    (struct ruler_title *)fc_realloc(gov->ruler_titles,
+    fc_realloc(gov->ruler_titles,
       gov->num_ruler_titles*sizeof(struct ruler_title));
   title = &(gov->ruler_titles[gov->num_ruler_titles-1]);
 
   title->nation = nation;
-  sz_strlcpy(title->male_title, male);
-  sz_strlcpy(title->female_title, female);
+
+  sz_strlcpy(title->male_title_orig, male);
+  title->male_title = title->male_title_orig;
+
+  sz_strlcpy(title->female_title_orig, female);
+  title->female_title = title->female_title_orig;
 }
 
 /***************************************************************
Index: common/government.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.h,v
retrieving revision 1.31
diff -u -r1.31 government.h
--- common/government.h 3 Sep 2004 04:22:37 -0000       1.31
+++ common/government.h 9 Nov 2004 03:46:50 -0000
@@ -56,8 +56,8 @@
 struct ruler_title
 {
   int  nation;
-  char male_title[MAX_LEN_NAME];
-  char female_title[MAX_LEN_NAME];
+  const char *male_title; /* Translated string - doesn't need freeing. */
+  const char *female_title; /* Translated string - doesn't need freeing. */
   
   /* untranslated copies: */
   char male_title_orig[MAX_LEN_NAME];    
@@ -70,7 +70,7 @@
 struct government
 {
   int   index;                 /* index into governments[] array */
-  char  name[MAX_LEN_NAME];    /* government name */
+  const char *name; /* Translated string - doesn't need freeing. */
   char  name_orig[MAX_LEN_NAME]; /* untranslated copy */
   char  graphic_str[MAX_LEN_NAME];
   char  graphic_alt[MAX_LEN_NAME];
Index: common/improvement.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.h,v
retrieving revision 1.34
diff -u -r1.34 improvement.h
--- common/improvement.h        25 Sep 2004 22:18:41 -0000      1.34
+++ common/improvement.h        9 Nov 2004 03:46:50 -0000
@@ -58,7 +58,7 @@
 
 /* Type of improvement. (Read from buildings.ruleset file.) */
 struct impr_type {
-  char name[MAX_LEN_NAME];
+  const char *name; /* Translated string - doesn't need freeing. */
   char name_orig[MAX_LEN_NAME];                /* untranslated */
   char graphic_str[MAX_LEN_NAME];      /* city icon of improv. */
   char graphic_alt[MAX_LEN_NAME];      /* city icon of improv. */
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.219.2.4
diff -u -r1.219.2.4 map.h
--- common/map.h        18 Oct 2004 22:40:33 -0000      1.219.2.4
+++ common/map.h        9 Nov 2004 03:46:50 -0000
@@ -75,7 +75,7 @@
 expand with government bonuses??
 *****************************************************************/
 struct tile_type {
-  char terrain_name[MAX_LEN_NAME];     /* "" if unused */
+  const char *terrain_name; /* Translated string - doesn't need freeing. */
   char terrain_name_orig[MAX_LEN_NAME];        /* untranslated copy */
   char graphic_str[MAX_LEN_NAME];
   char graphic_alt[MAX_LEN_NAME];
@@ -91,13 +91,13 @@
   int shield;
   int trade;
 
-  char special_1_name[MAX_LEN_NAME];   /* "" if none */
+  const char *special_1_name; /* Translated string - doesn't need freeing. */
   char special_1_name_orig[MAX_LEN_NAME]; /* untranslated copy */
   int food_special_1;
   int shield_special_1;
   int trade_special_1;
 
-  char special_2_name[MAX_LEN_NAME];   /* "" if none */
+  const char *special_2_name; /* Translated string - doesn't need freeing. */
   char special_2_name_orig[MAX_LEN_NAME]; /* untranslated copy */
   int food_special_2;
   int shield_special_2;
Index: common/nation.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v
retrieving revision 1.31
diff -u -r1.31 nation.h
--- common/nation.h     6 Sep 2004 02:58:11 -0000       1.31
+++ common/nation.h     9 Nov 2004 03:46:50 -0000
@@ -66,10 +66,9 @@
 };
 
 struct nation_type {
-  /* Pointer values are allocated in load_ruleset_nations() then freed in
-   * free_nations(). */
-  char name[MAX_LEN_NAME];
-  char name_plural[MAX_LEN_NAME];
+  /* Pointer values are allocated on load then freed in free_nations(). */
+  const char *name; /* Translated string - doesn't need freeing. */
+  const char *name_plural; /* Translated string - doesn't need freeing. */
   char flag_graphic_str[MAX_LEN_NAME];
   char flag_graphic_alt[MAX_LEN_NAME];
   int  leader_count;
Index: common/tech.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.h,v
retrieving revision 1.47
diff -u -r1.47 tech.h
--- common/tech.h       3 Sep 2004 04:22:37 -0000       1.47
+++ common/tech.h       9 Nov 2004 03:46:50 -0000
@@ -76,7 +76,7 @@
 };
 
 struct advance {
-  char name[MAX_LEN_NAME];
+  const char *name; /* Translated string - doesn't need freeing. */
   char name_orig[MAX_LEN_NAME];              /* untranslated */
   char graphic_str[MAX_LEN_NAME];      /* which named sprite to use */
   char graphic_alt[MAX_LEN_NAME];      /* alternate icon name */
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.31
diff -u -r1.31 unittype.h
--- common/unittype.h   3 Sep 2004 04:22:37 -0000       1.31
+++ common/unittype.h   9 Nov 2004 03:46:51 -0000
@@ -174,7 +174,7 @@
 };
 
 struct unit_type {
-  char name[MAX_LEN_NAME];
+  const char *name; /* Translated string - doesn't need freeing. */
   char name_orig[MAX_LEN_NAME];              /* untranslated */
   char graphic_str[MAX_LEN_NAME];
   char graphic_alt[MAX_LEN_NAME];
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.276.2.2
diff -u -r1.276.2.2 citytools.c
--- server/citytools.c  31 Oct 2004 22:01:15 -0000      1.276.2.2
+++ server/citytools.c  9 Nov 2004 03:46:51 -0000
@@ -1810,7 +1810,7 @@
 void change_build_target(struct player *pplayer, struct city *pcity,
                         int target, bool is_unit, enum event_type event)
 {
-  char *name;
+  const char *name;
   const char *source;
 
   /* If the city is already building this thing, don't do anything */
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.267.2.4
diff -u -r1.267.2.4 cityturn.c
--- server/cityturn.c   31 Oct 2004 21:58:36 -0000      1.267.2.4
+++ server/cityturn.c   9 Nov 2004 03:46:52 -0000
@@ -540,7 +540,7 @@
     unit_list_iterate_safe(pcity->units_supported, punit) {
       if (unit_type(punit)->food_cost > 0 
           && !unit_flag(punit, F_UNDISBANDABLE)) {
-       char *utname = unit_type(punit)->name;
+       const char *utname = unit_type(punit)->name;
        wipe_unit(punit);
        notify_player_ex(city_owner(pcity), pcity->tile, E_UNIT_LOST,
                         _("Game: Famine feared in %s, %s lost!"), 
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.196.2.1
diff -u -r1.196.2.1 ruleset.c
--- server/ruleset.c    23 Oct 2004 18:54:41 -0000      1.196.2.1
+++ server/ruleset.c    9 Nov 2004 03:46:52 -0000
@@ -530,14 +530,16 @@
   }
 
   /* Initialize dummy tech A_NONE */
-  sz_strlcpy(advances[A_NONE].name, "None");
+  sz_strlcpy(advances[A_NONE].name_orig, "None");
+  advances[A_NONE].name = advances[A_NONE].name_orig;
 
   game.num_tech_types = num_techs + 1; /* includes A_NONE */
 
   a = &advances[A_FIRST];
   for (i = 0; i < num_techs; i++ ) {
     char *name = secfile_lookup_str(file, "%s.name", sec[i]);
-    name_strlcpy(a->name, name);
+    name_strlcpy(a->name_orig, name);
+    a->name = a->name_orig;
     a++;
   }
   free(sec);
@@ -716,7 +718,9 @@
 
   unit_type_iterate(i) {
     char *name = secfile_lookup_str(file, "%s.name", sec[i]);
-    name_strlcpy(unit_types[i].name, name);
+
+    name_strlcpy(unit_types[i].name_orig, name);
+    unit_types[i].name = unit_types[i].name_orig;
   } unit_type_iterate_end;
 
   free(sec);
@@ -1143,8 +1147,9 @@
 
   impr_type_iterate(i) {
     char *name = secfile_lookup_str(file, "%s.name", sec[i]);
-    name_strlcpy(improvement_types[i].name, name);
-    improvement_types[i].name_orig[0] = 0;
+
+    name_strlcpy(improvement_types[i].name_orig, name);
+    improvement_types[i].name = improvement_types[i].name_orig;
   } impr_type_iterate_end;
 
   ruleset_cache_init();
@@ -1517,10 +1522,12 @@
 
   terrain_type_iterate(i) {
     char *name = secfile_lookup_str(file, "%s.terrain_name", sec[i]);
-    name_strlcpy(tile_types[i].terrain_name, name);
-    if (0 == strcmp(tile_types[i].terrain_name, "unused")) {
-      tile_types[i].terrain_name[0] = 0;
+
+    name_strlcpy(tile_types[i].terrain_name_orig, name);
+    if (0 == strcmp(tile_types[i].terrain_name_orig, "unused")) {
+      tile_types[i].terrain_name_orig[0] = '\0';
     }
+    tile_types[i].terrain_name = tile_types[i].terrain_name_orig;
   } terrain_type_iterate_end;
 
   free(sec);
@@ -1632,15 +1639,21 @@
       t->trade = secfile_lookup_int(file, "%s.trade", sec[i]);
 
       s1_name = secfile_lookup_str(file, "%s.special_1_name", sec[i]);
-      name_strlcpy(t->special_1_name, s1_name);
-      if (0 == strcmp(t->special_1_name, "none")) *(t->special_1_name) = '\0';
+      name_strlcpy(t->special_1_name_orig, s1_name);
+      if (0 == strcmp(t->special_1_name_orig, "none")) {
+       t->special_1_name_orig[0] = '\0';
+      }
+      t->special_1_name = t->special_1_name_orig;
       t->food_special_1 = secfile_lookup_int(file, "%s.food_special_1", 
sec[i]);
       t->shield_special_1 = secfile_lookup_int(file, "%s.shield_special_1", 
sec[i]);
       t->trade_special_1 = secfile_lookup_int(file, "%s.trade_special_1", 
sec[i]);
 
       s2_name = secfile_lookup_str(file, "%s.special_2_name", sec[i]);
-      name_strlcpy(t->special_2_name, s2_name);
-      if (0 == strcmp(t->special_2_name, "none")) *(t->special_2_name) = '\0';
+      name_strlcpy(t->special_2_name_orig, s2_name);
+      if (0 == strcmp(t->special_2_name_orig, "none")) {
+       t->special_2_name_orig[0] = '\0';
+      }
+      t->special_2_name = t->special_2_name_orig;
       t->food_special_2 = secfile_lookup_int(file, "%s.food_special_2", 
sec[i]);
       t->shield_special_2 = secfile_lookup_int(file, "%s.shield_special_2", 
sec[i]);
       t->trade_special_2 = secfile_lookup_int(file, "%s.trade_special_2", 
sec[i]);
@@ -1751,7 +1764,8 @@
   government_iterate(gov) {
     char *name = secfile_lookup_str(file, "%s.name", sec[gov->index]);
 
-    name_strlcpy(gov->name, name);
+    name_strlcpy(gov->name_orig, name);
+    gov->name = gov->name_orig;
   } government_iterate_end;
   free(sec);
 }
@@ -1917,10 +1931,12 @@
     title = &(g->ruler_titles[0]);
 
     title->nation = DEFAULT_TITLE;
-    sz_strlcpy(title->male_title,
+    sz_strlcpy(title->male_title_orig,
               secfile_lookup_str(file, "%s.ruler_male_title", sec[i]));
-    sz_strlcpy(title->female_title,
+    title->male_title = title->male_title_orig;
+    sz_strlcpy(title->female_title_orig,
               secfile_lookup_str(file, "%s.ruler_female_title", sec[i]));
+    title->female_title = title->female_title_orig;
   } government_iterate_end;
 
   /* ai tech_hints: */
@@ -2072,8 +2088,14 @@
     char *name_plural = secfile_lookup_str(file, "%s.plural", sec[i]);
     struct nation_type *pl = get_nation_by_idx(i);
 
-    name_strlcpy(pl->name, name);
-    name_strlcpy(pl->name_plural, name_plural);
+    name_strlcpy(pl->name_orig, name);
+    name_strlcpy(pl->name_plural_orig, name_plural);
+
+    /* These are overwritten later when translations are done.  However
+     * in the meantime some code (like the check below) accesses the name
+     * directly.  This isn't great but it would take some work to fix. */
+    pl->name = pl->name_orig;
+    pl->name_plural = pl->name_plural_orig;
 
     /* Check if nation name is already defined. */
     for(j = 0; j < i; j++) {
@@ -2524,7 +2546,8 @@
   /* Get names, so can lookup for replacements: */
   for (i = 0; i < game.styles_count; i++) {
     char *style_name = secfile_lookup_str(file, "%s.name", styles[i]);
-    name_strlcpy(city_styles[i].name, style_name);
+    name_strlcpy(city_styles[i].name_orig, style_name);
+    city_styles[i].name = city_styles[i].name_orig;
   }
   free(styles);
 }
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.308.2.1
diff -u -r1.308.2.1 unithand.c
--- server/unithand.c   14 Oct 2004 21:01:06 -0000      1.308.2.1
+++ server/unithand.c   9 Nov 2004 03:46:53 -0000
@@ -356,7 +356,7 @@
   /* Given that res came from test_unit_add_or_build_city, pcity will
      be non-null for all required status values. */
   struct city *pcity = map_get_city(punit->tile);
-  char *unit_name = unit_type(punit)->name;
+  const char *unit_name = unit_type(punit)->name;
 
   switch (res) {
   case AB_NOT_BUILD_LOC:
@@ -431,7 +431,7 @@
 static void city_add_unit(struct player *pplayer, struct unit *punit)
 {
   struct city *pcity = map_get_city(punit->tile);
-  char *unit_name = unit_type(punit)->name;
+  const char *unit_name = unit_type(punit)->name;
 
   assert(unit_pop_value(punit->type) > 0);
   pcity->size += unit_pop_value(punit->type);

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