Re: [gnome-mud] A patch about international



Falls Huang wrote:
> Hello!

Hi!

> I'm a mud player from China. The mud of China is encoded in charset of
> "GBK" , and the gnome-mud couldn't execute the trigger checking in my
> debian-box.
> 
> I viewed the source of gnome-mud and found a bug. The attach is my
> patch, I hope it will be useful to anyone need it .

The last time I saw the patch was that it looked pretty scary, but now I
realize the patch is reversed. I'll attach a diff-file that is "correct"
and it looks a lot better.



regards,
	Robin
Index: data.c
===================================================================
RCS file: /cvs/gnome/gnome-mud/src/data.c,v
retrieving revision 1.20
diff -u -r1.20 data.c
--- data.c	12 Dec 2003 19:44:31 -0000	1.20
+++ data.c	16 Feb 2005 14:06:38 -0000
@@ -114,16 +114,40 @@
 gchar *check_actions (GList *list, gchar *incoming)
 {
  	GList *entry;
-	gchar *str;
+	gchar *str ;
+	static gboolean c_a_flag = FALSE;
+	static gchar *mud_charset;
+	gboolean need_convert = FALSE;
+			
+	if ( FALSE == c_a_flag ) {
+		c_a_flag = TRUE;
+		if ( FALSE == g_get_charset(&mud_charset) )
+			fprintf(stdout, "mud charset:%s\n",mud_charset);
+		else 
+			fprintf(stdout, "mud charset is utf8(%s)\n",mud_charset);
+	} 
+
+	if ( 0 != strcasecmp("UTF-8",mud_charset) )
+		need_convert = TRUE;
 
 	for (entry = g_list_first(list); entry != NULL; entry = g_list_next(entry))
 	{
 		str = ((gchar **) entry->data)[0];
+		if ( need_convert )
+		{
+			str = g_convert( str, strlen(str) , mud_charset , "UTF-8" , 0 , 0 , 0);
+			if ( NULL == str )
+				return NULL;
+		} 
 
 		if (match_line(str, incoming))
 		{
+			if ( need_convert )
+				g_free(str);	
 			return ((gchar **) entry->data)[1];
 		}
+		if ( need_convert )
+			g_free(str);
 	}
  
 	return NULL;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]