2007.
[idzebra-moved-to-github.git] / util / charmap.c
1 /* $Id: charmap.c,v 1.44 2007-01-15 15:10:26 adam Exp $
2    Copyright (C) 1995-2007
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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
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"; /* CHECK CHR_BASE_CHAR as well */
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     const char *out = (const char*) maptab->output[c];
242
243     if (out)
244         (*from)++;
245     return out;
246 }
247
248 static int zebra_ucs4_strlen(ucs4_t *s)
249 {
250     int i = 0;
251     while (*s++)
252         i++;
253     return i;
254 }
255
256 ucs4_t zebra_prim_w(ucs4_t **s)
257 {
258     ucs4_t c;
259     ucs4_t i = 0;
260     char fmtstr[8];
261
262     yaz_log (YLOG_DEBUG, "prim_w %.3s", (char *) *s);
263     if (**s == '\\' && 1[*s])
264     {
265         (*s)++;
266         c = **s;
267         switch (c)
268         {
269         case '\\': c = '\\'; (*s)++; break;
270         case 'r': c = '\r'; (*s)++; break;
271         case 'n': c = '\n'; (*s)++; break;
272         case 't': c = '\t'; (*s)++; break;
273         case 's': c = ' '; (*s)++; break;
274         case 'x': 
275             if (zebra_ucs4_strlen(*s) >= 3)
276             {
277                 fmtstr[0] = (*s)[1];
278                 fmtstr[1] = (*s)[2];
279                 fmtstr[2] = 0;
280                 sscanf(fmtstr, "%x", &i);
281                 c = i;
282                 *s += 3;
283             }
284             break;
285         case '0':
286         case '1':
287         case '2':
288         case '3':
289         case '4':
290         case '5':
291         case '6':
292         case '7':
293         case '8':
294         case '9':
295             if (zebra_ucs4_strlen(*s) >= 3)
296             {
297                 fmtstr[0] = (*s)[0];
298                 fmtstr[1] = (*s)[1];
299                 fmtstr[2] = (*s)[2];
300                 fmtstr[3] = 0;
301                 sscanf(fmtstr, "%o", &i);
302                 c = i;
303                 *s += 3;
304             }
305             break;
306         case 'L':
307             if (zebra_ucs4_strlen(*s) >= 5)
308             {
309                 fmtstr[0] = (*s)[1];
310                 fmtstr[1] = (*s)[2];
311                 fmtstr[2] = (*s)[3];
312                 fmtstr[3] = (*s)[4];
313                 fmtstr[4] = 0;
314                 sscanf(fmtstr, "%x", &i);
315                 c = i;
316                 *s += 5;
317             }
318             break;
319         default:
320             (*s)++;
321         }
322     }
323     else
324     {
325         c = **s;
326         ++(*s);
327     }
328     yaz_log (YLOG_DEBUG, "out %d", c);
329     return c;
330 }
331
332 /*
333  * Callback function.
334  * Add an entry to the value space.
335  */
336 static void fun_addentry(const char *s, void *data, int num)
337 {
338     chrmaptab tab = (chrmaptab) data;
339     char tmp[2];
340     
341     tmp[0] = num; tmp[1] = '\0';
342     tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s), tmp, 0);
343     tab->output[num + tab->base_uppercase] =
344         (unsigned char *) nmem_strdup(tab->nmem, s);
345 }
346
347 /* 
348  * Callback function.
349  * Add a space-entry to the value space.
350  */
351 static void fun_addspace(const char *s, void *data, int num)
352 {
353     chrmaptab tab = (chrmaptab) data;
354     tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s),
355                                 (char*) CHR_SPACE, 0);
356 }
357
358 /* 
359  * Callback function.
360  * Add a space-entry to the value space.
361  */
362 static void fun_addcut(const char *s, void *data, int num)
363 {
364     chrmaptab tab = (chrmaptab) data;
365     tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s),
366                                 (char*) CHR_CUT, 0);
367 }
368
369 /*
370  * Create a string containing the mapped characters provided.
371  */
372 static void fun_mkstring(const char *s, void *data, int num)
373 {
374     chrwork *arg = (chrwork *) data;
375     const char **res, *p = s;
376
377     res = chr_map_input(arg->map, &s, strlen(s), 0);
378     if (*res == (char*) CHR_UNKNOWN)
379         yaz_log(YLOG_WARN, "Map: '%s' has no mapping", p);
380     strncat(arg->string, *res, CHR_MAXSTR - strlen(arg->string));
381     arg->string[CHR_MAXSTR] = '\0';
382 }
383
384 /*
385  * Create an unmodified string (scan_string handler).
386  */
387 static void fun_add_equivalent_string(const char *s, void *data, int num)
388 {
389     chr_equiv_work *arg = (chr_equiv_work *) data;
390     
391     if (arg->no_eq == CHR_MAXEQUIV)
392         return;
393     arg->eq[arg->no_eq++] = nmem_strdup(arg->nmem, s);
394 }
395
396 /*
397  * Add a map to the string contained in the argument.
398  */
399 static void fun_add_map(const char *s, void *data, int num)
400 {
401     chrwork *arg = (chrwork *) data;
402
403     assert(arg->map->input);
404     yaz_log (YLOG_DEBUG, "set map %.*s", (int) strlen(s), s);
405     set_map_string(arg->map->input, arg->map->nmem, s, strlen(s), arg->string,
406                    0);
407     for (s = arg->string; *s; s++)
408         yaz_log (YLOG_DEBUG, " %3d", (unsigned char) *s);
409 }
410
411 static int scan_to_utf8 (yaz_iconv_t t, ucs4_t *from, size_t inlen,
412                         char *outbuf, size_t outbytesleft)
413 {
414     size_t inbytesleft = inlen * sizeof(ucs4_t);
415     char *inbuf = (char*) from;
416     size_t ret;
417    
418     if (t == 0)
419         *outbuf++ = *from;  /* ISO-8859-1 is OK here */
420     else
421     {
422         ret = yaz_iconv (t, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
423         if (ret == (size_t) (-1))
424         {
425             yaz_log(YLOG_LOG, "from: %2X %2X %2X %2X",
426                     from[0], from[1], from[2], from[3]);
427             yaz_log (YLOG_WARN|YLOG_ERRNO, "bad unicode sequence");
428             return -1;
429         }
430     }
431     *outbuf = '\0';
432     return 0;
433 }
434
435 static int scan_string(char *s_native,
436                        yaz_iconv_t t_unicode, yaz_iconv_t t_utf8,
437                        void (*fun)(const char *c, void *data, int num),
438                        void *data, int *num)
439 {
440     char str[1024];
441
442     ucs4_t arg[512];
443     ucs4_t arg_prim[512];
444     ucs4_t *s0, *s = arg;
445     ucs4_t c, begin, end;
446     size_t i;
447
448     if (t_unicode != 0)
449     {
450         char *outbuf = (char *) arg;
451         char *inbuf = s_native;
452         size_t outbytesleft = sizeof(arg)-4;
453         size_t inbytesleft = strlen(s_native);
454         size_t ret;             
455         ret = yaz_iconv(t_unicode, &inbuf, &inbytesleft,
456                         &outbuf, &outbytesleft);
457         if (ret == (size_t)(-1))
458             return -1;
459         i = (outbuf - (char*) arg)/sizeof(ucs4_t);
460     }
461     else
462     { 
463         for (i = 0; s_native[i]; i++)
464             arg[i] = s_native[i] & 255; /* ISO-8859-1 conversion */
465     }
466     arg[i] = 0;      /* terminate */
467     if (s[0] == 0xfeff || s[0] == 0xfeff)  /* skip byte Order Mark */
468         s++;
469     while (*s)
470     {
471         switch (*s)
472         {
473         case '{':
474             s++;
475             begin = zebra_prim_w(&s);
476             if (*s != '-')
477             {
478                 yaz_log(YLOG_FATAL, "Bad range in char-map");
479                 return -1;
480             }
481             s++;
482             end = zebra_prim_w(&s);
483             if (end <= begin)
484             {
485                 yaz_log(YLOG_FATAL, "Bad range in char-map");
486                 return -1;
487             }
488             s++;
489             for (c = begin; c <= end; c++)
490             {
491                 if (scan_to_utf8 (t_utf8, &c, 1, str, sizeof(str)-1))
492                     return -1;
493                 (*fun)(str, data, num ? (*num)++ : 0);
494             }
495             break;
496         case '(':
497             ++s;
498             s0 = s; i = 0;
499             while (*s != ')' || s[-1] == '\\')
500                 arg_prim[i++] = zebra_prim_w(&s);
501             arg_prim[i] = 0;
502             if (scan_to_utf8 (t_utf8, arg_prim, zebra_ucs4_strlen(arg_prim), str, sizeof(str)-1))
503                 return -1;
504             (*fun)(str, data, num ? (*num)++ : 0);
505             s++;
506             break;
507         default:
508             c = zebra_prim_w(&s);
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     }
514     return 0;
515 }
516
517 chrmaptab chrmaptab_create(const char *tabpath, const char *name,
518                            const char *tabroot)
519 {
520     FILE *f;
521     char line[512], *argv[50];
522     chrmaptab res;
523     int lineno = 0;
524     int errors = 0;
525     int argc, num = (int) *CHR_BASE, i;
526     NMEM nmem;
527     yaz_iconv_t t_unicode = 0;
528     yaz_iconv_t t_utf8 = 0;
529     unsigned endian = 31;
530     const char *ucs4_native = "UCS-4";
531
532     yaz_log (YLOG_DEBUG, "maptab %s open", name);
533     if (!(f = yaz_fopen(tabpath, name, "r", tabroot)))
534     {
535         yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", name);
536         return 0;
537     }
538
539     if (*(char*) &endian == 31)      /* little endian? */
540         ucs4_native = "UCS-4LE";
541
542     t_utf8 = yaz_iconv_open ("UTF-8", ucs4_native);
543
544     nmem = nmem_create ();
545     res = (chrmaptab) nmem_malloc(nmem, sizeof(*res));
546     res->nmem = nmem;
547     res->input = (chr_t_entry *) nmem_malloc(res->nmem, sizeof(*res->input));
548     res->input->target = (unsigned char **)
549         nmem_malloc(res->nmem, sizeof(*res->input->target) * 2);
550     res->input->target[0] = (unsigned char*) CHR_UNKNOWN;
551     res->input->target[1] = 0;
552     res->input->children = (chr_t_entry **)
553         nmem_malloc(res->nmem, sizeof(res->input) * 256);
554     for (i = 0; i < 256; i++)
555     {
556         res->input->children[i] = (chr_t_entry *)
557             nmem_malloc(res->nmem, sizeof(*res->input));
558         res->input->children[i]->children = 0;
559         res->input->children[i]->target = (unsigned char **)
560             nmem_malloc (res->nmem, 2 * sizeof(unsigned char *));
561         res->input->children[i]->target[1] = 0;
562         res->input->children[i]->target[0] = (unsigned char*) CHR_UNKNOWN;
563     }
564     res->q_input = (chr_t_entry *)
565         nmem_malloc(res->nmem, sizeof(*res->q_input));
566     res->q_input->target = 0;
567     res->q_input->children = 0;
568
569     for (i = *CHR_BASE; i < 256; i++)
570         res->output[i] = 0;
571     res->output[(int) *CHR_SPACE] = (unsigned char *) " ";
572     res->output[(int) *CHR_UNKNOWN] = (unsigned char*) "@";
573     res->base_uppercase = 0;
574
575     while (!errors && (argc = readconf_line(f, &lineno, line, 512, argv, 50)))
576         if (!yaz_matchstr(argv[0], "lowercase"))
577         {
578             if (argc != 2)
579             {
580                 yaz_log(YLOG_FATAL, "Syntax error in charmap");
581                 ++errors;
582             }
583             if (scan_string(argv[1], t_unicode, t_utf8, fun_addentry,
584                             res, &num) < 0)
585             {
586                 yaz_log(YLOG_FATAL, "Bad value-set specification");
587                 ++errors;
588             }
589             res->base_uppercase = num;
590             res->output[(int) *CHR_SPACE + num] = (unsigned char *) " ";
591             res->output[(int) *CHR_UNKNOWN + num] = (unsigned char*) "@";
592             num = (int) *CHR_BASE;
593         }
594         else if (!yaz_matchstr(argv[0], "uppercase"))
595         {
596             if (!res->base_uppercase)
597             {
598                 yaz_log(YLOG_FATAL, "Uppercase directive with no lowercase set");
599                 ++errors;
600             }
601             if (argc != 2)
602             {
603                 yaz_log(YLOG_FATAL, "Missing arg for uppercase directive");
604                 ++errors;
605             }
606             if (scan_string(argv[1], t_unicode, t_utf8, fun_addentry,
607                             res, &num) < 0)
608             {
609                 yaz_log(YLOG_FATAL, "Bad value-set specification");
610                 ++errors;
611             }
612         }
613         else if (!yaz_matchstr(argv[0], "space"))
614         {
615             if (argc != 2)
616             {
617                 yaz_log(YLOG_FATAL, "Syntax error in charmap for space");
618                 ++errors;
619             }
620             if (scan_string(argv[1], t_unicode, t_utf8,
621                             fun_addspace, res, 0) < 0)
622             {
623                 yaz_log(YLOG_FATAL, "Bad space specification");
624                 ++errors;
625             }
626         }
627         else if (!yaz_matchstr(argv[0], "cut"))
628         {
629             if (argc != 2)
630             {
631                 yaz_log(YLOG_FATAL, "Syntax error in charmap for cut");
632                 ++errors;
633             }
634             if (scan_string(argv[1], t_unicode, t_utf8,
635                             fun_addcut, res, 0) < 0)
636             {
637                 yaz_log(YLOG_FATAL, "Bad cut specification");
638                 ++errors;
639             }
640         }
641         else if (!yaz_matchstr(argv[0], "map"))
642         {
643             chrwork buf;
644
645             if (argc != 3)
646             {
647                 yaz_log(YLOG_FATAL, "charmap directive map requires 2 args");
648                 ++errors;
649             }
650             buf.map = res;
651             buf.string[0] = '\0';
652             if (scan_string(argv[2], t_unicode, t_utf8,
653                             fun_mkstring, &buf, 0) < 0)
654             {
655                 yaz_log(YLOG_FATAL, "Bad map target");
656                 ++errors;
657             }
658             if (scan_string(argv[1], t_unicode, t_utf8,
659                             fun_add_map, &buf, 0) < 0)
660             {
661                 yaz_log(YLOG_FATAL, "Bad map source");
662                 ++errors;
663             }
664         }
665         else if (!yaz_matchstr(argv[0], "equivalent"))
666         {
667             chr_equiv_work w;
668
669             if (argc != 2)
670             {
671                 yaz_log(YLOG_FATAL, "equivalent requires 1 argument");
672                 ++errors;
673             }
674             w.nmem = res->nmem;
675             w.no_eq = 0;
676             if (scan_string(argv[1], t_unicode, t_utf8, 
677                             fun_add_equivalent_string, &w, 0) < 0)
678             {
679                 yaz_log(YLOG_FATAL, "equivalent: invalid string");
680                 ++errors;
681             }
682             else if (w.no_eq == 0)
683             {
684                 yaz_log(YLOG_FATAL, "equivalent: no strings");
685                 ++errors;
686             }
687             else
688             {
689                 char *result_str;
690                 int i, slen = 5;
691
692                 /* determine length of regular expression */
693                 for (i = 0; i<w.no_eq; i++)
694                     slen += strlen(w.eq[i]) + 1;
695                 result_str = nmem_malloc(res->nmem, slen + 5);
696
697                 /* build the regular expression */
698                 *result_str = '\0';
699                 slen = 0;
700                 for (i = 0; i<w.no_eq; i++)
701                 {
702                     result_str[slen++]  = i ? '|' : '(';
703                     strcpy(result_str + slen, w.eq[i]);
704                     slen += strlen(w.eq[i]);
705                 }
706                 result_str[slen++] = ')';
707                 result_str[slen] = '\0';
708
709                 /* each eq will map to this regular expression */
710                 for (i = 0; i<w.no_eq; i++)
711                 {
712                     set_map_string(res->q_input, res->nmem,
713                                    w.eq[i], strlen(w.eq[i]),
714                                    result_str, 0);
715                 }
716             }
717         }
718         else if (!yaz_matchstr(argv[0], "encoding"))
719         {
720             /*
721              * Fix me. When t_unicode==0 and use encoding directive in *.chr file the beheviour of the
722              * zebra need to comment next part of code.
723              */
724
725             /* Original code */
726 #if 1
727             if (t_unicode != 0)
728                 yaz_iconv_close (t_unicode);
729             t_unicode = yaz_iconv_open (ucs4_native, argv[1]);
730 #endif
731             /*
732              * Fix me. It is additional staff for conversion of characters from local encoding
733              * of *.chr file to UTF-8 (internal encoding).
734              * NOTE: The derective encoding must be first directive in *.chr file.
735              */
736             /* For whatever reason Oleg enabled this.. */
737 #if 0
738             if (t_utf8 != 0)
739                 yaz_iconv_close(t_utf8);
740             t_utf8 = yaz_iconv_open ("UTF-8", argv[1]);
741 #endif
742         }
743         else
744         {
745             yaz_log(YLOG_WARN, "Syntax error at '%s' in %s", line, name);
746         }
747     
748     yaz_fclose(f);
749     if (errors)
750     {
751         chrmaptab_destroy(res);
752         res = 0;
753     }
754     yaz_log (YLOG_DEBUG, "maptab %s close %d errors", name, errors);
755     if (t_utf8 != 0)
756         yaz_iconv_close(t_utf8);
757     if (t_unicode != 0)
758         yaz_iconv_close(t_unicode);
759     return res;
760 }
761
762 void chrmaptab_destroy(chrmaptab tab)
763 {
764     if (tab)
765         nmem_destroy (tab->nmem);
766 }
767
768
769 /*
770  * Local variables:
771  * c-basic-offset: 4
772  * indent-tabs-mode: nil
773  * End:
774  * vim: shiftwidth=4 tabstop=8 expandtab
775  */
776