| 1 |
/* This file is part of GNU Dico. |
| 2 |
Copyright (C) 2012-2024 Sergey Poznyakoff |
| 3 |
|
| 4 |
GNU Dico is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation; either version 3, or (at your option) |
| 7 |
any later version. |
| 8 |
|
| 9 |
GNU Dico is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. */ |
| 16 |
|
| 17 |
#include <config.h> |
| 18 |
#include <stdlib.h> |
| 19 |
#include <unistd.h> |
| 20 |
#include <sys/types.h> |
| 21 |
#include <signal.h> |
| 22 |
#include <sys/stat.h> |
| 23 |
#include <sys/wait.h> |
| 24 |
#include <dico.h> |
| 25 |
#include "gcide.h" |
| 26 |
#include <errno.h> |
| 27 |
#include <appi18n.h> |
| 28 |
#include <assert.h> |
| 29 |
|
| 30 |
#define GCIDE_NOPR 0x01 |
| 31 |
#define GCIDE_DBGLEX 0x02 |
| 32 |
#define GCIDE_WATCHER 0x04 |
| 33 |
#define GCIDE_IDX_FAIL 0x08 |
| 34 |
#define GCIDE_HTML 0x10 |
| 35 |
|
| 36 |
struct gcide_db { |
| 37 |
char *db_dir; |
| 38 |
char *idx_dir; |
| 39 |
char *tmpl_name; |
| 40 |
char *tmpl_letter; |
| 41 |
char *idxgcide; |
| 42 |
int flags; |
| 43 |
time_t latest_change; |
| 44 |
|
| 45 |
int file_letter; |
| 46 |
dico_stream_t file_stream; |
| 47 |
|
| 48 |
size_t idx_cache_size; |
| 49 |
gcide_idx_file_t idx; |
| 50 |
|
| 51 |
WATCHER watcher; |
| 52 |
}; |
| 53 |
|
| 54 |
enum result_type { |
| 55 |
result_match, |
| 56 |
result_define |
| 57 |
}; |
| 58 |
|
| 59 |
struct gcide_result { |
| 60 |
enum result_type type; |
| 61 |
struct gcide_db *db; |
| 62 |
size_t compare_count; |
| 63 |
dico_iterator_t itr; |
| 64 |
dico_list_t list; |
| 65 |
}; |
| 66 |
|
| 67 |
static char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
| 68 |
static char *idxgcide_program = LIBEXECDIR "/idxgcide"; |
| 69 |
|
| 70 |
static void |
| 71 |
free_db(struct gcide_db *db) |
| 72 |
{ |
| 73 |
free(db->db_dir); |
| 74 |
free(db->idx_dir); |
| 75 |
free(db->tmpl_name); |
| 76 |
free(db->idxgcide); |
| 77 |
if (db->file_stream) { |
| 78 |
dico_stream_close(db->file_stream); |
| 79 |
dico_stream_destroy(&db->file_stream); |
| 80 |
} |
| 81 |
gcide_idx_file_close(db->idx); |
| 82 |
watcher_close(db->watcher); |
| 83 |
free(db); |
| 84 |
} |
| 85 |
|
| 86 |
static int |
| 87 |
gcide_check_dir(const char *dir) |
| 88 |
{ |
| 89 |
struct stat st; |
| 90 |
|
| 91 |
if (stat(dir, &st)) { |
| 92 |
dico_log(L_ERR, errno, _("gcide: cannot stat `%s'"), dir); |
| 93 |
return 1; |
| 94 |
} |
| 95 |
if (!S_ISDIR(st.st_mode)) { |
| 96 |
dico_log(L_ERR, 0, _("gcide: `%s' is not a directory"), dir); |
| 97 |
return 1; |
| 98 |
} |
| 99 |
if (access(dir, R_OK)) { |
| 100 |
dico_log(L_ERR, 0, _("gcide: `%s' is not readable"), dir); |
| 101 |
return 1; |
| 102 |
} |
| 103 |
return 0; |
| 104 |
} |
| 105 |
|
| 106 |
static char * |
| 107 |
gcide_template_name(struct gcide_db *db, int let) |
| 108 |
{ |
| 109 |
*db->tmpl_letter = let; |
| 110 |
return db->tmpl_name; |
| 111 |
} |
| 112 |
|
| 113 |
static inline char * |
| 114 |
idxgcide_name(struct gcide_db *db) |
| 115 |
{ |
| 116 |
return db->idxgcide ? db->idxgcide : idxgcide_program; |
| 117 |
} |
| 118 |
|
| 119 |
static int |
| 120 |
gcide_run_idxgcide(struct gcide_db *db, int fd) |
| 121 |
{ |
| 122 |
pid_t pid; |
| 123 |
int status; |
| 124 |
char *idxgcide = idxgcide_name(db); |
| 125 |
|
| 126 |
dico_log(L_NOTICE, 0, _("gcide_run_idxgcide: creating index %s/%s"), |
| 127 |
db->idx_dir, GCIDE_IDX_FILE_NAME); |
| 128 |
if (access(idxgcide, X_OK)) { |
| 129 |
dico_log(L_ERR, errno, _("gcide_run_idxgcide: cannot run %s"), |
| 130 |
idxgcide); |
| 131 |
return 1; |
| 132 |
} |
| 133 |
pid = fork(); |
| 134 |
if (pid == 0) { |
| 135 |
char *argv[6]; |
| 136 |
int i = 0; |
| 137 |
|
| 138 |
argv[i++] = idxgcide; |
| 139 |
if (fd > 0) { |
| 140 |
char buf[16]; |
| 141 |
char *p = buf + sizeof(buf) - 1; |
| 142 |
|
| 143 |
*p = 0; |
| 144 |
while (fd > 0) { |
| 145 |
assert(p > buf); |
| 146 |
*--p = fd % 10 + '0'; |
| 147 |
fd /= 10; |
| 148 |
} |
| 149 |
|
| 150 |
argv[i++] = "-#"; |
| 151 |
argv[i++] = p; |
| 152 |
} |
| 153 |
argv[i++] = db->db_dir; |
| 154 |
argv[i++] = db->idx_dir; |
| 155 |
argv[i] = NULL; |
| 156 |
execv(idxgcide, argv); |
| 157 |
_exit(127); |
| 158 |
} |
| 159 |
if (pid == -1) { |
| 160 |
dico_log(L_ERR, errno, _("gcide_run_idxgcide: fork failed")); |
| 161 |
return 1; |
| 162 |
} |
| 163 |
if (waitpid(pid, &status, 0) != pid) { |
| 164 |
dico_log(L_ERR, errno, _("gcide_run_idxgcide: %s failed"), idxgcide); |
| 165 |
kill(pid, SIGKILL); |
| 166 |
return -1; |
| 167 |
} |
| 168 |
if (!WIFEXITED(status)) { |
| 169 |
dico_log(L_ERR, 0, _("gcide_run_idxgcide: %s failed"), idxgcide); |
| 170 |
return -1; |
| 171 |
} |
| 172 |
|
| 173 |
status = WEXITSTATUS(status); |
| 174 |
if (status) { |
| 175 |
dico_log(L_ERR, 0, |
| 176 |
_("gcide_run_idxgcide: %s exited with status %d"), |
| 177 |
idxgcide, status); |
| 178 |
return -1; |
| 179 |
} |
| 180 |
return 0; |
| 181 |
} |
| 182 |
|
| 183 |
static int |
| 184 |
gcide_check_files(struct gcide_db *db) |
| 185 |
{ |
| 186 |
int i; |
| 187 |
time_t t = 0; |
| 188 |
struct stat st; |
| 189 |
|
| 190 |
for (i = 0; letters[i]; i++) { |
| 191 |
char *p = gcide_template_name(db, letters[i]); |
| 192 |
if (access(p, R_OK)) { |
| 193 |
dico_log(L_ERR, 0, _("gcide: `%s' is not readable"), p); |
| 194 |
return 1; |
| 195 |
} |
| 196 |
if (stat(p, &st)) { |
| 197 |
dico_log(L_ERR, errno, _("gcide: can't stat `%s'"), p); |
| 198 |
return 1; |
| 199 |
} |
| 200 |
if (st.st_mtime > t) |
| 201 |
t = st.st_mtime; |
| 202 |
} |
| 203 |
db->latest_change = t; |
| 204 |
return 0; |
| 205 |
} |
| 206 |
|
| 207 |
static int |
| 208 |
gcide_db_reindex(struct gcide_db *db, int force) |
| 209 |
{ |
| 210 |
if (!force) { |
| 211 |
struct stat st; |
| 212 |
if (fstat(gcide_idx_fileno(db->idx), &st)) |
| 213 |
return -1; |
| 214 |
if (gcide_check_files(db)) |
| 215 |
return -1; |
| 216 |
force = db->latest_change > st.st_mtime; |
| 217 |
} |
| 218 |
if (force) { |
| 219 |
if (gcide_idx_lock(db->idx, 1)) { |
| 220 |
dico_log(L_ERR, errno, _("gcide: can't lock index file")); |
| 221 |
return -1; |
| 222 |
} |
| 223 |
gcide_run_idxgcide(db, gcide_idx_fileno(db->idx)); |
| 224 |
return gcide_idx_reopen(db->idx); |
| 225 |
} |
| 226 |
return 0; |
| 227 |
} |
| 228 |
|
| 229 |
/* Try to access IDXNAME. Return 0 on success, 1 if it should be (re)created |
| 230 |
and -1 on error */ |
| 231 |
static int |
| 232 |
gcide_access_idx(struct gcide_db *db, char *idxname) |
| 233 |
{ |
| 234 |
int rc = 1; |
| 235 |
struct stat st; |
| 236 |
|
| 237 |
if (access(idxname, R_OK) == 0) { |
| 238 |
if (stat(idxname, &st)) { |
| 239 |
dico_log(L_ERR, errno, _("gcide: can't stat `%s'"), idxname); |
| 240 |
/* try to create it, anyway */ |
| 241 |
} else if (db->latest_change <= st.st_mtime) |
| 242 |
rc = 0; |
| 243 |
else |
| 244 |
dico_log(L_NOTICE, 0, |
| 245 |
_("gcide: index file older than database, reindexing")); |
| 246 |
} else if (errno != ENOENT) { |
| 247 |
dico_log(L_ERR, errno, _("gcide_open_idx: cannot access %s"), |
| 248 |
idxname); |
| 249 |
rc = -1; |
| 250 |
} |
| 251 |
return rc; |
| 252 |
} |
| 253 |
|
| 254 |
static int |
| 255 |
print_idx_error(int rc, char const *idxname, int reindex) |
| 256 |
{ |
| 257 |
switch (rc) { |
| 258 |
case IDXE_OK: |
| 259 |
return 0; |
| 260 |
|
| 261 |
case IDXE_BADFILE: |
| 262 |
dico_log(L_ERR, 0, _("file `%s' is not a valid gcide index file"), |
| 263 |
idxname); |
| 264 |
break; |
| 265 |
|
| 266 |
case IDXE_BADVER: |
| 267 |
dico_log(reindex ? L_WARN : L_ERR, 0, |
| 268 |
_("file `%s' has unsupported version number"), |
| 269 |
idxname); |
| 270 |
break; |
| 271 |
|
| 272 |
case IDXE_CORRUPT: |
| 273 |
dico_log(L_ERR, 0, _("index file `%s' is corrupted"), idxname); |
| 274 |
break; |
| 275 |
|
| 276 |
case IDXE_SYSERR: |
| 277 |
dico_log(L_ERR, errno, "%s", idxname); |
| 278 |
break; |
| 279 |
} |
| 280 |
return rc; |
| 281 |
} |
| 282 |
|
| 283 |
static int |
| 284 |
gcide_open_idx(struct gcide_db *db) |
| 285 |
{ |
| 286 |
int rc = 1; |
| 287 |
char *idxname; |
| 288 |
int reindex = 1; |
| 289 |
|
| 290 |
idxname = dico_full_file_name(db->idx_dir, GCIDE_IDX_FILE_NAME); |
| 291 |
if (!idxname) { |
| 292 |
DICO_LOG_MEMERR(); |
| 293 |
return 1; |
| 294 |
} |
| 295 |
|
| 296 |
rc = gcide_access_idx(db, idxname); |
| 297 |
if (rc == 1) { |
| 298 |
rc = gcide_run_idxgcide(db, -1); |
| 299 |
reindex = 0; |
| 300 |
} |
| 301 |
|
| 302 |
if (rc == 0) { |
| 303 |
if (db->idx) { |
| 304 |
gcide_idx_file_close(db->idx); |
| 305 |
db->idx = NULL; |
| 306 |
} |
| 307 |
rc = gcide_idx_file_open(idxname, db->idx_cache_size, |
| 308 |
db->flags & GCIDE_WATCHER, |
| 309 |
&db->idx); |
| 310 |
if (rc != IDXE_OK) { |
| 311 |
print_idx_error(rc, idxname, reindex); |
| 312 |
if (reindex && (rc == IDXE_BADVER || rc == IDXE_CORRUPT)) { |
| 313 |
rc = gcide_run_idxgcide(db, -1); |
| 314 |
if (rc == 0) { |
| 315 |
rc = gcide_idx_file_open(idxname, db->idx_cache_size, |
| 316 |
db->flags & GCIDE_WATCHER, |
| 317 |
&db->idx); |
| 318 |
print_idx_error(rc, idxname, 0); |
| 319 |
} |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
free(idxname); |
| 325 |
return rc; |
| 326 |
} |
| 327 |
|
| 328 |
static dico_handle_t |
| 329 |
gcide_init_db(const char *dbname, int argc, char **argv) |
| 330 |
{ |
| 331 |
char *db_dir = NULL; |
| 332 |
char *idx_dir = NULL; |
| 333 |
char *idxgcide = NULL; |
| 334 |
long idx_cache_size = 16; |
| 335 |
int flags = 0; |
| 336 |
struct gcide_db *db; |
| 337 |
|
| 338 |
struct dico_option init_db_option[] = { |
| 339 |
{ DICO_OPTSTR(dbdir), dico_opt_string, &db_dir }, |
| 340 |
{ DICO_OPTSTR(idxdir), dico_opt_string, &idx_dir }, |
| 341 |
{ DICO_OPTSTR(index-program), dico_opt_string, &idxgcide }, |
| 342 |
{ DICO_OPTSTR(index-cache-size), dico_opt_long, &idx_cache_size }, |
| 343 |
{ DICO_OPTSTR(suppress-pr), dico_opt_bitmask, &flags, |
| 344 |
.v.value = GCIDE_NOPR }, |
| 345 |
{ DICO_OPTSTR(debug-lex), dico_opt_bitmask, &flags, |
| 346 |
.v.value = GCIDE_DBGLEX }, |
| 347 |
{ DICO_OPTSTR(watch), dico_opt_bitmask, &flags, |
| 348 |
.v.value = GCIDE_WATCHER }, |
| 349 |
{ DICO_OPTSTR(html), dico_opt_bitmask, &flags, |
| 350 |
.v.value = GCIDE_HTML }, |
| 351 |
{ NULL } |
| 352 |
}; |
| 353 |
|
| 354 |
if (dico_parseopt(init_db_option, argc, argv, 0, NULL)) |
| 355 |
return NULL; |
| 356 |
if (!db_dir) { |
| 357 |
dico_log(L_ERR, 0, |
| 358 |
_("gcide_init_db: database directory not given")); |
| 359 |
return NULL; |
| 360 |
} |
| 361 |
if (!idx_dir) { |
| 362 |
idx_dir = strdup(db_dir); |
| 363 |
if (!idx_dir) { |
| 364 |
DICO_LOG_ERRNO(); |
| 365 |
free(db_dir); |
| 366 |
return NULL; |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
db = calloc(1, sizeof(*db)); |
| 371 |
if (!db) { |
| 372 |
DICO_LOG_MEMERR(); |
| 373 |
free(db_dir); |
| 374 |
free(idx_dir); |
| 375 |
return NULL; |
| 376 |
} |
| 377 |
db->db_dir = db_dir; |
| 378 |
db->idx_dir = idx_dir; |
| 379 |
db->idx_cache_size = idx_cache_size; |
| 380 |
db->flags = flags; |
| 381 |
|
| 382 |
if (gcide_check_dir(db->db_dir) || gcide_check_dir(db->idx_dir)) { |
| 383 |
free_db(db); |
| 384 |
return NULL; |
| 385 |
} |
| 386 |
|
| 387 |
db->tmpl_name = dico_full_file_name(db->db_dir, "CIDE.A"); |
| 388 |
db->tmpl_letter = db->tmpl_name + strlen(db->tmpl_name) - 1; |
| 389 |
if (gcide_check_files(db)) { |
| 390 |
free_db(db); |
| 391 |
return NULL; |
| 392 |
} |
| 393 |
db->idxgcide = idxgcide; |
| 394 |
if (gcide_open_idx(db)) { |
| 395 |
free_db(db); |
| 396 |
return NULL; |
| 397 |
} |
| 398 |
if (flags & GCIDE_WATCHER) { |
| 399 |
db->watcher = watcher_setup(db->db_dir); |
| 400 |
} |
| 401 |
return (dico_handle_t)db; |
| 402 |
} |
| 403 |
|
| 404 |
static int |
| 405 |
gcide_free_db(dico_handle_t hp) |
| 406 |
{ |
| 407 |
struct gcide_db *db = (struct gcide_db *) hp; |
| 408 |
free_db(db); |
| 409 |
return 0; |
| 410 |
} |
| 411 |
|
| 412 |
static int |
| 413 |
reload_if_changed(struct gcide_db *db) |
| 414 |
{ |
| 415 |
if ((db->flags & GCIDE_WATCHER) && watcher_is_modified(db->watcher)) { |
| 416 |
if (gcide_db_reindex(db, 0)) { |
| 417 |
db->flags |= GCIDE_IDX_FAIL; |
| 418 |
} else { |
| 419 |
db->flags &= ~GCIDE_IDX_FAIL; |
| 420 |
} |
| 421 |
} |
| 422 |
if (db->flags & GCIDE_IDX_FAIL) |
| 423 |
return -1; |
| 424 |
return 0; |
| 425 |
} |
| 426 |
|
| 427 |
static int |
| 428 |
_is_nl_or_punct(int c) |
| 429 |
{ |
| 430 |
return !!strchr("\r\n!,-./:;?", c); |
| 431 |
} |
| 432 |
|
| 433 |
static char * |
| 434 |
read_info_file(const char *fname, int first_line) |
| 435 |
{ |
| 436 |
dico_stream_t stream; |
| 437 |
int rc; |
| 438 |
char *bufptr = NULL; |
| 439 |
size_t bufsize = 0; |
| 440 |
|
| 441 |
stream = dico_mapfile_stream_create(fname, DICO_STREAM_READ); |
| 442 |
if (!stream) { |
| 443 |
dico_log(L_NOTICE, errno, _("cannot create stream `%s'"), fname); |
| 444 |
return NULL; |
| 445 |
} |
| 446 |
|
| 447 |
rc = dico_stream_open(stream); |
| 448 |
if (rc) { |
| 449 |
dico_log(L_ERR, 0, |
| 450 |
_("cannot open stream `%s': %s"), |
| 451 |
fname, dico_stream_strerror(stream, rc)); |
| 452 |
dico_stream_destroy(&stream); |
| 453 |
return NULL; |
| 454 |
} |
| 455 |
|
| 456 |
if (first_line) { |
| 457 |
size_t n; |
| 458 |
|
| 459 |
rc = dico_stream_getline(stream, &bufptr, &bufsize, &n); |
| 460 |
if (rc) { |
| 461 |
dico_log(L_ERR, 0, |
| 462 |
_("read error in stream `%s': %s"), |
| 463 |
fname, dico_stream_strerror(stream, rc)); |
| 464 |
} else |
| 465 |
dico_string_trim(bufptr, n, _is_nl_or_punct); |
| 466 |
} else { |
| 467 |
off_t size; |
| 468 |
rc = dico_stream_size(stream, &size); |
| 469 |
if (rc) { |
| 470 |
dico_log(L_ERR, 0, |
| 471 |
_("cannot get size of stream `%s': %s"), |
| 472 |
fname, dico_stream_strerror(stream, rc)); |
| 473 |
} else { |
| 474 |
bufsize = size; |
| 475 |
bufptr = malloc (bufsize + 1); |
| 476 |
if (!bufptr) { |
| 477 |
dico_log(L_ERR, errno, |
| 478 |
_("cannot allocate dictionary information buffer")); |
| 479 |
} else if ((rc = dico_stream_read(stream, bufptr, bufsize, NULL))) { |
| 480 |
dico_log(L_ERR, 0, |
| 481 |
_("read error in stream `%s': %s"), |
| 482 |
fname, dico_stream_strerror(stream, rc)); |
| 483 |
free(bufptr); |
| 484 |
bufptr = NULL; |
| 485 |
} else |
| 486 |
bufptr[bufsize] = 0; |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
dico_stream_destroy(&stream); |
| 491 |
return bufptr; |
| 492 |
} |
| 493 |
|
| 494 |
static char * |
| 495 |
read_dictionary_info(struct gcide_db *db, int first_line) |
| 496 |
{ |
| 497 |
char *fname = dico_full_file_name(db->db_dir, "INFO"); |
| 498 |
char *info = read_info_file(fname, first_line); |
| 499 |
free(fname); |
| 500 |
return info; |
| 501 |
} |
| 502 |
|
| 503 |
char * |
| 504 |
gcide_info(dico_handle_t hp) |
| 505 |
{ |
| 506 |
return read_dictionary_info((struct gcide_db *) hp, 0); |
| 507 |
} |
| 508 |
|
| 509 |
char * |
| 510 |
gcide_descr(dico_handle_t hp) |
| 511 |
{ |
| 512 |
return read_dictionary_info((struct gcide_db *) hp, 1); |
| 513 |
} |
| 514 |
|
| 515 |
static gcide_iterator_t |
| 516 |
exact_match(struct gcide_db *db, const char *hw) |
| 517 |
{ |
| 518 |
return gcide_idx_locate(db->idx, (char*)hw, 0); |
| 519 |
} |
| 520 |
|
| 521 |
static gcide_iterator_t |
| 522 |
prefix_match(struct gcide_db *db, const char *hw) |
| 523 |
{ |
| 524 |
return gcide_idx_locate(db->idx, (char*)hw, utf8_strlen(hw)); |
| 525 |
} |
| 526 |
|
| 527 |
typedef gcide_iterator_t (*matcher_t)(struct gcide_db *, const char *); |
| 528 |
|
| 529 |
struct strategy_def { |
| 530 |
struct dico_strategy strat; |
| 531 |
matcher_t matcher; |
| 532 |
}; |
| 533 |
|
| 534 |
static struct strategy_def strat_tab[] = { |
| 535 |
{ { "exact", "Match words exactly" }, exact_match }, |
| 536 |
{ { "prefix", "Match word prefixes" }, prefix_match }, |
| 537 |
}; |
| 538 |
|
| 539 |
static int |
| 540 |
gcide_init(int argc, char **argv) |
| 541 |
{ |
| 542 |
int i; |
| 543 |
|
| 544 |
for (i = 0; i < DICO_ARRAY_SIZE(strat_tab); i++) |
| 545 |
dico_strategy_add(&strat_tab[i].strat); |
| 546 |
|
| 547 |
return 0; |
| 548 |
} |
| 549 |
|
| 550 |
static matcher_t |
| 551 |
find_matcher(const char *strat) |
| 552 |
{ |
| 553 |
int i; |
| 554 |
for (i = 0; i < DICO_ARRAY_SIZE(strat_tab); i++) |
| 555 |
if (strcmp(strat, strat_tab[i].strat.name) == 0) |
| 556 |
return strat_tab[i].matcher; |
| 557 |
return NULL; |
| 558 |
} |
| 559 |
|
| 560 |
static int |
| 561 |
compare_ref(const void *a, const void *b, void *closure) |
| 562 |
{ |
| 563 |
struct gcide_ref const *aref = a; |
| 564 |
struct gcide_ref const *bref = b; |
| 565 |
|
| 566 |
return utf8_strcasecmp(aref->ref_headword, bref->ref_headword); |
| 567 |
} |
| 568 |
|
| 569 |
static int |
| 570 |
free_ref(void *a, void *b) |
| 571 |
{ |
| 572 |
struct gcide_ref *ref = a; |
| 573 |
free(ref->ref_headword); |
| 574 |
free(ref); |
| 575 |
return 0; |
| 576 |
} |
| 577 |
|
| 578 |
static dico_list_t |
| 579 |
gcide_create_result_list(int unique) |
| 580 |
{ |
| 581 |
dico_list_t list; |
| 582 |
|
| 583 |
list = dico_list_create(); |
| 584 |
if (!list) { |
| 585 |
DICO_LOG_ERRNO(); |
| 586 |
return NULL; |
| 587 |
} |
| 588 |
if (unique) { |
| 589 |
dico_list_set_comparator(list, compare_ref, NULL); |
| 590 |
dico_list_set_flags(list, DICO_LIST_COMPARE_TAIL); |
| 591 |
} |
| 592 |
dico_list_set_free_item(list, free_ref, NULL); |
| 593 |
return list; |
| 594 |
} |
| 595 |
|
| 596 |
static int |
| 597 |
gcide_result_list_append(dico_list_t list, struct gcide_ref *ref) |
| 598 |
{ |
| 599 |
struct gcide_ref *copy = calloc(1,sizeof(*copy)); |
| 600 |
if (!copy) { |
| 601 |
DICO_LOG_ERRNO(); |
| 602 |
return -1; |
| 603 |
} |
| 604 |
*copy = *ref; |
| 605 |
copy->ref_headword = strdup(ref->ref_headword); |
| 606 |
if (!copy->ref_headword || |
| 607 |
(dico_list_append(list, copy) && errno == ENOMEM)) { |
| 608 |
DICO_LOG_ERRNO(); |
| 609 |
free(copy); |
| 610 |
return -1; |
| 611 |
} |
| 612 |
return 0; |
| 613 |
} |
| 614 |
|
| 615 |
struct match_closure { |
| 616 |
dico_strategy_t strat; |
| 617 |
dico_list_t list; |
| 618 |
struct dico_key key; |
| 619 |
}; |
| 620 |
|
| 621 |
static int |
| 622 |
match_key(struct gcide_ref *ref, void *data) |
| 623 |
{ |
| 624 |
struct match_closure *clos = data; |
| 625 |
|
| 626 |
if (dico_key_match(&clos->key, ref->ref_headword)) { |
| 627 |
if (gcide_result_list_append(clos->list, ref)) |
| 628 |
return 1; |
| 629 |
} |
| 630 |
return 0; |
| 631 |
} |
| 632 |
|
| 633 |
static struct gcide_result * |
| 634 |
gcide_match_all(struct gcide_db *db, const dico_strategy_t strat, |
| 635 |
const char *word) |
| 636 |
{ |
| 637 |
struct gcide_result *res; |
| 638 |
struct match_closure clos; |
| 639 |
|
| 640 |
clos.list = gcide_create_result_list(1); |
| 641 |
if (!clos.list) |
| 642 |
return NULL; |
| 643 |
|
| 644 |
if (dico_key_init(&clos.key, strat, word)) { |
| 645 |
dico_log(L_ERR, 0, _("%s: key initialization failed"), __func__); |
| 646 |
dico_list_destroy(&clos.list); |
| 647 |
return NULL; |
| 648 |
} |
| 649 |
|
| 650 |
clos.strat = strat; |
| 651 |
gcide_idx_enumerate(db->idx, match_key, &clos); |
| 652 |
|
| 653 |
dico_key_deinit(&clos.key); |
| 654 |
|
| 655 |
if (dico_list_count(clos.list) == 0) { |
| 656 |
dico_list_destroy(&clos.list); |
| 657 |
return NULL; |
| 658 |
} |
| 659 |
|
| 660 |
res = calloc(1, sizeof(*res)); |
| 661 |
if (!res) { |
| 662 |
DICO_LOG_ERRNO(); |
| 663 |
dico_list_destroy(&clos.list); |
| 664 |
} else { |
| 665 |
res->type = result_match; |
| 666 |
res->db = db; |
| 667 |
res->list = clos.list; |
| 668 |
res->compare_count = gcide_idx_defs(db->idx); |
| 669 |
} |
| 670 |
|
| 671 |
return res; |
| 672 |
} |
| 673 |
|
| 674 |
static dico_result_t |
| 675 |
gcide_match(dico_handle_t hp, const dico_strategy_t strat, const char *word) |
| 676 |
{ |
| 677 |
struct gcide_db *db = (struct gcide_db *) hp; |
| 678 |
matcher_t matcher = find_matcher(strat->name); |
| 679 |
struct gcide_result *res = NULL; |
| 680 |
|
| 681 |
gcide_idx_lock(db->idx, 0); |
| 682 |
|
| 683 |
if (reload_if_changed(db)) |
| 684 |
res = NULL; |
| 685 |
else if (!matcher) |
| 686 |
res = gcide_match_all(db, strat, word); |
| 687 |
else { |
| 688 |
gcide_iterator_t itr = matcher(db, word); |
| 689 |
if (itr) { |
| 690 |
res = calloc(1, sizeof(*res)); |
| 691 |
if (!res) { |
| 692 |
DICO_LOG_ERRNO(); |
| 693 |
} else { |
| 694 |
res->type = result_match; |
| 695 |
res->db = db; |
| 696 |
res->list = gcide_create_result_list(1); |
| 697 |
if (res->list) { |
| 698 |
do |
| 699 |
gcide_result_list_append(res->list, |
| 700 |
gcide_iterator_ref(itr)); |
| 701 |
while (gcide_iterator_next(itr) == 0); |
| 702 |
res->compare_count = gcide_iterator_compare_count(itr); |
| 703 |
} else { |
| 704 |
free(res); |
| 705 |
res = NULL; |
| 706 |
} |
| 707 |
} |
| 708 |
gcide_iterator_free(itr); |
| 709 |
} |
| 710 |
} |
| 711 |
gcide_idx_unlock(db->idx); |
| 712 |
return (dico_result_t) res; |
| 713 |
} |
| 714 |
|
| 715 |
static dico_result_t |
| 716 |
gcide_define(dico_handle_t hp, const char *word) |
| 717 |
{ |
| 718 |
struct gcide_db *db = (struct gcide_db *) hp; |
| 719 |
struct gcide_result *res = NULL; |
| 720 |
|
| 721 |
gcide_idx_lock(db->idx, 0); |
| 722 |
if (reload_if_changed(db)) |
| 723 |
res = NULL; |
| 724 |
else { |
| 725 |
gcide_iterator_t itr = exact_match(db, word); |
| 726 |
if (itr) { |
| 727 |
res = calloc(1, sizeof(*res)); |
| 728 |
if (!res) { |
| 729 |
DICO_LOG_ERRNO(); |
| 730 |
} else { |
| 731 |
res->type = result_define; |
| 732 |
res->db = db; |
| 733 |
res->list = gcide_create_result_list(0); |
| 734 |
if (res->list) { |
| 735 |
do |
| 736 |
gcide_result_list_append(res->list, |
| 737 |
gcide_iterator_ref(itr)); |
| 738 |
while (gcide_iterator_next(itr) == 0); |
| 739 |
res->compare_count = gcide_iterator_compare_count(itr); |
| 740 |
} else { |
| 741 |
free(res); |
| 742 |
res = NULL; |
| 743 |
} |
| 744 |
gcide_iterator_free(itr); |
| 745 |
} |
| 746 |
} |
| 747 |
} |
| 748 |
gcide_idx_unlock(db->idx); |
| 749 |
return (dico_result_t) res; |
| 750 |
} |
| 751 |
|
| 752 |
static struct gcide_ref * |
| 753 |
gcide_result_ref(struct gcide_result *res) |
| 754 |
{ |
| 755 |
struct gcide_ref *ref = NULL; |
| 756 |
if (!res->itr) { |
| 757 |
res->itr = dico_list_iterator(res->list); |
| 758 |
if (!res->itr) |
| 759 |
return NULL; |
| 760 |
ref = dico_iterator_first(res->itr); |
| 761 |
} else |
| 762 |
ref = dico_iterator_next(res->itr); |
| 763 |
return ref; |
| 764 |
} |
| 765 |
|
| 766 |
struct print_text_closure; |
| 767 |
typedef void (*tag_text_printer)(struct gcide_tag *, struct print_text_closure *); |
| 768 |
|
| 769 |
struct print_text_closure { |
| 770 |
tag_text_printer printer; |
| 771 |
dico_stream_t stream; |
| 772 |
unsigned indent; |
| 773 |
int flags; |
| 774 |
int newline; |
| 775 |
}; |
| 776 |
|
| 777 |
static int |
| 778 |
print_text_helper(void *item, void *data) |
| 779 |
{ |
| 780 |
struct gcide_tag *tag = item; |
| 781 |
struct print_text_closure *p = data; |
| 782 |
p->printer(tag, p); |
| 783 |
return 0; |
| 784 |
} |
| 785 |
|
| 786 |
static void print_text_tag(struct gcide_tag *tag, struct print_text_closure *); |
| 787 |
|
| 788 |
static void |
| 789 |
print_text_taglist(struct gcide_tag *tag, struct print_text_closure *clos) |
| 790 |
{ |
| 791 |
struct print_text_closure c = *clos; |
| 792 |
c.printer = print_text_tag; |
| 793 |
dico_list_iterate(tag->v.tag.taglist, print_text_helper, &c); |
| 794 |
clos->newline = c.newline; |
| 795 |
} |
| 796 |
|
| 797 |
static void print_text_as(struct gcide_tag *, struct print_text_closure *); |
| 798 |
static void print_text_ref(struct gcide_tag *, struct print_text_closure *); |
| 799 |
static void print_text_pr(struct gcide_tag *, struct print_text_closure *); |
| 800 |
static void print_text_a(struct gcide_tag *, struct print_text_closure *); |
| 801 |
static void print_text_source(struct gcide_tag *, struct print_text_closure *); |
| 802 |
static void print_text_rj(struct gcide_tag *, struct print_text_closure *); |
| 803 |
static void print_text_qau(struct gcide_tag *, struct print_text_closure *); |
| 804 |
static void print_text_sn(struct gcide_tag *, struct print_text_closure *); |
| 805 |
static void print_text_q(struct gcide_tag *, struct print_text_closure *); |
| 806 |
|
| 807 |
static struct tagdef_text { |
| 808 |
char const *tag; |
| 809 |
tag_text_printer printer; |
| 810 |
} tagdef_text[] = { |
| 811 |
{ "as", print_text_as }, |
| 812 |
{ "er", print_text_ref }, |
| 813 |
{ "cref", print_text_ref }, |
| 814 |
{ "pr", print_text_pr }, |
| 815 |
{ "a", print_text_a }, |
| 816 |
{ "source", print_text_source }, |
| 817 |
{ "qau", print_text_qau }, |
| 818 |
{ "rj", print_text_rj }, |
| 819 |
{ "sn", print_text_sn }, |
| 820 |
{ "q", print_text_q }, |
| 821 |
{ NULL } |
| 822 |
}; |
| 823 |
|
| 824 |
static tag_text_printer |
| 825 |
find_text_printer(char const *name) |
| 826 |
{ |
| 827 |
struct tagdef_text *p; |
| 828 |
for (p = tagdef_text; p->tag; p++) |
| 829 |
if (strcmp(p->tag, name) == 0) |
| 830 |
return p->printer; |
| 831 |
return NULL; |
| 832 |
} |
| 833 |
|
| 834 |
static void |
| 835 |
do_indent(struct print_text_closure *clos) |
| 836 |
{ |
| 837 |
static char indent[] = " "; |
| 838 |
int i; |
| 839 |
for (i = 0; i < clos->indent; i++) |
| 840 |
dico_stream_write(clos->stream, indent, strlen(indent)); |
| 841 |
clos->newline = 0; |
| 842 |
} |
| 843 |
|
| 844 |
static void |
| 845 |
print_text_tag(struct gcide_tag *tag, struct print_text_closure *clos) |
| 846 |
{ |
| 847 |
tag_text_printer printer; |
| 848 |
|
| 849 |
switch (tag->tag_type) { |
| 850 |
case gcide_content_top: |
| 851 |
print_text_taglist(tag, clos); |
| 852 |
break; |
| 853 |
|
| 854 |
case gcide_content_tag: |
| 855 |
if (gcide_is_block_tag(tag)) { |
| 856 |
if (clos->newline == 0) { |
| 857 |
dico_stream_write(clos->stream, "\n", 1); |
| 858 |
clos->newline++; |
| 859 |
} |
| 860 |
if (clos->newline < 2) { |
| 861 |
dico_stream_write(clos->stream, "\n", 1); |
| 862 |
clos->newline++; |
| 863 |
} |
| 864 |
} else if (clos->newline && clos->indent) |
| 865 |
do_indent(clos); |
| 866 |
printer = find_text_printer(tag->tag_name); |
| 867 |
if (printer) |
| 868 |
printer(tag, clos); |
| 869 |
else |
| 870 |
print_text_taglist(tag, clos); |
| 871 |
if (gcide_is_block_tag(tag)) { |
| 872 |
if (clos->newline == 0) { |
| 873 |
dico_stream_write(clos->stream, "\n", 1); |
| 874 |
clos->newline++; |
| 875 |
} |
| 876 |
if (clos->newline < 2) { |
| 877 |
dico_stream_write(clos->stream, "\n", 1); |
| 878 |
clos->newline++; |
| 879 |
} |
| 880 |
} |
| 881 |
break; |
| 882 |
|
| 883 |
case gcide_content_text: |
| 884 |
if (clos->newline && clos->indent) |
| 885 |
do_indent(clos); |
| 886 |
dico_stream_write(clos->stream, tag->v.text, strlen(tag->v.text)); |
| 887 |
clos->newline = 0; |
| 888 |
break; |
| 889 |
|
| 890 |
case gcide_content_nl: |
| 891 |
if (clos->newline && clos->indent) |
| 892 |
do_indent(clos); |
| 893 |
dico_stream_write(clos->stream, " ", 1); |
| 894 |
clos->newline = 0; |
| 895 |
break; |
| 896 |
|
| 897 |
case gcide_content_br: |
| 898 |
dico_stream_write(clos->stream, "\n", 1); |
| 899 |
clos->newline++; |
| 900 |
break; |
| 901 |
|
| 902 |
default: |
| 903 |
break; |
| 904 |
} |
| 905 |
} |
| 906 |
|
| 907 |
static void |
| 908 |
print_text_as(struct gcide_tag *tag, struct print_text_closure *clos) |
| 909 |
{ |
| 910 |
static char *quote[2] = { "“", "”" }; |
| 911 |
|
| 912 |
dico_stream_write(clos->stream, quote[0], strlen(quote[0])); |
| 913 |
print_text_taglist(tag, clos); |
| 914 |
dico_stream_write(clos->stream, quote[1], strlen(quote[1])); |
| 915 |
clos->newline = 0; |
| 916 |
} |
| 917 |
|
| 918 |
static void |
| 919 |
print_text_ref(struct gcide_tag *tag, struct print_text_closure *clos) |
| 920 |
{ |
| 921 |
static char *ref[2] = { "{" , "}" }; |
| 922 |
dico_stream_write(clos->stream, ref[0], strlen(ref[0])); |
| 923 |
print_text_taglist(tag, clos); |
| 924 |
dico_stream_write(clos->stream, ref[1], strlen(ref[1])); |
| 925 |
} |
| 926 |
|
| 927 |
static void |
| 928 |
print_text_pr(struct gcide_tag *tag, struct print_text_closure *clos) |
| 929 |
{ |
| 930 |
if (!(clos->flags & GCIDE_NOPR)) |
| 931 |
print_text_taglist(tag, clos); |
| 932 |
} |
| 933 |
|
| 934 |
static char * |
| 935 |
gcide_tag_get_param(struct gcide_tag *tag, char const *name) |
| 936 |
{ |
| 937 |
size_t i; |
| 938 |
size_t namelen = strlen(name); |
| 939 |
|
| 940 |
for (i = 0; i < tag->v.tag.tag_parmc; i++) { |
| 941 |
size_t len = strcspn(tag->v.tag.tag_parmv[i], "="); |
| 942 |
if (len == namelen && |
| 943 |
memcmp(tag->v.tag.tag_parmv[i], name, namelen) == 0) |
| 944 |
return tag->v.tag.tag_parmv[i]+namelen+1; |
| 945 |
} |
| 946 |
return NULL; |
| 947 |
} |
| 948 |
|
| 949 |
static void |
| 950 |
print_text_a(struct gcide_tag *tag, struct print_text_closure *clos) |
| 951 |
{ |
| 952 |
char *href = gcide_tag_get_param(tag, "href"); |
| 953 |
print_text_taglist(tag, clos); |
| 954 |
if (href != NULL) { |
| 955 |
dico_stream_write(clos->stream, " (see ", 6); |
| 956 |
dico_stream_write(clos->stream, href, strlen(href)); |
| 957 |
dico_stream_write(clos->stream, ")", 1); |
| 958 |
} |
| 959 |
} |
| 960 |
|
| 961 |
static void |
| 962 |
print_text_source(struct gcide_tag *tag, struct print_text_closure *clos) |
| 963 |
{ |
| 964 |
dico_stream_write(clos->stream, "[", 1); |
| 965 |
print_text_taglist(tag, clos); |
| 966 |
dico_stream_write(clos->stream, "]", 1); |
| 967 |
} |
| 968 |
|
| 969 |
static void |
| 970 |
print_text_qau(struct gcide_tag *tag, struct print_text_closure *clos) |
| 971 |
{ |
| 972 |
dico_stream_write(clos->stream, "-- ", 3); |
| 973 |
print_text_taglist(tag, clos); |
| 974 |
} |
| 975 |
|
| 976 |
static void |
| 977 |
print_text_sn(struct gcide_tag *tag, struct print_text_closure *clos) |
| 978 |
{ |
| 979 |
print_text_taglist(tag, clos); |
| 980 |
dico_stream_write(clos->stream, " ", 1); |
| 981 |
clos->newline = 2; |
| 982 |
} |
| 983 |
|
| 984 |
static void |
| 985 |
print_text_taglist_indent(struct gcide_tag *tag, struct print_text_closure *clos, |
| 986 |
unsigned level) |
| 987 |
{ |
| 988 |
struct print_text_closure c = { |
| 989 |
.printer = print_text_tag, |
| 990 |
.stream = clos->stream, |
| 991 |
.flags = clos->flags, |
| 992 |
.newline = clos->newline, |
| 993 |
.indent = level |
| 994 |
}; |
| 995 |
print_text_taglist(tag, &c); |
| 996 |
clos->newline = c.newline; |
| 997 |
} |
| 998 |
|
| 999 |
static void |
| 1000 |
print_text_q(struct gcide_tag *tag, struct print_text_closure *clos) |
| 1001 |
{ |
| 1002 |
print_text_taglist_indent(tag, clos, 1); |
| 1003 |
} |
| 1004 |
|
| 1005 |
static void |
| 1006 |
print_text_rj(struct gcide_tag *tag, struct print_text_closure *clos) |
| 1007 |
{ |
| 1008 |
print_text_taglist_indent(tag, clos, 3); |
| 1009 |
} |
| 1010 |
|
| 1011 |
static int |
| 1012 |
output_def_text(dico_stream_t str, struct gcide_db *db, |
| 1013 |
struct gcide_parse_tree *tree) |
| 1014 |
{ |
| 1015 |
struct print_text_closure c = { |
| 1016 |
.printer = print_text_tag, |
| 1017 |
.stream = str, |
| 1018 |
.flags = db->flags, |
| 1019 |
.newline = 2, |
| 1020 |
}; |
| 1021 |
print_text_tag(tree->root, &c); |
| 1022 |
return 0; // FIXME |
| 1023 |
} |
| 1024 |
|
| 1025 |
struct html_closure; |
| 1026 |
typedef void (*tag_html_printer)(struct gcide_tag *, struct html_closure *); |
| 1027 |
|
| 1028 |
struct html_closure { |
| 1029 |
tag_html_printer printer; |
| 1030 |
int flags; |
| 1031 |
dico_stream_t stream; |
| 1032 |
}; |
| 1033 |
|
| 1034 |
static int |
| 1035 |
print_html_helper(void *item, void *data) |
| 1036 |
{ |
| 1037 |
struct gcide_tag *tag = item; |
| 1038 |
struct html_closure *p = data; |
| 1039 |
p->printer(tag, p); |
| 1040 |
return 0; |
| 1041 |
} |
| 1042 |
|
| 1043 |
static void print_html_tag(struct gcide_tag *tag, struct html_closure *); |
| 1044 |
|
| 1045 |
static void |
| 1046 |
print_html_taglist(struct gcide_tag *tag, struct html_closure *clos) |
| 1047 |
{ |
| 1048 |
struct html_closure c = *clos; |
| 1049 |
c.printer = print_html_tag; |
| 1050 |
dico_list_iterate(tag->v.tag.taglist, print_html_helper, &c); |
| 1051 |
} |
| 1052 |
|
| 1053 |
static void |
| 1054 |
copy_html_tag(struct gcide_tag *tag, struct html_closure *clos) |
| 1055 |
{ |
| 1056 |
int i; |
| 1057 |
|
| 1058 |
dico_stream_write(clos->stream, "<", 1); |
| 1059 |
dico_stream_write(clos->stream, tag->tag_name, |
| 1060 |
strlen(tag->tag_name)); |
| 1061 |
for (i = 1; i < tag->v.tag.tag_parmc; i++) { |
| 1062 |
size_t len = strcspn(tag->v.tag.tag_parmv[i], "="); |
| 1063 |
dico_stream_write(clos->stream, " ", 1); |
| 1064 |
dico_stream_write(clos->stream, tag->v.tag.tag_parmv[i], len); |
| 1065 |
if (tag->v.tag.tag_parmv[i][len]) { |
| 1066 |
char *arg = tag->v.tag.tag_parmv[i] + len + 1; |
| 1067 |
dico_stream_write(clos->stream, "=\"", 2); |
| 1068 |
dico_stream_write(clos->stream, arg, strlen(arg)); |
| 1069 |
dico_stream_write(clos->stream, "\"", 1); |
| 1070 |
} |
| 1071 |
} |
| 1072 |
dico_stream_write(clos->stream, ">", 1); |
| 1073 |
print_html_taglist(tag, clos); |
| 1074 |
dico_stream_write(clos->stream, "</", 2); |
| 1075 |
dico_stream_write(clos->stream, tag->tag_name, strlen(tag->tag_name)); |
| 1076 |
dico_stream_write(clos->stream, ">", 1); |
| 1077 |
} |
| 1078 |
|
| 1079 |
static void |
| 1080 |
override_html_tag(struct gcide_tag *tag, struct html_closure *clos, |
| 1081 |
char **parmv) |
| 1082 |
{ |
| 1083 |
struct gcide_tag tag_copy = *tag; |
| 1084 |
int i; |
| 1085 |
for (i = 0; parmv[i] != NULL; i++) |
| 1086 |
; |
| 1087 |
tag_copy.tag_type = gcide_content_tag; |
| 1088 |
tag_copy.v.tag.tag_parmc = i; |
| 1089 |
tag_copy.v.tag.tag_parmv = parmv; |
| 1090 |
copy_html_tag(&tag_copy, clos); |
| 1091 |
} |
| 1092 |
|
| 1093 |
static void |
| 1094 |
print_html_pr(struct gcide_tag *tag, struct html_closure *clos) |
| 1095 |
{ |
| 1096 |
static char *params[] = { |
| 1097 |
"span", |
| 1098 |
"class=pron", |
| 1099 |
NULL |
| 1100 |
}; |
| 1101 |
if (!(clos->flags & GCIDE_NOPR)) |
| 1102 |
override_html_tag(tag, clos, params); |
| 1103 |
} |
| 1104 |
|
| 1105 |
static void print_html_override(struct gcide_tag *tag, |
| 1106 |
struct html_closure *clos, |
| 1107 |
char const *tagname, char const *class); |
| 1108 |
|
| 1109 |
struct text_buf |
| 1110 |
{ |
| 1111 |
char *text; |
| 1112 |
size_t len; |
| 1113 |
size_t cap; |
| 1114 |
int err; |
| 1115 |
}; |
| 1116 |
|
| 1117 |
#define TEXT_BUF_INITIALIZER { NULL, 0, 0, 0 } |
| 1118 |
|
| 1119 |
static void |
| 1120 |
text_buf_free(struct text_buf *tb) |
| 1121 |
{ |
| 1122 |
free(tb->text); |
| 1123 |
} |
| 1124 |
|
| 1125 |
static int |
| 1126 |
text_buf_expand(struct text_buf *tb, size_t len) |
| 1127 |
{ |
| 1128 |
if (tb->err) |
| 1129 |
return -1; |
| 1130 |
while (tb->len + len > tb->cap) { |
| 1131 |
char *p; |
| 1132 |
size_t cap; |
| 1133 |
|
| 1134 |
if (tb->cap == 0) { |
| 1135 |
cap = 32; |
| 1136 |
p = malloc(cap); |
| 1137 |
} else if (SIZE_MAX / 2 < tb->cap) { |
| 1138 |
tb->err = ENOMEM; |
| 1139 |
return -1; |
| 1140 |
} else { |
| 1141 |
cap = tb->cap * 2; |
| 1142 |
if ((p = realloc(tb->text, cap)) == NULL) { |
| 1143 |
tb->err = ENOMEM; |
| 1144 |
return -1; |
| 1145 |
} |
| 1146 |
} |
| 1147 |
tb->text = p; |
| 1148 |
tb->cap = cap; |
| 1149 |
} |
| 1150 |
return 0; |
| 1151 |
} |
| 1152 |
|
| 1153 |
static char * |
| 1154 |
text_buf_finish(struct text_buf *tb) |
| 1155 |
{ |
| 1156 |
if (text_buf_expand(tb, 1)) |
| 1157 |
return NULL; |
| 1158 |
tb->text[tb->len] = 0; |
| 1159 |
return tb->text; |
| 1160 |
} |
| 1161 |
|
| 1162 |
static int |
| 1163 |
cb_x_text(void *item, void *data) |
| 1164 |
{ |
| 1165 |
struct gcide_tag *tag = item; |
| 1166 |
struct text_buf *tb = data; |
| 1167 |
size_t len, i, j; |
| 1168 |
|
| 1169 |
switch (tag->tag_type) { |
| 1170 |
case gcide_content_text: |
| 1171 |
len = strlen(tag->v.text); |
| 1172 |
if (text_buf_expand(tb, len)) |
| 1173 |
return -1; |
| 1174 |
i = j = 0; |
| 1175 |
while (i < len) { |
| 1176 |
if (tag->v.text[i] == ' ' || tag->v.text[i] == '\t') { |
| 1177 |
i++; |
| 1178 |
j++; |
| 1179 |
} else { |
| 1180 |
size_t n; |
| 1181 |
if (j > 0) { |
| 1182 |
tb->text[tb->len++] = ' '; |
| 1183 |
j = 0; |
| 1184 |
} |
| 1185 |
n = strcspn(tag->v.text + i, " \t"); |
| 1186 |
memcpy(tb->text + tb->len, tag->v.text + i, n); |
| 1187 |
tb->len += n; |
| 1188 |
i += n; |
| 1189 |
} |
| 1190 |
} |
| 1191 |
break; |
| 1192 |
|
| 1193 |
case gcide_content_br: |
| 1194 |
case gcide_content_nl: |
| 1195 |
if (!(tb->len > 0 && tb->text[tb->len - 1] == ' ')) { |
| 1196 |
if (text_buf_expand(tb, 1)) |
| 1197 |
return -1; |
| 1198 |
tb->text[tb->len++] = ' '; |
| 1199 |
} |
| 1200 |
break; |
| 1201 |
|
| 1202 |
case gcide_content_tag: |
| 1203 |
dico_list_iterate(tag->v.tag.taglist, cb_x_text, tb); |
| 1204 |
if (tb->err) |
| 1205 |
return -1; |
| 1206 |
break; |
| 1207 |
|
| 1208 |
default: |
| 1209 |
tb->err = EINVAL; |
| 1210 |
return -1; |
| 1211 |
} |
| 1212 |
return 0; |
| 1213 |
} |
| 1214 |
|
| 1215 |
static char * |
| 1216 |
gcide_tag_to_text(struct gcide_tag *t) |
| 1217 |
{ |
| 1218 |
struct text_buf tb = TEXT_BUF_INITIALIZER; |
| 1219 |
char *ret = NULL; |
| 1220 |
dico_list_iterate(t->v.tag.taglist, cb_x_text, &tb); |
| 1221 |
if ((ret = text_buf_finish(&tb)) == NULL) { |
| 1222 |
errno = tb.err; |
| 1223 |
text_buf_free(&tb); |
| 1224 |
} |
| 1225 |
return ret; |
| 1226 |
} |
| 1227 |
|
| 1228 |
static void |
| 1229 |
print_html_ref(struct gcide_tag *tag, struct html_closure *clos) |
| 1230 |
{ |
| 1231 |
char *text; |
| 1232 |
|
| 1233 |
if ((text = gcide_tag_to_text(tag)) != NULL) { |
| 1234 |
static char *params[] = { |
| 1235 |
"a", |
| 1236 |
"class=ref", |
| 1237 |
NULL, |
| 1238 |
NULL |
| 1239 |
}; |
| 1240 |
static char href[] = "href=/define/"; |
| 1241 |
|
| 1242 |
size_t len = strlen(text); |
| 1243 |
char *ref = malloc(sizeof(href) + len); |
| 1244 |
if (!ref) { |
| 1245 |
DICO_LOG_MEMERR(); |
| 1246 |
free(text); |
| 1247 |
return; |
| 1248 |
} |
| 1249 |
strcat(strcpy(ref, href), text); |
| 1250 |
free(text); |
| 1251 |
params[2] = ref; |
| 1252 |
override_html_tag(tag, clos, params); |
| 1253 |
free(ref); |
| 1254 |
} else if (errno == ENOMEM) { |
| 1255 |
DICO_LOG_MEMERR(); |
| 1256 |
} else { |
| 1257 |
print_html_override(tag, clos, "span", tag->tag_name); |
| 1258 |
} |
| 1259 |
} |
| 1260 |
|
| 1261 |
static void |
| 1262 |
print_html_source(struct gcide_tag *tag, struct html_closure *clos) |
| 1263 |
{ |
| 1264 |
static char const *div[] = { |
| 1265 |
"<div class=\"source\">", |
| 1266 |
"</div>" |
| 1267 |
}; |
| 1268 |
dico_stream_write(clos->stream, div[0], strlen(div[0])); |
| 1269 |
print_html_override(tag, clos, "span", tag->tag_name); |
| 1270 |
dico_stream_write(clos->stream, div[1], strlen(div[1])); |
| 1271 |
} |
| 1272 |
|
| 1273 |
static struct tagdef_html { |
| 1274 |
char const *tag; |
| 1275 |
tag_html_printer printer; |
| 1276 |
char const *html_tag; |
| 1277 |
char const *class; |
| 1278 |
} tagdef_html[] = { |
| 1279 |
{ "p", copy_html_tag }, |
| 1280 |
{ "a", copy_html_tag }, |
| 1281 |
{ "pr", print_html_pr }, |
| 1282 |
{ "er", print_html_ref }, |
| 1283 |
{ "cref", print_html_ref }, |
| 1284 |
{ "source", print_html_source }, |
| 1285 |
{ "hw", NULL, "span", "hw" }, |
| 1286 |
{ "sn", NULL, "li", "def" }, |
| 1287 |
{ "ol", NULL, "ol", "def" }, |
| 1288 |
{ "grk", NULL, "span", "ets" }, |
| 1289 |
{ "q", NULL, "blockquote" }, |
| 1290 |
{ "pre", NULL, "pre" }, |
| 1291 |
{ NULL } |
| 1292 |
}; |
| 1293 |
|
| 1294 |
static struct tagdef_html * |
| 1295 |
find_tagdef_html(char const *name) |
| 1296 |
{ |
| 1297 |
struct tagdef_html *p; |
| 1298 |
for (p = tagdef_html; p->tag; p++) |
| 1299 |
if (strcmp(p->tag, name) == 0) |
| 1300 |
return p; |
| 1301 |
return NULL; |
| 1302 |
} |
| 1303 |
|
| 1304 |
static void |
| 1305 |
print_html_override(struct gcide_tag *tag, struct html_closure *clos, |
| 1306 |
char const *tagname, char const *class) |
| 1307 |
{ |
| 1308 |
char *params[] = { |
| 1309 |
(char*) tagname, |
| 1310 |
NULL, |
| 1311 |
NULL |
| 1312 |
}; |
| 1313 |
if (class) { |
| 1314 |
static char const prefix[] = "class="; |
| 1315 |
char *p = malloc(sizeof(prefix) + strlen(class)); |
| 1316 |
if (!p) |
| 1317 |
DICO_LOG_MEMERR(); |
| 1318 |
else { |
| 1319 |
strcpy(p, prefix); |
| 1320 |
strcat(p, class); |
| 1321 |
params[1] = p; |
| 1322 |
} |
| 1323 |
} |
| 1324 |
override_html_tag(tag, clos, params); |
| 1325 |
free(params[1]); |
| 1326 |
} |
| 1327 |
|
| 1328 |
static void |
| 1329 |
print_html_top(struct gcide_tag *tag, struct html_closure *clos) |
| 1330 |
{ |
| 1331 |
print_html_override(tag, clos, "div", "definition"); |
| 1332 |
} |
| 1333 |
|
| 1334 |
static void |
| 1335 |
print_html_tag(struct gcide_tag *tag, struct html_closure *clos) |
| 1336 |
{ |
| 1337 |
struct tagdef_html *td; |
| 1338 |
|
| 1339 |
switch (tag->tag_type) { |
| 1340 |
case gcide_content_top: |
| 1341 |
print_html_top(tag, clos); |
| 1342 |
break; |
| 1343 |
|
| 1344 |
case gcide_content_tag: |
| 1345 |
td = find_tagdef_html(tag->tag_name); |
| 1346 |
if (td) { |
| 1347 |
if (td->html_tag) |
| 1348 |
print_html_override(tag, clos, td->html_tag, td->class); |
| 1349 |
else |
| 1350 |
td->printer(tag, clos); |
| 1351 |
} else if (gcide_is_block_tag(tag)) |
| 1352 |
print_html_override(tag, clos, "div", tag->tag_name); |
| 1353 |
else |
| 1354 |
print_html_override(tag, clos, "span", tag->tag_name); |
| 1355 |
break; |
| 1356 |
|
| 1357 |
case gcide_content_text: |
| 1358 |
dico_stream_write(clos->stream, tag->v.text, strlen(tag->v.text)); |
| 1359 |
break; |
| 1360 |
|
| 1361 |
case gcide_content_nl: |
| 1362 |
dico_stream_write(clos->stream, " ", 1); |
| 1363 |
break; |
| 1364 |
|
| 1365 |
case gcide_content_br: |
| 1366 |
dico_stream_write(clos->stream, "<br/>", 5); |
| 1367 |
break; |
| 1368 |
|
| 1369 |
default: |
| 1370 |
abort (); |
| 1371 |
} |
| 1372 |
} |
| 1373 |
|
| 1374 |
/* |
| 1375 |
* Whenever a <p><sn>(...)</sn>(...)</p> is encountered, replace it with |
| 1376 |
* <sn>\2</sn>. Throw away the original "sn" tag. |
| 1377 |
*/ |
| 1378 |
static int |
| 1379 |
p_sn_join(void *item, void *data) |
| 1380 |
{ |
| 1381 |
struct gcide_tag *tag = item; |
| 1382 |
struct gcide_tag *head; |
| 1383 |
|
| 1384 |
if (gcide_is_tag(tag, "p") && |
| 1385 |
gcide_is_tag(head = dico_list_head(tag->v.tag.taglist), "sn")) { |
| 1386 |
/* Replace p with sn */ |
| 1387 |
free(tag->tag_name); |
| 1388 |
tag->tag_name = head->tag_name; |
| 1389 |
head->tag_name = NULL; |
| 1390 |
dico_list_remove(tag->v.tag.taglist, head, NULL); |
| 1391 |
} |
| 1392 |
return 0; |
| 1393 |
} |
| 1394 |
|
| 1395 |
static void |
| 1396 |
q_fixup(dico_list_t list) |
| 1397 |
{ |
| 1398 |
struct gcide_tag *tag; |
| 1399 |
dico_iterator_t itr; |
| 1400 |
itr = dico_list_iterator(list); |
| 1401 |
tag = dico_iterator_first(itr); |
| 1402 |
while (tag) { |
| 1403 |
if (gcide_is_tag(tag, "q")) { |
| 1404 |
struct gcide_tag *next = dico_iterator_next(itr), *head; |
| 1405 |
if (gcide_is_tag(next, "rj") && |
| 1406 |
(head = dico_list_head(next->v.tag.taglist)) != NULL && |
| 1407 |
gcide_is_tag(head, "qau")) { |
| 1408 |
char const tagname[] = "gcide_quote"; |
| 1409 |
struct gcide_tag *gq = gcide_tag_alloc(tagname, sizeof(tagname)-1); |
| 1410 |
|
| 1411 |
/* Get back to <q> and remove it. */ |
| 1412 |
dico_iterator_prev(itr); |
| 1413 |
dico_iterator_remove_current(itr, (void**)&tag); |
| 1414 |
/* Add <q> to the <gcide_quote> tag. */ |
| 1415 |
dico_list_append(gq->v.tag.taglist, tag); |
| 1416 |
|
| 1417 |
/* Advance to <rj> and remove it, */ |
| 1418 |
dico_iterator_next(itr); |
| 1419 |
dico_iterator_remove_current(itr, (void**)&tag); |
| 1420 |
/* Add <rj> to the <gcide_quote> tag. */ |
| 1421 |
dico_list_append(gq->v.tag.taglist, tag); |
| 1422 |
|
| 1423 |
/* Insert <gcide_quote> */ |
| 1424 |
dico_iterator_insert_before(itr, gq); |
| 1425 |
} |
| 1426 |
} else if (tag->tag_type == gcide_content_top || |
| 1427 |
tag->tag_type == gcide_content_tag) |
| 1428 |
q_fixup(tag->v.tag.taglist); |
| 1429 |
tag = dico_iterator_next(itr); |
| 1430 |
} |
| 1431 |
dico_iterator_destroy(&itr); |
| 1432 |
} |
| 1433 |
|
| 1434 |
static int |
| 1435 |
output_def_html(dico_stream_t str, struct gcide_db *db, |
| 1436 |
struct gcide_parse_tree *tree) |
| 1437 |
{ |
| 1438 |
struct html_closure c = { |
| 1439 |
.printer = print_html_tag, |
| 1440 |
.stream = str, |
| 1441 |
.flags = db->flags, |
| 1442 |
}; |
| 1443 |
dico_iterator_t itr; |
| 1444 |
struct gcide_tag *tag; |
| 1445 |
|
| 1446 |
/* Additional fix-ups: */ |
| 1447 |
|
| 1448 |
/* Join "<p><sn>(.*)</sn>(.*)</p>" -> "<sn>\2</sn>". */ |
| 1449 |
dico_list_iterate(tree->root->v.tag.taglist, p_sn_join, NULL); |
| 1450 |
|
| 1451 |
/* Additional fixups for <q></q><rj><qau> sequences/ */ |
| 1452 |
q_fixup(tree->root->v.tag.taglist); |
| 1453 |
|
| 1454 |
itr = dico_list_iterator(tree->root->v.tag.taglist); |
| 1455 |
tag = dico_iterator_first(itr); |
| 1456 |
|
| 1457 |
/* |
| 1458 |
* Replace initial <p> tag with its content. |
| 1459 |
*/ |
| 1460 |
if (gcide_is_tag(tag, "p")) { |
| 1461 |
void *t; |
| 1462 |
dico_iterator_t pitr; |
| 1463 |
struct gcide_tag *p; |
| 1464 |
|
| 1465 |
dico_iterator_remove_current(itr, &t); |
| 1466 |
pitr = dico_list_iterator(tag->v.tag.taglist); |
| 1467 |
p = dico_iterator_last(pitr); |
| 1468 |
while (p) { |
| 1469 |
dico_iterator_remove_current(pitr, &t); |
| 1470 |
dico_list_prepend(tree->root->v.tag.taglist, p); |
| 1471 |
p = dico_iterator_prev(pitr); |
| 1472 |
} |
| 1473 |
dico_iterator_destroy(&pitr); |
| 1474 |
gcide_tag_free(tag); |
| 1475 |
tag = dico_iterator_first(itr); |
| 1476 |
} |
| 1477 |
|
| 1478 |
/* Find first <sn> tag. */ |
| 1479 |
while (tag && !gcide_is_tag(tag, "sn")) { |
| 1480 |
tag = dico_iterator_next(itr); |
| 1481 |
} |
| 1482 |
|
| 1483 |
if (tag) { |
| 1484 |
/* |
| 1485 |
* Move it and all subsequent tags under a new <ol> tag, and |
| 1486 |
* append that to the end of tag list. |
| 1487 |
*/ |
| 1488 |
struct gcide_tag *oltag = gcide_tag_alloc("ol", 2); |
| 1489 |
do { |
| 1490 |
struct gcide_tag *p; |
| 1491 |
dico_iterator_remove_current(itr, (void **)&p); |
| 1492 |
dico_list_append(oltag->v.tag.taglist, p); |
| 1493 |
} while ((tag = dico_iterator_next(itr)) != NULL); |
| 1494 |
dico_list_append(tree->root->v.tag.taglist, oltag); |
| 1495 |
|
| 1496 |
dico_iterator_destroy(&itr); |
| 1497 |
|
| 1498 |
/* |
| 1499 |
* Rewrite the content of <ol> so that it contains only |
| 1500 |
* <sn> tags. Tuck anything between the two consecutive |
| 1501 |
* <sn> tags to the tag list of the first one. |
| 1502 |
*/ |
| 1503 |
itr = dico_list_iterator(oltag->v.tag.taglist); |
| 1504 |
tag = dico_iterator_first(itr); |
| 1505 |
|
| 1506 |
while (tag) { |
| 1507 |
if (gcide_is_tag(tag, "sn")) { |
| 1508 |
struct gcide_tag *p; |
| 1509 |
|
| 1510 |
if (dico_list_count(tag->v.tag.taglist) == 1 && |
| 1511 |
(p = dico_list_head(tag->v.tag.taglist)) != NULL && |
| 1512 |
p->tag_type == gcide_content_text) |
| 1513 |
dico_list_clear(tag->v.tag.taglist); |
| 1514 |
while ((p = dico_iterator_next(itr)) != NULL && |
| 1515 |
!gcide_is_tag(p, "sn")) { |
| 1516 |
dico_iterator_remove_current(itr, (void **)&p); |
| 1517 |
dico_list_append(tag->v.tag.taglist, p); |
| 1518 |
} |
| 1519 |
tag = p; |
| 1520 |
} else |
| 1521 |
tag = dico_iterator_next(itr); |
| 1522 |
} |
| 1523 |
} |
| 1524 |
|
| 1525 |
dico_iterator_destroy(&itr); |
| 1526 |
/* End of fixups. Now output the resulting document. */ |
| 1527 |
print_html_tag(tree->root, &c); |
| 1528 |
return 0; // FIXME |
| 1529 |
} |
| 1530 |
|
| 1531 |
static int |
| 1532 |
output_def(dico_stream_t str, struct gcide_db *db, struct gcide_ref *ref) |
| 1533 |
{ |
| 1534 |
char *buffer; |
| 1535 |
struct gcide_parse_tree *tree; |
| 1536 |
struct gcide_locus locus; |
| 1537 |
int rc; |
| 1538 |
|
| 1539 |
if (db->file_letter != ref->ref_letter) { |
| 1540 |
int rc; |
| 1541 |
|
| 1542 |
if (db->file_stream) { |
| 1543 |
dico_stream_close(db->file_stream); |
| 1544 |
dico_stream_destroy(&db->file_stream); |
| 1545 |
db->file_letter = 0; |
| 1546 |
} |
| 1547 |
|
| 1548 |
*db->tmpl_letter = ref->ref_letter; |
| 1549 |
|
| 1550 |
db->file_stream = |
| 1551 |
dico_mapfile_stream_create(db->tmpl_name, |
| 1552 |
DICO_STREAM_READ|DICO_STREAM_SEEK); |
| 1553 |
if (!db->file_stream) { |
| 1554 |
dico_log(L_ERR, errno, _("cannot create stream `%s'"), |
| 1555 |
db->tmpl_name); |
| 1556 |
return 1; |
| 1557 |
} |
| 1558 |
rc = dico_stream_open(db->file_stream); |
| 1559 |
if (rc) { |
| 1560 |
dico_log(L_ERR, 0, |
| 1561 |
_("cannot open stream `%s': %s"), |
| 1562 |
db->tmpl_name, dico_stream_strerror(db->file_stream, rc)); |
| 1563 |
dico_stream_destroy(&db->file_stream); |
| 1564 |
return 1; |
| 1565 |
} |
| 1566 |
db->file_letter = ref->ref_letter; |
| 1567 |
} |
| 1568 |
|
| 1569 |
if (dico_stream_seek(db->file_stream, ref->ref_offset, SEEK_SET) < 0) { |
| 1570 |
dico_log(L_ERR, errno, |
| 1571 |
_("seek error on `%s' while positioning to %lu: %s"), |
| 1572 |
db->tmpl_name, ref->ref_offset, |
| 1573 |
dico_stream_strerror(db->file_stream, |
| 1574 |
dico_stream_last_error(db->file_stream))); |
| 1575 |
return 1; |
| 1576 |
} |
| 1577 |
|
| 1578 |
buffer = malloc(ref->ref_size); |
| 1579 |
if (!buffer) { |
| 1580 |
DICO_LOG_ERRNO(); |
| 1581 |
return 1; |
| 1582 |
} |
| 1583 |
|
| 1584 |
if ((rc = dico_stream_read(db->file_stream, buffer, ref->ref_size, NULL))) { |
| 1585 |
dico_log(L_ERR, 0, _("%s: read error: %s"), |
| 1586 |
db->tmpl_name, |
| 1587 |
dico_stream_strerror(db->file_stream, rc)); |
| 1588 |
free(buffer); |
| 1589 |
return 1; |
| 1590 |
} |
| 1591 |
|
| 1592 |
locus.file = db->tmpl_name; |
| 1593 |
locus.offset = ref->ref_offset; |
| 1594 |
tree = gcide_markup_parse(buffer, ref->ref_size, db->flags & GCIDE_DBGLEX, |
| 1595 |
&locus); |
| 1596 |
if (!tree) { |
| 1597 |
// FIXME: if html? |
| 1598 |
rc = dico_stream_write(str, buffer, ref->ref_size); |
| 1599 |
} else if (db->flags & GCIDE_HTML) |
| 1600 |
rc = output_def_html(str, db, tree); |
| 1601 |
else |
| 1602 |
rc = output_def_text(str, db, tree); |
| 1603 |
free(buffer); |
| 1604 |
return rc; |
| 1605 |
} |
| 1606 |
|
| 1607 |
static int |
| 1608 |
gcide_output_result(dico_result_t rp, size_t n, dico_stream_t str) |
| 1609 |
{ |
| 1610 |
struct gcide_result *res = (struct gcide_result *) rp; |
| 1611 |
struct gcide_ref *ref; |
| 1612 |
|
| 1613 |
ref = gcide_result_ref(res); |
| 1614 |
if (!ref) |
| 1615 |
return 1; |
| 1616 |
switch (res->type) { |
| 1617 |
case result_match: |
| 1618 |
dico_stream_write(str, ref->ref_headword, ref->ref_hwbytelen - 1); |
| 1619 |
break; |
| 1620 |
|
| 1621 |
case result_define: |
| 1622 |
return output_def(str, res->db, ref); |
| 1623 |
} |
| 1624 |
return 0; |
| 1625 |
} |
| 1626 |
|
| 1627 |
static size_t |
| 1628 |
gcide_result_count(dico_result_t rp) |
| 1629 |
{ |
| 1630 |
struct gcide_result *res = (struct gcide_result *) rp; |
| 1631 |
return dico_list_count(res->list); |
| 1632 |
} |
| 1633 |
|
| 1634 |
static size_t |
| 1635 |
gcide_compare_count(dico_result_t rp) |
| 1636 |
{ |
| 1637 |
struct gcide_result *res = (struct gcide_result *) rp; |
| 1638 |
return res->compare_count; |
| 1639 |
} |
| 1640 |
|
| 1641 |
static void |
| 1642 |
gcide_free_result(dico_result_t rp) |
| 1643 |
{ |
| 1644 |
struct gcide_result *res = (struct gcide_result *) rp; |
| 1645 |
dico_iterator_destroy(&res->itr); |
| 1646 |
dico_list_destroy(&res->list); |
| 1647 |
} |
| 1648 |
|
| 1649 |
static char const *mime_headers[] = { |
| 1650 |
"Content-Type: text/plain; charset=utf-8\n" |
| 1651 |
"Content-Transfer-Encoding: 8bit\n", |
| 1652 |
|
| 1653 |
"Content-Type: text/html; charset=utf-8\n" |
| 1654 |
"Content-Transfer-Encoding: 8bit\n" |
| 1655 |
}; |
| 1656 |
|
| 1657 |
static char * |
| 1658 |
gcide_db_mime_header(dico_handle_t hp) |
| 1659 |
{ |
| 1660 |
struct gcide_db *db = (struct gcide_db *) hp; |
| 1661 |
return strdup(mime_headers[(db->flags & GCIDE_HTML) != 0]); |
| 1662 |
} |
| 1663 |
|
| 1664 |
struct dico_database_module DICO_EXPORT(gcide, module) = { |
| 1665 |
.dico_version = DICO_MODULE_VERSION, |
| 1666 |
.dico_capabilities = DICO_CAPA_NONE, |
| 1667 |
.dico_init = gcide_init, |
| 1668 |
.dico_init_db = gcide_init_db, |
| 1669 |
.dico_free_db = gcide_free_db, |
| 1670 |
.dico_db_info = gcide_info, |
| 1671 |
.dico_db_descr = gcide_descr, |
| 1672 |
.dico_match = gcide_match, |
| 1673 |
.dico_define = gcide_define, |
| 1674 |
.dico_output_result = gcide_output_result, |
| 1675 |
.dico_result_count = gcide_result_count, |
| 1676 |
.dico_compare_count = gcide_compare_count, |
| 1677 |
.dico_free_result = gcide_free_result, |
| 1678 |
.dico_db_mime_header = gcide_db_mime_header |
| 1679 |
}; |