static int k_lookup(char *s, char out[]) { unsigned int key; bzero(&key, sizeof(key)); u8cpy((char *)&key, s); int bot=0, top=N-1; while (bot <= top) { int mid = (bot + top)/2; T2S t; fseek(fp, mid*sizeof(T2S), SEEK_SET); fread(&t, sizeof(T2S), 1, fp); if (key > t.a) bot=mid+1; else if (key < t.a) top=mid-1; else return u8cpy(out, (char *)&t.b); } return u8cpy(out, s); }
void disp_pho_sub(GtkWidget *label, int index, char *pho) { if (!label) return; if (index>=text_pho_N) return; if (pho[0]==' ' && !pin_juyin) { u8cpy(text_pho[index], " "); /* Full width space */ } else { u8cpy(text_pho[index], pho); } char s[text_pho_N * CH_SZ+1]; int tn = 0; int i; for(i=0; i < text_pho_N; i++) { int n = utf8cpy(s + tn, text_pho[i]); tn += n; } // gtk_widget_show(label); gtk_label_set_text(GTK_LABEL(label), s); }
void disp_pho_sub(GtkWidget *label, int index, char *pho) { if (!label) return; if (index>=text_pho_N) return; if (pho[0]==' ' && !pin_juyin) { u8cpy(text_pho[index], _(_L(" "))); } else { u8cpy(text_pho[index], pho); } #if UNIX char s[text_pho_N * CH_SZ+1]; #else char *s = new char[text_pho_N * CH_SZ+1]; #endif int tn = 0; int i; for(i=0; i < text_pho_N; i++) { int n = utf8cpy(s + tn, text_pho[i]); tn += n; } // gtk_widget_show(label); gtk_label_set_text(GTK_LABEL(label), s); #if WIN32 delete s; #endif }
ITEM64 *find_ch64(char *s, int *N) { ITEM64 t; bzero(t.ch, CH_SZ); u8cpy((char *)t.ch, s); ITEM64 *p = (ITEM64 *)bsearch(&t, it64, itN, sizeof(ITEM64), qcmp_ch64); if (!p) return NULL; ITEM64 *q = p+1; while (p > it64 && !qcmp_ch64(p-1, &t)) p--; ITEM64 *end = it64 + itN; while (q < end && !qcmp_ch64(q, &t)) q++; *N = q - p; if (*N > 20) p_err("err"); return p; }
char *phokey_to_str2(phokey_t kk, int last_number) { u_int k1,k2,k3,k4; static char phchars[PHO_CHAR_LEN * 4 + 1]; int phcharsN=0; phokey_t okk = kk; k4=(kk&7); kk>>=3; k3=(kk&15) * PHO_CHAR_LEN; kk>>=4; k2=(kk&3) * PHO_CHAR_LEN; kk>>=2; k1=(kk&31) * PHO_CHAR_LEN; if (k1==BACK_QUOTE_NO * PHO_CHAR_LEN) { strcpy(phchars, _(_L("、"))); int len=strlen(phchars); phchars[len++]=okk & 0x7f; phchars[len]=0; return phchars; } if (k1) { phcharsN+=u8cpy(phchars, &pho_chars[0][k1]); } if (k2) { phcharsN+=u8cpy(&phchars[phcharsN], &pho_chars[1][k2]); } if (k3) { phcharsN+=u8cpy(&phchars[phcharsN], &pho_chars[2][k3]); } if (k4) { // dbg("k4 %d\n", k4); if (last_number) phchars[phcharsN++] = k4 + '0'; else phcharsN+=u8cpy(&phchars[phcharsN], &pho_chars[3][k4 * PHO_CHAR_LEN]); } phchars[phcharsN] = 0; return phchars; }
char *bch_cat(char *s, char *ch) { char t[CH_SZ + 1]; int len = u8cpy(t, ch); t[len]=0; return strcat(s, t); }
static char* load_tblidx(int tblidx) { char tt[MAX_CIN_PHR]; u_char *tbl_ch = tblch(tblidx); if (tbl_ch[0] < 0x80) { load_phr(tblidx, tt); } else { int len = u8cpy(tt, (char *)tbl_ch); tt[len] = 0; } return strdup(tt); }
static gboolean load_seltab(int tblidx, int seltabidx) { u_char *tbl_ch = tblch(tblidx); if (tbl_ch[0] < 0x80) { load_phr(tblidx, seltab[seltabidx]); return TRUE; } int len = u8cpy(seltab[seltabidx], (char *)tbl_ch); seltab[seltabidx][len] = 0; return FALSE; }
static void selection_received(GtkClipboard *pclip, const gchar *text, gpointer data) { if (!text) return; char *outtext = NULL; int outlen = 0; while (*text) { char tt[CH_SZ * 5 * MAX_SAME_PHO + 1]; int len = u8cpy(tt, (char *)text); tt[len]=0; phokey_t phokeys[MAX_SAME_PHO]; int phokeysN = utf8_pho_keys((char *)text, phokeys); int i; for(i=0; i <phokeysN ;i++) { char *phostr; if (b_pinyin) phostr = phokey2pinyin(phokeys[i]); else phostr = phokey_to_str(phokeys[i]); strcat(tt, phostr); } int ttlen = strlen(tt); outtext = (char *)realloc(outtext, outlen + ttlen + 1); memcpy(outtext + outlen, tt, ttlen); outlen+=ttlen; text += len; } outtext[outlen]=0; gtk_text_buffer_set_text (buffer, outtext, -1); free(outtext); all_wrap(); }
int get_DispInArea_str(char *out) { int outN=0, i; for(i=0;i<ggg.ci;i++) { char *p = (char *)&cur_inmd->keyname[ggg.inch[i] * CH_SZ]; if (*p & 0x80) outN+=u8cpy(out+outN, p); else { int len = strlen(p); memcpy(out+outN, p, len); outN+=len; } } #if 0 if (outN) { hide_gtab_pre_sel(); } #endif out[outN]=0; // dbg("get_DispInArea_str\n", out); return outN; }
int main(int argc, char **argv) { char *fname = "pho.tab2.src"; FILE *fp; char s[64]; int phrase_area_N=0; char *phrase_area = NULL; if (!getenv("NO_GTK_INIT")) gtk_init(&argc, &argv); if (argc > 1) fname = argv[1]; if ((fp=fopen(fname,"rb"))==NULL) p_err("cannot open %s\n", fname); while (!feof(fp)) { s[0]=0; myfgets(s,sizeof(s),fp); int len=strlen(s); if (s[len-1]=='\n') s[--len]=0; if (len==0) continue; phokey_t kk=0; char *p = s; while (*p && *p!=' ' && *p!=9) { if (kk==(BACK_QUOTE_NO << 9)) kk|=*p; else kk |= lookup((u_char *)p); p += utf8_sz(p); } items[itemsN].key = kk; p++; char *str = p; while (*p && *p != ' ' && *p!=9) p++; *p = 0; p++; int slen = strlen(str); if (slen==utf8_sz(str)) { u8cpy((char *)items[itemsN].ch, str); } else { dbg("str %s\n", str); int newN = phrase_area_N + slen + 1; phrase_area = trealloc(phrase_area, char, newN); strcpy(phrase_area + phrase_area_N, str); items[itemsN].ch[0] = PHO_PHRASE_ESCAPE; items[itemsN].ch[1] = phrase_area_N & 0xff; items[itemsN].ch[2] = (phrase_area_N>>8) & 0xff; items[itemsN].ch[3] = (phrase_area_N>>16) & 0xff; phrase_area_N = newN; } items[itemsN].count = atoi(p); items[itemsN].oseq = itemsN; itemsN++; } fclose(fp); qsort(items, itemsN, sizeof(PHITEM), qcmp_key_del); int i; #if 1 int newN = 1; for(i=1;i<itemsN;i++) if (qcmp_key_del(&items[i-1], &items[i])) items[newN++] = items[i]; else { #if 0 prph(items[i].key); utf8_putchar((char *)items[i].ch); dbg("\n"); #endif } if (itemsN != newN) { dbg("deleted %d %d\n",itemsN, newN); itemsN = newN; } #endif qsort(items, itemsN, sizeof(PHITEM), qcmp_key); PHO_IDX pho_idx[3000]; u_short pho_idxN=0; for(i=0; i < itemsN; ) { phokey_t key = items[i].key; pho_idx[pho_idxN].key = key; pho_idx[pho_idxN].start = i; pho_idxN++; int j; for (j=i+1; j < itemsN && items[j].key == key; j++); int l; for(l=i; l<j; l++) { bchcpy(pho_items[pho_itemsN].ch, items[l].ch); pho_items[pho_itemsN].count = items[l].count; pho_itemsN++; } i = j; } char *tp = strstr(fname, ".tab2.src"); if (!tp) p_err("file name should be *.tab2.src"); tp = strstr(fname, ".src"); *tp=0; char *fname_out = fname; if ((fp=fopen(fname_out,"wb"))==NULL) p_err("cannot create %s\n", fname_out); fwrite("PH",1,2,fp); // dbg("pho_itemsN:%d pho_idxN:%d\n", pho_itemsN, pho_idxN); fwrite(&pho_idxN, sizeof(u_short), 1, fp); fwrite(&pho_itemsN, sizeof(pho_itemsN), 1, fp); fwrite(&phrase_area_N, sizeof(phrase_area_N), 1, fp); #if 0 fclose(fp); exit(0); #endif fwrite(pho_idx, sizeof(PHO_IDX), pho_idxN, fp); fwrite(pho_items, sizeof(PHO_ITEM), pho_itemsN, fp); fwrite(phrase_area, 1, phrase_area_N, fp); fclose(fp); if (getenv("HIME_NO_RELOAD")==NULL) { /* caleb- does found where "reload" is used. * caleb- think the send_hime_message() here does nothing. */ send_hime_message(GDK_DISPLAY(), "reload"); } return 0; }