diff options
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | doc/dico.texi | 26 | ||||
-rw-r--r-- | include/dico/util.h | 1 | ||||
-rw-r--r-- | modules/gcide/gcide.c | 91 | ||||
-rw-r--r-- | modules/gcide/tests/Makefile.am | 4 | ||||
-rw-r--r-- | modules/gcide/tests/def00.at | 2 | ||||
-rw-r--r-- | modules/gcide/tests/def01.at | 4 | ||||
-rw-r--r-- | modules/gcide/tests/def02.at | 2 | ||||
-rw-r--r-- | modules/gcide/tests/def03.at | 2 | ||||
-rw-r--r-- | modules/gcide/tests/def04.at | 2 | ||||
-rw-r--r-- | modules/gcide/tests/def05.at | 2 | ||||
-rw-r--r-- | modules/gcide/tests/descr.at | 31 | ||||
-rw-r--r-- | modules/gcide/tests/dicod.cfin | 1 | ||||
-rw-r--r-- | modules/gcide/tests/dict/INFO | 14 | ||||
-rw-r--r-- | modules/gcide/tests/info.at | 45 | ||||
-rw-r--r-- | modules/gcide/tests/testsuite.at | 4 | ||||
-rw-r--r-- | scripts/Makefile.am | 1 |
17 files changed, 206 insertions, 30 deletions
@@ -1,14 +1,14 @@ -GNU Dico NEWS -- history of user-visible changes. 2012-03-03 +GNU Dico NEWS -- history of user-visible changes. 2012-03-04 Copyright (C) 2008-2010, 2012 Sergey Poznyakoff See the end of file for copying conditions. Please send Dico bug reports to <bug-dico@gnu.org.ua> -Version 2.2 (Git) +Version 2.2, 2012-03-04 * Configuration changes ** load-module The load-module form allows for a statement use, e.g.: diff --git a/doc/dico.texi b/doc/dico.texi index 59639a2..8c55707 100644 --- a/doc/dico.texi +++ b/doc/dico.texi @@ -2987,13 +2987,14 @@ otherwise, this file is created in the same directory where the database files are located, therefore the directory must be writable for the user @command{dicod} is started as. Other options are: @deffn {gcide parameter} idxdir directory -Specifies alternate directory for the @file{CIDE.IDX} index file. +Specifies the directory where the @file{CIDE.IDX} index file resides +or should reside. @end deffn @deffn {gcide parameter} index-cache-size size Sets the maximum number of index pages the module keeps in memory simultaneously. The default value is 16. The pages are cached using the @dfn{last recently used} algorithm. Raising this value will make @@ -3011,44 +3012,35 @@ useful for the module developers. This parameter suppresses the output of @samp{pr} (pronunciation) tags. According to GCIDE docs, @cite{very few of the pronunciation fields have been filled in}, so it might be reasonable to avoid displaying them at all. @end deffn + Starting from version 0.51, GCIDE contains the file @file{INFO}, +which provides basic information about the dictionary. The +@command{gcide} module returns contents of this file at the +@samp{SHOW INFO} request. The first line of this file (with the +trailing newline and final point removed) is returned as the short +database description. Here's a full example of a @samp{gcide} as used in @indicateurl{dico.gnu.org.ua}: @example @group load-module gcide; database @{ name "gcide"; - handler "gcide dbdir=/var/dictdb/gcide suppress-pr"; + handler "gcide dbdir=/var/dictdb/gcide-0.51 suppress-pr"; languages-from "en"; languages-to "en"; - description "Collaborative International Dictionary" - " of English"; - info <<EOT -The dictionary was derived from the - Webster's Revised Unabridged Dictionary - Version published 1913 - by the C. & G. Merriam Co. - Springfield, Mass. - Under the direction of - Noah Porter, D.D., LL.D. -@dots{} -EOT; @} @end group @end example - The dots represent further content of the description which is too -big and irrelevant to copy it here. - @menu * idxgcide:: @end menu @node idxgcide @subsection @command{idxgcide} 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 @@ -15,10 +15,11 @@ along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. */ #ifndef __dico_util_h #define __dico_util_h char *dico_full_file_name(const char *dir, const char *file); +size_t dico_string_trim(char *buf, size_t len, int (*pred)(int c)); size_t dico_trim_nl(char *buf); size_t dico_trim_ws(char *buf); #endif 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 @@ -294,12 +294,99 @@ gcide_free_db(dico_handle_t hp) { struct gcide_db *db = (struct gcide_db *) hp; free_db(db); return 0; } +static int +_is_nl_or_punct(int c) +{ + return !!strchr("\r\n!,-./:;?", c); +} + +static char * +read_info_file(const char *fname, int first_line) +{ + dico_stream_t stream; + int rc; + char *bufptr = NULL; + size_t bufsize = 0; + + stream = dico_mapfile_stream_create(fname, DICO_STREAM_READ); + if (!stream) { + dico_log(L_NOTICE, errno, _("cannot create stream `%s'"), fname); + return NULL; + } + + rc = dico_stream_open(stream); + if (rc) { + dico_log(L_ERR, 0, + _("cannot open stream `%s': %s"), + fname, dico_stream_strerror(stream, rc)); + dico_stream_destroy(&stream); + return NULL; + } + + if (first_line) { + size_t n; + + rc = dico_stream_getline(stream, &bufptr, &bufsize, &n); + if (rc) { + dico_log(L_ERR, 0, + _("read error in stream `%s': %s"), + fname, dico_stream_strerror(stream, rc)); + } else + dico_string_trim(bufptr, n, _is_nl_or_punct); + } else { + off_t size; + rc = dico_stream_size(stream, &size); + if (rc) { + dico_log(L_ERR, 0, + _("cannot get size of stream `%s': %s"), + fname, dico_stream_strerror(stream, rc)); + } else { + bufsize = size; + bufptr = malloc (bufsize + 1); + if (!bufptr) { + dico_log(L_ERR, errno, + _("cannot allocate dictionary information buffer")); + } else if ((rc = dico_stream_read(stream, bufptr, bufsize, NULL))) { + dico_log(L_ERR, 0, + _("read error in stream `%s': %s"), + fname, dico_stream_strerror(stream, rc)); + free(bufptr); + bufptr = NULL; + } else + bufptr[bufsize] = 0; + } + } + + dico_stream_destroy(&stream); + return bufptr; +} + +static char * +read_dictionary_info(struct gcide_db *db, int first_line) +{ + char *fname = dico_full_file_name(db->db_dir, "INFO"); + char *info = read_info_file(fname, first_line); + free(fname); + return info; +} + +char * +gcide_info(dico_handle_t hp) +{ + return read_dictionary_info((struct gcide_db *) hp, 0); +} + +char * +gcide_descr(dico_handle_t hp) +{ + return read_dictionary_info((struct gcide_db *) hp, 1); +} static gcide_iterator_t exact_match(struct gcide_db *db, const char *hw) { return gcide_idx_locate(db->idx, (char*)hw, 0); } @@ -745,14 +832,14 @@ struct dico_database_module DICO_EXPORT(gcide, module) = { DICO_CAPA_NONE, gcide_init, gcide_init_db, gcide_free_db, NULL, NULL, - NULL, - NULL, + gcide_info, + gcide_descr, NULL, gcide_match, gcide_define, gcide_output_result, gcide_result_count, gcide_compare_count, 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 @@ -24,13 +24,13 @@ SUFFIXES = .cfin .conf $(AM_V_GEN)sed 's|~moddir~|$(abs_top_builddir)/modules|g;s|~dictdir~|$(abs_srcdir)/dict|g;s|~idxdir~|$(abs_builddir)|g' $< > $@ noinst_DATA = dicod.conf CLEANFILES = dicod.conf dist-hook: - tar -C $(srcdir) -c -f - dict/CIDE.[A-Z] | \ + tar -C $(srcdir) -c -f - dict/CIDE.[A-Z] dict/INFO | \ tar -C $(distdir) -x -f - ## ------------ ## ## package.m4. ## ## ------------ ## @@ -68,15 +68,17 @@ TESTSUITE_AT = \ def00.at\ def01.at\ def02.at\ def03.at\ def04.at\ def05.at\ + descr.at\ exact.at\ greek.at\ idx.at\ + info.at\ markup.at\ nopr.at\ prefix.at\ testsuite.at TESTSUITE = $(srcdir)/testsuite diff --git a/modules/gcide/tests/def00.at b/modules/gcide/tests/def00.at index bd8a153..bbf134e 100644 --- a/modules/gcide/tests/def00.at +++ b/modules/gcide/tests/def00.at @@ -18,13 +18,13 @@ AT_SETUP([define (single entry)]) AT_KEYWORDS([define def00]) AT_DICOD([define gcide GNU quit ], [220 150 1 definitions found: list follows -151 "GNU" gcide "A mock GCIDE dictionary" +151 "GNU" gcide "A mock GCIDE dictionary for GNU Dico test suite" GNU n. GNU's Not UNIX. [[Dico testsuite]] . diff --git a/modules/gcide/tests/def01.at b/modules/gcide/tests/def01.at index 0f2ed99..f12d5bb 100644 --- a/modules/gcide/tests/def01.at +++ b/modules/gcide/tests/def01.at @@ -18,20 +18,20 @@ AT_SETUP([define (multiple entries)]) AT_KEYWORDS([define def01]) AT_DICOD([define gcide kludge quit ], [220 150 2 definitions found: list follows -151 "kludge" gcide "A mock GCIDE dictionary" +151 "kludge" gcide "A mock GCIDE dictionary for GNU Dico test suite" kludge n. A working solution, not particularly elegant. [[Dico testsuite]] . -151 "kludge" gcide "A mock GCIDE dictionary" +151 "kludge" gcide "A mock GCIDE dictionary for GNU Dico test suite" kludge v. To use such a solution. [[Dico testsuite]] diff --git a/modules/gcide/tests/def02.at b/modules/gcide/tests/def02.at index eeb2722..18631ff 100644 --- a/modules/gcide/tests/def02.at +++ b/modules/gcide/tests/def02.at @@ -18,13 +18,13 @@ AT_SETUP([double-bar handling]) AT_KEYWORDS([define def02]) AT_DICOD([define gcide atlantes quit ], [220 150 1 definitions found: list follows -151 "atlantes" gcide "A mock GCIDE dictionary" +151 "atlantes" gcide "A mock GCIDE dictionary for GNU Dico test suite" ‖Atlantes, n. pl. A definition with alternate name telamones. [[Dico testsuite]] diff --git a/modules/gcide/tests/def03.at b/modules/gcide/tests/def03.at index 6393734..f20f01a 100644 --- a/modules/gcide/tests/def03.at +++ b/modules/gcide/tests/def03.at @@ -18,13 +18,13 @@ AT_SETUP([altname]) AT_KEYWORDS([define def03]) AT_DICOD([define gcide telamones quit ], [220 150 1 definitions found: list follows -151 "telamones" gcide "A mock GCIDE dictionary" +151 "telamones" gcide "A mock GCIDE dictionary for GNU Dico test suite" ||Atlantes, n. pl. A definition with alternate name telamones. [[Dico testsuite]] diff --git a/modules/gcide/tests/def04.at b/modules/gcide/tests/def04.at index 73b49a3..1b23b32 100644 --- a/modules/gcide/tests/def04.at +++ b/modules/gcide/tests/def04.at @@ -18,13 +18,13 @@ AT_SETUP([mhw]) AT_KEYWORDS([define def04]) AT_DICOD([define gcide cyclic quit ], [220 150 1 definitions found: list follows -151 "cyclic" gcide "A mock GCIDE dictionary" +151 "cyclic" gcide "A mock GCIDE dictionary for GNU Dico test suite" { Cyclic, Cyclical} a. [[Gr. κυκλικός, fr. κύκλος See {Cycle}.]] Going in cycles [[Dico testsuite]] diff --git a/modules/gcide/tests/def05.at b/modules/gcide/tests/def05.at index 16f17e0..bd8db48 100644 --- a/modules/gcide/tests/def05.at +++ b/modules/gcide/tests/def05.at @@ -18,13 +18,13 @@ AT_SETUP([mhw (second definition)]) AT_KEYWORDS([define def05]) AT_DICOD([define gcide cyclical quit ], [220 150 1 definitions found: list follows -151 "cyclical" gcide "A mock GCIDE dictionary" +151 "cyclical" gcide "A mock GCIDE dictionary for GNU Dico test suite" { Cyclic, Cyclical} a. [[Gr. κυκλικός, fr. κύκλος See {Cycle}.]] Going in cycles [[Dico testsuite]] diff --git a/modules/gcide/tests/descr.at b/modules/gcide/tests/descr.at new file mode 100644 index 0000000..9d3d153 --- /dev/null +++ b/modules/gcide/tests/descr.at @@ -0,0 +1,31 @@ +# This file is part of GNU Dico -*- Autotest -*- +# Copyright (C) 2012 Sergey Poznyakoff +# +# GNU Dico is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Dico is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([descr]) +AT_KEYWORDS([descr]) + +AT_DICOD([show db +quit +], +[220 +110 1 databases present +gcide "A mock GCIDE dictionary for GNU Dico test suite" +. +250 +221 +]) +AT_CLEANUP + diff --git a/modules/gcide/tests/dicod.cfin b/modules/gcide/tests/dicod.cfin index 056f82a..8e5edf5 100644 --- a/modules/gcide/tests/dicod.cfin +++ b/modules/gcide/tests/dicod.cfin @@ -2,13 +2,12 @@ capability lang; timing no; prepend-load-path ("~moddir~/gcide","~moddir~/stratall"); load-module gcide; load-module stratall; database { name "gcide"; - description "A mock GCIDE dictionary"; handler "gcide dbdir=~dictdir~ idxdir=~idxdir~ index-program=~moddir~/gcide/idxgcide"; } diff --git a/modules/gcide/tests/dict/INFO b/modules/gcide/tests/dict/INFO new file mode 100644 index 0000000..a392421 --- /dev/null +++ b/modules/gcide/tests/dict/INFO @@ -0,0 +1,14 @@ +A mock GCIDE dictionary for GNU Dico test suite. + +GNU Dico is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GNU Dico is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. diff --git a/modules/gcide/tests/info.at b/modules/gcide/tests/info.at new file mode 100644 index 0000000..b237c8c --- /dev/null +++ b/modules/gcide/tests/info.at @@ -0,0 +1,45 @@ +# This file is part of GNU Dico -*- Autotest -*- +# Copyright (C) 2012 Sergey Poznyakoff +# +# GNU Dico is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Dico is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([info]) +AT_KEYWORDS([info]) + +AT_DICOD([show info gcide +quit +], +[220 +112 information for gcide +A mock GCIDE dictionary for GNU Dico test suite. + +GNU Dico is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GNU Dico is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. + +. +250 +221 +]) +AT_CLEANUP + diff --git a/modules/gcide/tests/testsuite.at b/modules/gcide/tests/testsuite.at index 681ae90..0d034f9 100644 --- a/modules/gcide/tests/testsuite.at +++ b/modules/gcide/tests/testsuite.at @@ -31,12 +31,16 @@ AT_BANNER(General) m4_include(markup.at) m4_include(nopr.at) m4_include(greek.at) m4_include(idx.at) m4_include(autoidx.at) +AT_BANNER([Dictionary info]) +m4_include(descr.at) +m4_include(info.at) + AT_BANNER(Match) m4_include(exact.at) m4_include(prefix.at) m4_include(all.at) AT_BANNER(Define) diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 3db7a7c..e09a234 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -16,6 +16,7 @@ if TK_WISH_COND GCIDER=gcider endif bin_SCRIPTS = $(GCIDER) EXTRA_DIST = gcider +AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = gcider |