aboutsummaryrefslogtreecommitdiff
path: root/modules/gcide
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gcide')
-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
13 files changed, 193 insertions, 11 deletions
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)

Return to:

Send suggestions and report system problems to the System administrator.