📄 xlocalim.c
字号:
static FuncTbl *get_command(name)char *name;{ register FuncTbl *p; for (p = func_tbl; p->name; p++) { if (!strcmp(p->name, name)) { return(p); } } fprintf(stderr, "Sorry, \"%s\" is not a supported command.\n", name); fprintf(stderr, "XIM supported commands are \n"); for (p = func_tbl; p->name; p++) { fprintf(stderr, " %s \n", p->name); } return(NULL);}static Boolconvert_on(xcvt)XipLocalCvt *xcvt;{ xcvt->off = False; return(1);}static Boolconvert_off(xcvt)XipLocalCvt *xcvt;{ xcvt->off = True; return(True);}static intconvert_on_init(xcvt, tbl, len)XipLocalCvt *xcvt;XipLocalCvtTbl *tbl;int len;{ register XipLocalKeySymTbl *to, *from, *p; p = (XipLocalKeySymTbl *) Xmalloc(sizeof(XipLocalKeySymTbl) * (len + 1)); if (!p) return(-1); for (to = p, from = tbl->fromkey; len > 0; to++, from++, len--) { to->keysym = from->keysym; to->state = from->state; } to->keysym = XK_VoidSymbol; to->state = 0; xcvt->off_tbl.to.func = tbl->to.func; xcvt->off_tbl.com = True; xcvt->off_tbl.fromkey = p; return(0);}static intno_filter(xcvt, tbl, len)XipLocalCvt *xcvt;XipLocalCvtTbl *tbl;int len;{ XipLocalNestedKeySym *nested_keysym; nested_keysym = (XipLocalNestedKeySym *) Xmalloc(sizeof(XipLocalNestedKeySym)); if (!nested_keysym) return(-1); nested_keysym->keysym = tbl->fromkey->keysym; nested_keysym->next = xcvt->no_filter; xcvt->no_filter = nested_keysym; return(1);}static Boolis_nofilter(xcvt, keysym)XipLocalCvt *xcvt;KeySym keysym;{ XipLocalNestedKeySym *p; for (p = xcvt->no_filter; p; p = p->next) { if (p->keysym == keysym) return(True); } return(False);}static FILE *open_convert_file(lang, filename)char *lang;char *filename;{ FILE *fp; char nlspath[PATH_MAX]; char *path; char *dir; char *env; if ((env = getenv("XNLSPATH")) == NULL) { env = XNLSPATHDEFAULT; } path = nlspath; strcpy(path, env); while (1) { if (path == NULL) { fprintf(stderr, "%s \"%s\".\n%s%s%s.\n", "XIM: Couldn't find any convert table for lang", lang, "Please, create xnls_dir", LOCAL_CVT_TBL_DIR, lang); return(NULL); } dir = path; if ((dir = index(dir, ':')) != NULL) { *dir++ = '\0'; } strcpy(filename, path); strcat(filename, LOCAL_CVT_TBL_DIR); strcat(filename, lang); if (fp = fopen(filename, "r")) { return(fp); } path = dir; }}static XipLocalCvt *_XipLocalCvtSetUp(xlc)XLocale xlc;{ char filename[PATH_MAX]; char tmp_buf[32], *p; FILE *fp; char buf[256], tobuf[256], frombuf[256], tostr[256]; int cnt = 0; int len; int k; XipLocalCvt *cvt; KeySym bs; FuncTbl *func_tbl; int line = 0; int ret; strcpy(tmp_buf, xlc->xlc_db->lc_name); for (p = tmp_buf; *p && *p != '@'; p++); if (*p) *p = '\0'; if(CHANGE_MAX < div_up(ENTRY_CNT, BITSIZ)){ fprintf(stderr, "XIM: %s%s%d%s", "Sorry, please set CHANGE_MAX(in file ", "Xi18nint.h) larger than ", div_up(ENTRY_CNT, BITSIZ) - 1, ",\r\nand recompile.\r\n"); return(NULL); } if(!(fp = open_convert_file(tmp_buf, filename))) return(NULL); if (!(cvt = (XipLocalCvt *) Xmalloc(sizeof(XipLocalCvt)))) { fprintf(stderr, "XIM: Malloc failed\n"); goto _err_ret2; } if (!(cvt->tbl = (XipLocalCvtTbl *) Xmalloc(sizeof(XipLocalCvtTbl) * ENTRY_CNT))) { fprintf(stderr, "XIM: Malloc failed\n"); goto _err_ret1; } cnt = 0; cvt->nmax = 0; cvt->no_filter = NULL; cvt->off = False; while(fgets(buf, BUFSIZ, fp)) { line++; if(is_comment(*buf) || (k = sscanf(buf, "%s %s %s", frombuf, tobuf, tostr)) <= 0) continue; if (k < 2) { goto _err_ret; } if(!(cvt->tbl[cnt].fromkey = get_keysym(frombuf, &len))){ if (!is_state_command(cvt, frombuf, tobuf)) goto _err_ret; continue; } if (len > cvt->nmax) cvt->nmax = len; if (is_command(*tobuf)) { if(!(func_tbl = get_command(tobuf))) { goto _err_ret; } cvt->tbl[cnt].to.func = func_tbl->func; cvt->tbl[cnt].com = True; if (func_tbl->init_func) { if ((ret = (*func_tbl->init_func)(cvt, &cvt->tbl[cnt], len)) == -1) goto _err_ret; else if (ret == 0) continue; } } else { if (is_keysym(*tobuf)) { if(!(cvt->tbl[cnt].to.tokey = get_keysym(tobuf, &len))){ goto _err_ret; } if (k > 2) { if(!(get_string(tostr, cvt->tbl[cnt].to.tokey))){ goto _err_ret; } } } else { if(!(cvt->tbl[cnt].to.tokey = get_string(tobuf, NULL))){ goto _err_ret; } } cvt->tbl[cnt].com = False; } cnt++; } cvt->cnt = cnt; cvt->buf = (XipLocalKeySymTbl *) Xmalloc(sizeof(XipLocalKeySymTbl) * (cvt->nmax + 1)); cvt->buf_cnt = 0; cvt->bs = ((bs = XStringToKeysym("BackSpace"))? bs: 0x8); fclose(fp); return(cvt);_err_ret: fprintf(stderr, "XIM: Error occurred at line %d in file \"%s\".\n", line, filename); Xfree(cvt->tbl);_err_ret1: Xfree(cvt);_err_ret2: fclose(fp); return(NULL);}static XipLocalCvt *_XipLocalDupCvt(cvt)XipLocalCvt *cvt;{ XipLocalCvt *new; if (!(new = (XipLocalCvt *) Xmalloc(sizeof(XipLocalCvt)))) { return(NULL); } new->tbl = cvt->tbl; new->off_tbl = cvt->off_tbl; new->no_filter = cvt->no_filter; new->bs = cvt->bs; new->cnt = cvt->cnt; new->nmax = cvt->nmax; new->buf = (XipLocalKeySymTbl *) Xmalloc(sizeof(XipLocalKeySymTbl) * (new->nmax + 1)); new->buf_cnt = 0; new->off = cvt->off; return(new);}static void_XipLocalFreeCvt(cvt)XipLocalCvt *cvt;{ register int i, j; XipLocalCvtTbl *tbl; tbl = cvt->tbl; for (i = 0; i < cvt->cnt; i++, tbl++) { Xfree((*tbl).fromkey); if ((*tbl).com != True) { for (j = 0; (*tbl).to.tokey[j].str; j++) Xfree((*tbl).to.tokey[j].str); Xfree((*tbl).to.tokey); } } Xfree(cvt->tbl); Xfree(cvt);}/* * Close the connection to the input manager, and free the private data */static Status_XipLocalCloseIM(supim) XIM supim;{ XipLocalIM im = (XipLocalIM)supim; _XlcFreeLocale(im->xlc); if (im->xcvt) _XipLocalFreeCvt(im->xcvt); return(Success);}static RConst XIMMethodsRec im_methods = { _XipLocalCloseIM, _XipLocalGetIMValues, _XipLocalCreateIC};XIM _XipLocalOpenIM(lcd, display, rdb, res_name, res_class) XLCd lcd; Display *display; XrmDatabase rdb; char *res_name; char *res_class;{ XipLocalIM xim; XLocale xlc = ((XsiLCd)lcd)->xlc; XipLocalCvt *xcvt; XIMStyle *supported_styles; if ((xcvt = _XipLocalCvtSetUp(xlc)) == NULL) return(NULL); /* * Attempt to allocate a XIM structure. Return NULL if allocation * failed. */ if ((xim = (XipLocalIM)Xmalloc(sizeof(XipLocalIMRec))) == NULL) { return(NULL); } xim->methods = (XIMMethods)&im_methods; xim->core.lcd = lcd; xim->core.ic_chain = NULL; xim->core.display = display; xim->core.rdb = rdb; xim->core.res_name = res_name; xim->core.res_class = res_class; if (!compiled_resources) { _XIMCompileResourceList(im_resources, XIMNumber(im_resources)); _XIMCompileResourceList(ic_resources, XIMNumber(ic_resources)); _XIMCompileResourceList(attr_resources, XIMNumber(attr_resources)); compiled_resources = 1; } xim->resources = (XIMrmResourceList)im_resources; xim->num_resources = XIMNumber(im_resources); xim->core.ic_resources = (XIMrmResourceList)ic_resources; xim->core.ic_num_resources = XIMNumber(ic_resources); xim->core.ic_attr_resources = (XIMrmResourceList)attr_resources; xim->core.ic_num_attr_resources = XIMNumber(attr_resources); if ((supported_styles = (XIMStyle *)Xmalloc((unsigned)(sizeof(XIMStyle)))) == NULL) { return(NULL); } supported_styles[0] = (XIMPreeditNothing | XIMStatusNothing); xim->values.input_styles.supported_styles = supported_styles; xim->values.input_styles.count_styles = 1; xim->xlc = _XlcDupLocale(xlc); xim->xcvt = xcvt; return((XIM)xim);}int_XipLocalCallCallbacks(ic) XipIC ic;{ return(0);}static intkey_check(cvt)XipLocalCvt *cvt;{ int dist, base; XipLocalKeySymTbl *code_p; int i; for(base = 0; cvt->buf[base].keysym != XK_VoidSymbol; base++) { for(dist = 0; dist < cvt->cnt; dist++) { if(BITONP(cvt->check_flg, dist) && cvt->tbl[dist].fromkey->keysym != XK_VoidSymbol){ code_p = cvt->tbl[dist].fromkey + base; if((code_p->keysym == cvt->buf[base].keysym) && ((!(code_p->state | (cvt->buf[base].state & ~ShiftMask))) || (code_p->state == (cvt->buf[base].state & ~ShiftMask)))) { if((code_p + 1)->keysym == (KeySym)XK_VoidSymbol){ /* matched */ for(i = 0, base++; (cvt->buf[i].keysym = cvt->buf[base].keysym) != XK_VoidSymbol; i++, base++); return(dist); } /* Not yet matched */ } else { BITDWN(cvt->check_flg, dist); /* off bit vecter */ } } } } /* Check bit vercters */ for(i = 0; i < cvt->cnt / BITSIZ; i++){ if(cvt->check_flg[i]) return(-1); } if((cvt->cnt % BITSIZ) && (cvt->check_flg[i]& ~(~0 << (cvt->cnt % BITSIZ)))) return(-1); /* posiblity */ return(-2); /* Not matched */}static intoff_key_check(cvt)XipLocalCvt *cvt;{ int base; XipLocalKeySymTbl *code_p = cvt->off_tbl.fromkey; int i; for(base = 0; cvt->buf[base].keysym != XK_VoidSymbol; base++) { if((code_p->keysym == cvt->buf[base].keysym) && ((!(code_p->state | (cvt->buf[base].state & ~ShiftMask))) || (code_p->state == (cvt->buf[base].state & ~ShiftMask)))) { if((code_p + 1)->keysym == (KeySym)XK_VoidSymbol){ /* matched */ for(i = 0, base++; (cvt->buf[i].keysym = cvt->buf[base].keysym) != XK_VoidSymbol; i++, base++); return(0); } } else { return(-2); } } return(-1); /* posiblity */}static void_XipLocalClearCvt(cvt)XipLocalCvt *cvt;{ register int i; for(i = 0; i < div_up(cvt->cnt, BITSIZ); cvt->check_flg[i++] = ~0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -