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 | 3 |
17 files changed, 207 insertions, 31 deletions
@@ -1,11 +1,11 @@ -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 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. 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 @@ -3014,6 +3015,12 @@ 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}: @@ -3024,28 +3031,13 @@ 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 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 @@ #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); 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) 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) @@ -748,8 +835,8 @@ struct dico_database_module DICO_EXPORT(gcide, module) = { gcide_free_db, NULL, NULL, - NULL, - NULL, + gcide_info, + gcide_descr, NULL, gcide_match, 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 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 - ## ------------ ## @@ -71,9 +71,11 @@ TESTSUITE_AT = \ def03.at\ def04.at\ def05.at\ + descr.at\ exact.at\ greek.at\ idx.at\ + info.at\ markup.at\ nopr.at\ prefix.at\ 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 @@ -21,7 +21,7 @@ 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 @@ -21,14 +21,14 @@ 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 @@ -21,7 +21,7 @@ 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 @@ -21,7 +21,7 @@ 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 @@ -21,7 +21,7 @@ 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 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 @@ -21,7 +21,7 @@ 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 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 @@ -5,7 +5,6 @@ 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 @@ -34,6 +34,10 @@ 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) diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 3db7a7c..e09a234 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -18,4 +18,5 @@ if TK_WISH_COND GCIDER=gcider endif bin_SCRIPTS = $(GCIDER) -EXTRA_DIST = gcider
\ No newline at end of file +EXTRA_DIST = gcider +AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = gcider |