3
Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
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. */
43
#include <eb/binary.h>
50
#define MAX_LENGTH 10000
54
EB_Subbook_Code subCodes[EB_MAX_SUBBOOKS];
58
static void go_text_eb (uim_eb *ueb,
62
static unsigned int eb_ref_count = 0;
65
uim_eb_new (const char *bookpath)
70
ueb = malloc(sizeof(uim_eb));
73
err = eb_initialize_library();
74
if (err != EB_SUCCESS)
75
fprintf(stderr, "failed to initialize EB library : error = %s\n",
76
eb_error_message(err));
78
eb_initialize_book(&ueb->book);
80
err = eb_bind(&ueb->book, bookpath);
81
if (err != EB_SUCCESS) {
82
fprintf(stderr, "wrong bookpath\n");
87
err = eb_subbook_list(&ueb->book, ueb->subCodes, &ueb->subCount);
88
if (err != EB_SUCCESS) {
89
g_printerr("eb_subbook_list() failed\n");
99
uim_eb_destroy (uim_eb *ueb)
104
eb_finalize_book(&ueb->book);
107
if (eb_ref_count == 0)
108
eb_finalize_library();
113
uim_eb_search_text (uim_eb *ueb, const gchar *text_utf8)
117
gsize bytes_read, bytes_written;
120
/* FIXME! check return value */
121
text = g_convert(text_utf8, strlen(text_utf8),
123
&bytes_read, &bytes_written,
125
g_return_val_if_fail(text, FALSE);
127
str = g_string_new("");
129
for (i = 0; i < ueb->subCount; i++) {
130
EB_Hit hits[MAX_HITS];
134
/* specify subbook */
135
if (eb_set_subbook(&ueb->book, ueb->subCodes[i]) != EB_SUCCESS) {
136
g_print("eb_set_subbook() failed\n"); continue;
139
eb_search_word(&ueb->book, text);
140
eb_hit_list(&ueb->book, MAX_HITS, hits, &hitCount);
141
for (j = 0; j < hitCount; j++) {
142
/*EB_Position headp = hits[j].heading;*/
143
EB_Position textp = hits[j].text;
145
go_text_eb(ueb, textp, str);
146
g_string_append(str, "\n");
152
return g_string_free(str, FALSE);
157
go_text_eb (uim_eb *ueb, EB_Position position, GString *str)
160
char text[MAX_TEXT + 1];
165
if (eb_seek_text(&ueb->book, &position) != EB_SUCCESS) {
166
g_print("eb_seek_text error occurs");
170
eb_initialize_hookset(&hookset);
171
for (i = 0; i < 1; i++) {
173
gsize bytes_read, bytes_written;
175
if (eb_read_text(&ueb->book, NULL, &hookset,
176
NULL, MAX_TEXT, text, &text_length) != EB_SUCCESS) {
178
g_print("eb_read_text : an error occurs.\n");
182
bytes += text_length;
186
/* FIXME! check return value */
187
text_utf8 = g_convert(text, strlen(text),
189
&bytes_read, &bytes_written,
191
g_string_append(str, text_utf8);
194
eb_finalize_hookset(&hookset);