1 /* $NetBSD: unicode_template.c,v 1.4 2014/12/10 04:37:55 christos Exp $ */
3 /* Id: unicode_template.c,v 1.1 2003/06/04 00:26:16 marka Exp */
6 * Copyright (c) 2000,2001 Japan Network Information Center.
9 * By using this file, you agree to the terms and conditions set forth bellow.
11 * LICENSE TERMS AND CONDITIONS
13 * The following License Terms and Conditions apply, unless a different
14 * license is obtained from Japan Network Information Center ("JPNIC"),
15 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
16 * Chiyoda-ku, Tokyo 101-0047, Japan.
18 * 1. Use, Modification and Redistribution (including distribution of any
19 * modified or derived work) in source and/or binary forms is permitted
20 * under this License Terms and Conditions.
22 * 2. Redistribution of source code must retain the copyright notices as they
23 * appear in each source code file, this License Terms and Conditions.
25 * 3. Redistribution in binary form must reproduce the Copyright Notice,
26 * this License Terms and Conditions, in the documentation and/or other
27 * materials provided with the distribution. For the purposes of binary
28 * distribution the "Copyright Notice" refers to the following language:
29 * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
31 * 4. The name of JPNIC may not be used to endorse or promote products
32 * derived from this Software without specific prior written approval of
35 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
36 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
38 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
43 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
44 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
45 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
48 #ifndef UNICODE_TEMPLATE_INIT
49 #define UNICODE_TEMPLATE_INIT
52 * Macro for multi-level index table.
54 #define LOOKUPTBL(vprefix, mprefix, v) \
57 IMAP(vprefix)[IDX0(mprefix, v)] + IDX1(mprefix, v)\
59 ].tbl[IDX2(mprefix, v)]
61 #define IDX0(mprefix, v) IDX_0(v, BITS1(mprefix), BITS2(mprefix))
62 #define IDX1(mprefix, v) IDX_1(v, BITS1(mprefix), BITS2(mprefix))
63 #define IDX2(mprefix, v) IDX_2(v, BITS1(mprefix), BITS2(mprefix))
65 #define IDX_0(v, bits1, bits2) ((v) >> ((bits1) + (bits2)))
66 #define IDX_1(v, bits1, bits2) (((v) >> (bits2)) & ((1 << (bits1)) - 1))
67 #define IDX_2(v, bits1, bits2) ((v) & ((1 << (bits2)) - 1))
69 #define BITS1(mprefix) mprefix ## _BITS_1
70 #define BITS2(mprefix) mprefix ## _BITS_2
72 #define IMAP(vprefix) concat4(VERSION, _, vprefix, _imap)
73 #define DMAP(vprefix) concat4(VERSION, _, vprefix, _table)
74 #define SEQ(vprefix) concat4(VERSION, _, vprefix, _seq)
75 #define concat4(a,b,c,d) concat4X(a, b, c, d)
76 #define concat4X(a,b,c,d) a ## b ## c ## d
78 #endif /* UNICODE_TEMPLATE_INIT */
81 compose_sym(canonclass_
, VERSION
) (unsigned long c
) {
82 /* Look up canonicalclass table. */
83 return (LOOKUPTBL(canon_class
, CANON_CLASS
, c
));
87 compose_sym(decompose_
, VERSION
) (unsigned long c
, const unsigned long **seqp
)
89 /* Look up decomposition table. */
90 int seqidx
= LOOKUPTBL(decompose
, DECOMP
, c
);
91 *seqp
= SEQ(decompose
) + (seqidx
& ~DECOMP_COMPAT
);
96 compose_sym(compose_
, VERSION
) (unsigned long c
,
97 const struct composition
**compp
)
99 /* Look up composition table. */
100 int seqidx
= LOOKUPTBL(compose
, CANON_COMPOSE
, c
);
101 *compp
= SEQ(compose
) + (seqidx
& 0xffff);
102 return (seqidx
>> 16);