filter 함수 인자 바뀐 것을 적용함
[platform/core/uifw/libhangul.git] / test / test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <locale.h>
5 #include <wchar.h>
6
7 #include "../hangul/hangul.h"
8
9 bool filter(ucschar *str, ucschar cho, ucschar jung, ucschar jong, void *data)
10 {
11     //printf("Filter: %x %x %x\n", cho, jung, jong);
12     //return jong == 0;
13     return true;
14 }
15
16 int
17 main(int argc, char *argv[])
18 {
19     int n;
20     int ascii;
21     int keyboard = HANGUL_KEYBOARD_2;
22     char commit[32] = { '\0', };
23     wchar_t *commit_string;
24     HangulInputContext *hic;
25
26     if (argc > 1) {
27         keyboard = atoi(argv[1]);
28     }
29
30     setlocale(LC_CTYPE, "");
31
32     hic = hangul_ic_new(keyboard);
33     if (hic == NULL) {
34         printf("hic is null\n");
35         return -1;
36     }
37     hangul_ic_set_filter(hic, filter, NULL);
38
39     for (ascii = getchar(); ascii != EOF; ascii = getchar()) {
40         int ret = hangul_ic_process(hic, ascii);
41         commit_string = (wchar_t*)hangul_ic_get_commit_string(hic);
42         n = wcstombs(commit, commit_string, sizeof(commit));
43         commit[n] = '\0';
44         if (strlen(commit) > 0) {
45             printf("%s", commit);
46         }
47         if (!ret) {
48             printf("%c", ascii);
49         }
50     } 
51     if (!hangul_ic_is_empty(hic)) {
52         hangul_ic_flush(hic);
53         commit_string = (wchar_t*)hangul_ic_get_commit_string(hic);
54         n = wcstombs(commit, commit_string, sizeof(commit));
55         commit[n] = '\0';
56         if (strlen(commit) > 0) {
57             printf("%s", commit);
58         }
59     }
60
61     hangul_ic_delete(hic);
62
63     return 0;
64 }