*** Imakefile.orig	Sun Jul 10 16:22:53 1994
--- Imakefile	Sun Jul 10 16:25:00 1994
***************
*** 1,4 ****
--- 1,5 ----
  XCOMM $XConsortium: Imakefile,v 1.62 94/04/10 16:02:56 rws Exp $
+ XCOMM With I18N support by MaF
  XCOMM
  XCOMM                         Attention xterm porters
  XCOMM
***************
*** 23,28 ****
--- 24,30 ----
   OSMAJORVERSION = OSMajorVersion
   OSMINORVERSION = OSMinorVersion
  
+ 	DEFINES = -DI18N
     MAIN_DEFINES = -DUTMP $(TTYGROUPDEF) $(PUCCPTYDDEF) \
  		  -DOSMAJORVERSION=$(OSMAJORVERSION) \
  		  -DOSMINORVERSION=$(OSMINORVERSION)
*** charproc.c.orig	Sun Jul 10 16:22:55 1994
--- charproc.c	Sun Jul 10 16:25:16 1994
***************
*** 1,5 ****
--- 1,6 ----
  /*
   * $XConsortium: charproc.c,v 1.180 94/04/17 20:23:25 hersh Exp $
+  * With I18N support by MaF
   */
  
  /*
***************
*** 67,72 ****
--- 68,76 ----
  #include <X11/Xmu/Atoms.h>
  #include <X11/Xmu/CharSet.h>
  #include <X11/Xmu/Converters.h>
+ #ifdef I18N
+ #include <X11/Xaw/XawImP.h>
+ #endif
  #include <stdio.h>
  #include <errno.h>
  #include <setjmp.h>
***************
*** 514,519 ****
--- 518,534 ----
  {"font6", "Font6", XtRString, sizeof(String),
  	XtOffsetOf(XtermWidgetRec, screen.menu_font_names[fontMenu_font6]),
  	XtRString, (XtPointer) NULL},
+ #ifdef I18N
+   {XtNinputMethod, XtCInputMethod, XtRString, sizeof(char*),
+                 XtOffsetOf(XtermWidgetRec, misc.input_method),
+                 XtRString, (XtPointer)NULL},
+   {XtNpreeditType, XtCPreeditType, XtRString, sizeof(char*),
+                 XtOffsetOf(XtermWidgetRec, misc.preedit_type),
+                 XtRString, (XtPointer)"Root"},
+   {XtNopenIm, XtCOpenIm, XtRBoolean, sizeof(Boolean),
+                 XtOffsetOf(XtermWidgetRec, misc.open_im),
+                 XtRImmediate, (XtPointer)TRUE},
+ #endif
  };
  
  static void VTClassInit();
***************
*** 523,528 ****
--- 538,546 ----
  static void VTResize();
  static void VTDestroy();
  static Boolean VTSetValues();
+ #ifdef I18N
+ static void VTInitI18N();
+ #endif
  
  static WidgetClassRec xtermClassRec = {
    {
***************
*** 2466,2471 ****
--- 2484,2493 ----
  		InputOutput, CopyFromParent,	
  		*valuemask|CWBitGravity, values);
  
+ #ifdef I18N
+ 	VTInitI18N();
+ #endif
+ 
  	set_cursor_gcs (screen);
  
  	/* Reset variables used by ANSI emulation. */
***************
*** 2508,2513 ****
--- 2530,2658 ----
  	CursorSave (term, &screen->sc);
  	return;
  }
