aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-03-04 13:57:53 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-03-04 14:32:54 +0200
commit37147d7c6229cfb997a4a4bdac2d9e441f79b2c7 (patch)
tree8d990de594c58f70ca0d5493d97bad7c67e109b1
parent2aa9df8a67de14d1167ac96823b97461a9c28c96 (diff)
downloaddico-37147d7c6229cfb997a4a4bdac2d9e441f79b2c7.tar.gz
dico-37147d7c6229cfb997a4a4bdac2d9e441f79b2c7.tar.bz2
Implement info/descr for gcide.release-2.2
* NEWS: Update. * doc/dico.texi: Update. * include/dico/util.h (dico_string_trim): Add missing proto. * modules/gcide/gcide.c (gcide_info, gcide_descr): Implement info and description methods. * modules/gcide/tests/dict/INFO: New file. * modules/gcide/tests/Makefile.am (TESTSUITE_AT): Add descr.at and info.at. * modules/gcide/tests/testsuite.at: Include descr.at and info.at * modules/gcide/tests/dicod.cfin: Remove description. * modules/gcide/tests/descr.at: New test case. * modules/gcide/tests/info.at: New test case. * modules/gcide/tests/def00.at: Update. * modules/gcide/tests/def01.at: Update. * modules/gcide/tests/def02.at: Update. * modules/gcide/tests/def03.at: Update. * modules/gcide/tests/def04.at: Update. * modules/gcide/tests/def05.at: Update. * scripts/Makefile.am: Exempt gcider from standard options check.
-rw-r--r--NEWS4
-rw-r--r--doc/dico.texi26
-rw-r--r--include/dico/util.h1
-rw-r--r--modules/gcide/gcide.c91
-rw-r--r--modules/gcide/tests/Makefile.am4
-rw-r--r--modules/gcide/tests/def00.at2
-rw-r--r--modules/gcide/tests/def01.at4
-rw-r--r--modules/gcide/tests/def02.at2
-rw-r--r--modules/gcide/tests/def03.at2
-rw-r--r--modules/gcide/tests/def04.at2
-rw-r--r--modules/gcide/tests/def05.at2
-rw-r--r--modules/gcide/tests/descr.at31
-rw-r--r--modules/gcide/tests/dicod.cfin1
-rw-r--r--modules/gcide/tests/dict/INFO14
-rw-r--r--modules/gcide/tests/info.at45
-rw-r--r--modules/gcide/tests/testsuite.at4
-rw-r--r--scripts/Makefile.am3
17 files changed, 207 insertions, 31 deletions
diff --git a/NEWS b/NEWS
index 3fd7b93..a0cc8d1 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,11 @@
1GNU Dico NEWS -- history of user-visible changes. 2012-03-03 1GNU Dico NEWS -- history of user-visible changes. 2012-03-04
2Copyright (C) 2008-2010, 2012 Sergey Poznyakoff 2Copyright (C) 2008-2010, 2012 Sergey Poznyakoff
3See the end of file for copying conditions. 3See the end of file for copying conditions.
4 4
5Please send Dico bug reports to <bug-dico@gnu.org.ua> 5Please send Dico bug reports to <bug-dico@gnu.org.ua>
6 6
7 7
8Version 2.2 (Git) 8Version 2.2, 2012-03-04
9 9
10* Configuration changes 10* Configuration changes
11 11
diff --git a/doc/dico.texi b/doc/dico.texi
index 59639a2..8c55707 100644
--- a/doc/dico.texi
+++ b/doc/dico.texi
@@ -2990,7 +2990,8 @@ for the user @command{dicod} is started as.
2990Other options are: 2990Other options are:
2991 2991
2992@deffn {gcide parameter} idxdir directory 2992@deffn {gcide parameter} idxdir directory
2993Specifies alternate directory for the @file{CIDE.IDX} index file. 2993Specifies the directory where the @file{CIDE.IDX} index file resides
2994or should reside.
2994@end deffn 2995@end deffn
2995 2996
2996@deffn {gcide parameter} index-cache-size size 2997@deffn {gcide parameter} index-cache-size size
@@ -3014,6 +3015,12 @@ fields have been filled in}, so it might be reasonable to avoid
3014displaying them at all. 3015displaying them at all.
3015@end deffn 3016@end deffn
3016 3017
3018 Starting from version 0.51, GCIDE contains the file @file{INFO},
3019which provides basic information about the dictionary. The
3020@command{gcide} module returns contents of this file at the
3021@samp{SHOW INFO} request. The first line of this file (with the
3022trailing newline and final point removed) is returned as the short
3023database description.
3017 3024
3018 Here's a full example of a @samp{gcide} as used in 3025 Here's a full example of a @samp{gcide} as used in
3019@indicateurl{dico.gnu.org.ua}: 3026@indicateurl{dico.gnu.org.ua}:
@@ -3024,28 +3031,13 @@ load-module gcide;
3024 3031
3025database @{ 3032database @{
3026 name "gcide"; 3033 name "gcide";
3027 handler "gcide dbdir=/var/dictdb/gcide suppress-pr"; 3034 handler "gcide dbdir=/var/dictdb/gcide-0.51 suppress-pr";
3028 languages-from "en"; 3035 languages-from "en";
3029 languages-to "en"; 3036 languages-to "en";
3030 description "Collaborative International Dictionary"
3031 " of English";
3032 info <<EOT
3033The dictionary was derived from the
3034 Webster's Revised Unabridged Dictionary
3035 Version published 1913
3036 by the C. & G. Merriam Co.
3037 Springfield, Mass.
3038 Under the direction of
3039 Noah Porter, D.D., LL.D.
3040@dots{}
3041EOT;
3042@} 3037@}
3043@end group 3038@end group
3044@end example 3039@end example
3045 3040
3046 The dots represent further content of the description which is too
3047big and irrelevant to copy it here.
3048
3049@menu 3041@menu
3050* idxgcide:: 3042* idxgcide::
3051@end menu 3043@end menu
diff --git a/include/dico/util.h b/include/dico/util.h
index 115ae08..899dbcb 100644
--- a/include/dico/util.h
+++ b/include/dico/util.h
@@ -18,6 +18,7 @@
18#define __dico_util_h 18#define __dico_util_h
19 19
20char *dico_full_file_name(const char *dir, const char *file); 20char *dico_full_file_name(const char *dir, const char *file);
21size_t dico_string_trim(char *buf, size_t len, int (*pred)(int c));
21size_t dico_trim_nl(char *buf); 22size_t dico_trim_nl(char *buf);
22size_t dico_trim_ws(char *buf); 23size_t dico_trim_ws(char *buf);
23 24
diff --git a/modules/gcide/gcide.c b/modules/gcide/gcide.c
index fa10c02..fbbd788 100644
--- a/modules/gcide/gcide.c
+++ b/modules/gcide/gcide.c
@@ -296,7 +296,94 @@ gcide_free_db(dico_handle_t hp)
296 free_db(db); 296 free_db(db);
297 return 0; 297 return 0;
298} 298}
299
300static int
301_is_nl_or_punct(int c)
302{
303 return !!strchr("\r\n!,-./:;?", c);
304}
305
306static char *
307read_info_file(const char *fname, int first_line)
308{
309 dico_stream_t stream;
310 int rc;
311 char *bufptr = NULL;
312 size_t bufsize = 0;
313
314 stream = dico_mapfile_stream_create(fname, DICO_STREAM_READ);
315 if (!stream) {
316 dico_log(L_NOTICE, errno, _("cannot create stream `%s'"), fname);
317 return NULL;
318 }
319
320 rc = dico_stream_open(stream);
321 if (rc) {
322 dico_log(L_ERR, 0,
323 _("cannot open stream `%s': %s"),
324 fname, dico_stream_strerror(stream, rc));
325 dico_stream_destroy(&stream);
326 return NULL;
327 }
328
329 if (first_line) {
330 size_t n;
331
332 rc = dico_stream_getline(stream, &bufptr, &bufsize, &n);
333 if (rc) {
334 dico_log(L_ERR, 0,
335 _("read error in stream `%s': %s"),
336 fname, dico_stream_strerror(stream, rc));
337 } else
338 dico_string_trim(bufptr, n, _is_nl_or_punct);
339 } else {
340 off_t size;
341 rc = dico_stream_size(stream, &size);
342 if (rc) {
343 dico_log(L_ERR, 0,
344 _("cannot get size of stream `%s': %s"),
345 fname, dico_stream_strerror(stream, rc));
346 } else {
347 bufsize = size;
348 bufptr = malloc (bufsize + 1);
349 if (!bufptr) {
350 dico_log(L_ERR, errno,
351 _("cannot allocate dictionary information buffer"));
352 } else if ((rc = dico_stream_read(stream, bufptr, bufsize, NULL))) {
353 dico_log(L_ERR, 0,
354 _("read error in stream `%s': %s"),
355 fname, dico_stream_strerror(stream, rc));
356 free(bufptr);
357 bufptr = NULL;
358 } else
359 bufptr[bufsize] = 0;
360 }
361 }
362
363 dico_stream_destroy(&stream);
364 return bufptr;
365}
366
367static char *
368read_dictionary_info(struct gcide_db *db, int first_line)
369{
370 char *fname = dico_full_file_name(db->db_dir, "INFO");
371 char *info = read_info_file(fname, first_line);
372 free(fname);
373 return info;
374}
375
376char *
377gcide_info(dico_handle_t hp)
378{
379 return read_dictionary_info((struct gcide_db *) hp, 0);
380}
299 381
382char *
383gcide_descr(dico_handle_t hp)
384{
385 return read_dictionary_info((struct gcide_db *) hp, 1);
386}
300 387
301static gcide_iterator_t 388static gcide_iterator_t
302exact_match(struct gcide_db *db, const char *hw) 389exact_match(struct gcide_db *db, const char *hw)
@@ -748,8 +835,8 @@ struct dico_database_module DICO_EXPORT(gcide, module) = {
748 gcide_free_db, 835 gcide_free_db,
749 NULL, 836 NULL,
750 NULL, 837 NULL,
751 NULL, 838 gcide_info,
752 NULL, 839 gcide_descr,
753 NULL, 840 NULL,
754 gcide_match, 841 gcide_match,
755 gcide_define, 842 gcide_define,
diff --git a/modules/gcide/tests/Makefile.am b/modules/gcide/tests/Makefile.am
index 3bbda92..3145258 100644
--- a/modules/gcide/tests/Makefile.am
+++ b/modules/gcide/tests/Makefile.am
@@ -27,7 +27,7 @@ noinst_DATA = dicod.conf
27CLEANFILES = dicod.conf 27CLEANFILES = dicod.conf
28 28