Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#10971) gtk client always crashes on bad string convers
Home

[Freeciv-Dev] (PR#10971) gtk client always crashes on bad string convers

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: th@xxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#10971) gtk client always crashes on bad string conversion
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Nov 2004 11:08:41 -0800
Reply-to: rt@xxxxxxxxxxx

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

Here's a better transliteration patch.  This one should probably be used.

Transliteration is used in the xaw, gtk, win32, and ftwl clients.  It is
not used in the gtk2 client or the server.

It is targeted for S2_0 but should be easily adapted for the dev version
(the ftwl part may need changing).

jason

Index: client/gui-ftwl/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/gui_main.c,v
retrieving revision 1.3.2.1
diff -u -r1.3.2.1 gui_main.c
--- client/gui-ftwl/gui_main.c  13 Nov 2004 09:27:22 -0000      1.3.2.1
+++ client/gui-ftwl/gui_main.c  23 Nov 2004 19:07:20 -0000
@@ -178,7 +178,7 @@
   struct ct_size res;
   struct ct_size size;
 
-  init_character_encodings("ISO-8859-1");
+  init_character_encodings("ISO-8859-1", TRUE);
 
   if (!auto_connect) {
     die("Connection dialog not yet implemented. Start client using "
Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.152.2.1
diff -u -r1.152.2.1 gui_main.c
--- client/gui-gtk/gui_main.c   13 Nov 2004 09:27:22 -0000      1.152.2.1
+++ client/gui-gtk/gui_main.c   23 Nov 2004 19:07:20 -0000
@@ -804,7 +804,7 @@
 **************************************************************************/
 void ui_init(void)
 {
-  init_character_encodings(NULL);
+  init_character_encodings(NULL, TRUE);
 }
 
 /**************************************************************************
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.81.2.11
diff -u -r1.81.2.11 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       23 Nov 2004 15:44:34 -0000      
1.81.2.11
+++ client/gui-gtk-2.0/gui_main.c       23 Nov 2004 19:07:20 -0000
@@ -1004,7 +1004,7 @@
 {
   gchar *s;
 
-  init_character_encodings("UTF-8");
+  init_character_encodings("UTF-8", FALSE);
 
   log_set_callback(log_callback_utf8);
 
Index: client/gui-win32/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/gui_main.c,v
retrieving revision 1.30
diff -u -r1.30 gui_main.c
--- client/gui-win32/gui_main.c 22 Sep 2004 08:38:48 -0000      1.30
+++ client/gui-win32/gui_main.c 23 Nov 2004 19:07:20 -0000
@@ -526,7 +526,7 @@
 **************************************************************************/
 void ui_init(void)
 {
-  init_character_encodings(NULL);
+  init_character_encodings(NULL, TRUE);
 }
 
 /**************************************************************************
Index: client/gui-xaw/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v
retrieving revision 1.95.2.1
diff -u -r1.95.2.1 gui_main.c
--- client/gui-xaw/gui_main.c   13 Nov 2004 09:27:23 -0000      1.95.2.1
+++ client/gui-xaw/gui_main.c   23 Nov 2004 19:07:21 -0000
@@ -262,7 +262,7 @@
 **************************************************************************/
 void ui_init(void)
 {
-  init_character_encodings(NULL);
+  init_character_encodings(NULL, TRUE);
 }
 
 /**************************************************************************
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.201.2.4
diff -u -r1.201.2.4 srv_main.c
--- server/srv_main.c   16 Nov 2004 18:14:00 -0000      1.201.2.4
+++ server/srv_main.c   23 Nov 2004 19:07:21 -0000
@@ -202,7 +202,7 @@
   has_been_srv_init = TRUE;
 
   /* init character encodings. */
-  init_character_encodings(FC_DEFAULT_DATA_ENCODING);
+  init_character_encodings(FC_DEFAULT_DATA_ENCODING, FALSE);
 
   /* done */
   return;
Index: utility/fciconv.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/fciconv.c,v
retrieving revision 1.7.2.2
diff -u -r1.7.2.2 fciconv.c
--- utility/fciconv.c   13 Nov 2004 09:16:58 -0000      1.7.2.2
+++ utility/fciconv.c   23 Nov 2004 19:07:21 -0000
@@ -43,6 +43,7 @@
 
 #ifdef HAVE_ICONV
 static const char *local_encoding, *data_encoding, *internal_encoding;
+static const char *transliteration_string;
 #else
 /* Hack to confuse the compiler into working. */
 #  define local_encoding get_local_encoding()
@@ -56,9 +57,16 @@
 
   Pass an internal encoding of NULL to use the local encoding internally.
 ***************************************************************************/
-void init_character_encodings(char *my_internal_encoding)
+void init_character_encodings(char *my_internal_encoding,
+                             bool my_use_transliteration)
 {
 #ifdef HAVE_ICONV
+  if (my_use_transliteration) {
+    transliteration_string = "//TRANSLIT";
+  } else {
+    transliteration_string = "";
+  }
+
   /* Set the data encoding - first check $FREECIV_DATA_ENCODING,
    * then fall back to the default. */
   data_encoding = getenv("FREECIV_DATA_ENCODING");
@@ -119,12 +127,7 @@
 #endif
 
 #else
-   /* freelog may not work at this point. */
-  fprintf(stderr,
-            _("You are running Freeciv without using iconv.  Unless\n"
-              "you are using the latin1 character set, some characters\n"
-              "may not be displayed properly.  You can download iconv\n"
-              "at http://gnu.org/.\n";));
+#  error No iconv present!
 #endif
 
   is_init = TRUE;
@@ -271,16 +274,26 @@
 #define CONV_FUNC_MALLOC(src, dst)                                          \
 char *src ## _to_ ## dst ## _string_malloc(const char *text)                \
 {                                                                           \
+  const char *encoding1 = (dst ## _encoding);                              \
+  char encoding[strlen(encoding1) + strlen(transliteration_string) + 1];    \
+                                                                           \
+  my_snprintf(encoding, sizeof(encoding),                                  \
+             "%s%s", encoding1, transliteration_string);                   \
   return convert_string(text, (src ## _encoding),                          \
-                       (dst ## _encoding), NULL, 0);                       \
+                       (encoding), NULL, 0);                               \
 }
 
 #define CONV_FUNC_BUFFER(src, dst)                                          \
 char *src ## _to_ ## dst ## _string_buffer(const char *text,                \
                                           char *buf, size_t bufsz)         \
 {                                                                           \
+  const char *encoding1 = (dst ## _encoding);                              \
+  char encoding[strlen(encoding1) + strlen(transliteration_string) + 1];    \
+                                                                           \
+  my_snprintf(encoding, sizeof(encoding),                                  \
+             "%s%s", encoding1, transliteration_string);                   \
   return convert_string(text, (src ## _encoding),                          \
-                        (dst ## _encoding), buf, bufsz);                    \
+                        encoding, buf, bufsz);                             \
 }
 
 #define CONV_FUNC_STATIC(src, dst)                                          \
Index: utility/fciconv.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/fciconv.h,v
retrieving revision 1.5.2.1
diff -u -r1.5.2.1 fciconv.h
--- utility/fciconv.h   13 Nov 2004 09:16:58 -0000      1.5.2.1
+++ utility/fciconv.h   23 Nov 2004 19:07:21 -0000
@@ -19,7 +19,8 @@
 
 #define FC_DEFAULT_DATA_ENCODING "UTF-8"
 
-void init_character_encodings(char *internal_encoding);
+void init_character_encodings(char *internal_encoding,
+                             bool use_transliteration);
 
 const char *get_data_encoding(void);
 const char *get_local_encoding(void);

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