3
Copyright (c) 2003-2011 uim Project http://code.google.com/p/uim/
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions
11
1. Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
2. Redistributions in binary form must reproduce the above copyright
14
notice, this list of conditions and the following disclaimer in the
15
documentation and/or other materials provided with the distribution.
16
3. Neither the name of authors nor the names of its contributors
17
may be used to endorse or promote products derived from this software
18
without specific prior written permission.
20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
21
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34
/* FIXME! This is a ad-hoc solution to advance
35
annotation related discussion. */
42
#include <sys/types.h>
48
#include <eb/binary.h>
53
#include "uim-notify.h"
60
#define MAX_LENGTH 10000
64
EB_Subbook_Code subCodes[EB_MAX_SUBBOOKS];
68
static void go_text_eb (uim_eb *ueb,
74
uim_eb_strappend(char **dest, const char *append, size_t append_len)
78
size_t dest_len = strlen(*dest);
79
size_t len = dest_len + append_len;
81
str = uim_realloc(*dest, len + 1);
82
memcpy(&str[dest_len], append, append_len);
88
str = uim_malloc(append_len + 1);
89
memcpy(str, append, append_len);
90
str[append_len] = '\0';
101
err = eb_initialize_library();
102
if (err != EB_SUCCESS)
103
uim_notify_fatal(_("eb: failed to initialize EB library : error = %s\n"),
104
eb_error_message(err));
110
eb_finalize_library();
114
uim_eb_new (const char *bookpath)
119
ueb = uim_malloc(sizeof(uim_eb));
121
eb_initialize_book(&ueb->book);
123
err = eb_bind(&ueb->book, bookpath);
124
if (err != EB_SUCCESS) {
125
uim_notify_fatal(N_("eb: wrong bookpath"));
130
err = eb_subbook_list(&ueb->book, ueb->subCodes, &ueb->subCount);
131
if (err != EB_SUCCESS) {
132
uim_notify_fatal(N_("eb: eb_subbook_list() failed\n"));
141
uim_eb_destroy (uim_eb *ueb)
144
eb_finalize_book(&ueb->book);
152
uim_eb_search_text (uim_eb *ueb, const char *key, const char *enc)
159
/* FIXME! check return value */
161
cd = (iconv_t)uim_iconv->create("EUC-JP", enc);
162
text = uim_iconv->convert(cd, key);
163
uim_iconv->release(cd);
168
for (i = 0; i < ueb->subCount; i++) {
169
EB_Hit hits[MAX_HITS];
173
/* specify subbook */
174
if (eb_set_subbook(&ueb->book, ueb->subCodes[i]) != EB_SUCCESS) {
175
uim_notify_fatal(N_("eb: eb_set_subbook() failed")); continue;
178
eb_search_word(&ueb->book, text);
179
eb_hit_list(&ueb->book, MAX_HITS, hits, &hitCount);
180
for (j = 0; j < hitCount; j++) {
181
/*EB_Position headp = hits[j].heading;*/
182
EB_Position textp = hits[j].text;
184
go_text_eb(ueb, textp, &str, enc);
185
uim_eb_strappend(&str, "\n", sizeof("\n"));
196
go_text_eb (uim_eb *ueb, EB_Position position, char **str, const char *enc)
199
char text[MAX_TEXT + 1];
204
if (eb_seek_text(&ueb->book, &position) != EB_SUCCESS) {
205
uim_notify_fatal(N_("eb: eb_seek_text error occurs"));
209
eb_initialize_hookset(&hookset);
210
for (i = 0; i < 1; i++) {
214
if (eb_read_text(&ueb->book, NULL, &hookset,
215
NULL, MAX_TEXT, text, &text_length) != EB_SUCCESS) {
217
uim_notify_fatal(N_("eb_read_text : an error occurs"));
221
bytes += text_length;
225
/* FIXME! check return value */
226
cd = (iconv_t)uim_iconv->create(enc, "EUC-JP");
227
local = uim_iconv->convert(cd, text);
228
uim_iconv->release(cd);
230
uim_eb_strappend(str, local, strlen(local));
234
eb_finalize_hookset(&hookset);