+ 
+ #ifdef I18N
+ 
+ static void VTInitI18N()
+ {
+     int		i,
+ 		ic_cnt = 0;
+     char       *p,
+ 	       *s,
+ 	       *ns,
+ 	       *end,
+ 		tmp[1024],
+ 	  	buf[32];
+     XIM		xim;
+     XIMStyles  *xim_styles;
+     XIMStyle	input_style;
+     Boolean	found;
+ 
+     term->screen.xic = NULL;
+ 
+     if (!term->misc.open_im) return;
+ 
+     if (term->misc.input_method) {
+ 	strcpy(tmp, term->misc.input_method);
+ 	for(s=tmp; *s;) {
+ 	    while (*s && isspace(*s)) s++;
+ 	    if (!*s) break;
+ 	    if (!(ns = end = index(s, ',')))
+ 		end = s + strlen(s);
+ 	    while (isspace(*end)) end--;
+ 	    *end = '\0';
+ 
+ 	    strcpy(buf, "@im=");
+ 	    strcat(buf, s);
+ 	    if ((p = XSetLocaleModifiers(buf)) != NULL && *p
+ 		&& (xim = XOpenIM(XtDisplay(term), NULL, NULL, NULL)) != NULL)
+ 		break;
+ 
+ 	    s = ns + 1;
+ 	}
+     } else {
+ 	if ((p = XSetLocaleModifiers("@im=none")) != NULL && *p)
+ 	    xim = XOpenIM(XtDisplay(term), NULL, NULL, NULL);
+     }
+ 
+     if (xim == NULL && (p = XSetLocaleModifiers("")) != NULL && *p)
+ 	xim = XOpenIM(XtDisplay(term), NULL, NULL, NULL);
+     
+     if (!xim) {
+ 	fprintf(stderr, "Failed to open input method");
+ 	return;
+     }
+ 
+     if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL)
+         || !xim_styles) {
+ 	fprintf(stderr, "input method doesn't support any style\n");
+         XCloseIM(xim);
+         return;
+     }
+ 
+     found = False;
+     strcpy(tmp, term->misc.preedit_type);
+     for(s = tmp; s && !found;) {
+ 	while (*s && isspace(*s)) s++;
+ 	if (!*s) break;
+ 	if (ns = end = index(s, ','))
+ 	    ns++;
+ 	else
+ 	    end = s + strlen(s);
+ 	while (isspace(*end)) end--;
+ 	*end = '\0';
+ 
+ 	if (!strcmp(s, "OverTheSpot")) {
+ 	    input_style = (XIMPreeditPosition | XIMStatusArea);
+ 	} else if (!strcmp(s, "OffTheSpot")) {
+ 	    input_style = (XIMPreeditArea | XIMStatusArea);
+ 	} else if (!strcmp(s, "Root")) {
+ 	    input_style = (XIMPreeditNothing | XIMStatusNothing);
+ 	}
+ 	for (i = 0; (unsigned short)i < xim_styles->count_styles; i++)
+ 	    if (input_style == xim_styles->supported_styles[i]) {
+ 		found = True;
+ 		break;
+ 	    }
+ 
+ 	s = ns;
+     }
+     XFree(xim_styles);
+ 
+     if (!found) {
+ 	fprintf(stderr, "input method doesn't support my preedit type\n");
+ 	XCloseIM(xim);
+ 	return;
+     }
+ 
+     /*
+      * This program only understands the Root preedit_style yet
+      * Then misc.preedit_type should default to:
+      *		"OverTheSpot,OffTheSpot,Root"
+      *
+      *	/MaF
+      */
+     if (input_style != (XIMPreeditNothing | XIMStatusNothing)) {
+ 	fprintf(stderr,"This program only supports the 'Root' preedit type\n");
+ 	XCloseIM(xim);
+ 	return;
+     }
+ 
+     term->screen.xic = XCreateIC(xim, XNInputStyle, input_style,
+ 				      XNClientWindow, term->core.window,
+ 				      XNFocusWindow, term->core.window,
+ 				      NULL);
+ 
+     if (!term->screen.xic) {
+ 	fprintf(stderr,"Failed to create input context\n");
+ 	XCloseIM(xim);
+     }
+ 
+     return;
+ }
+ 
+ #endif
+ 
  
  static Boolean VTSetValues (cur, request, new, args, num_args)
      Widget cur, request, new;
