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

« back to all changes in this revision

Viewing changes to helper/dict-anthy.c

  • Committer: Bazaar Package Importer
  • Author(s): Steinar H. Gunderson
  • Date: 2006-07-06 22:17:24 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060706221724-6sobw1fcsxj647hp
Tags: 1:1.1.0-1.2
* Non-maintainer upload.
* Added -Wno-cast-align to CFLAGS, as per the RM's recommendations:

  < vorlon> Sesse: -Wno-cast-align and to hell with it :P

  Really fixes FTBFS. (Really Closes: #375081)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  $Id:$
3
3
 *  Copyright (c) 2003,2004 Masahito Omote <omote@utyuuzin.net>
4
 
 *                2005 uim Project http://uim.freedesktop.org/
 
4
 *                2005-2006 uim Project http://uim.freedesktop.org/
5
5
 *
6
6
 *  All rights reserved.
7
7
 *
37
37
#include <stdlib.h>
38
38
#include <glib.h>
39
39
 
 
40
#include <anthy/dicutil.h>
 
41
 
40
42
#include "uim/gettext.h"
41
43
#include "dict-anthy.h"
42
44
#include "dict-canna.h"
78
80
  N_("Anthy private dictionary"),
79
81
};
80
82
 
81
 
struct _anthy_dic_api {
82
 
    void        (*util_init)                   (void);
83
 
    void        (*util_set_personality)        (char *);
84
 
    const char *(*util_get_anthydir)           (void);
85
 
 
86
 
    void        (*priv_dic_delete)             (void);
87
 
    int         (*priv_dic_select_first_entry) (void);
88
 
    int         (*priv_dic_select_next_entry)  (void);
89
 
    int         (*priv_dic_select_entry)       (char *);
90
 
 
91
 
    char       *(*priv_dic_get_index)          (char *, int);
92
 
    int         (*priv_dic_get_freq)           (void);
93
 
    char       *(*priv_dic_get_wtype)          (char *, int);
94
 
    char       *(*priv_dic_get_word)           (char *, int);
95
 
 
96
 
    int         (*priv_dic_add_entry)          (char *, char *, char *, int);
97
 
};
98
 
static struct _anthy_dic_api anthy_dic_api;
99
 
static void *anthy_dic_lib;
100
 
 
101
 
#ifdef __APPLE__
102
 
  #define ANTHYDIC_DYLIB        "libanthydic.0.dylib"
103
 
#else
104
 
  #define ANTHYDIC_DYLIB        "libanthydic.so.0"
105
 
#endif
106
 
static int
107
 
get_anthydic_api()
108
 
{
109
 
    anthy_dic_lib = dlopen(ANTHYDIC_DYLIB, RTLD_GLOBAL |RTLD_NOW);
110
 
    if (anthy_dic_lib == NULL) {
111
 
        return -1;
112
 
    }
113
 
 
114
 
    anthy_dic_api.util_init = dlsym(anthy_dic_lib, "anthy_dic_util_init");
115
 
    anthy_dic_api.util_set_personality = dlsym(anthy_dic_lib, "anthy_dic_util_set_personality");
116
 
    anthy_dic_api.util_get_anthydir = dlsym(anthy_dic_lib, "anthy_dic_util_get_anthydir");
117
 
 
118
 
    anthy_dic_api.priv_dic_delete = dlsym(anthy_dic_lib, "anthy_priv_dic_delete");
119
 
    anthy_dic_api.priv_dic_select_first_entry = dlsym(anthy_dic_lib, "anthy_priv_dic_select_first_entry");
120
 
    anthy_dic_api.priv_dic_select_next_entry = dlsym(anthy_dic_lib, "anthy_priv_dic_select_next_entry");
121
 
    anthy_dic_api.priv_dic_select_entry = dlsym(anthy_dic_lib, "anthy_priv_dic_select_entry");
122
 
 
123
 
    anthy_dic_api.priv_dic_get_index = dlsym(anthy_dic_lib, "anthy_priv_dic_get_index");
124
 
    anthy_dic_api.priv_dic_get_freq = dlsym(anthy_dic_lib, "anthy_priv_dic_get_freq");
125
 
    anthy_dic_api.priv_dic_get_wtype = dlsym(anthy_dic_lib, "anthy_priv_dic_get_wtype");
126
 
    anthy_dic_api.priv_dic_get_word = dlsym(anthy_dic_lib, "anthy_priv_dic_get_word");
127
 
 
128
 
    anthy_dic_api.priv_dic_add_entry = dlsym(anthy_dic_lib, "anthy_priv_dic_add_entry");
129
 
 
130
 
    if (!anthy_dic_api.util_init && !anthy_dic_api.util_set_personality
131
 
       && !anthy_dic_api.util_get_anthydir && !anthy_dic_api.priv_dic_delete
132
 
       && !anthy_dic_api.priv_dic_select_first_entry
133
 
       && !anthy_dic_api.priv_dic_select_next_entry
134
 
       && !anthy_dic_api.priv_dic_select_entry
135
 
       && !anthy_dic_api.priv_dic_get_index
136
 
       && !anthy_dic_api.priv_dic_get_freq
137
 
       && !anthy_dic_api.priv_dic_get_wtype
138
 
       && !anthy_dic_api.priv_dic_get_word
139
 
       && !anthy_dic_api.priv_dic_add_entry) {
140
 
        dlclose(anthy_dic_lib);
141
 
        return -1;
142
 
    }
143
 
    return 0;
144
 
}
145
 
 
146
83
static int
147
84
dict_anthy_init(void)
148
85
{
149
 
    if (get_anthydic_api() == -1)
150
 
        return -1;
151
 
    anthy_dic_api.util_init();
152
 
    return 0;
 
86
  anthy_dic_util_init();
 
87
  return 0;
153
88
}
154
89
 
