strcpy(buf, "@im="); if (end - (s + (sizeof(buf) - 5)) > 0) end = s + (sizeof(buf) - 5); strncat(buf, s, end - s);
if (end != s) { strcpy(t, "@im="); strncat(t, s, end - s);
static void VTInitI18N(){    int		i;    char       *p,	       *s,	       *ns,	       *end,	  	buf[32];    XIM		xim = (XIM) NULL;    XIMStyles  *xim_styles;    XIMStyle	input_style = 0;    Boolean	found;    term->screen.xic = NULL;    if (!term->misc.open_im) return;    if (!term->misc.input_method || !*term->misc.input_method) {	if ((p = XSetLocaleModifiers("@im=none")) != NULL && *p)	    xim = XOpenIM(XtDisplay(term), NULL, NULL, NULL);    } else {	for(ns=s=term->misc.input_method; ns && *s;) {	    while (*s && isspace(*s)) s++;	    if (!*s) break;	    if ((ns = end = strchr(s, ',')) == 0)		end = s + strlen(s);	    while (isspace(*end)) end--;	    strcpy(buf, "@im=");	    if (end - (s + (sizeof(buf) - 5)) > 0)		end = s + (sizeof(buf) - 5);	    strncat(buf, s, end - s);	    if ((p = XSetLocaleModifiers(buf)) != NULL && *p		&& (xim = XOpenIM(XtDisplay(term), NULL, NULL, NULL)) != NULL)		break;	    s = ns + 1;	}    }    if (xim == NULL && (p = XSetLocaleModifiers("@im=none")) != NULL && *p)	xim = XOpenIM(XtDisplay(term), NULL, NULL, NULL);    if (!xim) {	fprintf(stderr, "Failed to open input method\n");	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;    for(s = term->misc.preedit_type; s && !found;) {	while (*s && isspace(*s)) s++;	if (!*s) break;	if ((ns = end = strchr(s, ',')) != 0)	    ns++;	else	    end = s + strlen(s);	while (isspace(*end)) end--;	if (!strncmp(s, "OverTheSpot", end - s)) {	    input_style = (XIMPreeditPosition | XIMStatusArea);	} else if (!strncmp(s, "OffTheSpot", end - s)) {	    input_style = (XIMPreeditArea | XIMStatusArea);	} else if (!strncmp(s, "Root", end - s)) {	    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;}