*** input.c.orig	Sun Jul 10 16:22:55 1994
--- input.c	Sun Jul 10 16:25:20 1994
***************
*** 1,5 ****
--- 1,6 ----
  /*
   *	$XConsortium: input.c,v 1.18 94/05/14 15:53:34 gildea Exp $
+  * With I18N support by MaF
   */
  
  /*
***************
*** 70,76 ****
--- 71,81 ----
      Bool eightbit;
  {
  
+ #ifdef I18N
+ #define STRBUFSIZE 500
+ #else
  #define STRBUFSIZE 100
+ #endif
  
  	char strbuf[STRBUFSIZE];
  	register char *string;
***************
*** 77,87 ****
  	register int key = FALSE;
  	int	pty	= screen->respond;
  	int	nbytes;
! 	KeySym  keysym;
  	ANSI	reply;
  
  	nbytes = XLookupString (event, strbuf, STRBUFSIZE,
  				&keysym, &compose_status);
  
  	string = &strbuf[0];
  	reply.a_pintro = 0;
--- 82,104 ----
  	register int key = FALSE;
  	int	pty	= screen->respond;
  	int	nbytes;
! 	KeySym  keysym = 0;
  	ANSI	reply;
+ #ifdef I18N
+ 	Status	status_return;
+ #endif
  
+ #ifdef I18N
+ 	if (screen->xic)
+ 	    nbytes = XmbLookupString (screen->xic, event, strbuf, STRBUFSIZE,
+ 				      &keysym, &status_return);
+ 	else
+ 	    nbytes = XLookupString (event, strbuf, STRBUFSIZE,
+ 				    &keysym, &compose_status);
+ #else
  	nbytes = XLookupString (event, strbuf, STRBUFSIZE,
  				&keysym, &compose_status);
+ #endif
  
  	string = &strbuf[0];
  	reply.a_pintro = 0;
*** main.c.orig	Sun Jul 10 16:22:56 1994
--- main.c	Sun Jul 10 16:25:31 1994
***************
*** 1,5 ****
--- 1,6 ----
  #ifndef lint
  static char *rid="$XConsortium: main.c,v 1.222 94/04/17 20:23:28 gildea Exp $";
+ /* With I18N support by MaF */
  #endif /* lint */
  
  /*
***************
*** 73,78 ****
--- 74,82 ----
  #include "menu.h"
  #include <X11/StringDefs.h>
  #include <X11/Shell.h>
+ #ifdef I18N
+ #include <X11/Xlocale.h>
+ #endif
  
  #include <X11/Xos.h>
  #include <X11/cursorfont.h>
***************
*** 832,837 ****
--- 836,845 ----
  	int Xsocket, mode;
  	char *base_name();
  	int xerror(), xioerror();
+ 
+ #ifdef I18N
+ 	setlocale(LC_ALL, NULL);
+ #endif
  
  	ProgramName = argv[0];
  
*** misc.c.orig	Sun Jul 10 16:22:56 1994
--- misc.c	Sun Jul 10 16:25:38 1994
***************
*** 1,5 ****
--- 1,6 ----
  /*
   *	$XConsortium: misc.c,v 1.102 94/03/28 18:27:08 gildea Exp $
+  *	With I18N support by MaF
   */
  
  /*
***************
*** 273,278 ****
--- 274,283 ----
  			TCursorToggle(TOGGLE);
  		return;
  	} else {
+ #ifdef I18N
+ 		if (screen->xic)
+ 		    XSetICFocus(screen->xic);
+ #endif
  		if(screen->cursor_state &&
  		   (screen->cursor_col != screen->cur_col ||
  		    screen->cursor_row != screen->cur_row))
***************
*** 295,300 ****
--- 300,309 ----
  	screen->select &= ~flag;
  	if(!Ttoggled) TCursorToggle(TOGGLE);
      } else {
+ #ifdef I18N
+ 		if (screen->xic)
+ 		    XUnsetICFocus(screen->xic);
+ #endif
  	screen->select &= ~flag;
  	if(screen->cursor_state &&
  	   (screen->cursor_col != screen->cur_col ||
*** ptyx.h.orig	Sun Jul 10 16:22:56 1994
--- ptyx.h	Sun Jul 10 16:25:41 1994
***************
*** 1,5 ****
--- 1,6 ----
  /*
   *	$XConsortium: ptyx.h,v 1.62 93/02/25 17:21:26 gildea Exp $
+  *	With I18N support by MaF
   */
  
  /*
***************
*** 356,361 ****
--- 357,365 ----
  	Widget		mainMenu, vtMenu, tekMenu, fontMenu;
  	char*		menu_font_names[NMENUFONTS];
  	int		menu_font_number;
+ #ifdef I18N
+ 	XIC		xic;
+ #endif
  } TScreen;
  
  typedef struct _TekPart {
***************
*** 399,404 ****
--- 403,414 ----
      Boolean tekSmall;	/* start tek window in small size */
      Boolean appcursorDefault;
      Boolean appkeypadDefault;
+ #ifdef I18N
+     char *input_method;
+     char *preedit_type;
+     Boolean open_im;
+     Boolean shared_ic;
+ #endif
  } Misc;
  
  typedef struct {int foo;} XtermClassPart, TekClassPart;

