#ifndef lint
#endif
/*
* Copyright (c) 2001 Japan Network Information Center. All rights reserved.
*
* By using this file, you agree to the terms and conditions set forth bellow.
*
* LICENSE TERMS AND CONDITIONS
*
* The following License Terms and Conditions apply, unless a different
* license is obtained from Japan Network Information Center ("JPNIC"),
* a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
* Chiyoda-ku, Tokyo 101-0047, Japan.
*
* 1. Use, Modification and Redistribution (including distribution of any
* under this License Terms and Conditions.
*
* 2. Redistribution of source code must retain the copyright notices as they
* appear in each source code file, this License Terms and Conditions.
*
* 3. Redistribution in binary form must reproduce the Copyright Notice,
* materials provided with the distribution. For the purposes of binary
* distribution the "Copyright Notice" refers to the following language:
* "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
*
* 4. The name of JPNIC may not be used to endorse or promote products
* derived from this Software without specific prior written approval of
* JPNIC.
*
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <idn/logmacro.h>
/*
* Code point range.
*
* The set of code points is represented by an array of code point ranges.
* In the building phase, specified ranges by 'idn_ucsset_add' or
* 'idn_ucsset_addrange' are simply appended to the array.
* And 'idn_ucsset_fix' sorts the array by the code point value, and also
* merges any intersecting ranges. Since the array is sorted, a binary
* search can be used for looking up.
*/
typedef struct {
unsigned long from;
unsigned long to;
} range_t;
/*
* Code point segment.
*
* To speed up searching further, the entire region of UCS-4 code points
* (U+0000 - U+7FFFFFFF) are divided into segments. For each segment,
* the first and last element of the range array corresponding to the
* segment are computed by 'idn_ucsset_fix'. This narrows down the
* (initial) search range.
*/
typedef struct {
} segment_t;
/*
* Code point to segment index conversion.
*
* Below is the function that maps a code point to the corresponding segment.
* The mapping is non-uniform, so that BMP, the following 16 planes that
* comprise Unicode code points together with BMP, and other planes
* have different granularity.
*/
#define SEG_INDEX(v) \
/*
* Representation of set of UCS code points.
*/
typedef struct idn_ucsset {
int fixed;
} ucsset;
TRACE(("idn_ucsset_create()\n"));
WARNING(("idn_ucsset_create: malloc failed\n"));
return idn_nomemory;
}
return (idn_success);
}
void
TRACE(("idn_ucsset_destroy()\n"));
}
}
void
TRACE(("idn_ucsset_incrref()\n"));
}
TRACE(("idn_ucsset_add(v=U+%lX)\n", v));
}
unsigned long to)
{
TRACE(("idn_ucsset_addrange(from=U+%lX, to=U+%lX)\n",
}
void
int nranges;
int i, j;
TRACE(("idn_ucsset_fix()\n"));
return;
/* Initialize segment array */
for (i = 0; i < SEG_LEN; i++) {
}
/* If the set is empty, there's nothing to be done. */
if (nranges == 0)
return;
/* Sort ranges. */
/* Merge overlapped/continuous ranges. */
for (i = 0, j = 1; j < nranges; j++) {
/* can be merged */
}
} else {
i++;
if (i < j)
}
}
/* 'i' points the last range in the array. */
/* Create segment array. */
for (i = 0; i < nranges; i++) {
if (segments[j].range_start < 0)
segments[j].range_start = i;
}
}
#if 0
/*
* Does the standard guarantee realloc() always succeeds
* when shrinking?
*/
/* Shrink malloc'ed space if possible. */
#endif
}
int idx;
TRACE(("idn_ucsset_lookup(v=U+%lX)\n", v));
/* Make sure it is fixed. */
WARNING(("idn_ucsset_lookup: not fixed yet\n"));
return (idn_failure);
}
/* Check the given code point. */
if (v >= UCS_MAX)
return (idn_invalid_codepoint);
/* Get the segment 'v' belongs to. */
/* Do binary search. */
*found = 0;
} else {
*found = 1;
break;
}
}
}
return (idn_success);
}
static idn_result_t
char *func_name)
{
/* Check the given code points. */
WARNING(("%s: code point out of range (U+%lX)\n",
return (idn_invalid_codepoint);
WARNING(("%s: code point out of range (U+%lX)\n",
return (idn_invalid_codepoint);
WARNING(("%s: invalid range spec (U+%lX-U+%lX)\n",
return (idn_invalid_codepoint);
}
/* Make sure it is not fixed yet. */
WARNING(("%s: attempt to add to already fixed object\n",
func_name));
return (idn_failure);
}
/* Append the specified range to the 'ranges' array. */
/* Make it bigger. */
else
return (idn_nomemory);
}
return (idn_success);
}
static int
/*
* Range comparation function suitable for qsort().
*/
return (-1);
return (1);
else
return (0);
}