Exemple #1
0
int ch_to_gtab_keys(INMD *tinmd, char *ch, u_int64_t keys[])
{
  int n = utf8_str_N(ch);
  gboolean phrase = n > 1 || !(ch[0] & 0x80);
  int i, keysN=0;
  for(i=0; i < tinmd->DefChars; i++) {
    char *chi = (char *)tblch2(tinmd, i);

    if (phrase) {
      if ((chi[0] & 0x80))
        continue;
      char tstr[512];
      load_phr_ch(tinmd, (u_char *)chi, tstr);
      if (strcmp(tstr, ch))
        continue;
    } else {
      if (!(chi[0] & 0x80))
        continue;
      if (!utf8_eq(chi, ch))
        continue;
    }

    u_int64_t key = CONVT2(tinmd, i);
    keys[keysN++] = key;
  }
  return keysN;
}
Exemple #2
0
int lookup_gtab_key(char *ch, void *out)
{
    int outN=0;
    INMD *tinmd = &inmd[default_input_method];

    int i;
    for(i=0; i < tinmd->DefChars; i++) {
        char *chi = (char *)tblch2(tinmd, i);

        if (!(chi[0] & 0x80))
            continue;
        if (!utf8_eq(chi, ch))
            continue;

        u_int64_t key = CONVT2(tinmd, i);
        if (ph_key_sz==4) {
            u_int32_t key32 = (u_int32_t)key;
            memcpy(get_ph_key_ptr(out, outN), &key32, ph_key_sz);
        } else
            memcpy(get_ph_key_ptr(out, outN), &key, ph_key_sz);
        outN++;
    }

    return outN;
}
Exemple #3
0
int pho_lookup(char *s, char *num, char *typ)
{
  int i;
  char tt[CH_SZ+1], *pp;
  int len = utf8_sz(s);

  if (utf8_eq(s, "1")) {
    *num = 0;
    *typ = 3;
    return TRUE;
  }

  if (!(*s&0x80))
    return *s-'0';

  bchcpy(tt, s);
  tt[len]=0;

  for(i=0;i<4;i++) {
    if ((pp=strstr(pho_chars[i], tt)))
      break;
  }

  if (!pp)
    return FALSE;

  *typ=i;
  *num=(pp - pho_chars[i])/3;

  return TRUE;
}
int utf8_pho_keys(char *utf8, phokey_t *phkeys)
{
  int i;
  int ofs=0;
  int phkeysN=0;
  PH_COUNT phcou[256];

  do {
    for(; ofs < ch_phoN; ofs++)
      if (utf8_eq(utf8, pho_idx_str(ofs)))
        break;

    if (ofs==ch_phoN)
      goto ret;

    for(i=0; i < idxnum_pho; i++) {
      if (idx_pho[i].start<= ofs && ofs < idx_pho[i+1].start) {
//        dbg("ofs:%d %d  %d %d\n", ofs, i, idx_pho[i].start, idx_pho[i+1].start);
        phcou[phkeysN].count = ch_pho[ofs].count;
        phcou[phkeysN++].key = idx_pho[i].key;
        break;
      }
    }

    ofs++;
  } while (ofs < ch_phoN);

ret:

#if 0
    utf8_putchar(utf8);
    dbg("n %d\n", phkeysN);
#endif
  qsort(phcou, phkeysN, sizeof(PH_COUNT), qcmp_pho_count);

  for(i=0; i < phkeysN; i++)
    phkeys[i] = phcou[i].key;

  return phkeysN;
}