Patch for Emacs-21, encode string for menubar.

Set locale correctly before start Emacs.

Original patch (emacs-20.4-fontset-19990915.diff) is coded by Daiki Ueno.

-- 
Akihiro Arisawa <ari@nijino.com>

--- emacs-21.1.orig/src/xmenu.c	Mon Jul 30 17:12:46 2001
+++ emacs-21.1/src/xmenu.c	Fri Nov  9 17:57:16 2001
@@ -64,7 +64,9 @@
 #include "dispextern.h"
 
 #ifdef HAVE_X_WINDOWS
-#undef HAVE_MULTILINGUAL_MENU
+#define HAVE_MULTILINGUAL_MENU 1
+#include "charset.h"
+#include "coding.h"
 #ifdef USE_X_TOOLKIT
 #include "widget.h"
 #include <X11/Xlib.h>
@@ -203,6 +205,24 @@
    needed on Motif, according to Marcus Daniels <marcus@sysc.pdx.edu>.  */
 
 int pending_menu_activation;
+
+static void 
+lisp_string_to_menu_string (obj, data_ret)
+Lisp_Object obj;
+unsigned char **data_ret;
+{
+#ifdef HAVE_MULTILINGUAL_MENU
+  int bytes, stringp;
+  extern Lisp_Object Qcompound_text;
+  *data_ret = x_encode_text (obj,
+			     NILP (Vlocale_coding_system)
+			     ? Qcompound_text : Vlocale_coding_system,
+			     &bytes, &stringp);
+  if (*data_ret != XSTRING (obj)->data) (*data_ret)[bytes] = '\0';
+#else
+  *data_ret = XSTRING (obj)->data;
+#endif
+}
 
 #ifdef USE_X_TOOLKIT
 
@@ -1452,8 +1472,12 @@
 	      AREF (menu_items, i + MENU_ITEMS_PANE_NAME) = pane_name;
 	    }
 #endif
-	  pane_string = (NILP (pane_name)
-			 ? "" : (char *) XSTRING (pane_name)->data);
+
+	  if (NILP (pane_name))
+	    pane_string = "";
+	  else 
+	    lisp_string_to_menu_string (pane_name, &pane_string);
+
 	  /* If there is just one top-level pane, put all its items directly
 	     under the top-level menu.  */
 	  if (menu_items_n_panes == 1)
@@ -1515,8 +1539,7 @@
 	    prev_wv->next = wv;
 	  else
 	    save_wv->contents = wv;
-
-	  wv->name = (char *) XSTRING (item_name)->data;
+	  lisp_string_to_menu_string (item_name, &wv->name);
 	  if (!NILP (descrip))
 	    wv->key = (char *) XSTRING (descrip)->data;
 	  wv->value = 0;
@@ -1748,7 +1771,7 @@
 	  string = XVECTOR (items)->contents[i + 1];
 	  if (NILP (string))
 	    break;
-	  wv->name = (char *) XSTRING (string)->data;
+	  lisp_string_to_menu_string (string, &wv->name);
 	  wv = wv->next;
 	}
 
@@ -1771,7 +1794,7 @@
 	    break;
 
 	  wv = xmalloc_widget_value ();
-	  wv->name = (char *) XSTRING (string)->data;
+	  lisp_string_to_menu_string (string, &wv->name);
 	  wv->value = 0;
 	  wv->enabled = 1;
 	  wv->button_type = BUTTON_TYPE_NONE;
@@ -2043,8 +2066,10 @@
 	      AREF (menu_items, i + MENU_ITEMS_PANE_NAME) = pane_name;
 	    }
 #endif
-	  pane_string = (NILP (pane_name)
-			 ? "" : (char *) XSTRING (pane_name)->data);
+	  if (NILP (pane_name))
+	    pane_string = "";
+	  else 
+	    lisp_string_to_menu_string (pane_name, &pane_string);
 	  /* If there is just one top-level pane, put all its items directly
 	     under the top-level menu.  */
 	  if (menu_items_n_panes == 1)
@@ -2108,7 +2133,7 @@
 	    prev_wv->next = wv;
 	  else 
 	    save_wv->contents = wv;
-	  wv->name = (char *) XSTRING (item_name)->data;
+	  lisp_string_to_menu_string (item_name, &wv->name);
 	  if (!NILP (descrip))
 	    wv->key = (char *) XSTRING (descrip)->data;
 	  wv->value = 0;
@@ -2156,7 +2181,7 @@
 	title = string_make_unibyte (title);
 #endif
       
-      wv_title->name = (char *) XSTRING (title)->data;
+      lisp_string_to_menu_string (title, &wv_title->name);
       wv_title->enabled = True;
       wv_title->button_type = BUTTON_TYPE_NONE;
       wv_title->next = wv_sep1;
