static int match_keystroke_wild(gen_inp_conf_t *cf, inpinfo_t *inpinfo, gen_inp_iccf_t *iccf) { icode_t icode[2]; unsigned int md, n_mcch; int idx; char *s1, *s2, *s, tmpch; md = (cf->header.icode_mode == ICODE_MODE2) ? 1 : 0; icode[0] = icode[1] = 0; /* * Search for the first char. */ s1 = strchr(iccf->keystroke, '*'); s2 = strchr(iccf->keystroke, '?'); if (s1 && s2) s = (s1 < s2) ? s1 : s2; else if (s1) s = s1; else s = s2; tmpch = *s; *s = '\0'; oxim_keys2codes(icode, 2, iccf->keystroke); idx = bsearch_char(cf->ic1, cf->ic2, icode[0], icode[1], cf->header.n_icode, md, 1, NULL); *s = tmpch; iccf->mcch_hidx = idx; /* refer to head index of cf->icidx */ /* * Pick up the remaining chars; */ if (pick_cch_wild(cf, iccf, &idx, 1, inpinfo, &n_mcch) == 0) { inpinfo->mcch_pgstate = MCCH_ONEPG; } else { inpinfo->mcch_pgstate = MCCH_BEGIN; } iccf->mcch_eidx = idx; /* refer to end index of cf->icidx */ return (n_mcch) ? 1 : 0; }
int match_keystroke_normal(unsigned char *inpinfo, unsigned int inpinfo_size, wchar_t *outbuff, unsigned int *outsize) { // const gen_inp_conf_t *cf=&mycf; unsigned char inbuf[MAX_KEYSTROKE_LEN]; icode_t icode[4]; unsigned int size, md, n_ich, mcch_size; int idx; unsigned int i; int end_pos;//,start_pos; char tmp; int keylen; int homophone_flag; //mcch=&outbuff; for (i=0;(i<inpinfo_size /*& i<(MAX_KEYSTROKE_LEN-1)*/);i++) { inbuf[i]=inpinfo[i]; } //md = (cf->header.icode_mode == ICODE_MODE2) ? 1 : 0;//md=1 md=0; n_ich = 0; mcch_size =0xa; //inpinfo->n_selkey; //mcch = (wch_t *)malloc(mcch_size * sizeof(wch_t)); for (end_pos=min(MAX_USER_KEYSTROKE_LEN,inpinfo_size); end_pos>=0; end_pos=-1/*end_pos--*/) { keylen = end_pos; if (keylen > MAX_KEYSTROKE_LEN) continue; /*not for sys char and phr, jimc*/ icode[0] = icode[1] = icode[2] = icode[3] = 0; /* the following's indents are wrong, I just leave it, jimc */ tmp = inbuf[end_pos]; inbuf[end_pos] = '\0'; keys2codes(icode, 2, ((char *)(&inbuf[0])) ); //size = cf->header.n_icode; // size = 0x1df0; size = PINYIN_SIZE; //chang by zhanglei if ((idx = bsearch_char(icode[0], icode[1], size, &homophone_flag)) != -1) { // d_printf("icode1= %x,%x,%x %d mode=%d\r\n",icode[0],icode[1],icode[2],idx,md); do { Readicidx_2(mcch[n_ich].s, idx); n_ich ++; idx ++; } while (idx < HANZI_SIZE && idx < homophone_flag); // d_printf("iiiiixxxxx %d , %x, %d\r\n",n_ich,mcch[n_ich].wch,mcch_size); } inbuf[end_pos] = tmp; } /* * Prepare mcch for display. */ for (i=0;i<n_ich;i++) { outbuff[i]=mcch[i].wch; } *outsize=n_ich; return 1; }
static int match_keystroke_normal(gen_inp_conf_t *cf, inpinfo_t *inpinfo, gen_inp_iccf_t *iccf) { icode_t icode[2]; unsigned int size, md, n_ich=0, n_igrp=0, mcch_size; int idx, end_idx; uch_t *mcch = NULL; word_group_t *mcch_grouping = NULL; size = cf->header.n_icode; md = (cf->header.icode_mode == ICODE_MODE2) ? 1 : 0; icode[0] = icode[1] = 0; /* * Search for the first char. */ oxim_keys2codes(icode, 2, iccf->keystroke); if ((idx = bsearch_char(cf->ic1, cf->ic2, icode[0], icode[1], size, md, 0, &end_idx)) == -1) return 0; /* * Search for all the chars with the same keystroke. */ mcch_size = end_idx - idx + 1; /* 總共幾筆紀錄 */ /* 預先配置記憶體 */ mcch = oxim_malloc(mcch_size*sizeof(uch_t), False); mcch_grouping = oxim_malloc(mcch_size*sizeof(word_group_t), False); while(idx <= end_idx) { mcch_grouping[n_igrp].n_idx = n_ich; if (cf->ichar[idx] & WORD_MASK) { unsigned int ret_len; char *ret_word = get_word(cf, cf->ichar[idx], &ret_len); if (ret_word) { unsigned int ucs4; int nbytes; char *p = ret_word; unsigned int utf8_len = 0; while (ret_len && (nbytes = oxim_utf8_to_ucs4(p, &ucs4, ret_len)) > 0) { utf8_len ++; if (utf8_len > 1) { mcch_size ++; mcch = oxim_realloc(mcch, mcch_size*sizeof(uch_t)); } mcch[n_ich].uch = 0; memcpy((char *)mcch[n_ich].s, p, nbytes); n_ich ++; p += nbytes; ret_len -= nbytes; } mcch_grouping[n_igrp].n_word = utf8_len; n_igrp ++; free(ret_word); } } else if (ccode_to_char(cf->ichar[idx], (char *)mcch[n_ich].s)) { mcch_grouping[n_igrp].n_word = 1; n_ich ++; n_igrp ++; } idx ++; } if (iccf->n_mcch_list) { free(iccf->mcch_list); free(iccf->mcch_list_grouping); } iccf->mcch_list = mcch; iccf->mcch_list_grouping = mcch_grouping; iccf->n_mcch_list = n_igrp; iccf->mcch_hidx = 0; /* refer to index of iccf->mcch_list */ fillpage(cf, inpinfo, iccf, 0); return 1; }