cb9d0b41803a24a0ba5e18d91a9d42d20d0fbcdc
[idzebra-moved-to-github.git] / util / charmap.c
1 /* $Id: charmap.c,v 1.39 2005-08-22 08:17:01 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23
24
25 /*
26  * Support module to handle character-conversions into and out of the
27  * Zebra dictionary.
28  */
29
30 #include <ctype.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <assert.h>
34
35 typedef unsigned ucs4_t;
36
37 #include <charmap.h>
38
39 #include <yaz/yaz-util.h>
40
41 #define CHR_MAXSTR 1024
42 #define CHR_MAXEQUIV 32
43
44 const unsigned char CHR_FIELD_BEGIN = '^';
45
46 const char *CHR_UNKNOWN = "\001";
47 const char *CHR_SPACE   = "\002";
48 const char *CHR_CUT     = "\003";
49 const char *CHR_BASE    = "\005";
50
51 struct chrmaptab_info
52 {
53     chr_t_entry *input;         /* mapping table for input data */
54     chr_t_entry *q_input;       /* mapping table for queries */
55     unsigned char *output[256]; /* return mapping - for display of registers */
56     int base_uppercase;         /* Start of upper-case ordinals */
57     NMEM nmem;
58 };
59
60 /*
61  * Character map trie node.
62  */
63 struct chr_t_entry
64 {
65     chr_t_entry **children;  /* array of children */
66     unsigned char **target;  /* target for this node, if any */
67 };
68
69 /*
70  * General argument structure for callback functions (internal use only)
71  */
72 typedef struct chrwork 
73 {
74     chrmaptab map;
75     char string[CHR_MAXSTR+1];
76 } chrwork;
77
78 /*
79  * Callback for equivalent stuff
80  */
81 typedef struct
82 {
83     NMEM nmem;
84     int no_eq;
85     char *eq[CHR_MAXEQUIV];
86 } chr_equiv_work;
87 /*
88  * Add an entry to the character map.
89  */
90 static chr_t_entry *set_map_string(chr_t_entry *root, NMEM nmem,
91                                    const char *from, int len, char *to,
92                                    const char *from_0)
93 {
94     if (!from_0)
95         from_0 = from;
96     if (!root)
97     {
98         root = (chr_t_entry *) nmem_malloc(nmem, sizeof(*root));
99         root->children = 0;
100         root->target = 0;
101     }
102     if (!len)
103     {
104         if (!root->target || !root->target[0] || 
105             strcmp((const char *) root->target[0], to))
106         {
107             if (from_0 && 
108                 root->target && root->target[0] && root->target[0][0] &&
109                 strcmp((const char *) root->target[0], CHR_UNKNOWN))
110             {
111                 yaz_log (YLOG_WARN, "duplicate entry for charmap from '%s'",
112                          from_0);
113             }
114             root->target = (unsigned char **)
115                 nmem_malloc(nmem, sizeof(*root->target)*2);
116             root->target[0] = (unsigned char *) nmem_strdup(nmem, to);
117             root->target[1] = 0;
118         }
119     }
120     else
121     {
122         if (!root->children)
123         {
124             int i;
125
126             root->children = (chr_t_entry **)
127                 nmem_malloc(nmem, sizeof(chr_t_entry*) * 256);
128             for (i = 0; i < 256; i++)
129                 root->children[i] = 0;
130         }
131         if (!(root->children[(unsigned char) *from] =
132             set_map_string(root->children[(unsigned char) *from], nmem,
133                            from + 1, len - 1, to, from_0)))
134             return 0;
135     }
136     return root;
137 }
138
139 static chr_t_entry *find_entry(chr_t_entry *t, const char **from, int len)
140 {
141     chr_t_entry *res;
142
143     if (len && t->children && t->children[(unsigned char) **from])
144     {
145         const char *pos = *from;
146
147         (*from)++;
148         if ((res = find_entry(t->children[(unsigned char) *pos],
149             from, len - 1)))
150             return res;
151         /* no match */
152         *from = pos;
153     }
154     /* no children match. use ourselves, if we have a target */
155     return t->target ? t : 0;
156 }
157
158 static chr_t_entry *find_entry_x(chr_t_entry *t, const char **from, int *len, int first)
159 {
160     chr_t_entry *res;
161
162     while (*len <= 0)
163     {   /* switch to next buffer */
164         if (*len < 0)
165             break;
166         from++;
167         len++;
168     }
169     if (*len > 0 && t->children)
170     {
171         const char *old_from = *from;
172         int old_len = *len;
173
174         res = 0;
175
176         if (first && t->children[CHR_FIELD_BEGIN])
177         {
178             if ((res = find_entry_x(t->children[CHR_FIELD_BEGIN], from, len, 0)) && res != t->children[CHR_FIELD_BEGIN])
179                 return res;
180             else
181                 res = 0;
182             /* otherwhise there was no match on beginning of field, move on */
183         } 
184         
185         if (!res && t->children[(unsigned char) **from])
186         {
187             (*len)--;
188             (*from)++;
189             if ((res = find_entry_x(t->children[(unsigned char) *old_from],
190                                     from, len, 0)))
191                 return res;
192             /* no match */
193             *len = old_len;
194             *from = old_from;
195         }
196     }
197     /* no children match. use ourselves, if we have a target */
198     return t->target ? t : 0;
199 }
200
201 const char **chr_map_input_x(chrmaptab maptab, const char **from, int *len, int first)
202 {
203     chr_t_entry *t = maptab->input;
204     chr_t_entry *res;
205
206     if (!(res = find_entry_x(t, from, len, first)))
207         abort();
208     return (const char **) (res->target);
209 }
210
211 const char **chr_map_input(chrmaptab maptab, const char **from, int len, int first)
212 {
213     chr_t_entry *t = maptab->input;
214     chr_t_entry *res;
215     int len_tmp[2];
216
217     len_tmp[0] = len;
218     len_tmp[1] = -1;
219     if (!(res = find_entry_x(t, from, len_tmp, first)))
220         abort();
221     return (const char **) (res->target);
222 }
223
224 const char **chr_map_q_input(chrmaptab maptab,
225                              const char **from, int len, int first)
226 {
227     chr_t_entry *t = maptab->q_input;
228     chr_t_entry *res;
229     int len_tmp[2];
230     
231     len_tmp[0] = len;
232     len_tmp[1] = -1;
233     if (!(res = find_entry_x(t, from, len_tmp, first)))
234         return 0;
235     return (const char **) (res->target);
236 }
237
238 const char *chr_map_output(chrmaptab maptab, const char **from, int len)
239 {
240     unsigned char c = ** (unsigned char **) from;
241     (*from)++;
242     return (const char*) maptab->output[c];
243 }
244
245 static int zebra_ucs4_strlen(ucs4_t *s)
246 {
247     int i = 0;
248     while (*s++)
249         i++;
250     return i;
251 }
252
253 ucs4_t zebra_prim_w(ucs4_t **s)
254 {
255     ucs4_t c;
256     ucs4_t i = 0;
257     char fmtstr[8];
258
259     yaz_log (YLOG_DEBUG, "prim_w %.3s", (char *) *s);
260     if (**s == '\\' && 1[*s])
261     {
262         (*s)++;
263         c = **s;
264         switch (c)
265         {
266         case '\\': c = '\\'; (*s)++; break;
267         case 'r': c = '\r'; (*s)++; break;
268         case 'n': c = '\n'; (*s)++; break;
269         case 't': c = '\t'; (*s)++; break;
270         case 's': c = ' '; (*s)++; break;
271         case 'x': 
272             if (zebra_ucs4_strlen(*s) >= 3)
273             {
274                 fmtstr[0] = (*s)[1];
275                 fmtstr[1] = (*s)[2];
276                 fmtstr[2] = 0;
277                 sscanf(fmtstr, "%x", &i);
278                 c = i;
279                 *s += 3;
280             }
281             break;
282         case '0':
283         case '1':
284         case '2':
285         case '3':
286         case '4':
287         case '5':
288         case '6':
289         case '7':
290         case '8':
291         case '9':
292             if (zebra_ucs4_strlen(*s) >= 3)
293             {
294                 fmtstr[0] = (*s)[0];
295                 fmtstr[1] = (*s)[1];
296                 fmtstr[2] = (*s)[2];
297                 fmtstr[3] = 0;
298                 sscanf(fmtstr, "%o", &i);
299                 c = i;
300                 *s += 3;
301             }
302             break;
303         case 'L':
304             if (zebra_ucs4_strlen(*s) >= 5)
305             {
306                 fmtstr[0] = (*s)[1];
307                 fmtstr[1] = (*s)[2];
308                 fmtstr[2] = (*s)[3];
309                 fmtstr[3] = (*s)[4];
310                 fmtstr[4] = 0;
311                 sscanf(fmtstr, "%x", &i);
312                 c = i;
313                 *s += 5;
314             }
315             break;
316         default:
317             (*s)++;
318         }
319     }
320     else
321     {
322         c = **s;
323         ++(*s);
324     }
325     yaz_log (YLOG_DEBUG, "out %d", c);
326     return c;
327 }
328
329 /*
330  * Callback function.
331  * Add an entry to the value space.
332  */
333 static void fun_addentry(const char *s, void *data, int num)
334 {
335     chrmaptab tab = (chrmaptab) data;
336     char tmp[2];
337     
338     tmp[0] = num; tmp[1] = '\0';
339     tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s), tmp, 0);
340     tab->output[num + tab->base_uppercase] =
341         (unsigned char *) nmem_strdup(tab->nmem, s);
342 }
343
344 /* 
345  * Callback function.
346  * Add a space-entry to the value space.
347  */
348 static void fun_addspace(const char *s, void *data, int num)
349 {
350     chrmaptab tab = (chrmaptab) data;
351     tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s),
352                                 (char*) CHR_SPACE, 0);
353 }
354
355 /* 
356  * Callback function.
357  * Add a space-entry to the value space.
358  */
359 static void fun_addcut(const char *s, void *data, int num)
360 {
361     chrmaptab tab = (chrmaptab) data;
362     tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s),
363                                 (char*) CHR_CUT, 0);
364 }
365
366 /*
367  * Create a string containing the mapped characters provided.
368  */
369 static void fun_mkstring(const char *s, void *data, int num)
370 {
371     chrwork *arg = (chrwork *) data;
372     const char **res, *p = s;
373
374     res = chr_map_input(arg->map, &s, strlen(s), 0);
375     if (*res == (char*) CHR_UNKNOWN)
376         yaz_log(YLOG_WARN, "Map: '%s' has no mapping", p);
377     strncat(arg->string, *res, CHR_MAXSTR - strlen(arg->string));
378     arg->string[CHR_MAXSTR] = '\0';
379 }
380
381 /*
382  * Create an unmodified string (scan_string handler).
383  */
384 static void fun_add_equivalent_string(const char *s, void *data, int num)
385 {
386     chr_equiv_work *arg = (chr_equiv_work *) data;
387     
388     if (arg->no_eq == CHR_MAXEQUIV)
389         return;
390     arg->eq[arg->no_eq++] = nmem_strdup(arg->nmem, s);
391 }
392
393 /*
394  * Add a map to the string contained in the argument.
395  */
396 static void fun_add_map(const char *s, void *data, int num)
397 {
398     chrwork *arg = (chrwork *) data;
399
400     assert(arg->map->input);
401     yaz_log (YLOG_DEBUG, "set map %.*s", (int) strlen(s), s);
402     set_map_string(arg->map->input, arg->map->nmem, s, strlen(s), arg->string,
403                    0);
404     for (s = arg->string; *s; s++)
405         yaz_log (YLOG_DEBUG, " %3d", (unsigned char) *s);
406 }
407
408 static int scan_to_utf8 (yaz_iconv_t t, ucs4_t *from, size_t inlen,
409                         char *outbuf, size_t outbytesleft)
410 {
411     size_t inbytesleft = inlen * sizeof(ucs4_t);
412     char *inbuf = (char*) from;
413     size_t ret;
414    
415     if (t == 0)
416         *outbuf++ = *from;  /* ISO-8859-1 is OK here */
417     else
418     {
419         ret = yaz_iconv (t, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
420         if (ret == (size_t) (-1))
421         {
422             yaz_log(YLOG_LOG, "from: %2X %2X %2X %2X",
423                     from[0], from[1], from[2], from[3]);
424             yaz_log (YLOG_WARN|YLOG_ERRNO, "bad unicode sequence");
425             return -1;
426         }
427     }
428     *outbuf = '\0';
429     return 0;
430 }
431
432 static int scan_string(char *s_native,
433                        yaz_iconv_t t_unicode, yaz_iconv_t t_utf8,
434                        void (*fun)(const char *c, void *data, int num),
435                        void *data, int *num)
436 {
437     char str[1024];
438
439     ucs4_t arg[512];
440     ucs4_t arg_prim[512];
441     ucs4_t *s0, *s = arg;
442     ucs4_t c, begin, end;
443     size_t i;
444
445     if (t_unicode != 0)
446     {
447         char *outbuf = (char *) arg;
448         char *inbuf = s_native;
449         size_t outbytesleft = sizeof(arg)-4;
450         size_t inbytesleft = strlen(s_native);
451         size_t ret;             
452         ret = yaz_iconv(t_unicode, &inbuf, &inbytesleft,
453                         &outbuf, &outbytesleft);
454         if (ret == (size_t)(-1))
455             return -1;
456         i = (outbuf - (char*) arg)/sizeof(ucs4_t);
457     }
458     else
459     { 
460         for (i = 0; s_native[i]; i++)
461             arg[i] = s_native[i] & 255; /* ISO-8859-1 conversion */
462     }
463     arg[i] = 0;      /* terminate */
464     if (s[0] == 0xfeff || s[0] == 0xfeff)  /* skip byte Order Mark */
465         s++;
466     while (*s)
467     {
468         switch (*s)
469         {
470         case '{':
471             s++;
472             begin = zebra_prim_w(&s);
473             if (*s != '-')
474             {
475                 yaz_log(YLOG_FATAL, "Bad range in char-map");
476                 return -1;
477             }
478             s++;
479             end = zebra_prim_w(&s);
480             if (end <= begin)
481             {
482                 yaz_log(YLOG_FATAL, "Bad range in char-map");
483                 return -1;
484             }
485             s++;
486             for (c = begin; c <= end; c++)
487             {
488                 if (scan_to_utf8 (t_utf8, &c, 1, str, sizeof(str)-1))
489                     return -1;
490                 (*fun)(str, data, num ? (*num)++ : 0);
491             }
492             break;
493         case '(':
494             ++s;
495             s0 = s; i = 0;
496             while (*s != ')' || s[-1] == '\\')
497                 arg_prim[i++] = zebra_prim_w(&s);
498             arg_prim[i] = 0;
499             if (scan_to_utf8 (t_utf8, arg_prim, zebra_ucs4_strlen(arg_prim), str, sizeof(str)-1))
500                 return -1;
501             (*fun)(str, data, num ? (*num)++ : 0);
502             s++;
503             break;
504         default:
505             c = zebra_prim_w(&s);
506             if (scan_to_utf8 (t_utf8, &c, 1, str, sizeof(str)-1))
507                 return -1;
508             (*fun)(str, data, num ? (*num)++ : 0);
509         }
510     }
511     return 0;
512 }
513
514 chrmaptab chrmaptab_create(const char *tabpath, const char *name,
515                            const char *tabroot)
516 {
517     FILE *f;
518     char line[512], *argv[50];
519     chrmaptab res;
520     int lineno = 0;
521     int errors = 0;
522     int argc, num = (int) *CHR_BASE, i;
523     NMEM nmem;
524     yaz_iconv_t t_unicode = 0;
525     yaz_iconv_t t_utf8 = 0;
526     unsigned endian = 31;
527     const char *ucs4_native = "UCS-4";
528
529     yaz_log (YLOG_DEBUG, "maptab %s open", name);
530     if (!(f = yaz_fopen(tabpath, name, "r", tabroot)))
531     {
532         yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", name);
533         return 0;
534     }
535
536     if (*(char*) &endian == 31)      /* little endian? */
537         ucs4_native = "UCS-4LE";
538
539     t_utf8 = yaz_iconv_open ("UTF-8", ucs4_native);
540
541     nmem = nmem_create ();
542     res = (chrmaptab) nmem_malloc(nmem, sizeof(*res));
543     res->nmem = nmem;
544     res->input = (chr_t_entry *) nmem_malloc(res->nmem, sizeof(*res->input));
545     res->input->target = (unsigned char **)
546         nmem_malloc(res->nmem, sizeof(*res->input->target) * 2);
547     res->input->target[0] = (unsigned char*) CHR_UNKNOWN;
548     res->input->target[1] = 0;
549     res->input->children = (chr_t_entry **)
550         nmem_malloc(res->nmem, sizeof(res->input) * 256);
551     for (i = 0; i < 256; i++)
552     {
553         res->input->children[i] = (chr_t_entry *)
554             nmem_malloc(res->nmem, sizeof(*res->input));
555         res->input->children[i]->children = 0;
556         res->input->children[i]->target = (unsigned char **)
557             nmem_malloc (res->nmem, 2 * sizeof(unsigned char *));
558         res->input->children[i]->target[1] = 0;
559         res->input->children[i]->target[0] = (unsigned char*) CHR_UNKNOWN;
560     }
561     res->q_input = (chr_t_entry *)
562         nmem_malloc(res->nmem, sizeof(*res->q_input));
563     res->q_input->target = 0;
564     res->q_input->children = 0;
565
566     for (i = *CHR_BASE; i < 256; i++)
567         res->output[i] = 0;
568     res->output[(int) *CHR_SPACE] = (unsigned char *) " ";
569     res->output[(int) *CHR_UNKNOWN] = (unsigned char*) "@";
570     res->base_uppercase = 0;
571
572     while (!errors && (argc = readconf_line(f, &lineno, line, 512, argv, 50)))
573         if (!yaz_matchstr(argv[0], "lowercase"))
574         {
575             if (argc != 2)
576             {
577                 yaz_log(YLOG_FATAL, "Syntax error in charmap");
578                 ++errors;
579             }
580             if (scan_string(argv[1], t_unicode, t_utf8, fun_addentry,
581                             res, &num) < 0)
582             {
583                 yaz_log(YLOG_FATAL, "Bad value-set specification");
584                 ++errors;
585             }
586             res->base_uppercase = num;
587             res->output[(int) *CHR_SPACE + num] = (unsigned char *) " ";
588             res->output[(int) *CHR_UNKNOWN + num] = (unsigned char*) "@";
589             num = (int) *CHR_BASE;
590         }
591         else if (!yaz_matchstr(argv[0], "uppercase"))
592         {
593             if (!res->base_uppercase)
594             {
595                 yaz_log(YLOG_FATAL, "Uppercase directive with no lowercase set");
596                 ++errors;
597             }
598             if (argc != 2)
599             {
600                 yaz_log(YLOG_FATAL, "Missing arg for uppercase directive");
601                 ++errors;
602             }
603             if (scan_string(argv[1], t_unicode, t_utf8, fun_addentry,
604                             res, &num) < 0)
605             {
606                 yaz_log(YLOG_FATAL, "Bad value-set specification");
607                 ++errors;
608             }
609         }
610         else if (!yaz_matchstr(argv[0], "space"))
611         {
612             if (argc != 2)
613             {
614                 yaz_log(YLOG_FATAL, "Syntax error in charmap for space");
615                 ++errors;
616             }
617             if (scan_string(argv[1], t_unicode, t_utf8,
618                             fun_addspace, res, 0) < 0)
619             {
620                 yaz_log(YLOG_FATAL, "Bad space specification");
621                 ++errors;
622             }
623         }
624         else if (!yaz_matchstr(argv[0], "cut"))
625         {
626             if (argc != 2)
627             {
628                 yaz_log(YLOG_FATAL, "Syntax error in charmap for cut");
629                 ++errors;
630             }
631             if (scan_string(argv[1], t_unicode, t_utf8,
632                             fun_addcut, res, 0) < 0)
633             {
634                 yaz_log(YLOG_FATAL, "Bad cut specification");
635                 ++errors;
636             }
637         }
638         else if (!yaz_matchstr(argv[0], "map"))
639         {
640             chrwork buf;
641
642             if (argc != 3)
643             {
644                 yaz_log(YLOG_FATAL, "charmap directive map requires 2 args");
645                 ++errors;
646             }
647             buf.map = res;
648             buf.string[0] = '\0';
649             if (scan_string(argv[2], t_unicode, t_utf8,
650                             fun_mkstring, &buf, 0) < 0)
651             {
652                 yaz_log(YLOG_FATAL, "Bad map target");
653                 ++errors;
654             }
655             if (scan_string(argv[1], t_unicode, t_utf8,
656                             fun_add_map, &buf, 0) < 0)
657             {
658                 yaz_log(YLOG_FATAL, "Bad map source");
659                 ++errors;
660             }
661         }
662         else if (!yaz_matchstr(argv[0], "equivalent"))
663         {
664             chr_equiv_work w;
665
666             if (argc != 2)
667             {
668                 yaz_log(YLOG_FATAL, "equivalent requires 1 argument");
669                 ++errors;
670             }
671             w.nmem = res->nmem;
672             w.no_eq = 0;
673             if (scan_string(argv[1], t_unicode, t_utf8, 
674                             fun_add_equivalent_string, &w, 0) < 0)
675             {
676                 yaz_log(YLOG_FATAL, "equivalent: invalid string");
677                 ++errors;
678             }
679             else if (w.no_eq == 0)
680             {
681                 yaz_log(YLOG_FATAL, "equivalent: no strings");
682                 ++errors;
683             }
684             else
685             {
686                 char *result_str;
687                 int i, slen = 5;
688
689                 /* determine length of regular expression */
690                 for (i = 0; i<w.no_eq; i++)
691                     slen += strlen(w.eq[i]) + 1;
692                 result_str = nmem_malloc(res->nmem, slen + 5);
693
694                 /* build the regular expression */
695                 *result_str = '\0';
696                 slen = 0;
697                 for (i = 0; i<w.no_eq; i++)
698                 {
699                     result_str[slen++]  = i ? '|' : '(';
700                     strcpy(result_str + slen, w.eq[i]);
701                     slen += strlen(w.eq[i]);
702                 }
703                 result_str[slen++] = ')';
704                 result_str[slen] = '\0';
705
706                 /* each eq will map to this regular expression */
707                 for (i = 0; i<w.no_eq; i++)
708                 {
709                     set_map_string(res->q_input, res->nmem,
710                                    w.eq[i], strlen(w.eq[i]),
711                                    result_str, 0);
712                 }
713             }
714         }
715         else if (!yaz_matchstr(argv[0], "encoding"))
716         {
717             /*
718              * Fix me. When t_unicode==0 and use encoding directive in *.chr file the beheviour of the
719              * zebra need to comment next part of code.
720              */
721
722             /* Original code */
723 #if 1
724             if (t_unicode != 0)
725                 yaz_iconv_close (t_unicode);
726             t_unicode = yaz_iconv_open (ucs4_native, argv[1]);
727 #endif
728             /*
729              * Fix me. It is additional staff for conversion of characters from local encoding
730              * of *.chr file to UTF-8 (internal encoding).
731              * NOTE: The derective encoding must be first directive in *.chr file.
732              */
733             /* For whatever reason Oleg enabled this.. */
734 #if 0
735             if (t_utf8 != 0)
736                 yaz_iconv_close(t_utf8);
737             t_utf8 = yaz_iconv_open ("UTF-8", argv[1]);
738 #endif
739         }
740         else
741         {
742             yaz_log(YLOG_WARN, "Syntax error at '%s' in %s", line, name);
743         }
744     
745     yaz_fclose(f);
746     if (errors)
747     {
748         chrmaptab_destroy(res);
749         res = 0;
750     }
751     yaz_log (YLOG_DEBUG, "maptab %s close %d errors", name, errors);
752     if (t_utf8 != 0)
753         yaz_iconv_close(t_utf8);
754     if (t_unicode != 0)
755         yaz_iconv_close(t_unicode);
756     return res;
757 }
758
759 void chrmaptab_destroy(chrmaptab tab)
760 {
761     if (tab)
762         nmem_destroy (tab->nmem);
763 }
764
765