static uim_lisp get_nth_candidate(uim_lisp ac_, uim_lisp seg_, uim_lisp nth_) { anthy_context_t ac; int seg, nth, buflen; char *buf; uim_lisp buf_; ac = get_anthy_context(ac_); seg = C_INT(seg_); nth = C_INT(nth_); buflen = anthy_get_segment(ac, seg, nth, NULL, 0); if (buflen == -1) uim_fatal_error("anthy_get_segment() failed"); buf = uim_malloc(buflen + 1); buflen = anthy_get_segment(ac, seg, nth, buf, buflen + 1); if (buflen == -1) { free(buf); uim_fatal_error("anthy_get_segment() failed"); } buf_ = MAKE_STR_DIRECTLY(buf); return buf_; }
static void load_seg() { dbg("load_seg sel_segN:%d\n", sel_segN); clear_seg_label(); struct anthy_conv_stat acs; anthy_get_stat(ac, &acs); segN = 0; if (acs.nr_segment > 0) { char buf[256]; int i; int ofs = 0; for(i=0; i < acs.nr_segment; i++) { struct anthy_segment_stat ss; anthy_get_segment_stat(ac, i, &ss); int len = ss.seg_len; int idx = get_sel_seg_with_ofs(ofs); dbg("%d] sel idx:%d ofs:%d\n",i, idx, ofs); int selN = seg[i].selN = ss.nr_candidate; char *old_str = NULL; seg[i].selidx = 0; if (idx < sel_segN && sel_seg[idx].len==len) { int j; for(j=0;j<selN;j++) { anthy_get_segment(ac, i, j, buf, sizeof(buf)); if (!strcmp(buf, sel_seg[idx].sel_str) ) { dbg("old found %s", buf); seg[i].selidx = j; break; } } } anthy_get_segment(ac, i, seg[i].selidx, buf, sizeof(buf)); gtk_label_set_text(GTK_LABEL(seg[i].label), buf); dbg("seg len:%d\n", len); seg[i].ofs = ofs; seg[i].len = len; segN++; ofs += len; } state=STATE_CONVERT; // cursor = 0; if (cursor >= acs.nr_segment) cursor = acs.nr_segment - 1; disp_convert(); } keysN=0; }
static void load_seg() { clear_seg_label(); struct anthy_conv_stat acs; anthy_get_stat(ac, &acs); segN = 0; if (acs.nr_segment > 0) { char buf[256]; int i; for(i=0; i < acs.nr_segment; i++) { anthy_get_segment(ac, i, 0, buf, sizeof(buf)); seg[i].selidx = 0; gtk_label_set_text(GTK_LABEL(seg[i].label), buf); struct anthy_segment_stat ss; anthy_get_segment_stat(ac, i, &ss); seg[i].selN = ss.nr_candidate; segN++; } state=STATE_CONVERT; // cursor = 0; if (cursor >= acs.nr_segment) cursor = acs.nr_segment - 1; disp_convert(); } keysN=0; }
static void disp_select() { // puts("disp_select"); gmf.mf_clear_sele(); int endn = pageidx + gmf.mf_phkbm->selkeyN; if (endn > seg[cursor].selN) endn = seg[cursor].selN; int i; for(i=pageidx; i<endn; i++) { char buf[256]; anthy_get_segment(ac, cursor, i, buf, sizeof(buf)); // printf("%d %s\n", i, buf); gmf.mf_set_sele_text(seg[cursor].selN, i - pageidx, buf, -1); } if (pageidx) gmf.mf_disp_arrow_up(); if (i < seg[cursor].selN) gmf.mf_disp_arrow_down(); int x,y; gmf.mf_get_widget_xy(win_anthy, seg[cursor].label, &x, &y); // printf("%x cusor %d %d\n", win_anthy, cursor, x); y = gmf.mf_hime_edit_display_ap_only()? *gmf.mf_win_y:*gmf.mf_win_y+*gmf.mf_win_yl; gmf.mf_disp_selections(x, y); }
static gboolean select_idx(int c) { int idx = pageidx + c; if (idx < seg[cursor].selN) { char buf[256]; anthy_get_segment(ac, cursor, idx, buf, sizeof(buf)); struct anthy_segment_stat ss; anthy_get_segment_stat(ac, cursor, &ss); int len = ss.seg_len; gtk_label_set_text(GTK_LABEL(seg[cursor].label), buf); seg[cursor].selidx = idx; int sidx = get_sel_seg_with_ofs(seg[cursor].ofs); if (sidx==sel_segN) { sel_segN++; } if (sel_seg[sidx].sel_str) free(sel_seg[sidx].sel_str); dbg("select_idx idx:%d sidx:%d %s\n", idx, sidx, buf); sel_seg[sidx].sel_str = strdup(buf); sel_seg[sidx].ofs = seg[cursor].ofs; sel_seg[sidx].len = len; state = STATE_CONVERT; gmf.mf_hide_selections_win(); return (segN==1); } return FALSE; }
int main(int argc,char **argv){ if(anthy_init()) { printf("anthy_init() is failed.\n"); return 1; } anthy_set_personality(""); ac = anthy_create_context(); if(!ac) { printf("anthy_create_context() is failed.\n"); return 1; } //準備完了! for(k=0; k<1000; k++){ anthy_set_string(ac, "わたしのなまえはおくのです。"); //anthy_commit_segment(ac); anthy_get_stat(ac, &cs); //printf("segment:%d\n",cs.nr_segment); for(i=0; i<cs.nr_segment; i++){ struct anthy_segment_stat ss; anthy_get_segment_stat(ac,i,&ss); //printf("can:%d,len:%d |", ss.nr_candidate, ss.seg_len); for(j=0; j<ss.nr_candidate; j++){ char buffer[256]; anthy_get_segment(ac,i,j,buffer,256); //printf(" %s ", buffer); } //printf("\n"); } //printf("\n"); //anthy_print_context(ac); } anthy_release_context(ac); anthy_quit(); return 0; }
void toHira(char* str) { int len, cur, isquestion; char buf[BUFSIZE]; struct anthy_conv_stat cs; replaceSign(str); replaceGrass(str); printf("rgr_str:%s\n", str); if (anthy_init()) { fprintf(stderr, "anthy init error\n"); abort(); } anthy_context_t ctx = anthy_create_context(); if (!ctx) { fprintf(stderr, "can not create context\n"); abort(); } anthy_context_set_encoding(ctx, ANTHY_UTF8_ENCODING); if (anthy_set_string(ctx, str)) { fprintf(stderr, "can not set string\n"); abort(); } if (anthy_get_stat(ctx, &cs)) { fprintf(stderr, "can not get stat\n"); abort(); } cur = 0; for (int i = 0; i < cs.nr_segment; i++) { if ((len = anthy_get_segment(ctx, i, NTH_UNCONVERTED_CANDIDATE, buf, BUFSIZE)) == -1) { fprintf(stderr, "can not get segment %d\n", i); abort(); } if (istalk(buf)) { memcpy(str + cur, buf, len); cur += len; } if (i < cs.nr_segment - 1) if (i == cs.nr_segment - 3 && isquestion) continue; else if (i == cs.nr_segment - 2) continue; else str[cur] = '/'; else str[cur] = '\0'; cur++; } anthy_release_context(ctx); }
static gboolean select_idx(int c) { int idx = pageidx + c; if (idx < seg[cursor].selN) { char buf[256]; anthy_get_segment(ac, cursor, idx, buf, sizeof(buf)); gtk_label_set_text(GTK_LABEL(seg[cursor].label), buf); seg[cursor].selidx = idx; state = STATE_CONVERT; gmf.mf_hide_selections_win(); return (segN==1); } return FALSE; }
std::string Conversion::get_segment_string (int segment_id, int candidate_id) { if (segment_id < 0) { if (m_cur_segment < 0) return std::string (); else segment_id = m_cur_segment; } struct anthy_conv_stat conv_stat; anthy_get_stat (m_anthy_context, &conv_stat); if (conv_stat.nr_segment <= 0) return std::string (); if (m_start_id < 0 || m_start_id >= conv_stat.nr_segment) { return std::string (); // error } if (segment_id < 0 || segment_id + m_start_id >= conv_stat.nr_segment) { return std::string (); //error } // character position of the head of segment. unsigned int real_seg_start = 0; for (int i = m_start_id; i < m_start_id + segment_id; i++) { struct anthy_segment_stat seg_stat; anthy_get_segment_stat (m_anthy_context, i, &seg_stat); real_seg_start += seg_stat.seg_len; } int real_seg = segment_id + m_start_id; int cand; if (candidate_id <= FCITX_ANTHY_LAST_SPECIAL_CANDIDATE) cand = m_segments[segment_id].get_candidate_id (); else cand = candidate_id; // get information of this segment struct anthy_segment_stat seg_stat; anthy_get_segment_stat (m_anthy_context, real_seg, &seg_stat); // get string of this segment std::string segment_str; if (cand < 0) { get_reading_substr (segment_str, segment_id, cand, real_seg_start, seg_stat.seg_len); } else { int len = anthy_get_segment (m_anthy_context, real_seg, cand, NULL, 0); if (len > 0) { char buf[len + 1]; anthy_get_segment (m_anthy_context, real_seg, cand, buf, len + 1); buf[len] = '\0'; segment_str = buf; } } return segment_str; }