michael@0: /* michael@0: * Copyright (c) 2001 Japan Network Information Center. All rights reserved. michael@0: * michael@0: * By using this file, you agree to the terms and conditions set forth bellow. michael@0: * michael@0: * LICENSE TERMS AND CONDITIONS michael@0: * michael@0: * The following License Terms and Conditions apply, unless a different michael@0: * license is obtained from Japan Network Information Center ("JPNIC"), michael@0: * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda, michael@0: * Chiyoda-ku, Tokyo 101-0047, Japan. michael@0: * michael@0: * 1. Use, Modification and Redistribution (including distribution of any michael@0: * modified or derived work) in source and/or binary forms is permitted michael@0: * under this License Terms and Conditions. michael@0: * michael@0: * 2. Redistribution of source code must retain the copyright notices as they michael@0: * appear in each source code file, this License Terms and Conditions. michael@0: * michael@0: * 3. Redistribution in binary form must reproduce the Copyright Notice, michael@0: * this License Terms and Conditions, in the documentation and/or other michael@0: * materials provided with the distribution. For the purposes of binary michael@0: * distribution the "Copyright Notice" refers to the following language: michael@0: * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved." michael@0: * michael@0: * 4. The name of JPNIC may not be used to endorse or promote products michael@0: * derived from this Software without specific prior written approval of michael@0: * JPNIC. michael@0: * michael@0: * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A michael@0: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE michael@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR michael@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF michael@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR michael@0: * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, michael@0: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR michael@0: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF michael@0: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. michael@0: */ michael@0: michael@0: /* michael@0: * Include this file once for each version of NAMEPREP. michael@0: * VERSION should be defined to appropriate value before inclusion. michael@0: */ michael@0: michael@0: #ifndef NAMEPREP_TEMPLATE_INIT michael@0: #define NAMEPREP_TEMPLATE_INIT michael@0: michael@0: /* Symbol composition. */ michael@0: #define compose_sym2(a, b) compose_sym2X(a, b) michael@0: #define compose_sym2X(a, b) a ## b michael@0: #define compose_sym3(a, b, c) compose_sym3X(a, b, c) michael@0: #define compose_sym3X(a, b, c) a ## b ## c michael@0: michael@0: /* The table is based on "Optimized Two-Stage Table" mentioned in michael@0: * Unicode 3.0 page 106, extended to handle 21bit data instead of 16 bit. michael@0: */ michael@0: michael@0: /* Index calculation for multi-level index tables. */ michael@0: #define IDX0(type, v) IDX_0(v, BITS1(type), BITS2(type)) michael@0: #define IDX1(type, v) IDX_1(v, BITS1(type), BITS2(type)) michael@0: #define IDX2(type, v) IDX_2(v, BITS1(type), BITS2(type)) michael@0: michael@0: #define IDX_0(v, bits1, bits2) ((v) >> ((bits1) + (bits2))) michael@0: #define IDX_1(v, bits1, bits2) (((v) >> (bits2)) & ((1 << (bits1)) - 1)) michael@0: #define IDX_2(v, bits1, bits2) ((v) & ((1 << (bits2)) - 1)) michael@0: michael@0: #define BITS1(type) type ## _BITS_1 michael@0: #define BITS2(type) type ## _BITS_2 michael@0: michael@0: #endif /* NAMEPREP_TEMPLATE_INIT */ michael@0: michael@0: static const char * michael@0: compose_sym2(nameprep_map_, VERSION) (uint32_t v) { michael@0: int idx0 = IDX0(MAP, v); michael@0: int idx1 = IDX1(MAP, v); michael@0: int idx2 = IDX2(MAP, v); michael@0: int offset; michael@0: michael@0: #define IMAP compose_sym3(nameprep_, VERSION, _map_imap) michael@0: #define TABLE compose_sym3(nameprep_, VERSION, _map_table) michael@0: #define DATA compose_sym3(nameprep_, VERSION, _map_data) michael@0: offset = TABLE[IMAP[IMAP[idx0] + idx1]].tbl[idx2]; michael@0: if (offset == 0) michael@0: return (NULL); /* no mapping */ michael@0: return (const char *)(DATA + offset); michael@0: #undef IMAP michael@0: #undef TABLE michael@0: #undef DATA michael@0: } michael@0: michael@0: static int michael@0: compose_sym2(nameprep_prohibited_, VERSION) (uint32_t v) { michael@0: int idx0 = IDX0(PROH, v); michael@0: int idx1 = IDX1(PROH, v); michael@0: int idx2 = IDX2(PROH, v); michael@0: const unsigned char *bm; michael@0: michael@0: #define IMAP compose_sym3(nameprep_, VERSION, _prohibited_imap) michael@0: #define BITMAP compose_sym3(nameprep_, VERSION, _prohibited_bitmap) michael@0: bm = BITMAP[IMAP[IMAP[idx0] + idx1]].bm; michael@0: return (bm[idx2 / 8] & (1 << (idx2 % 8))); michael@0: #undef IMAP michael@0: #undef BITMAP michael@0: } michael@0: michael@0: static int michael@0: compose_sym2(nameprep_unassigned_, VERSION) (uint32_t v) { michael@0: int idx0 = IDX0(UNAS, v); michael@0: int idx1 = IDX1(UNAS, v); michael@0: int idx2 = IDX2(UNAS, v); michael@0: const unsigned char *bm; michael@0: michael@0: #define IMAP compose_sym3(nameprep_, VERSION, _unassigned_imap) michael@0: #define BITMAP compose_sym3(nameprep_, VERSION, _unassigned_bitmap) michael@0: bm = BITMAP[IMAP[IMAP[idx0] + idx1]].bm; michael@0: return (bm[idx2 / 8] & (1 << (idx2 % 8))); michael@0: #undef IMAP michael@0: #undef BITMAP michael@0: } michael@0: michael@0: static idn_biditype_t michael@0: compose_sym2(nameprep_biditype_, VERSION) (uint32_t v) { michael@0: int idx0 = IDX0(BIDI, v); michael@0: int idx1 = IDX1(BIDI, v); michael@0: int idx2 = IDX2(BIDI, v); michael@0: int offset; michael@0: michael@0: #define IMAP compose_sym3(nameprep_, VERSION, _bidi_imap) michael@0: #define TABLE compose_sym3(nameprep_, VERSION, _bidi_table) michael@0: #define DATA compose_sym3(nameprep_, VERSION, _bidi_data) michael@0: offset = TABLE[IMAP[IMAP[idx0] + idx1]].tbl[idx2]; michael@0: return DATA[offset]; michael@0: #undef IMAP michael@0: #undef TABLE michael@0: #undef DATA michael@0: }