📄 xlocalim.c
字号:
/* * $XConsortium: XLocalIM.c,v 1.11 92/10/22 14:26:20 rws Exp $ *//* * Copyright 1990, 1991 by OMRON Corporation * Copyright 1991 by the Massachusetts Institute of Technology * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the names of OMRON and MIT not be used in * advertising or publicity pertaining to distribution of the software without * specific, written prior permission. OMRON and MIT make no representations * about the suitability of this software for any purpose. It is provided * "as is" without express or implied warranty. * * OMRON AND MIT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL OMRON OR MIT BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. * * Author: Seiji Kuwari OMRON Corporation * kuwa@omron.co.jp * kuwa%omron.co.jp@uunet.uu.net */ #include <stdio.h>#define NEED_EVENTS#include "Xlibint.h"#include "Xi18nint.h"#include "XIMlibint.h"#include <X11/Xos.h>#include <X11/keysymdef.h>#if NeedVarargsPrototypes# include <stdarg.h># define Va_start(a,b) va_start(a,b)#else# include <varargs.h># define Va_start(a,b) va_start(a)#endif#ifndef X_NOT_POSIX#ifdef _POSIX_SOURCE#include <limits.h>#else#define _POSIX_SOURCE#include <limits.h>#undef _POSIX_SOURCE#endif#endif#ifndef PATH_MAX#include <sys/param.h>#ifndef PATH_MAX#ifdef MAXPATHLEN#define PATH_MAX MAXPATHLEN#else#define PATH_MAX 1024#endif#endif#endif#ifdef X_NOT_STDC_ENVextern char *getenv();#endif#if __STDC__ && !defined(NORCONST)#define RConst const#else#define RConst /**/#endif#define offset(field) XOffsetOf(XipLocalIMRec, field)static int compiled_resources;static XIMResource im_resources[] = { { XNQueryInputStyle, sizeof(XIMStyles), offset(values.input_styles), (unsigned short)IMResourceRead, (int)IMQueryInputStyle },#ifdef XML { XNQueryLanguage, sizeof(char *), offset(values.supported_language), (unsigned short)IMResourceRead, (int)IMQueryLanguage }#endif /* XML */};#undef offset#define offset(field) XOffsetOf(XipLocalICRec, field)static XIMResource ic_resources[] = { { XNInputStyle, sizeof(XIMStyle), offset(core.input_style), (unsigned short)IMResourceReadWrite, ICInputStyle }, { XNClientWindow, sizeof(Window), offset(core.client_window), (unsigned short)IMResourceReadWrite, -1 }, { XNFocusWindow, sizeof(Window), offset(core.focus_window), (unsigned short)IMResourceReadWrite, ICFocusWindow }, { XNResourceName, sizeof(char *), offset(values.res_name), (unsigned short)IMResourceReadWrite, -1 }, { XNResourceClass, sizeof(char *), offset(values.res_class), (unsigned short)IMResourceReadWrite, -1 }, { XNFilterEvents, sizeof(long), offset(core.filter_events), (unsigned short)IMResourceRead, ICFilterEvents }, { XNPreeditAttributes, sizeof(ICAttributes *), offset(core.preedit_attr), (unsigned short)IMResourceReadWrite, -1 }, { XNStatusAttributes, sizeof(ICAttributes *), offset(core.status_attr), (unsigned short)IMResourceReadWrite, -1 }#ifdef XML , { XNUsingLanguage, sizeof(char *), offset(values.using_language), (unsigned short)IMResourceReadWrite, ICUsingLanguage }, { XNCurrentLanguage, sizeof(char *), offset(values.current_language), (unsigned short)IMResourceReadWrite, ICCurrentLanguage }, { XNChangeLocaleCB, sizeof(char **), offset(values.ch_locale_cb), (unsigned short)IMResourceReadWrite, ICChangeLocaleCB },#endif /* XML */};#undef offset#define attroffset(field) XOffsetOf(ICAttributes, field)static XIMResource attr_resources[] = { { XNArea, sizeof(XRectangle), attroffset(area), (unsigned short)IMResourceReadWrite, ICArea }, { XNAreaNeeded, sizeof(XRectangle), attroffset(area_needed), (unsigned short)IMResourceReadWrite, ICAreaNeeded }, { XNSpotLocation, (sizeof(XPoint) + 4), attroffset(spot_location), (unsigned short)IMResourceReadWrite, ICSpotLocation }, { XNColormap, sizeof(Colormap), attroffset(colormap), (unsigned short)IMResourceReadWrite, ICColormap }, { XNStdColormap, sizeof(Atom), attroffset(std_colormap), (unsigned short)IMResourceReadWrite, ICStdColormap }, { XNForeground, sizeof(long), attroffset(foreground), (unsigned short)IMResourceReadWrite, ICForeground }, { XNBackground, sizeof(long), attroffset(background), (unsigned short)IMResourceReadWrite, ICBackground }, { XNBackgroundPixmap, sizeof(Pixmap), attroffset(background_pixmap), (unsigned short)IMResourceReadWrite, ICBackgroundPixmap }, { XNFontSet, sizeof(XFontSet *), attroffset(fontset), (unsigned short)IMResourceReadWrite, ICFontSet }, { XNLineSpace, sizeof(int), attroffset(line_space), (unsigned short)IMResourceReadWrite, ICLineSpace }, { XNCursor, sizeof(Cursor), attroffset(cursor), (unsigned short)IMResourceReadWrite, ICCursor }, { XNPreeditStartCallback, sizeof(XIMCallback), attroffset(callbacks.start), (unsigned short)IMResourceReadWrite, -1 }, { XNPreeditDoneCallback, sizeof(XIMCallback), attroffset(callbacks.done), (unsigned short)IMResourceReadWrite, -1 }, { XNPreeditDrawCallback, sizeof(XIMCallback), attroffset(callbacks.draw), (unsigned short)IMResourceReadWrite, -1 }, { XNPreeditCaretCallback, sizeof(XIMCallback), attroffset(callbacks.caret), (unsigned short)IMResourceReadWrite, -1 }, { XNStatusStartCallback, sizeof(XIMCallback), attroffset(callbacks.start), (unsigned short)IMResourceReadWrite, -1 }, { XNStatusDoneCallback, sizeof(XIMCallback), attroffset(callbacks.done), (unsigned short)IMResourceReadWrite, -1 }, { XNStatusDrawCallback, sizeof(XIMCallback), attroffset(callbacks.draw), (unsigned short)IMResourceReadWrite, -1 }};#undef attroffset#define ENTRY_CNT 256#define BITONP(h, i) (h[i / BITSIZ] & (1 << (i % BITSIZ)))#define BITOFP(h, i) (!BITONP(h, i))#define BIT_UP(h, i) (h[i / BITSIZ] |= (1 << (i % BITSIZ)))#define BITDWN(h, i) (h[i / BITSIZ] &= ~(1 << (i % BITSIZ)))#define div_up(a, b) ((a + b - 1) / b)#ifndef XNLSPATHDEFAULT#define XNLSPATHDEFAULT "/usr/lib/X11/nls"#endif#ifndef LOCAL_CVT_TBL_DIR#define LOCAL_CVT_TBL_DIR "/local_im_tbl/"#endiftypedef struct { char *name; unsigned int mask;} StateTbl;static StateTbl state_tbl[] = { { "Lock", LockMask }, { "Control", ControlMask }, { "Mod1", Mod1Mask }, { "Mod2", Mod2Mask }, { "Mod3", Mod3Mask }, { "Mod4", Mod4Mask }, { "Mod5", Mod5Mask }, { NULL, 0 }};typedef struct { char *name; Bool (*func)(); int (*init_func)();} FuncTbl;static int convert_on();static int convert_off();static int convert_on_init();static int no_filter();static FuncTbl func_tbl[] = { { "ConvertOn", convert_on, convert_on_init }, { "ConvertOff", convert_off, NULL }, { "NoFilter", NULL, no_filter }};static unsigned intis_state(name)register char *name;{ register StateTbl *p; for (p = state_tbl; p->name; p++) { if (!strcmp(p->name, name)) return(p->mask); } return(0);}static intparse_bslash(buf, work)register char *buf;register unsigned char *work;{ register int i; switch(*buf) { case 'x': /* 16 */ for (buf++, *work = '\0', i = 1; i >= 0; i--, buf++) { if (*buf >= '0' && *buf <= '9') { *work |= ((1 << (i * 4)) * (*buf - '0')); } else if (*buf >= 'A' && *buf <= 'F') { *work |= ((1 << (i * 4)) * (*buf - 'A' + 10)); } else if (*buf >= 'a' && *buf <= 'f') { *work |= ((1 << (i * 4)) * (*buf - 'a' + 10)); } else { return(0); } } return(3); case 'o': /* 8 */ for (buf++, *work = '\0', i = 2; i >= 0; i--, buf++) { if (*buf >= '0' && *buf <= '7') { *work |= ((1 << (i * 3)) * (*buf - '0')); } else { return(0); } } return(4); case 'n': /* */ *work = '\n'; return(1); case 't': /* */ *work = '\t'; return(1); case 'b': /* */ *work = '\b'; return(1); case 'r': /* */ *work = '\r'; return(1); case 'f': /* */ *work = '\f'; return(1); case 'e': /* */ case 'E': /* */ *work = '\033'; return(1); case '\\': /* */ *work = '\\'; return(1); default: for (*work = '\0', i = 2; i >= 0; i--, buf++) { if (*buf >= '0' && *buf <= '7') { *work |= ((1 << (i * 3)) * (*buf - '0')); } else { return(*buf); } } return(3); }}static XipLocalKeySymTbl *get_string(buf, tbl)register char *buf;XipLocalKeySymTbl *tbl;{ XipLocalKeySymTbl work_tbl[8], *p, *t; unsigned char work[32], *str; register int i = 0, total = 0, ret; for (p = work_tbl, total = 0; *buf; p++, total++, buf++) { if ((buf = index(buf, '{')) == NULL) { break; } buf++; for ( i = 0; *buf != '}';) { if (*buf == (char)0x5c) { buf++; if (!(ret = parse_bslash(buf, &work[i]))) { return(NULL); } buf += ret; i++; } else { work[i++] = *buf; buf++; } if (!*buf) return(NULL); } if (i == 0) return(NULL); work[i] = '\0'; str = (unsigned char *) Xmalloc(i + 1); strcpy((char *)str, (char *)work); p->str = str; p->keysym = NoSymbol; p->state = 0; total++; } if (total < 1) return(NULL); p->str = NULL; p->keysym = XK_VoidSymbol; p->state = 0; if (tbl) { for (i = 0, t = tbl, p = work_tbl; t->keysym != XK_VoidSymbol && i < total; i++, t++, p++) { t->str = p->str; } } else { tbl = (XipLocalKeySymTbl *) Xmalloc((sizeof(XipLocalKeySymTbl) * (total + 1))); if (!tbl) return (NULL); bcopy((char *)work_tbl, (char *)tbl, sizeof(XipLocalKeySymTbl) * (total + 1)); } return(tbl);}static XipLocalKeySymTbl *get_keysym(buf, len)char *buf;int *len;{ int cnt, total = 0; int i; XipLocalKeySymTbl work_tbl[8], *keysym_tbl, *p; char *k[8]; *len = 0; for (cnt = 0; ; cnt++) { if ((buf = index(buf, '<')) == NULL) { break; } k[cnt] = ++buf; if (buf = index(buf, '>')) { *buf = '\0'; buf++; } } if (cnt < 1) return (NULL); for (i = 0, p = work_tbl, total = 0; i < cnt; i++, p++) { if (p->state = is_state(k[i])) { i++; } if ((p->keysym = XStringToKeysym(k[i])) == 0) { fprintf(stderr, "Can't convert to KeySym \"%s\".", k[i]); return (NULL); } p->str = NULL; total++; } p->keysym = XK_VoidSymbol; p->str = NULL; total++; keysym_tbl = (XipLocalKeySymTbl *) Xmalloc((sizeof(XipLocalKeySymTbl) * total)); if (!keysym_tbl) return (NULL); bcopy((char *)work_tbl, (char *)keysym_tbl, sizeof(XipLocalKeySymTbl) * total); *len = (total - 1); return (keysym_tbl);}static intis_comment(c)char c;{ if (c == '#') return (1); return (0);}static intis_command(c)char c;{ if (c != '<' && c != '{') return (1); return (0);}static intis_keysym(c)char c;{ if (c == '<') return (1); return (0);}static intis_state_command(xcvt, f, t)XipLocalCvt *xcvt;char *f, *t;{ if (!*f || !*t) return(0); if (!strcmp(f, "InitialState")) if (!strcmp(t, "OnState")) xcvt->off = False; else if (!strcmp(t, "OffState")) xcvt->off = True; else return(0); return(1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -