1/* $Id: filemapper.h,v 1.1 2003/06/04 00:25:38 marka Exp $ */
2/*
3 * Copyright (c) 2001 Japan Network Information Center.  All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set forth bellow.
6 *
7 * 			LICENSE TERMS AND CONDITIONS
8 *
9 * The following License Terms and Conditions apply, unless a different
10 * license is obtained from Japan Network Information Center ("JPNIC"),
11 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
12 * Chiyoda-ku, Tokyo 101-0047, Japan.
13 *
14 * 1. Use, Modification and Redistribution (including distribution of any
15 *    modified or derived work) in source and/or binary forms is permitted
16 *    under this License Terms and Conditions.
17 *
18 * 2. Redistribution of source code must retain the copyright notices as they
19 *    appear in each source code file, this License Terms and Conditions.
20 *
21 * 3. Redistribution in binary form must reproduce the Copyright Notice,
22 *    this License Terms and Conditions, in the documentation and/or other
23 *    materials provided with the distribution.  For the purposes of binary
24 *    distribution the "Copyright Notice" refers to the following language:
25 *    "Copyright (c) 2000-2002 Japan Network Information Center.  All rights reserved."
26 *
27 * 4. The name of JPNIC may not be used to endorse or promote products
28 *    derived from this Software without specific prior written approval of
29 *    JPNIC.
30 *
31 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
32 *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
34 *    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL JPNIC BE LIABLE
35 *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 *    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#ifndef IDN_FILEMAPPER_H
45#define IDN_FILEMAPPER_H 1
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/*
52 * Perform character mapping (substitution) according to a
53 * map file.
54 */
55
56#include <idn/result.h>
57
58/*
59 * Mapping object type.
60 */
61typedef struct idn__filemapper *idn__filemapper_t;
62
63/*
64 * Read the contents of the given map file and create a context for mapping.
65 *
66 * 'file' is the pathname of the file, which specifies the character
67 * mapping.  The file is a simple text file, and each line specifies
68 * a mapping of a single character.  The format of each line is
69 *
70 *   <code_point>; [<code_point>..][;]
71 *
72 * where <code_point> is a UCS code point represented as a hexadecimal
73 * string with optional prefix `U+' (ex. `0041' or `U+FEDC').
74 * The code point before the first semicolon will be mapped to the
75 * sequence of code points separated by space characters after the
76 * first semicolon.  The sequence may be empty, denoting wiping out
77 * the character.
78 *
79 * For example,
80 *	U+0041; U+0061		-- maps 'A' to 'a'
81 *	20;;			-- wipes out ' '
82 *
83 * Anything after the second semicolon is ignored.  Also lines beginning
84 * with '#' are treated as comments.
85 *
86 * If there is no error, the created context is stored in '*ctxp'.
87 *
88 * Returns:
89 *	idn_success		-- ok.
90 *	idn_nofile		-- cannot open the specified file.
91 *	idn_nomemory		-- malloc failed.
92 *	idn_invalid_syntax	-- file format is not valid.
93 */
94extern idn_result_t
95idn__filemapper_create(const char *file, idn__filemapper_t *ctxp);
96
97/*
98 * Release memory for the given context.
99 */
100extern void
101idn__filemapper_destroy(idn__filemapper_t ctx);
102
103/*
104 * Perform character substitution.
105 *
106 * Each character in the string 'from' is examined and if it
107 * has a mapping, it is substituted to the corresponding
108 * character sequence.  The substituted string is stored in 'to',
109 * whose length is specified by 'tolen'.
110 *
111 * Returns:
112 *	idn_success		-- ok.
113 *	idn_buffer_overflow	-- result buffer is too small.
114 */
115extern idn_result_t
116idn__filemapper_map(idn__filemapper_t ctx, const unsigned long *from,
117		    unsigned long *to, size_t tolen);
118
119/*
120 * The following functions are for internal use.
121 * They are used for this module to be add to the mapper module.
122 */
123extern idn_result_t
124idn__filemapper_createproc(const char *parameter, void **ctxp);
125
126extern void
127idn__filemapper_destroyproc(void *ctxp);
128
129extern idn_result_t
130idn__filemapper_mapproc(void *ctx, const unsigned long *from,
131			unsigned long *to, size_t tolen);
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* IDN_FILEMAPPER_H */
138