~ubuntu-branches/ubuntu/hardy/uim/hardy

« back to all changes in this revision

Viewing changes to uim/canna.c

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2005-12-04 13:10:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051204131042-ktzc8b17zi7a3cw8
Tags: 1:0.4.9.1-1
* New upstream release
* libuim0-nox, libuim-nox-dev, and libuim0-dbg-nox is now obsolete.
  Because libuim0 does not depends on X11. They now become dummy package,
  therefore you can safely remove them.
* Add --enable-debug in configure again.
* debian/patches/08_fix_privilage_escalation_CVE_2005_3149: disabled.
* Fix Error on purge because update-uim-config is not found.
  (closes: Bug#339345)
* uim-qt: New package for Qt utilities for uim. qt-immodule does not
  contained yet because of Debian's Qt3 does not support immodule and
  because uim does not recognize libqt4-dev's headers properly. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
  $Id$
 
2
  $Id:$
3
3
 
4
4
  canna.c: Canna for uim.
5
5
 
6
 
  Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
 
6
  Copyright (c) 2003,2004,2005 uim Project http://uim.freedesktop.org/
7
7
 
8
8
  All rights reserved.
9
9
 
20
20
     may be used to endorse or promote products derived from this software
21
21
     without specific prior written permission.
22
22
 
23
 
  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 
23
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
24
24
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
25
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
 
  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
26
  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
27
27
  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
28
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29
29
  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41
41
#include <errno.h>
42
42
#include <string.h>
43
43
#include "context.h"
 
44
#include "uim-scm.h"
 
45
#include "uim-compat-scm.h"
 
46
#include "plugin.h"
 
47
 
 
48
/* #define UIM_CANNA_DEBUG */
44
49
 
45
50
#define MAX_CONTEXT 256
46
51
#define LIBCANNA_SO     "libcanna.so"
47
52
 
48
53
#define BUFSIZE 1024
49
54
 
50
 
static LISP true_sym;
51
 
 
52
55
struct canna_context {
53
56
  char diclist[BUFSIZE];
54
57
 
64
67
 
65
68
static struct canna_context *context_array = NULL;
66
69
 
 
70
#if 0
67
71
static int context_array_len;
 
72
#endif
68
73
static int rk_initialized = -1;
69
74
static char *cannaserver = NULL;
70
75
 
71
 
static struct canna_api {
72
 
  void *lib;
73
 
  /*  struct rkfuncs Rk; */
74
 
  int (*RkInitialize)(char *);
75
 
  int (*RkCreateContext)(void);
76
 
  int (*RkCloseContext)(int);
77
 
  int (*RkBgnBun)(int, char *, int, int);
78
 
  int (*RkEndBun)(int, int);
79
 
  int (*RkFinalize)(void);
80
 
  int (*RkGetDicList)(int, char *, int);
81
 
  int (*RkMountDic)(int, char *, int);
82
 
  int (*RkNfer)(int);
83
 
  int (*RkXfer)(int, int);
84
 
  int (*RkEnlarge)(int);
85
 
  int (*RkShorten)(int);
86
 
  int (*RkGetStat)(int, RkStat *);
87
 
  int (*RkGoTo)(int, int);
88
 
  int (*RkGetKanji)(int, char *, int);
89
 
  int (*RkGetKanjiList)(int, char *, int);
90
 
  int (*RkSetServerName)(char *);
91
 
} api;
92
 
 
93
 
static int
94
 
get_canna_api(void)
95
 
{
96
 
  api.lib = dlopen(LIBCANNA_SO, RTLD_NOW);
97
 
  if(!api.lib)
98
 
    return -1;
99
 
 
100
 
  *(int **)(&api.RkInitialize) = dlsym(api.lib, "RkInitialize");
101
 
  *(int **)(&api.RkFinalize) = dlsym(api.lib, "RkFinalize");
102
 
  *(int **)(&api.RkGetDicList) = dlsym(api.lib, "RkGetDicList");
103
 
  *(int **)(&api.RkMountDic) = dlsym(api.lib, "RkMountDic");
104
 
  *(int **)(&api.RkCreateContext) = dlsym(api.lib, "RkCreateContext");
105
 
  *(int **)(&api.RkCloseContext) = dlsym(api.lib, "RkCloseContext");
106
 
  *(int **)(&api.RkBgnBun) = dlsym(api.lib, "RkBgnBun");
107
 
  *(int **)(&api.RkEndBun) = dlsym(api.lib, "RkEndBun");
108
 
  *(int **)(&api.RkGoTo) = dlsym(api.lib, "RkGoTo");
109
 
  *(int **)(&api.RkGetKanji) = dlsym(api.lib, "RkGetKanji");
110
 
  *(int **)(&api.RkGetKanjiList) = dlsym(api.lib, "RkGetKanjiList");
111
 
  *(int **)(&api.RkGetStat) = dlsym(api.lib, "RkGetStat");
112
 
  *(int **)(&api.RkXfer) = dlsym(api.lib, "RkXfer");
113
 
  *(int **)(&api.RkNfer) = dlsym(api.lib, "RkXfer");
114
 
  *(int **)(&api.RkEnlarge) = dlsym(api.lib, "RkEnlarge");
115
 
  *(int **)(&api.RkShorten) = dlsym(api.lib, "RkShorten");
116
 
  if(api.RkInitialize && api.RkFinalize && api.RkGetDicList &&
117
 
     api.RkMountDic && api.RkCreateContext && api.RkCloseContext &&
118
 
     api.RkBgnBun && api.RkEndBun && api.RkGoTo && api.RkGetKanji &&
119
 
     api.RkGetKanjiList && api.RkGetStat && api.RkXfer && api.RkNfer &&
120
 
     api.RkEnlarge && api.RkShorten)
121
 
  {
122
 
    /* ok! */
123
 
    return 0;
124
 
  }
125
 
  return -1;
126
 
}
127
 
 
128
76
static struct canna_context *
129
77
get_canna_context(int id)
130
78
{
133
81
 
134
82
  context = context_array;
135
83
 
136
 
  if(id >= MAX_CONTEXT || id < 0)
 
84
  if (id >= MAX_CONTEXT || id < 0)
137
85
    return NULL;
138
 
  for(i = 0; i < id; i++)
 
86
  for (i = 0; i < id; i++)
139
87
    context++;
140
 
 
141
 
/*  printf("rk_context_id: %d\n", context->rk_context_id);
142
 
    printf("segment_num: %d\n", context->segment_num); */
 
88
#ifdef UIM_CANNA_DEBUG
 
89
  printf("rk_context_id: %d\n", context->rk_context_id);
 
90
  printf("segment_num: %d\n", context->segment_num);
 
91
#endif
143
92
  return context;
144
93
}
145
94
 
146
 
static LISP
147
 
init_canna_lib(LISP str_)
 
95
static uim_lisp
 
96
init_canna_lib(uim_lisp str_)
148
97
{
149
98
  struct canna_context *context;
150
99
  int i;
151
100
 
152
 
  if (get_canna_api() == -1)
153
 
    return NIL;
154
 
 
155
 
  if(str_ != NIL)
 
101
  if (str_ != uim_scm_f())
156
102
    cannaserver = uim_scm_c_str(str_);
157
103
  else
158
104
    cannaserver = NULL;
159
105
 
160
106
  context_array = malloc(sizeof(struct canna_context) * MAX_CONTEXT);
161
 
  if(context_array == NULL)
162
 
    return NIL;
 
107
  if (context_array == NULL)
 
108
    return uim_scm_f();
163
109
 
164
110
  context = context_array;
165
111
 
177
123
    context++;
178
124
  }
179
125
 
180
 
  return true_sym;
 
126
  if (rk_initialized == -1) {
 
127
    if (RkInitialize(cannaserver) == -1) {
 
128
      fprintf(stderr, "%s\n", strerror(errno));
 
129
      return uim_scm_f();
 
130
    }
 
131
    RkFinalize();
 
132
  }
 
133
 
 
134
  return uim_scm_t();
181
135
}
182
136
 
183
 
static LISP
 
137
static uim_lisp
184
138
create_context() {
185
139
  int i;
186
140
  char *buf;
187
141
  int buflen;
188
142
  struct canna_context *cc = context_array;
189
143
 
190
 
  if(rk_initialized == -1) {
191
 
    if(api.RkInitialize(cannaserver) == -1) {
 
144
  if (rk_initialized == -1) {
 
145
    if (RkInitialize(cannaserver) == -1) {
192
146
      fprintf(stderr, "%s\n", strerror(errno));
193
 
      return NIL;
 
147
      return uim_scm_f();
194
148
    }
195
149
    rk_initialized = 1;
196
150
  }
197
151
 
198
 
  for(i = 0; i < MAX_CONTEXT; i++) {
199
 
     if(cc->rk_context_id == -1) {
 
152
  for (i = 0; i < MAX_CONTEXT; i++) {
 
153
     if (cc->rk_context_id == -1) {
200
154
        int dic_num;
201
 
        cc->rk_context_id = api.RkCreateContext();
202
 
        dic_num = api.RkGetDicList(cc->rk_context_id,
 
155
        cc->rk_context_id = RkCreateContext();
 
156
        dic_num = RkGetDicList(cc->rk_context_id,
203
157
                                   cc->diclist, BUFSIZE);
204
 
        if(dic_num == 0) {
205
 
            return NIL;
206
 
        } else if(dic_num == -1) {
 
158
        if (dic_num == 0) {
 
159
            return uim_scm_make_int(i);
 
160
        } else if (dic_num == -1) {
207
161
            /* invalid context number */
208
 
            return NIL;
 
162
            return uim_scm_f();
209
163
        } else {
210
164
            int j;
211
165
            /* buf[] = "dicname1\0dicname2\0dicname3\0...dicname_n\0\0" */
212
166
            buf = cc->diclist;
213
 
            for(j = 0; j < dic_num; j++) {
214
 
                api.RkMountDic(cc->rk_context_id, buf, 0);
 
167
            for (j = 0; j < dic_num; j++) {
 
168
                RkMountDic(cc->rk_context_id, buf, 0);
215
169
                buflen = strlen(buf) + 1;
216
170
                buf += buflen;
217
171
            }
218
172
        }
219
 
        return intcons(i);
 
173
        return uim_scm_make_int(i);
220
174
     }
221
175
     cc++;
222
176
  }
223
 
  return NIL;
 
177
  return uim_scm_f();
224
178
}
225
179
 
226
 
static LISP
227
 
release_context(LISP id_)
 
180
static uim_lisp
 
181
release_context(uim_lisp id_)
228
182
{
229
183
  int id = uim_scm_c_int(id_);
230
184
  struct canna_context *cc = get_canna_context(id);
231
185
 
232
 
  if(cc == NULL)
233
 
    return NIL;
234
 
 
235
 
  if(cc->rk_context_id == -1)
236
 
    return NIL;
237
 
 
238
 
  if(api.RkCloseContext(cc->rk_context_id) != -1) {
 
186
  if (cc == NULL)
 
187
    return uim_scm_f();
 
188
 
 
189
  if (cc->rk_context_id == -1)
 
190
    return uim_scm_f();
 
191
 
 
192
  if (RkCloseContext(cc->rk_context_id) != -1) {
239
193
    cc->rk_context_id = -1;
240
 
    return true_sym;
 
194
    return uim_scm_t();
241
195
  } else {
242
 
    return NIL;
 
196
    return uim_scm_f();
243
197
  }
244
198
}
245
199
 
247
201
_reset_conversion(int id)
248
202
{
249
203
  struct canna_context *cc = get_canna_context(id);
250
 
  if(cc == NULL)
 
204
  if (cc == NULL)
251
205
     return;
252
206
 
253
 
  if(cc->segment_num >= 0) {
 
207
  if (cc->segment_num >= 0) {
254
208
     cc->segment_num = -1;
255
 
     api.RkEndBun(cc->rk_context_id, 0);
 
209
     RkEndBun(cc->rk_context_id, 0);
256
210
  }
257
211
}
258
212
 
261
215
{
262
216
  RkStat stat;
263
217
  struct canna_context *cc = get_canna_context(id);
264
 
  if(cc == NULL)
265
 
     return;
266
 
 
267
 
  if(cc->rk_context_id == -1)
268
 
     return;
269
 
 
270
 
  if(api.RkGetStat(cc->rk_context_id, &stat) == 0)
 
218
  if (cc == NULL)
 
219
     return;
 
220
 
 
221
  if (cc->rk_context_id == -1)
 
222
     return;
 
223
 
 
224
  if (RkGetStat(cc->rk_context_id, &stat) == 0)
271
225
  {
272
226
    cc->current_segment_num = stat.bunnum;
273
227
    cc->current_cand_num = stat.candnum;
284
238
  char buf[BUFSIZE];
285
239
  struct canna_context *cc = get_canna_context(id);
286
240
 
287
 
  if(cc == NULL)
 
241
  if (cc == NULL)
288
242
    return;
289
243
 
290
 
  if(cc->rk_context_id == -1)
 
244
  if (cc->rk_context_id == -1)
291
245
    return;
292
246
 
293
247
  tmp_segment_num = segment_num;
294
 
  if(segment_num >= cc->segment_num)
 
248
  if (segment_num >= cc->segment_num)
295
249
    tmp_segment_num = 0;
296
250
 
297
 
  for(i = 0; i <= tmp_segment_num; i++) {
 
251
  for (i = 0; i <= tmp_segment_num; i++) {
298
252
    int len;
299
 
    api.RkGoTo(cc->rk_context_id, i);
300
 
    len = api.RkGetKanji(cc->rk_context_id, buf, BUFSIZE);
301
 
/*    printf("segment: %d, buf: %s\n", i, buf); */
 
253
    RkGoTo(cc->rk_context_id, i);
 
254
    len = RkGetKanji(cc->rk_context_id, (unsigned char *)buf, BUFSIZE);
 
255
#ifdef UIM_CANNA_DEBUG
 
256
    printf("segment: %d, buf: %s\n", i, buf);
 
257
#endif
302
258
  }
303
259
 
304
 
  api.RkGoTo(cc->rk_context_id, tmp_segment_num);
 
260
  RkGoTo(cc->rk_context_id, tmp_segment_num);
305
261
  _update_status(id);
306
262
}
307
263
 
308
 
static LISP
309
 
begin_conversion(LISP id_, LISP str_)
 
264
static uim_lisp
 
265
begin_conversion(uim_lisp id_, uim_lisp str_)
310
266
{
311
267
  int id = uim_scm_c_int(id_);
312
268
  char *str;
313
269
  int len, segment_num, mode;
314
270
  struct canna_context *cc = get_canna_context(id);
315
271
 
316
 
  if(cc == NULL)
317
 
    return NIL;
 
272
  if (cc == NULL)
 
273
    return uim_scm_f();
318
274
 
319
 
  if(cc->rk_context_id == -1)
320
 
    return NIL;
 
275
  if (cc->rk_context_id == -1)
 
276
    return uim_scm_f();
321
277
 
322
278
  mode = cc->rk_mode;
323
279
  str = uim_scm_c_str(str_);
324
280
  len = strlen(str);
325
281
 
326
 
  segment_num = api.RkBgnBun(cc->rk_context_id, str, len, mode);
 
282
  segment_num = RkBgnBun(cc->rk_context_id, str, len, mode);
327
283
 
328
 
  if(segment_num == -1) {
 
284
  if (segment_num == -1) {
329
285
     /* failed to conversion */
330
 
     if(str != NULL)
 
286
     if (str != NULL)
331
287
        free(str);
332
 
     return NIL;
 
288
     return uim_scm_f();
333
289
  }
334
290
 
335
291
  cc->segment_num = segment_num;
336
292
  _update_segment(id, 0);
337
293
 
338
 
  if(str != NULL)
 
294
  if (str != NULL)
339
295
     free(str);
340
296
 
341
 
  return intcons(cc->segment_num);
 
297
  return uim_scm_make_int(cc->segment_num);
342
298
}
343
299
 
344
 
static LISP
345
 
get_nth_candidate(LISP id_, LISP seg_, LISP nth_)
 
300
static uim_lisp
 
301
get_nth_candidate(uim_lisp id_, uim_lisp seg_, uim_lisp nth_)
346
302
{
347
303
  int id = uim_scm_c_int(id_);
348
304
  int seg = uim_scm_c_int(seg_);
351
307
  char buf[BUFSIZE];
352
308
  int len;
353
309
 
354
 
  if(cc == NULL)
355
 
    return NIL;
 
310
  if (cc == NULL)
 
311
    return uim_scm_f();
356
312
 
357
313
  _update_segment(id, seg);
358
 
  if(nth > cc->max_current_cand_num)
 
314
  if (nth > cc->max_current_cand_num)
359
315
    nth = 0;
360
316
 
361
 
  api.RkXfer(cc->rk_context_id, nth);
362
 
  len = api.RkGetKanji(cc->rk_context_id, buf, BUFSIZE);
363
 
 
364
 
/*  printf("nth: %d, kanji: %s\n", nth, buf); */
365
 
  return strcons(len, buf);
 
317
  RkXfer(cc->rk_context_id, nth);
 
318
  len = RkGetKanji(cc->rk_context_id, (unsigned char *)buf, BUFSIZE);
 
319
#ifdef UIM_CANNA_DEBUG
 
320
  printf("nth: %d, kanji: %s\n", nth, buf);
 
321
#endif
 
322
  return uim_scm_make_str(buf);
366
323
}
367
324
 
368
 
static LISP
369
 
get_nr_segments(LISP id_)
 
325
static uim_lisp
 
326
get_nr_segments(uim_lisp id_)
370
327
{
371
328
  int id = uim_scm_c_int(id_);
372
 
  RkStat stat;
 
329
/*  RkStat stat; */
373
330
  struct canna_context *cc = get_canna_context(id);
374
331
 
375
 
  if(cc == NULL)
376
 
     return NIL;
377
 
 
378
 
  if(cc->rk_context_id == -1)
379
 
     return NIL;
380
 
 
381
 
  return intcons(cc->segment_num);
 
332
  if (cc == NULL)
 
333
     return uim_scm_f();
 
334
 
 
335
  if (cc->rk_context_id == -1)
 
336
     return uim_scm_f();
 
337
 
 
338
  return uim_scm_make_int(cc->segment_num);
382
339
}
383
340
 
384
 
static LISP
385
 
get_nr_candidate(LISP id_, LISP nth_)
 
341
static uim_lisp
 
342
get_nr_candidate(uim_lisp id_, uim_lisp nth_)
386
343
{
387
344
  int id = uim_scm_c_int(id_);
388
345
  int nth = uim_scm_c_int(nth_);
389
346
  RkStat stat;
390
347
  struct canna_context *cc = get_canna_context(id);
391
348
 
392
 
  if(cc == NULL)
393
 
     return NIL;
394
 
 
395
 
  if(cc->rk_context_id == -1)
396
 
     return NIL;
397
 
 
398
 
  api.RkGoTo(cc->rk_context_id, nth);
399
 
 
400
 
  if(api.RkGetStat(cc->rk_context_id, &stat) == 0)
401
 
    return intcons(stat.maxcand);
 
349
  if (cc == NULL)
 
350
     return uim_scm_f();
 
351
 
 
352
  if (cc->rk_context_id == -1)
 
353
     return uim_scm_f();
 
354
 
 
355
  RkGoTo(cc->rk_context_id, nth);
 
356
 
 
357
  if (RkGetStat(cc->rk_context_id, &stat) == 0)
 
358
    return uim_scm_make_int(stat.maxcand);
402
359
  else
403
 
    return NIL;
 
360
    return uim_scm_f();
404
361
}
405
362
 
406
 
static LISP
407
 
resize_segment(LISP id_, LISP s_, LISP nth_)
 
363
static uim_lisp
 
364
resize_segment(uim_lisp id_, uim_lisp s_, uim_lisp nth_)
408
365
{
409
366
  int id = uim_scm_c_int(id_);
410
367
  int s = uim_scm_c_int(s_);
411
368
  int nth = uim_scm_c_int(nth_);
412
369
  struct canna_context *cc = get_canna_context(id);
413
370
 
414
 
  if(cc == NULL)
415
 
     return NIL;
416
 
 
417
 
  if(cc->rk_context_id == -1)
418
 
     return NIL;
419
 
 
420
 
  api.RkGoTo(cc->rk_context_id, s);
421
 
  api.RkNfer(cc->rk_context_id);
422
 
 
423
 
  if(nth > 0)
424
 
      cc->segment_num = api.RkEnlarge(cc->rk_context_id);
 
371
  if (cc == NULL)
 
372
     return uim_scm_f();
 
373
 
 
374
  if (cc->rk_context_id == -1)
 
375
     return uim_scm_f();
 
376
 
 
377
  RkGoTo(cc->rk_context_id, s);
 
378
  RkNfer(cc->rk_context_id);
 
379
 
 
380
  if (nth > 0)
 
381
      cc->segment_num = RkEnlarge(cc->rk_context_id);
425
382
  else
426
 
      cc->segment_num = api.RkShorten(cc->rk_context_id);
 
383
      cc->segment_num = RkShorten(cc->rk_context_id);
427
384
 
428
385
  _update_segment(id, cc->current_segment_num);
429
386
 
430
 
  return true_sym;
 
387
  return uim_scm_t();
431
388
}
432
389
 
433
 
static LISP
434
 
commit_segment(LISP id_, LISP s_, LISP nth_)
 
390
static uim_lisp
 
391
commit_segment(uim_lisp id_, uim_lisp s_, uim_lisp nth_)
435
392
{
436
393
  int id = uim_scm_c_int(id_);
 
394
#if 0
437
395
  int s = uim_scm_c_int(s_);
438
396
  int nth = uim_scm_c_int(nth_);
 
397
#endif
439
398
  struct canna_context *cc = get_canna_context(id);
440
399
 
441
 
  if(cc == NULL)
442
 
     return NIL;
443
 
 
444
 
  if(cc->rk_context_id == -1)
445
 
     return NIL;
446
 
 
447
 
  api.RkEndBun(cc->rk_context_id, 1);
 
400
  if (cc == NULL)
 
401
     return uim_scm_f();
 
402
 
 
403
  if (cc->rk_context_id == -1)
 
404
     return uim_scm_f();
 
405
 
 
406
  RkEndBun(cc->rk_context_id, 1);
448
407
  cc->segment_num = -1;
 
408
 
 
409
  return uim_scm_t();
449
410
}
450
411
 
451
 
static LISP
452
 
reset_conversion(LISP id_)
 
412
static uim_lisp
 
413
reset_conversion(uim_lisp id_)
453
414
{
454
415
  int id = uim_scm_c_int(id_);
455
416
 
456
417
  _reset_conversion(id);
457
 
}
458
 
 
459
 
void
460
 
uim_init_canna(void)
461
 
{
462
 
  true_sym = siod_true_value();
463
 
  init_subr_1("canna-lib-init", init_canna_lib);
464
 
 
465
 
  init_subr_0("canna-lib-alloc-context", create_context);
466
 
  init_subr_1("canna-lib-release-context", release_context);
467
 
  init_subr_3("canna-lib-get-nth-candidate", get_nth_candidate);
468
 
  init_subr_1("canna-lib-get-nr-segments",get_nr_segments);
469
 
  init_subr_2("canna-lib-get-nr-candidates", get_nr_candidate);
470
 
  init_subr_3("canna-lib-resize-segment", resize_segment);
471
 
  init_subr_2("canna-lib-begin-conversion", begin_conversion);
472
 
  init_subr_3("canna-lib-commit-segment", commit_segment);
473
 
  init_subr_1("canna-lib-reset-conversion", reset_conversion);
474
 
}
475
 
 
476
 
void
477
 
uim_quit_canna(void)
478
 
{
479
 
  if(cannaserver != NULL) {
 
418
 
 
419
  return uim_scm_t();
 
420
}
 
421
 
 
422
void
 
423
uim_plugin_instance_init(void)
 
424
{
 
425
  uim_scm_init_subr_1("canna-lib-init", init_canna_lib);
 
426
 
 
427
  uim_scm_init_subr_0("canna-lib-alloc-context", create_context);
 
428
  uim_scm_init_subr_1("canna-lib-release-context", release_context);
 
429
  uim_scm_init_subr_3("canna-lib-get-nth-candidate", get_nth_candidate);
 
430
  uim_scm_init_subr_1("canna-lib-get-nr-segments",get_nr_segments);
 
431
  uim_scm_init_subr_2("canna-lib-get-nr-candidates", get_nr_candidate);
 
432
  uim_scm_init_subr_3("canna-lib-resize-segment", resize_segment);
 
433
  uim_scm_init_subr_2("canna-lib-begin-conversion", begin_conversion);
 
434
  uim_scm_init_subr_3("canna-lib-commit-segment", commit_segment);
 
435
  uim_scm_init_subr_1("canna-lib-reset-conversion", reset_conversion);
 
436
}
 
437
 
 
438
void
 
439
uim_plugin_instance_quit(void)
 
440
{
 
441
  if (cannaserver != NULL) {
480
442
     free(cannaserver);
481
443
     cannaserver = NULL;
482
444
  }
483
445
 
484
 
  if(api.RkFinalize && rk_initialized == 1) {
485
 
     api.RkFinalize();
 
446
  if (/* RkFinalize && */ rk_initialized == 1) {
 
447
     RkFinalize();
486
448
     rk_initialized = -1;
487
449
  }
488
450
 
489
 
  if(api.lib) {
490
 
     dlclose(api.lib);
491
 
     memset(&api, 0, sizeof(struct canna_api));
492
 
  }
493
 
 
494
 
  if(context_array != NULL) {
 
451
  if (context_array != NULL) {
495
452
     free(context_array);
496
453
     context_array = NULL;
497
454
  }