2N/A/* $OpenLDAP: pkg/ldap/libraries/liblunicode/ucdata/ucdata.c,v 1.36 2008/01/07 23:20:05 kurt Exp $ */
2N/A/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
2N/A *
2N/A * Copyright 1998-2008 The OpenLDAP Foundation.
2N/A * All rights reserved.
2N/A *
2N/A * Redistribution and use in source and binary forms, with or without
2N/A * modification, are permitted only as authorized by the OpenLDAP
2N/A * Public License.
2N/A *
2N/A * A copy of this license is available in file LICENSE in the
2N/A * top-level directory of the distribution or, alternatively, at
2N/A * <http://www.OpenLDAP.org/license.html>.
2N/A */
2N/A/* Copyright 2001 Computing Research Labs, New Mexico State University
2N/A *
2N/A * Permission is hereby granted, free of charge, to any person obtaining a
2N/A * copy of this software and associated documentation files (the "Software"),
2N/A * to deal in the Software without restriction, including without limitation
2N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
2N/A * and/or sell copies of the Software, and to permit persons to whom the
2N/A * Software is furnished to do so, subject to the following conditions:
2N/A *
2N/A * The above copyright notice and this permission notice shall be included in
2N/A * all copies or substantial portions of the Software.
2N/A *
2N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2N/A * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
2N/A * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
2N/A * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
2N/A * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2N/A */
2N/A/* $Id: ucdata.c,v 1.4 2001/01/02 18:46:20 mleisher Exp $" */
2N/A
2N/A#include "k5-int.h"
2N/A#include "k5-utf8.h"
2N/A#include "k5-unicode.h"
2N/A
2N/A#include "ucdata.h"
2N/A
2N/A#ifndef HARDCODE_DATA
2N/A#define HARDCODE_DATA 1
2N/A#endif
2N/A
2N/A#if HARDCODE_DATA
2N/A#include "uctable.h"
2N/A#endif
2N/A
2N/A/**************************************************************************
2N/A *
2N/A * Miscellaneous types, data, and support functions.
2N/A *
2N/A **************************************************************************/
2N/A
2N/Atypedef struct {
2N/A krb5_ui_2 bom;
2N/A krb5_ui_2 cnt;
2N/A union {
2N/A krb5_ui_4 bytes;
2N/A krb5_ui_2 len[2];
2N/A } size;
2N/A} _ucheader_t;
2N/A
2N/A/*
2N/A * A simple array of 32-bit masks for lookup.
2N/A */
2N/Astatic krb5_ui_4 masks32[32] = {
2N/A 0x00000001UL, 0x00000002UL, 0x00000004UL, 0x00000008UL,
2N/A 0x00000010UL, 0x00000020UL, 0x00000040UL, 0x00000080UL,
2N/A 0x00000100UL, 0x00000200UL, 0x00000400UL, 0x00000800UL,
2N/A 0x00001000UL, 0x00002000UL, 0x00004000UL, 0x00008000UL,
2N/A 0x00010000UL, 0x00020000UL, 0x00040000UL, 0x00080000UL,
2N/A 0x00100000UL, 0x00200000UL, 0x00400000UL, 0x00800000UL,
2N/A 0x01000000UL, 0x02000000UL, 0x04000000UL, 0x08000000UL,
2N/A 0x10000000UL, 0x20000000UL, 0x40000000UL, 0x80000000UL
2N/A};
2N/A
2N/A#define endian_short(cc) (((cc) >> 8) | (((cc) & 0xff) << 8))
2N/A#define endian_long(cc) ((((cc) & 0xff) << 24)|((((cc) >> 8) & 0xff) << 16)|\
2N/A ((((cc) >> 16) & 0xff) << 8)|((cc) >> 24))
2N/A
2N/A#if !HARDCODE_DATA
2N/Astatic FILE *
2N/A_ucopenfile(char *paths, char *filename, char *mode)
2N/A{
2N/A FILE *f;
2N/A char *fp, *dp, *pp, path[BUFSIZ];
2N/A
2N/A if (filename == 0 || *filename == 0)
2N/A return 0;
2N/A
2N/A dp = paths;
2N/A while (dp && *dp) {
2N/A pp = path;
2N/A while (*dp && *dp != ':')
2N/A *pp++ = *dp++;
2N/A *pp++ = *LDAP_DIRSEP;
2N/A
2N/A fp = filename;
2N/A while (*fp)
2N/A *pp++ = *fp++;
2N/A *pp = 0;
2N/A
2N/A if ((f = fopen(path, mode)) != 0)
2N/A return f;
2N/A
2N/A if (*dp == ':')
2N/A dp++;
2N/A }
2N/A
2N/A return 0;
2N/A}
2N/A#endif
2N/A
2N/A/**************************************************************************
2N/A *
2N/A * Support for the character properties.
2N/A *
2N/A **************************************************************************/
2N/A
2N/A#if !HARDCODE_DATA
2N/A
2N/Astatic krb5_ui_4 _ucprop_size;
2N/Astatic krb5_ui_2 *_ucprop_offsets;
2N/Astatic krb5_ui_4 *_ucprop_ranges;
2N/A
2N/A/*
2N/A * Return -1 on error, 0 if okay
2N/A */
2N/Astatic int
2N/A_ucprop_load(char *paths, int reload)
2N/A{
2N/A FILE *in;
2N/A krb5_ui_4 size, i;
2N/A _ucheader_t hdr;
2N/A
2N/A if (_ucprop_size > 0) {
2N/A if (!reload)
2N/A /*
2N/A * The character properties have already been loaded.
2N/A */
2N/A return 0;
2N/A
2N/A /*
2N/A * Unload the current character property data in preparation for
2N/A * loading a new copy. Only the first array has to be deallocated
2N/A * because all the memory for the arrays is allocated as a single
2N/A * block.
2N/A */
2N/A free((char *) _ucprop_offsets);
2N/A _ucprop_size = 0;
2N/A }
2N/A
2N/A if ((in = _ucopenfile(paths, "ctype.dat", "rb")) == 0)
2N/A return -1;
2N/A
2N/A /*
2N/A * Load the header.
2N/A */
2N/A fread((char *) &hdr, sizeof(_ucheader_t), 1, in);
2N/A
2N/A if (hdr.bom == 0xfffe) {
2N/A hdr.cnt = endian_short(hdr.cnt);
2N/A hdr.size.bytes = endian_long(hdr.size.bytes);
2N/A }
2N/A
2N/A if ((_ucprop_size = hdr.cnt) == 0) {
2N/A fclose(in);
2N/A return -1;
2N/A }
2N/A
2N/A /*
2N/A * Allocate all the storage needed for the lookup table.
2N/A */
2N/A _ucprop_offsets = (krb5_ui_2 *) malloc(hdr.size.bytes);
2N/A
2N/A /*
2N/A * Calculate the offset into the storage for the ranges. The offsets
2N/A * array is on a 4-byte boundary and one larger than the value provided in
2N/A * the header count field. This means the offset to the ranges must be
2N/A * calculated after aligning the count to a 4-byte boundary.
2N/A */
2N/A if ((size = ((hdr.cnt + 1) * sizeof(krb5_ui_2))) & 3)
2N/A size += 4 - (size & 3);
2N/A size >>= 1;
2N/A _ucprop_ranges = (krb5_ui_4 *) (_ucprop_offsets + size);
2N/A
2N/A /*
2N/A * Load the offset array.
2N/A */
2N/A fread((char *) _ucprop_offsets, sizeof(krb5_ui_2), size, in);
2N/A
2N/A /*
2N/A * Do an endian swap if necessary. Don't forget there is an extra node on
2N/A * the end with the final index.
2N/A */
2N/A if (hdr.bom == 0xfffe) {
2N/A for (i = 0; i <= _ucprop_size; i++)
2N/A _ucprop_offsets[i] = endian_short(_ucprop_offsets[i]);
2N/A }
2N/A
2N/A /*
2N/A * Load the ranges. The number of elements is in the last array position
2N/A * of the offsets.
2N/A */
2N/A fread((char *) _ucprop_ranges, sizeof(krb5_ui_4),
2N/A _ucprop_offsets[_ucprop_size], in);
2N/A
2N/A fclose(in);
2N/A
2N/A /*
2N/A * Do an endian swap if necessary.
2N/A */
2N/A if (hdr.bom == 0xfffe) {
2N/A for (i = 0; i < _ucprop_offsets[_ucprop_size]; i++)
2N/A _ucprop_ranges[i] = endian_long(_ucprop_ranges[i]);
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/Astatic void
2N/A_ucprop_unload(void)
2N/A{
2N/A if (_ucprop_size == 0)
2N/A return;
2N/A
2N/A /*
2N/A * Only need to free the offsets because the memory is allocated as a
2N/A * single block.
2N/A */
2N/A free((char *) _ucprop_offsets);
2N/A _ucprop_size = 0;
2N/A}
2N/A#endif
2N/A
2N/Astatic int
2N/A_ucprop_lookup(krb5_ui_4 code, krb5_ui_4 n)
2N/A{
2N/A long l, r, m;
2N/A
2N/A if (_ucprop_size == 0)
2N/A return 0;
2N/A
2N/A /*
2N/A * There is an extra node on the end of the offsets to allow this routine
2N/A * to work right. If the index is 0xffff, then there are no nodes for the
2N/A * property.
2N/A */
2N/A if ((l = _ucprop_offsets[n]) == 0xffff)
2N/A return 0;
2N/A
2N/A /*
2N/A * Locate the next offset that is not 0xffff. The sentinel at the end of
2N/A * the array is the max index value.
2N/A */
2N/A for (m = 1;
2N/A n + m < _ucprop_size && _ucprop_offsets[n + m] == 0xffff; m++) ;
2N/A
2N/A r = _ucprop_offsets[n + m] - 1;
2N/A
2N/A while (l <= r) {
2N/A /*
2N/A * Determine a "mid" point and adjust to make sure the mid point is at
2N/A * the beginning of a range pair.
2N/A */
2N/A m = (l + r) >> 1;
2N/A m -= (m & 1);
2N/A if (code > _ucprop_ranges[m + 1])
2N/A l = m + 2;
2N/A else if (code < _ucprop_ranges[m])
2N/A r = m - 2;
2N/A else if (code >= _ucprop_ranges[m] && code <= _ucprop_ranges[m + 1])
2N/A return 1;
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/Aint
2N/Aucisprop(krb5_ui_4 code, krb5_ui_4 mask1, krb5_ui_4 mask2)
2N/A{
2N/A krb5_ui_4 i;
2N/A
2N/A if (mask1 == 0 && mask2 == 0)
2N/A return 0;
2N/A
2N/A for (i = 0; mask1 && i < 32; i++) {
2N/A if ((mask1 & masks32[i]) && _ucprop_lookup(code, i))
2N/A return 1;
2N/A }
2N/A
2N/A for (i = 32; mask2 && i < _ucprop_size; i++) {
2N/A if ((mask2 & masks32[i & 31]) && _ucprop_lookup(code, i))
2N/A return 1;
2N/A }
2N/A
2N/A return 0;
2N/A}
2N/A
2N/A/**************************************************************************
2N/A *
2N/A * Support for case mapping.
2N/A *
2N/A **************************************************************************/
2N/A
2N/A#if !HARDCODE_DATA
2N/A
2N/A/* These record the number of slots in the map.
2N/A * There are 3 words per slot.
2N/A */
2N/Astatic krb5_ui_4 _uccase_size;
2N/Astatic krb5_ui_2 _uccase_len[2];
2N/Astatic krb5_ui_4 *_uccase_map;
2N/A
2N/A/*
2N/A * Return -1 on error, 0 if okay
2N/A */
2N/Astatic int
2N/A_uccase_load(char *paths, int reload)
2N/A{
2N/A FILE *in;
2N/A krb5_ui_4 i;
2N/A _ucheader_t hdr;
2N/A
2N/A if (_uccase_size > 0) {
2N/A if (!reload)
2N/A /*
2N/A * The case mappings have already been loaded.
2N/A */
2N/A return 0;
2N/A
2N/A free((char *) _uccase_map);
2N/A _uccase_size = 0;
2N/A }
2N/A
2N/A if ((in = _ucopenfile(paths, "case.dat", "rb")) == 0)
2N/A return -1;
2N/A
2N/A /*
2N/A * Load the header.
2N/A */
2N/A fread((char *) &hdr, sizeof(_ucheader_t), 1, in);
2N/A
2N/A if (hdr.bom == 0xfffe) {
2N/A hdr.cnt = endian_short(hdr.cnt);
2N/A hdr.size.len[0] = endian_short(hdr.size.len[0]);
2N/A hdr.size.len[1] = endian_short(hdr.size.len[1]);
2N/A }
2N/A
2N/A /*
2N/A * Set the node count and lengths of the upper and lower case mapping
2N/A * tables.
2N/A */
2N/A _uccase_size = hdr.cnt;
2N/A _uccase_len[0] = hdr.size.len[0];
2N/A _uccase_len[1] = hdr.size.len[1];
2N/A
2N/A _uccase_map = (krb5_ui_4 *)
2N/A malloc(_uccase_size * 3 * sizeof(krb5_ui_4));
2N/A
2N/A /*
2N/A * Load the case mapping table.
2N/A */
2N/A fread((char *) _uccase_map, sizeof(krb5_ui_4), _uccase_size * 3, in);
2N/A
2N/A /*
2N/A * Do an endian swap if necessary.
2N/A */
2N/A if (hdr.bom == 0xfffe) {
2N/A for (i = 0; i < _uccase_size * 3; i++)
2N/A _uccase_map[i] = endian_long(_uccase_map[i]);
2N/A }
2N/A fclose(in);
2N/A return 0;
2N/A}
2N/A
2N/Astatic void
2N/A_uccase_unload(void)
2N/A{
2N/A if (_uccase_size == 0)
2N/A return;
2N/A
2N/A free((char *) _uccase_map);
2N/A _uccase_size = 0;
2N/A}
2N/A#endif
2N/A
2N/Astatic krb5_ui_4
2N/A_uccase_lookup(krb5_ui_4 code, long l, long r, int field)
2N/A{
2N/A long m;
2N/A const krb5_ui_4 *tmp;
2N/A
2N/A /*
2N/A * Do the binary search.
2N/A */
2N/A while (l <= r) {
2N/A /*
2N/A * Determine a "mid" point and adjust to make sure the mid point is at
2N/A * the beginning of a case mapping triple.
2N/A */
2N/A m = (l + r) >> 1;
2N/A tmp = &_uccase_map[m*3];
2N/A if (code > *tmp)
2N/A l = m + 1;
2N/A else if (code < *tmp)
2N/A r = m - 1;
2N/A else if (code == *tmp)
2N/A return tmp[field];
2N/A }
2N/A
2N/A return code;
2N/A}
2N/A
2N/Akrb5_ui_4
2N/Auctoupper(krb5_ui_4 code)
2N/A{
2N/A int field;
2N/A long l, r;
2N/A
2N/A if (ucisupper(code))
2N/A return code;
2N/A
2N/A if (ucislower(code)) {
2N/A /*
2N/A * The character is lower case.
2N/A */
2N/A field = 2;
2N/A l = _uccase_len[0];
2N/A r = (l + _uccase_len[1]) - 1;
2N/A } else {
2N/A /*
2N/A * The character is title case.
2N/A */
2N/A field = 1;
2N/A l = _uccase_len[0] + _uccase_len[1];
2N/A r = _uccase_size - 1;
2N/A }
2N/A return _uccase_lookup(code, l, r, field);
2N/A}
2N/A
2N/Akrb5_ui_4
2N/Auctolower(krb5_ui_4 code)
2N/A{
2N/A int field;
2N/A long l, r;
2N/A
2N/A if (ucislower(code))
2N/A return code;
2N/A
2N/A if (ucisupper(code)) {
2N/A /*
2N/A * The character is upper case.
2N/A */
2N/A field = 1;
2N/A l = 0;
2N/A r = _uccase_len[0] - 1;
2N/A } else {
2N/A /*
2N/A * The character is title case.
2N/A */
2N/A field = 2;
2N/A l = _uccase_len[0] + _uccase_len[1];
2N/A r = _uccase_size - 1;
2N/A }
2N/A return _uccase_lookup(code, l, r, field);
2N/A}
2N/A
2N/Akrb5_ui_4
2N/Auctotitle(krb5_ui_4 code)
2N/A{
2N/A int field;
2N/A long l, r;
2N/A
2N/A if (ucistitle(code))
2N/A return code;
2N/A
2N/A /*
2N/A * The offset will always be the same for converting to title case.
2N/A */
2N/A field = 2;
2N/A
2N/A if (ucisupper(code)) {
2N/A /*
2N/A * The character is upper case.
2N/A */
2N/A l = 0;
2N/A r = _uccase_len[0] - 1;
2N/A } else {
2N/A /*
2N/A * The character is lower case.
2N/A */
2N/A l = _uccase_len[0];
2N/A r = (l + _uccase_len[1]) - 1;
2N/A }
2N/A return _uccase_lookup(code, l, r, field);
2N/A}
2N/A
2N/A/**************************************************************************
2N/A *
2N/A * Support for compositions.
2N/A *
2N/A **************************************************************************/
2N/A
2N/A#if !HARDCODE_DATA
2N/A
2N/Astatic krb5_ui_4 _uccomp_size;
2N/Astatic krb5_ui_4 *_uccomp_data;
2N/A
2N/A/*
2N/A * Return -1 on error, 0 if okay
2N/A */
2N/Astatic int
2N/A_uccomp_load(char *paths, int reload)
2N/A{
2N/A FILE *in;
2N/A krb5_ui_4 size, i;
2N/A _ucheader_t hdr;
2N/A
2N/A if (_uccomp_size > 0) {
2N/A if (!reload)
2N/A /*
2N/A * The compositions have already been loaded.
2N/A */
2N/A return 0;
2N/A
2N/A free((char *) _uccomp_data);
2N/A _uccomp_size = 0;
2N/A }
2N/A
2N/A if ((in = _ucopenfile(paths, "comp.dat", "rb")) == 0)
2N/A return -1;
2N/A
2N/A /*
2N/A * Load the header.
2N/A */
2N/A fread((char *) &hdr, sizeof(_ucheader_t), 1, in);
2N/A
2N/A if (hdr.bom == 0xfffe) {
2N/A hdr.cnt = endian_short(hdr.cnt);
2N/A hdr.size.bytes = endian_long(hdr.size.bytes);
2N/A }
2N/A
2N/A _uccomp_size = hdr.cnt;
2N/A _uccomp_data = (krb5_ui_4 *) malloc(hdr.size.bytes);
2N/A
2N/A /*
2N/A * Read the composition data in.
2N/A */
2N/A size = hdr.size.bytes / sizeof(krb5_ui_4);
2N/A fread((char *) _uccomp_data, sizeof(krb5_ui_4), size, in);
2N/A
2N/A /*
2N/A * Do an endian swap if necessary.
2N/A */
2N/A if (hdr.bom == 0xfffe) {
2N/A for (i = 0; i < size; i++)
2N/A _uccomp_data[i] = endian_long(_uccomp_data[i]);
2N/A }
2N/A
2N/A /*
2N/A * Assume that the data is ordered on count, so that all compositions
2N/A * of length 2 come first. Only handling length 2 for now.
2N/A */
2N/A for (i = 1; i < size; i += 4)
2N/A if (_uccomp_data[i] != 2)
2N/A break;
2N/A _uccomp_size = i - 1;
2N/A
2N/A fclose(in);
2N/A return 0;
2N/A}
2N/A
2N/Astatic void
2N/A_uccomp_unload(void)
2N/A{
2N/A if (_uccomp_size == 0)
2N/A return;
2N/A
2N/A free((char *) _uccomp_data);
2N/A _uccomp_size = 0;
2N/A}
2N/A#endif
2N/A
2N/Aint
2N/Auccomp(krb5_ui_4 node1, krb5_ui_4 node2, krb5_ui_4 *comp)
2N/A{
2N/A int l, r, m;
2N/A
2N/A l = 0;
2N/A r = _uccomp_size - 1;
2N/A
2N/A while (l <= r) {
2N/A m = ((r + l) >> 1);
2N/A m -= m & 3;
2N/A if (node1 > _uccomp_data[m+2])
2N/A l = m + 4;
2N/A else if (node1 < _uccomp_data[m+2])
2N/A r = m - 4;
2N/A else if (node2 > _uccomp_data[m+3])
2N/A l = m + 4;
2N/A else if (node2 < _uccomp_data[m+3])
2N/A r = m - 4;
2N/A else {
2N/A *comp = _uccomp_data[m];
2N/A return 1;
2N/A }
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/Aint
2N/Auccomp_hangul(krb5_ui_4 *str, int len)
2N/A{
2N/A const int SBase = 0xAC00, LBase = 0x1100,
2N/A VBase = 0x1161, TBase = 0x11A7,
2N/A LCount = 19, VCount = 21, TCount = 28,
2N/A NCount = VCount * TCount, /* 588 */
2N/A SCount = LCount * NCount; /* 11172 */
2N/A
2N/A int i, rlen;
2N/A krb5_ui_4 ch, last, lindex, sindex;
2N/A
2N/A last = str[0];
2N/A rlen = 1;
2N/A for ( i = 1; i < len; i++ ) {
2N/A ch = str[i];
2N/A
2N/A /* check if two current characters are L and V */
2N/A lindex = last - LBase;
2N/A if (lindex < (krb5_ui_4) LCount) {
2N/A krb5_ui_4 vindex = ch - VBase;
2N/A if (vindex < (krb5_ui_4) VCount) {
2N/A /* make syllable of form LV */
2N/A last = SBase + (lindex * VCount + vindex) * TCount;
2N/A str[rlen-1] = last; /* reset last */
2N/A continue;
2N/A }
2N/A }
2N/A
2N/A /* check if two current characters are LV and T */
2N/A sindex = last - SBase;
2N/A if (sindex < (krb5_ui_4) SCount
2N/A && (sindex % TCount) == 0)
2N/A {
2N/A krb5_ui_4 tindex = ch - TBase;
2N/A if (tindex <= (krb5_ui_4) TCount) {
2N/A /* make syllable of form LVT */
2N/A last += tindex;
2N/A str[rlen-1] = last; /* reset last */
2N/A continue;
2N/A }
2N/A }
2N/A
2N/A /* if neither case was true, just add the character */
2N/A last = ch;
2N/A str[rlen] = ch;
2N/A rlen++;
2N/A }
2N/A return rlen;
2N/A}
2N/A
2N/Aint
2N/Auccanoncomp(krb5_ui_4 *str, int len)
2N/A{
2N/A int i, stpos, copos;
2N/A krb5_ui_4 cl, prevcl, st, ch, co;
2N/A
2N/A st = str[0];
2N/A stpos = 0;
2N/A copos = 1;
2N/A prevcl = uccombining_class(st) == 0 ? 0 : 256;
2N/A
2N/A for (i = 1; i < len; i++) {
2N/A ch = str[i];
2N/A cl = uccombining_class(ch);
2N/A if (uccomp(st, ch, &co) && (prevcl < cl || prevcl == 0))
2N/A st = str[stpos] = co;
2N/A else {
2N/A if (cl == 0) {
2N/A stpos = copos;
2N/A st = ch;
2N/A }
2N/A prevcl = cl;
2N/A str[copos++] = ch;
2N/A }
2N/A }
2N/A
2N/A return uccomp_hangul(str, copos);
2N/A}
2N/A
2N/A/**************************************************************************
2N/A *
2N/A * Support for decompositions.
2N/A *
2N/A **************************************************************************/
2N/A
2N/A#if !HARDCODE_DATA
2N/A
2N/Astatic krb5_ui_4 _ucdcmp_size;
2N/Astatic krb5_ui_4 *_ucdcmp_nodes;
2N/Astatic krb5_ui_4 *_ucdcmp_decomp;
2N/A
2N/Astatic krb5_ui_4 _uckdcmp_size;
2N/Astatic krb5_ui_4 *_uckdcmp_nodes;
2N/Astatic krb5_ui_4 *_uckdcmp_decomp;
2N/A
2N/A/*
2N/A * Return -1 on error, 0 if okay
2N/A */
2N/Astatic int
2N/A_ucdcmp_load(char *paths, int reload)
2N/A{
2N/A FILE *in;
2N/A krb5_ui_4 size, i;
2N/A _ucheader_t hdr;
2N/A
2N/A if (_ucdcmp_size > 0) {
2N/A if (!reload)
2N/A /*
2N/A * The decompositions have already been loaded.
2N/A */
2N/A return 0;
2N/A
2N/A free((char *) _ucdcmp_nodes);
2N/A _ucdcmp_size = 0;
2N/A }
2N/A
2N/A if ((in = _ucopenfile(paths, "decomp.dat", "rb")) == 0)
2N/A return -1;
2N/A
2N/A /*
2N/A * Load the header.
2N/A */
2N/A fread((char *) &hdr, sizeof(_ucheader_t), 1, in);
2N/A
2N/A if (hdr.bom == 0xfffe) {
2N/A hdr.cnt = endian_short(hdr.cnt);
2N/A hdr.size.bytes = endian_long(hdr.size.bytes);
2N/A }
2N/A
2N/A _ucdcmp_size = hdr.cnt << 1;
2N/A _ucdcmp_nodes = (krb5_ui_4 *) malloc(hdr.size.bytes);
2N/A _ucdcmp_decomp = _ucdcmp_nodes + (_ucdcmp_size + 1);
2N/A
2N/A /*
2N/A * Read the decomposition data in.
2N/A */
2N/A size = hdr.size.bytes / sizeof(krb5_ui_4);
2N/A fread((char *) _ucdcmp_nodes, sizeof(krb5_ui_4), size, in);
2N/A
2N/A /*
2N/A * Do an endian swap if necessary.
2N/A */
2N/A if (hdr.bom == 0xfffe) {
2N/A for (i = 0; i < size; i++)
2N/A _ucdcmp_nodes[i] = endian_long(_ucdcmp_nodes[i]);
2N/A }
2N/A fclose(in);
2N/A return 0;
2N/A}
2N/A
2N/A/*
2N/A * Return -1 on error, 0 if okay
2N/A */
2N/Astatic int
2N/A_uckdcmp_load(char *paths, int reload)
2N/A{
2N/A FILE *in;
2N/A krb5_ui_4 size, i;
2N/A _ucheader_t hdr;
2N/A
2N/A if (_uckdcmp_size > 0) {
2N/A if (!reload)
2N/A /*
2N/A * The decompositions have already been loaded.
2N/A */
2N/A return 0;
2N/A
2N/A free((char *) _uckdcmp_nodes);
2N/A _uckdcmp_size = 0;
2N/A }
2N/A
2N/A if ((in = _ucopenfile(paths, "kdecomp.dat", "rb")) == 0)
2N/A return -1;
2N/A
2N/A /*
2N/A * Load the header.
2N/A */
2N/A fread((char *) &hdr, sizeof(_ucheader_t), 1, in);
2N/A
2N/A if (hdr.bom == 0xfffe) {
2N/A hdr.cnt = endian_short(hdr.cnt);
2N/A hdr.size.bytes = endian_long(hdr.size.bytes);
2N/A }
2N/A
2N/A _uckdcmp_size = hdr.cnt << 1;
2N/A _uckdcmp_nodes = (krb5_ui_4 *) malloc(hdr.size.bytes);
2N/A _uckdcmp_decomp = _uckdcmp_nodes + (_uckdcmp_size + 1);
2N/A
2N/A /*
2N/A * Read the decomposition data in.
2N/A */
2N/A size = hdr.size.bytes / sizeof(krb5_ui_4);
2N/A fread((char *) _uckdcmp_nodes, sizeof(krb5_ui_4), size, in);
2N/A
2N/A /*
2N/A * Do an endian swap if necessary.
2N/A */
2N/A if (hdr.bom == 0xfffe) {
2N/A for (i = 0; i < size; i++)
2N/A _uckdcmp_nodes[i] = endian_long(_uckdcmp_nodes[i]);
2N/A }
2N/A fclose(in);
2N/A return 0;
2N/A}
2N/A
2N/Astatic void
2N/A_ucdcmp_unload(void)
2N/A{
2N/A if (_ucdcmp_size == 0)
2N/A return;
2N/A
2N/A /*
2N/A * Only need to free the offsets because the memory is allocated as a
2N/A * single block.
2N/A */
2N/A free((char *) _ucdcmp_nodes);
2N/A _ucdcmp_size = 0;
2N/A}
2N/A
2N/Astatic void
2N/A_uckdcmp_unload(void)
2N/A{
2N/A if (_uckdcmp_size == 0)
2N/A return;
2N/A
2N/A /*
2N/A * Only need to free the offsets because the memory is allocated as a
2N/A * single block.
2N/A */
2N/A free((char *) _uckdcmp_nodes);
2N/A _uckdcmp_size = 0;
2N/A}
2N/A#endif
2N/A
2N/Aint
2N/Aucdecomp(krb5_ui_4 code, krb5_ui_4 *num, krb5_ui_4 **decomp)
2N/A{
2N/A long l, r, m;
2N/A
2N/A if (code < _ucdcmp_nodes[0]) {
2N/A return 0;
2N/A }
2N/A
2N/A l = 0;
2N/A r = _ucdcmp_nodes[_ucdcmp_size] - 1;
2N/A
2N/A while (l <= r) {
2N/A /*
2N/A * Determine a "mid" point and adjust to make sure the mid point is at
2N/A * the beginning of a code+offset pair.
2N/A */
2N/A m = (l + r) >> 1;
2N/A m -= (m & 1);
2N/A if (code > _ucdcmp_nodes[m])
2N/A l = m + 2;
2N/A else if (code < _ucdcmp_nodes[m])
2N/A r = m - 2;
2N/A else if (code == _ucdcmp_nodes[m]) {
2N/A *num = _ucdcmp_nodes[m + 3] - _ucdcmp_nodes[m + 1];
2N/A *decomp = (krb5_ui_4*)&_ucdcmp_decomp[_ucdcmp_nodes[m + 1]];
2N/A return 1;
2N/A }
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/Aint
2N/Auckdecomp(krb5_ui_4 code, krb5_ui_4 *num, krb5_ui_4 **decomp)
2N/A{
2N/A long l, r, m;
2N/A
2N/A if (code < _uckdcmp_nodes[0]) {
2N/A return 0;
2N/A }
2N/A
2N/A l = 0;
2N/A r = _uckdcmp_nodes[_uckdcmp_size] - 1;
2N/A
2N/A while (l <= r) {
2N/A /*
2N/A * Determine a "mid" point and adjust to make sure the mid point is at
2N/A * the beginning of a code+offset pair.
2N/A */
2N/A m = (l + r) >> 1;
2N/A m -= (m & 1);
2N/A if (code > _uckdcmp_nodes[m])
2N/A l = m + 2;
2N/A else if (code < _uckdcmp_nodes[m])
2N/A r = m - 2;
2N/A else if (code == _uckdcmp_nodes[m]) {
2N/A *num = _uckdcmp_nodes[m + 3] - _uckdcmp_nodes[m + 1];
2N/A *decomp = (krb5_ui_4*)&_uckdcmp_decomp[_uckdcmp_nodes[m + 1]];
2N/A return 1;
2N/A }
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/Aint
2N/Aucdecomp_hangul(krb5_ui_4 code, krb5_ui_4 *num, krb5_ui_4 decomp[])
2N/A{
2N/A if (!ucishangul(code))
2N/A return 0;
2N/A
2N/A code -= 0xac00;
2N/A decomp[0] = 0x1100 + (krb5_ui_4) (code / 588);
2N/A decomp[1] = 0x1161 + (krb5_ui_4) ((code % 588) / 28);
2N/A decomp[2] = 0x11a7 + (krb5_ui_4) (code % 28);
2N/A *num = (decomp[2] != 0x11a7) ? 3 : 2;
2N/A
2N/A return 1;
2N/A}
2N/A
2N/A/* mode == 0 for canonical, mode == 1 for compatibility */
2N/Astatic int
2N/Auccanoncompatdecomp(const krb5_ui_4 *in, int inlen,
2N/A krb5_ui_4 **out, int *outlen, short mode)
2N/A{
2N/A int l, size;
2N/A unsigned i, j, k;
2N/A krb5_ui_4 num, class, *decomp, hangdecomp[3];
2N/A
2N/A size = inlen * 2;
2N/A *out = (krb5_ui_4 *) malloc(size * sizeof(**out));
2N/A if (*out == NULL)
2N/A return *outlen = -1;
2N/A
2N/A i = 0;
2N/A for (j = 0; j < (unsigned) inlen; j++) {
2N/A if (mode ? uckdecomp(in[j], &num, &decomp) : ucdecomp(in[j], &num, &decomp)) {
2N/A if ( size - i < num) {
2N/A size = inlen + i - j + num - 1;
2N/A *out = (krb5_ui_4 *) realloc(*out, size * sizeof(**out));
2N/A if (*out == NULL)
2N/A return *outlen = -1;
2N/A }
2N/A for (k = 0; k < num; k++) {
2N/A class = uccombining_class(decomp[k]);
2N/A if (class == 0) {
2N/A (*out)[i] = decomp[k];
2N/A } else {
2N/A for (l = i; l > 0; l--)
2N/A if (class >= uccombining_class((*out)[l-1]))
2N/A break;
2N/A memcpy(*out + l + 1, *out + l, (i - l) * sizeof(**out));
2N/A (*out)[l] = decomp[k];
2N/A }
2N/A i++;
2N/A }
2N/A } else if (ucdecomp_hangul(in[j], &num, hangdecomp)) {
2N/A if (size - i < num) {
2N/A size = inlen + i - j + num - 1;
2N/A *out = (krb5_ui_4 *) realloc(*out, size * sizeof(**out));
2N/A if (*out == NULL)
2N/A return *outlen = -1;
2N/A }
2N/A for (k = 0; k < num; k++) {
2N/A (*out)[i] = hangdecomp[k];
2N/A i++;
2N/A }
2N/A } else {
2N/A if (size - i < 1) {
2N/A size = inlen + i - j;
2N/A *out = (krb5_ui_4 *) realloc(*out, size * sizeof(**out));
2N/A if (*out == NULL)
2N/A return *outlen = -1;
2N/A }
2N/A class = uccombining_class(in[j]);
2N/A if (class == 0) {
2N/A (*out)[i] = in[j];
2N/A } else {
2N/A for (l = i; l > 0; l--)
2N/A if (class >= uccombining_class((*out)[l-1]))
2N/A break;
2N/A memcpy(*out + l + 1, *out + l, (i - l) * sizeof(**out));
2N/A (*out)[l] = in[j];
2N/A }
2N/A i++;
2N/A }
2N/A }
2N/A return *outlen = i;
2N/A}
2N/A
2N/Aint
2N/Auccanondecomp(const krb5_ui_4 *in, int inlen,
2N/A krb5_ui_4 **out, int *outlen)
2N/A{
2N/A return uccanoncompatdecomp(in, inlen, out, outlen, 0);
2N/A}
2N/A
2N/Aint
2N/Auccompatdecomp(const krb5_ui_4 *in, int inlen,
2N/A krb5_ui_4 **out, int *outlen)
2N/A{
2N/A return uccanoncompatdecomp(in, inlen, out, outlen, 1);
2N/A}
2N/A
2N/A/**************************************************************************
2N/A *
2N/A * Support for combining classes.
2N/A *
2N/A **************************************************************************/
2N/A
2N/A#if !HARDCODE_DATA
2N/Astatic krb5_ui_4 _uccmcl_size;
2N/Astatic krb5_ui_4 *_uccmcl_nodes;
2N/A
2N/A/*
2N/A * Return -1 on error, 0 if okay
2N/A */
2N/Astatic int
2N/A_uccmcl_load(char *paths, int reload)
2N/A{
2N/A FILE *in;
2N/A krb5_ui_4 i;
2N/A _ucheader_t hdr;
2N/A
2N/A if (_uccmcl_size > 0) {
2N/A if (!reload)
2N/A /*
2N/A * The combining classes have already been loaded.
2N/A */
2N/A return 0;
2N/A
2N/A free((char *) _uccmcl_nodes);
2N/A _uccmcl_size = 0;
2N/A }
2N/A
2N/A if ((in = _ucopenfile(paths, "cmbcl.dat", "rb")) == 0)
2N/A return -1;
2N/A
2N/A /*
2N/A * Load the header.
2N/A */
2N/A fread((char *) &hdr, sizeof(_ucheader_t), 1, in);
2N/A
2N/A if (hdr.bom == 0xfffe) {
2N/A hdr.cnt = endian_short(hdr.cnt);
2N/A hdr.size.bytes = endian_long(hdr.size.bytes);
2N/A }
2N/A
2N/A _uccmcl_size = hdr.cnt * 3;
2N/A _uccmcl_nodes = (krb5_ui_4 *) malloc(hdr.size.bytes);
2N/A
2N/A /*
2N/A * Read the combining classes in.
2N/A */
2N/A fread((char *) _uccmcl_nodes, sizeof(krb5_ui_4), _uccmcl_size, in);
2N/A
2N/A /*
2N/A * Do an endian swap if necessary.
2N/A */
2N/A if (hdr.bom == 0xfffe) {
2N/A for (i = 0; i < _uccmcl_size; i++)
2N/A _uccmcl_nodes[i] = endian_long(_uccmcl_nodes[i]);
2N/A }
2N/A fclose(in);
2N/A return 0;
2N/A}
2N/A
2N/Astatic void
2N/A_uccmcl_unload(void)
2N/A{
2N/A if (_uccmcl_size == 0)
2N/A return;
2N/A
2N/A free((char *) _uccmcl_nodes);
2N/A _uccmcl_size = 0;
2N/A}
2N/A#endif
2N/A
2N/Akrb5_ui_4
2N/Auccombining_class(krb5_ui_4 code)
2N/A{
2N/A long l, r, m;
2N/A
2N/A l = 0;
2N/A r = _uccmcl_size - 1;
2N/A
2N/A while (l <= r) {
2N/A m = (l + r) >> 1;
2N/A m -= (m % 3);
2N/A if (code > _uccmcl_nodes[m + 1])
2N/A l = m + 3;
2N/A else if (code < _uccmcl_nodes[m])
2N/A r = m - 3;
2N/A else if (code >= _uccmcl_nodes[m] && code <= _uccmcl_nodes[m + 1])
2N/A return _uccmcl_nodes[m + 2];
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/A/**************************************************************************
2N/A *
2N/A * Support for numeric values.
2N/A *
2N/A **************************************************************************/
2N/A
2N/A#if !HARDCODE_DATA
2N/Astatic krb5_ui_4 *_ucnum_nodes;
2N/Astatic krb5_ui_4 _ucnum_size;
2N/Astatic short *_ucnum_vals;
2N/A
2N/A/*
2N/A * Return -1 on error, 0 if okay
2N/A */
2N/Astatic int
2N/A_ucnumb_load(char *paths, int reload)
2N/A{
2N/A FILE *in;
2N/A krb5_ui_4 size, i;
2N/A _ucheader_t hdr;
2N/A
2N/A if (_ucnum_size > 0) {
2N/A if (!reload)
2N/A /*
2N/A * The numbers have already been loaded.
2N/A */
2N/A return 0;
2N/A
2N/A free((char *) _ucnum_nodes);
2N/A _ucnum_size = 0;
2N/A }
2N/A
2N/A if ((in = _ucopenfile(paths, "num.dat", "rb")) == 0)
2N/A return -1;
2N/A
2N/A /*
2N/A * Load the header.
2N/A */
2N/A fread((char *) &hdr, sizeof(_ucheader_t), 1, in);
2N/A
2N/A if (hdr.bom == 0xfffe) {
2N/A hdr.cnt = endian_short(hdr.cnt);
2N/A hdr.size.bytes = endian_long(hdr.size.bytes);
2N/A }
2N/A
2N/A _ucnum_size = hdr.cnt;
2N/A _ucnum_nodes = (krb5_ui_4 *) malloc(hdr.size.bytes);
2N/A _ucnum_vals = (short *) (_ucnum_nodes + _ucnum_size);
2N/A
2N/A /*
2N/A * Read the combining classes in.
2N/A */
2N/A fread((char *) _ucnum_nodes, sizeof(unsigned char), hdr.size.bytes, in);
2N/A
2N/A /*
2N/A * Do an endian swap if necessary.
2N/A */
2N/A if (hdr.bom == 0xfffe) {
2N/A for (i = 0; i < _ucnum_size; i++)
2N/A _ucnum_nodes[i] = endian_long(_ucnum_nodes[i]);
2N/A
2N/A /*
2N/A * Determine the number of values that have to be adjusted.
2N/A */
2N/A size = (hdr.size.bytes -
2N/A (_ucnum_size * (sizeof(krb5_ui_4) << 1))) /
2N/A sizeof(short);
2N/A
2N/A for (i = 0; i < size; i++)
2N/A _ucnum_vals[i] = endian_short(_ucnum_vals[i]);
2N/A }
2N/A fclose(in);
2N/A return 0;
2N/A}
2N/A
2N/Astatic void
2N/A_ucnumb_unload(void)
2N/A{
2N/A if (_ucnum_size == 0)
2N/A return;
2N/A
2N/A free((char *) _ucnum_nodes);
2N/A _ucnum_size = 0;
2N/A}
2N/A#endif
2N/A
2N/Aint
2N/Aucnumber_lookup(krb5_ui_4 code, struct ucnumber *num)
2N/A{
2N/A long l, r, m;
2N/A short *vp;
2N/A
2N/A l = 0;
2N/A r = _ucnum_size - 1;
2N/A while (l <= r) {
2N/A /*
2N/A * Determine a "mid" point and adjust to make sure the mid point is at
2N/A * the beginning of a code+offset pair.
2N/A */
2N/A m = (l + r) >> 1;
2N/A m -= (m & 1);
2N/A if (code > _ucnum_nodes[m])
2N/A l = m + 2;
2N/A else if (code < _ucnum_nodes[m])
2N/A r = m - 2;
2N/A else {
2N/A vp = (short *)_ucnum_vals + _ucnum_nodes[m + 1];
2N/A num->numerator = (int) *vp++;
2N/A num->denominator = (int) *vp;
2N/A return 1;
2N/A }
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/Aint
2N/Aucdigit_lookup(krb5_ui_4 code, int *digit)
2N/A{
2N/A long l, r, m;
2N/A short *vp;
2N/A
2N/A l = 0;
2N/A r = _ucnum_size - 1;
2N/A while (l <= r) {
2N/A /*
2N/A * Determine a "mid" point and adjust to make sure the mid point is at
2N/A * the beginning of a code+offset pair.
2N/A */
2N/A m = (l + r) >> 1;
2N/A m -= (m & 1);
2N/A if (code > _ucnum_nodes[m])
2N/A l = m + 2;
2N/A else if (code < _ucnum_nodes[m])
2N/A r = m - 2;
2N/A else {
2N/A vp = (short *)_ucnum_vals + _ucnum_nodes[m + 1];
2N/A if (*vp == *(vp + 1)) {
2N/A *digit = *vp;
2N/A return 1;
2N/A }
2N/A return 0;
2N/A }
2N/A }
2N/A return 0;
2N/A}
2N/A
2N/Astruct ucnumber
2N/Aucgetnumber(krb5_ui_4 code)
2N/A{
2N/A struct ucnumber num;
2N/A
2N/A /*
2N/A * Initialize with some arbitrary value, because the caller simply cannot
2N/A * tell for sure if the code is a number without calling the ucisnumber()
2N/A * macro before calling this function.
2N/A */
2N/A num.numerator = num.denominator = -111;
2N/A
2N/A (void) ucnumber_lookup(code, &num);
2N/A
2N/A return num;
2N/A}
2N/A
2N/Aint
2N/Aucgetdigit(krb5_ui_4 code)
2N/A{
2N/A int dig;
2N/A
2N/A /*
2N/A * Initialize with some arbitrary value, because the caller simply cannot
2N/A * tell for sure if the code is a number without calling the ucisdigit()
2N/A * macro before calling this function.
2N/A */
2N/A dig = -111;
2N/A
2N/A (void) ucdigit_lookup(code, &dig);
2N/A
2N/A return dig;
2N/A}
2N/A
2N/A/**************************************************************************
2N/A *
2N/A * Setup and cleanup routines.
2N/A *
2N/A **************************************************************************/
2N/A
2N/A#if HARDCODE_DATA
2N/Aint ucdata_load(char *paths, int masks) { return 0; }
2N/Avoid ucdata_unload(int masks) { }
2N/Aint ucdata_reload(char *paths, int masks) { return 0; }
2N/A#else
2N/A/*
2N/A * Return 0 if okay, negative on error
2N/A */
2N/Aint
2N/Aucdata_load(char *paths, int masks)
2N/A{
2N/A int error = 0;
2N/A
2N/A if (masks & UCDATA_CTYPE)
2N/A error |= _ucprop_load(paths, 0) < 0 ? UCDATA_CTYPE : 0;
2N/A if (masks & UCDATA_CASE)
2N/A error |= _uccase_load(paths, 0) < 0 ? UCDATA_CASE : 0;
2N/A if (masks & UCDATA_DECOMP)
2N/A error |= _ucdcmp_load(paths, 0) < 0 ? UCDATA_DECOMP : 0;
2N/A if (masks & UCDATA_CMBCL)
2N/A error |= _uccmcl_load(paths, 0) < 0 ? UCDATA_CMBCL : 0;
2N/A if (masks & UCDATA_NUM)
2N/A error |= _ucnumb_load(paths, 0) < 0 ? UCDATA_NUM : 0;
2N/A if (masks & UCDATA_COMP)
2N/A error |= _uccomp_load(paths, 0) < 0 ? UCDATA_COMP : 0;
2N/A if (masks & UCDATA_KDECOMP)
2N/A error |= _uckdcmp_load(paths, 0) < 0 ? UCDATA_KDECOMP : 0;
2N/A
2N/A return -error;
2N/A}
2N/A
2N/Avoid
2N/Aucdata_unload(int masks)
2N/A{
2N/A if (masks & UCDATA_CTYPE)
2N/A _ucprop_unload();
2N/A if (masks & UCDATA_CASE)
2N/A _uccase_unload();
2N/A if (masks & UCDATA_DECOMP)
2N/A _ucdcmp_unload();
2N/A if (masks & UCDATA_CMBCL)
2N/A _uccmcl_unload();
2N/A if (masks & UCDATA_NUM)
2N/A _ucnumb_unload();
2N/A if (masks & UCDATA_COMP)
2N/A _uccomp_unload();
2N/A if (masks & UCDATA_KDECOMP)
2N/A _uckdcmp_unload();
2N/A}
2N/A
2N/A/*
2N/A * Return 0 if okay, negative on error
2N/A */
2N/Aint
2N/Aucdata_reload(char *paths, int masks)
2N/A{
2N/A int error = 0;
2N/A
2N/A if (masks & UCDATA_CTYPE)
2N/A error |= _ucprop_load(paths, 1) < 0 ? UCDATA_CTYPE : 0;
2N/A if (masks & UCDATA_CASE)
2N/A error |= _uccase_load(paths, 1) < 0 ? UCDATA_CASE : 0;
2N/A if (masks & UCDATA_DECOMP)
2N/A error |= _ucdcmp_load(paths, 1) < 0 ? UCDATA_DECOMP : 0;
2N/A if (masks & UCDATA_CMBCL)
2N/A error |= _uccmcl_load(paths, 1) < 0 ? UCDATA_CMBCL : 0;
2N/A if (masks & UCDATA_NUM)
2N/A error |= _ucnumb_load(paths, 1) < 0 ? UCDATA_NUM : 0;
2N/A if (masks & UCDATA_COMP)
2N/A error |= _uccomp_load(paths, 1) < 0 ? UCDATA_COMP : 0;
2N/A if (masks & UCDATA_KDECOMP)
2N/A error |= _uckdcmp_load(paths, 1) < 0 ? UCDATA_KDECOMP : 0;
2N/A
2N/A return -error;
2N/A}
2N/A#endif
2N/A
2N/A#ifdef TEST
2N/A
2N/Avoid
2N/Amain(void)
2N/A{
2N/A int dig;
2N/A krb5_ui_4 i, lo, *dec;
2N/A struct ucnumber num;
2N/A
2N/A/* ucdata_setup("."); */
2N/A
2N/A if (ucisweak(0x30))
2N/A printf("WEAK\n");
2N/A else
2N/A printf("NOT WEAK\n");
2N/A
2N/A printf("LOWER 0x%04lX\n", uctolower(0xff3a));
2N/A printf("UPPER 0x%04lX\n", uctoupper(0xff5a));
2N/A
2N/A if (ucisalpha(0x1d5))
2N/A printf("ALPHA\n");
2N/A else
2N/A printf("NOT ALPHA\n");
2N/A
2N/A if (ucisupper(0x1d5)) {
2N/A printf("UPPER\n");
2N/A lo = uctolower(0x1d5);
2N/A printf("0x%04lx\n", lo);
2N/A lo = uctotitle(0x1d5);
2N/A printf("0x%04lx\n", lo);
2N/A } else
2N/A printf("NOT UPPER\n");
2N/A
2N/A if (ucistitle(0x1d5))
2N/A printf("TITLE\n");
2N/A else
2N/A printf("NOT TITLE\n");
2N/A
2N/A if (uciscomposite(0x1d5))
2N/A printf("COMPOSITE\n");
2N/A else
2N/A printf("NOT COMPOSITE\n");
2N/A
2N/A if (ucdecomp(0x1d5, &lo, &dec)) {
2N/A for (i = 0; i < lo; i++)
2N/A printf("0x%04lx ", dec[i]);
2N/A putchar('\n');
2N/A }
2N/A
2N/A if ((lo = uccombining_class(0x41)) != 0)
2N/A printf("0x41 CCL %ld\n", lo);
2N/A
2N/A if (ucisxdigit(0xfeff))
2N/A printf("0xFEFF HEX DIGIT\n");
2N/A else
2N/A printf("0xFEFF NOT HEX DIGIT\n");
2N/A
2N/A if (ucisdefined(0x10000))
2N/A printf("0x10000 DEFINED\n");
2N/A else
2N/A printf("0x10000 NOT DEFINED\n");
2N/A
2N/A if (ucnumber_lookup(0x30, &num)) {
2N/A if (num.denominator != 1)
2N/A printf("UCNUMBER: 0x30 = %d/%d\n", num.numerator, num.denominator);
2N/A else
2N/A printf("UCNUMBER: 0x30 = %d\n", num.numerator);
2N/A } else
2N/A printf("UCNUMBER: 0x30 NOT A NUMBER\n");
2N/A
2N/A if (ucnumber_lookup(0xbc, &num)) {
2N/A if (num.denominator != 1)
2N/A printf("UCNUMBER: 0xbc = %d/%d\n", num.numerator, num.denominator);
2N/A else
2N/A printf("UCNUMBER: 0xbc = %d\n", num.numerator);
2N/A } else
2N/A printf("UCNUMBER: 0xbc NOT A NUMBER\n");
2N/A
2N/A
2N/A if (ucnumber_lookup(0xff19, &num)) {
2N/A if (num.denominator != 1)
2N/A printf("UCNUMBER: 0xff19 = %d/%d\n", num.numerator, num.denominator);
2N/A else
2N/A printf("UCNUMBER: 0xff19 = %d\n", num.numerator);
2N/A } else
2N/A printf("UCNUMBER: 0xff19 NOT A NUMBER\n");
2N/A
2N/A if (ucnumber_lookup(0x4e00, &num)) {
2N/A if (num.denominator != 1)
2N/A printf("UCNUMBER: 0x4e00 = %d/%d\n", num.numerator, num.denominator);
2N/A else
2N/A printf("UCNUMBER: 0x4e00 = %d\n", num.numerator);
2N/A } else
2N/A printf("UCNUMBER: 0x4e00 NOT A NUMBER\n");
2N/A
2N/A if (ucdigit_lookup(0x06f9, &dig))
2N/A printf("UCDIGIT: 0x6f9 = %d\n", dig);
2N/A else
2N/A printf("UCDIGIT: 0x6f9 NOT A NUMBER\n");
2N/A
2N/A dig = ucgetdigit(0x0969);
2N/A printf("UCGETDIGIT: 0x969 = %d\n", dig);
2N/A
2N/A num = ucgetnumber(0x30);
2N/A if (num.denominator != 1)
2N/A printf("UCGETNUMBER: 0x30 = %d/%d\n", num.numerator, num.denominator);
2N/A else
2N/A printf("UCGETNUMBER: 0x30 = %d\n", num.numerator);
2N/A
2N/A num = ucgetnumber(0xbc);
2N/A if (num.denominator != 1)
2N/A printf("UCGETNUMBER: 0xbc = %d/%d\n", num.numerator, num.denominator);
2N/A else
2N/A printf("UCGETNUMBER: 0xbc = %d\n", num.numerator);
2N/A
2N/A num = ucgetnumber(0xff19);
2N/A if (num.denominator != 1)
2N/A printf("UCGETNUMBER: 0xff19 = %d/%d\n", num.numerator, num.denominator);
2N/A else
2N/A printf("UCGETNUMBER: 0xff19 = %d\n", num.numerator);
2N/A
2N/A/* ucdata_cleanup(); */
2N/A exit(0);
2N/A}
2N/A
2N/A#endif /* TEST */