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