File: main.cpp

package info (click to toggle)
fcitx-googlepinyin 0.1.6-5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 224 kB
  • sloc: cpp: 520; makefile: 9
file content (48 lines) | stat: -rw-r--r-- 1,172 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "pinyinime.h"
#include "dictdef.h"
#include <iostream>
#include <iconv.h>
#include <string>
#include <string.h>
#define RET_BUF_LEN 256

using namespace std;
using namespace ime_pinyin;

static char16 retbuf[RET_BUF_LEN];
static char16 (*predict_buf)[kMaxPredictSize + 1] = NULL;
static size_t predict_len;

int main(int argc, char *argv[])
{
    if (argc < 3)
        return 0;
    im_open_decoder(argv[1], argv[2]);
    string s;
    cin >> s ;
    char ubuf[4096];

    iconv_t conv = iconv_open("utf8", "utf16");
    while (true)
    {
        int len = im_search(s.c_str(), s.length());
        for (int i = 0 ;i < len ; i ++)
        {
            char16 *p;
            char *pp = ubuf;
            p = im_get_candidate(i, retbuf, 1024);
            size_t a = utf16_strlen(p) * 2,b = 4096;
            cout << a;
            memset(ubuf, 0 , 4096);
            iconv(conv, (char**) &p, &a, &pp, &b);
            cout << ubuf << endl;
        }
        int cand;
        cin >> cand;
//      if (cand == -1)
//          im_delsearch();
        im_choose(cand);
    }
    im_close_decoder();
}
// kate: indent-mode cstyle; space-indent on; indent-width 0;