From: Adam Dickmeiss Date: Wed, 15 Jun 2005 21:31:45 +0000 (+0000) Subject: Removed map_only arg from chrmaptab_create. Added skeleton for proper X-Git-Tag: before.bug.529~386 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=be32b4e5c154545c2b91b76144d6cbf1238f969a Removed map_only arg from chrmaptab_create. Added skeleton for proper charmap test. --- diff --git a/include/charmap.h b/include/charmap.h index c3cd730..ed248e1 100644 --- a/include/charmap.h +++ b/include/charmap.h @@ -1,4 +1,4 @@ -/* $Id: charmap.h,v 1.13 2005-06-15 18:52:49 adam Exp $ +/* $Id: charmap.h,v 1.14 2005-06-15 21:31:45 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -38,7 +38,7 @@ typedef struct chr_t_entry chr_t_entry; typedef struct chrmaptab_info *chrmaptab; YAZ_EXPORT chrmaptab chrmaptab_create(const char *tabpath, const char *name, - int map_only, const char *tabroot); + const char *tabroot); YAZ_EXPORT void chrmaptab_destroy (chrmaptab tab); YAZ_EXPORT const char **chr_map_input(chrmaptab t, const char **from, int len, int first); diff --git a/util/.cvsignore b/util/.cvsignore index 7214120..07a336a 100644 --- a/util/.cvsignore +++ b/util/.cvsignore @@ -3,6 +3,8 @@ Makefile Makefile.in passtest +tstcharmap idzebra-config *.lo *.la +*.log diff --git a/util/Makefile.am b/util/Makefile.am index 11c6178..008071e 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,12 +1,16 @@ -## $Id: Makefile.am,v 1.14 2005-06-07 11:36:42 adam Exp $ +## $Id: Makefile.am,v 1.15 2005-06-15 21:31:45 adam Exp $ lib_LTLIBRARIES = libidzebra-util.la noinst_PROGRAMS = passtest +check_PROGRAMS = tstcharmap + +TESTS = $(check_PROGRAMS) + bin_SCRIPTS = idzebra-config -EXTRA_DIST = zebrasrv.rh +EXTRA_DIST = zebrasrv.rh tstcharmap.chr DISTCLEANFILES = idzebra-config @@ -17,3 +21,5 @@ libidzebra_util_la_SOURCES = zint.c res.c charmap.c zebramap.c passwddb.c \ zebra-lock.c dirent.c xpath.c atoi_zn.c snippet.c passtest_SOURCES = passtest.c + +tstcharmap_SOURCES = tstcharmap.c diff --git a/util/charmap.c b/util/charmap.c index 2919837..f5f6207 100644 --- a/util/charmap.c +++ b/util/charmap.c @@ -1,4 +1,4 @@ -/* $Id: charmap.c,v 1.37 2005-06-14 12:42:49 adam Exp $ +/* $Id: charmap.c,v 1.38 2005-06-15 21:31:45 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -510,8 +510,8 @@ static int scan_string(char *s_native, return 0; } -chrmaptab chrmaptab_create(const char *tabpath, const char *name, int map_only, - const char *tabroot) +chrmaptab chrmaptab_create(const char *tabpath, const char *name, + const char *tabroot) { FILE *f; char line[512], *argv[50]; @@ -525,17 +525,18 @@ chrmaptab chrmaptab_create(const char *tabpath, const char *name, int map_only, unsigned endian = 31; const char *ucs4_native = "UCS-4"; - if (*(char*) &endian == 31) /* little endian? */ - ucs4_native = "UCS-4LE"; - - t_utf8 = yaz_iconv_open ("UTF-8", ucs4_native); - yaz_log (YLOG_DEBUG, "maptab %s open", name); if (!(f = yaz_fopen(tabpath, name, "r", tabroot))) { yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", name); return 0; } + + if (*(char*) &endian == 31) /* little endian? */ + ucs4_native = "UCS-4LE"; + + t_utf8 = yaz_iconv_open ("UTF-8", ucs4_native); + nmem = nmem_create (); res = (chrmaptab) nmem_malloc(nmem, sizeof(*res)); res->nmem = nmem; @@ -554,15 +555,7 @@ chrmaptab chrmaptab_create(const char *tabpath, const char *name, int map_only, res->input->children[i]->target = (unsigned char **) nmem_malloc (res->nmem, 2 * sizeof(unsigned char *)); res->input->children[i]->target[1] = 0; - if (map_only) - { - res->input->children[i]->target[0] = (unsigned char *) - nmem_malloc (res->nmem, 2 * sizeof(unsigned char)); - res->input->children[i]->target[0][0] = i; - res->input->children[i]->target[0][1] = 0; - } - else - res->input->children[i]->target[0] = (unsigned char*) CHR_UNKNOWN; + res->input->children[i]->target[0] = (unsigned char*) CHR_UNKNOWN; } res->q_input = (chr_t_entry *) nmem_malloc(res->nmem, sizeof(*res->q_input)); @@ -576,7 +569,7 @@ chrmaptab chrmaptab_create(const char *tabpath, const char *name, int map_only, res->base_uppercase = 0; while (!errors && (argc = readconf_line(f, &lineno, line, 512, argv, 50))) - if (!map_only && !yaz_matchstr(argv[0], "lowercase")) + if (!yaz_matchstr(argv[0], "lowercase")) { if (argc != 2) { @@ -594,7 +587,7 @@ chrmaptab chrmaptab_create(const char *tabpath, const char *name, int map_only, res->output[(int) *CHR_UNKNOWN + num] = (unsigned char*) "@"; num = (int) *CHR_BASE; } - else if (!map_only && !yaz_matchstr(argv[0], "uppercase")) + else if (!yaz_matchstr(argv[0], "uppercase")) { if (!res->base_uppercase) { @@ -613,7 +606,7 @@ chrmaptab chrmaptab_create(const char *tabpath, const char *name, int map_only, ++errors; } } - else if (!map_only && !yaz_matchstr(argv[0], "space")) + else if (!yaz_matchstr(argv[0], "space")) { if (argc != 2) { @@ -627,7 +620,7 @@ chrmaptab chrmaptab_create(const char *tabpath, const char *name, int map_only, ++errors; } } - else if (!map_only && !yaz_matchstr(argv[0], "cut")) + else if (!yaz_matchstr(argv[0], "cut")) { if (argc != 2) { diff --git a/util/tstcharmap.c b/util/tstcharmap.c new file mode 100644 index 0000000..edff882 --- /dev/null +++ b/util/tstcharmap.c @@ -0,0 +1,59 @@ +/* $Id: tstcharmap.c,v 1.1 2005-06-15 21:31:45 adam Exp $ + Copyright (C) 1995-2005 + Index Data ApS + +This file is part of the Zebra server. + +Zebra 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 2, or (at your option) any later +version. + +Zebra 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 Zebra; see the file LICENSE.zebra. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. +*/ + +#include +#include +#include +#include + +void tst1() +{ + /* open existing map chrmaptab.chr */ + chrmaptab tab = chrmaptab_create(0 /* tabpath */, + "tstcharmap.chr" /* file */, + 0 /* tabroot */ ); + assert(tab); + + chrmaptab_destroy(tab); +} + +void tst2() +{ + /* open non-existing nonexist.chr */ + chrmaptab tab = chrmaptab_create(0 /* tabpath */, + "nonexist.chr" /* file */, + 0 /* tabroot */ ); + assert(!tab); +} + +int main(int argc, char **argv) +{ + char logname[2048]; + sprintf(logname, "%s.log", argv[0]); + yaz_log_init_file(logname); + + tst1(); + tst2(); + + exit(0); +} + diff --git a/util/tstcharmap.chr b/util/tstcharmap.chr new file mode 100644 index 0000000..c217831 --- /dev/null +++ b/util/tstcharmap.chr @@ -0,0 +1,42 @@ +# Generic character map. +# +# $Id: tstcharmap.chr,v 1.1 2005-06-15 21:31:45 adam Exp $ + +# Define the basic value-set. *Beware* of changing this without re-indexing +# your databases. + +lowercase {0-9}{a-y}üzæäøöå +uppercase {0-9}{A-Y}ÜZÆÄØÖÅ + +# Breaking characters + +space {\001-\040}!"#$%&'\()*+,-./:;<=>?@\[\\]^_`\{|}~ + +# Characters to be considered equivalent for searching purposes. + +# equivalent æä(ae) +# equivalent øö(oe) +# equivalent å(aa) +# equivalent uü + +# Supplemental mappings + +#map (ä) ä +#map (æ) æ +#map (ø) ø +#map (å) å +#map (ö) ö +#map (Ä) Ä +#map (&Aelig;) Æ +#map (Ø) Ø +#map (Å) Å +#map (Ö) Ö + +#map éÉ e +#map á a +#map ó o +#map í i + +#map (Aa) (AA) + +#map (aa) a diff --git a/util/zebramap.c b/util/zebramap.c index 991d16b..30f74c6 100644 --- a/util/zebramap.c +++ b/util/zebramap.c @@ -1,4 +1,4 @@ -/* $Id: zebramap.c,v 1.41 2005-06-14 12:42:49 adam Exp $ +/* $Id: zebramap.c,v 1.42 2005-06-15 21:31:45 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -215,7 +215,7 @@ chrmaptab zebra_charmap_get (ZebraMaps zms, unsigned reg_id) if (!zm->maptab_name || !yaz_matchstr (zm->maptab_name, "@")) return NULL; if (!(zm->maptab = chrmaptab_create (zms->tabpath, - zm->maptab_name, 0, + zm->maptab_name, zms->tabroot))) yaz_log(YLOG_WARN, "Failed to read character table %s", zm->maptab_name);