Update headers and omit CVS Ids.
[yaz-moved-to-github.git] / include / yaz / yaz-iconv.h
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2008 Index Data.
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of Index Data nor the names of its contributors
13  *       may be used to endorse or promote products derived from this
14  *       software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 /**
29  * \file yaz-iconv.h
30  * \brief Header for YAZ iconv interface
31  */
32
33 #ifndef YAZ_ICONV_H
34 #define YAZ_ICONV_H
35
36 #include <stddef.h>
37 #include <yaz/yconfig.h>
38
39 YAZ_BEGIN_CDECL
40
41 /** \brief yaz_iconv handle (similar to iconv_t) */
42 typedef struct yaz_iconv_struct *yaz_iconv_t;
43
44 /** \brief error code: unknown */
45 #define YAZ_ICONV_UNKNOWN 1
46 /** \brief error code: Not sufficient room for output buffer */
47 #define YAZ_ICONV_E2BIG 2
48 /** \brief error code: Invalid sequence */
49 #define YAZ_ICONV_EILSEQ 3
50 /** \brief error code: An incomplete multibyte sequence is in input buffer */
51 #define YAZ_ICONV_EINVAL 4
52
53 /** \brief just like iconv_open(3) */
54 YAZ_EXPORT yaz_iconv_t yaz_iconv_open (const char *tocode,
55                                        const char *fromcode);
56 /** \brief just like iconv(3) */
57 YAZ_EXPORT size_t yaz_iconv (yaz_iconv_t cd, char **inbuf, size_t *inbytesleft,
58                              char **outbuf, size_t *outbytesleft);
59 /** \brief returns last error - like errno for iconv(3) */
60 YAZ_EXPORT int yaz_iconv_error (yaz_iconv_t cd);
61
62 /** \brief just like iconv_close(3) */
63 YAZ_EXPORT int yaz_iconv_close (yaz_iconv_t cd);
64
65 /** \brief tests whether conversion is handled by YAZ' iconv or system iconv */
66 YAZ_EXPORT int yaz_iconv_isbuiltin(yaz_iconv_t cd);
67
68 /** \brief match strings - independent of case and '-'
69     \param s1 first string
70     \param s2 second string (May include wildcard ? and .)
71     \retval 0 strings are similar
72     \retval !=0 strings are different
73 */
74 YAZ_EXPORT int yaz_matchstr(const char *s1, const char *s2);
75
76 YAZ_EXPORT int yaz_strcmp_del(const char *a, const char *b, const char *b_del);
77
78 /** \brief decodes UTF-8 sequence
79     \param inp input buffer with UTF-8 bytes
80     \param inbytesleft length of input buffer
81     \param no_read holds number of bytes read if conversion is successful
82     \param error pointer to error code if error occurs
83     \retval 0 if error
84     \retval >0 if conversion is successful
85 */
86 YAZ_EXPORT unsigned long yaz_read_UTF8_char(unsigned char *inp,
87                                             size_t inbytesleft,
88                                             size_t *no_read,
89                                             int *error);
90
91 /** \brief encodes UTF-8 sequence 
92     \param x the UNICODE value
93     \param outbuf output buffer pointer, updated if conversion is successful
94     \param outbytesleft length of buffer, updated if conversino is successful
95     \param error pointer to error code if error occurs
96     \retval 0 if successful
97     \retval -1 for error
98 */
99 YAZ_EXPORT size_t yaz_write_UTF8_char(unsigned long x,
100                                       char **outbuf, size_t *outbytesleft,
101                                       int *error);
102
103 YAZ_END_CDECL
104
105 #endif
106 /*
107  * Local variables:
108  * c-basic-offset: 4
109  * indent-tabs-mode: nil
110  * End:
111  * vim: shiftwidth=4 tabstop=8 expandtab
112  */
113