IDZEBRA 2.2.8
untrans.c
Go to the documentation of this file.
1/* This file is part of the Zebra server.
2 Copyright (C) Index Data
3
4Zebra is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License as published by the Free
6Software Foundation; either version 2, or (at your option) any later
7version.
8
9Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18*/
19
20#if HAVE_CONFIG_H
21#include <config.h>
22#endif
23#include <stdio.h>
24#include <assert.h>
25#include <ctype.h>
26
27#include <yaz/diagbib1.h>
28#include "index.h"
29#include <charmap.h>
30
31int zebra_term_untrans(ZebraHandle zh, const char *index_type,
32 char *dst, const char *src)
33{
34 zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, index_type);
35 if (!zm)
36 {
37 return -2;
38 }
39 if (zebra_maps_is_icu(zm))
40 {
41 return -1;
42 }
43 else
44 {
45 int len = 0;
46 while (*src)
47 {
48 const char *cp = zebra_maps_output(zm, &src);
49 if (!cp)
50 {
51 if (len < IT_MAX_WORD-1)
52 dst[len++] = *src;
53 src++;
54 }
55 else
56 while (*cp && len < IT_MAX_WORD-1)
57 dst[len++] = *cp++;
58 }
59 dst[len] = '\0';
60 }
61 return 0;
62}
63
65 char **dst, const char *src)
66{
67 char term_dst[IT_MAX_WORD];
68
69 if (zh->iconv_from_utf8 != 0)
70 {
71 int len;
72 char *inbuf = (char *) src;
73 size_t inleft = strlen(src);
74 char *outbuf = term_dst;
75 size_t outleft = sizeof(term_dst)-1;
76 size_t ret;
77
78 ret = yaz_iconv (zh->iconv_from_utf8, &inbuf, &inleft,
79 &outbuf, &outleft);
80 if (ret == (size_t)(-1))
81 len = 0;
82 else
83 {
84 yaz_iconv (zh->iconv_from_utf8, 0, 0, &outbuf, &outleft);
85 len = outbuf - term_dst;
86 }
87 *dst = nmem_malloc(stream, len + 1);
88 if (len > 0)
89 memcpy (*dst, term_dst, len);
90 (*dst)[len] = '\0';
91 }
92 else
93 *dst = nmem_strdup(stream, src);
94}
95
97 const char *index_type,
98 char **dst, const char *src)
99{
100 int r;
101 char term_src[IT_MAX_WORD];
102
103 r = zebra_term_untrans(zh, index_type, term_src, src);
104 if (r == 0)
105 zebra_term_untrans_iconv2(zh, stream, dst, term_src);
106 return r;
107}
108
109
110
111/*
112 * Local variables:
113 * c-basic-offset: 4
114 * c-file-style: "Stroustrup"
115 * indent-tabs-mode: nil
116 * End:
117 * vim: shiftwidth=4 tabstop=8 expandtab
118 */
119
#define IT_MAX_WORD
Definition it_key.h:27
zebra_maps_t zebra_maps
Definition index.h:143
struct zebra_register * reg
Definition index.h:174
yaz_iconv_t iconv_from_utf8
Definition index.h:216
void zebra_term_untrans_iconv2(ZebraHandle zh, NMEM stream, char **dst, const char *src)
Definition untrans.c:64
int zebra_term_untrans(ZebraHandle zh, const char *index_type, char *dst, const char *src)
Definition untrans.c:31
int zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream, const char *index_type, char **dst, const char *src)
Definition untrans.c:96
zebra_map_t zebra_map_get(zebra_maps_t zms, const char *id)
Definition zebramap.c:355
int zebra_maps_is_icu(zebra_map_t zm)
Definition zebramap.c:741
const char * zebra_maps_output(zebra_map_t zm, const char **from)
Definition zebramap.c:438