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