155
90
static int
156
91
dict_anthy_exit(void)
157
92
{
158
 
    if (anthy_dic_lib)
159
 
        return dlclose(anthy_dic_lib);
160
 
    else
161
 
        return -1;
 
93
  anthy_dic_util_quit();
 
94
  return 0;
162
95
}
163
96
 
164
97
static int
165
98
dict_anthy_read_priv_dic_list(uim_word **head)
166
99
{
167
 
    char phon[100], desc[100], cclass_code[100];
168
 
    int ret = 0;
169
 
 
170
 
    if (anthy_dic_api.priv_dic_select_first_entry() == -1) {
171
 
        *head = NULL;
172
 
        return -1;
173
 
    }
174
 
 
175
 
    while (ret == 0) {
176
 
        if (anthy_dic_api.priv_dic_get_index(phon, sizeof(phon))
177
 
           && anthy_dic_api.priv_dic_get_wtype(cclass_code, sizeof(cclass_code))
178
 
           && anthy_dic_api.priv_dic_get_word(desc, sizeof(desc))) {
179
 
            gint pos;
180
 
            char *cclass_desc = NULL;
181
 
 
182
 
            for (pos = 0; pos < NR_POS; pos++) {
183
 
                cclass_desc = find_desc_from_code(cclass_code, pos);
184
 
                if (cclass_desc) break;
185
 
            }
186
 
 
187
 
            word_append(head, WORD_TYPE_ANTHY,
188
 
                        "EUC-JP",
189
 
                        phon, desc, cclass_desc,
190
 
                        anthy_dic_api.priv_dic_get_freq(),
191
 
                        0, NULL);
192
 
        }
193
 
        ret = anthy_dic_api.priv_dic_select_next_entry();
194
 
    }
195
 
    return 0;
 
100
  char phon[100], desc[100], cclass_native[100];
 
101
  int ret = 0;
 
102
 
 
103
  if (anthy_priv_dic_select_first_entry() == -1) {
 
104
    *head = NULL;
 
105
    return -1;
 
106
  }
 
107
 
 
108
  while (ret == 0) {
 
109
    if (anthy_priv_dic_get_index(phon, sizeof(phon))
 
110
        && anthy_priv_dic_get_wtype(cclass_native,
 
111
                                    sizeof(cclass_native))
 
112
        && anthy_priv_dic_get_word(desc, sizeof(desc))) {
 
113
      gint pos;
 
114
      const char *cclass_code = NULL;
 
115
 
 
116
      for (pos = 0; pos < NR_POS; pos++) {
 
117
        cclass_code = find_desc_from_code_with_type(cclass_native, pos);
 
118
        if (cclass_code)
 
119
          break;
 
120
      }
 
121
 
 
122
      word_append(head, WORD_TYPE_ANTHY, "EUC-JP",
 
123
                  phon, desc, cclass_code, cclass_native,
 
124
                  anthy_priv_dic_get_freq(),
 
125
                  0, NULL);
 
126
    }
 
127
    ret = anthy_priv_dic_select_next_entry();
 
128
  }
 
129
  return 0;
196
130
}
197
131
 
198
132
static int
199
133
dict_anthy_add_priv_dic_with_flags(char *phon, char *desc,
200
134
                                   char *cclass_code, int freq)
201
135
{
202
 
    if ((strlen(phon) == 0) ||
203
 
       (strlen(desc) == 0) ||
204
 
       (strlen(cclass_code) == 0)) {
205
 
        return -1;
206
 
    }
 
136
  if ((strlen(phon) == 0) || (strlen(desc) == 0) ||
 
137
      (strlen(cclass_code) == 0)) {
 
138
    return -1;
 
139
  }
207
140
 
208
 
    return anthy_dic_api.priv_dic_add_entry(phon, desc,
209
 
                                            cclass_code, freq);
 
141
  return anthy_priv_dic_add_entry(phon, desc, cclass_code, freq);
210
142
}
211
143
 
212
144
static int
213
145
dict_anthy_delete_priv_dic(char *phon, char *desc, char *cclass_code)
214
146
{
215
 
    return anthy_dic_api.priv_dic_add_entry(phon, desc,
216
 
                                            cclass_code, 0);
 
147
  return anthy_priv_dic_add_entry(phon, desc, cclass_code, 0);
217
148
}
218
149
 
219
150
static uim_dict *
258
189
  free(dict->filename);
259
190
  free(dict->charset);
260
191
  free(dict);
 
192
 
 
193
  dict_anthy_exit();
261
194
}
262
195
 
263
196
static int
268
201
  if (dict == NULL || word == NULL)
269
202
    return -1;
270
203
 
271
 
  /* FIXME! refresh word list */
272
204
  ret = dict_anthy_add_priv_dic_with_flags(word->phon, word->desc,
273
 
                                           word->cclass_code, word->freq);
 
205
                                           word->cclass_native, word->freq);
274
206
 
275
207
  return ret;
276
208
}
290
222
    return 0;
291
223
 
292
224
  ret = dict_anthy_delete_priv_dic(word->phon, word->desc,
293
 
                                   word->cclass_code);
 
225
                                   word->cclass_native);
294
226
 
295
 
  return ret;
 
227
  return ret ? 0 : 1;
296
228
}
297
229
 
298
230
static void