runetype.c revision 150065
111695Sache/*- 211695Sache * Copyright (c) 1993 311695Sache * The Regents of the University of California. All rights reserved. 411695Sache * 511695Sache * This code is derived from software contributed to Berkeley by 611695Sache * Paul Borman at Krystal Technologies. 711695Sache * 811695Sache * Redistribution and use in source and binary forms, with or without 911695Sache * modification, are permitted provided that the following conditions 1011695Sache * are met: 1111695Sache * 1. Redistributions of source code must retain the above copyright 1211695Sache * notice, this list of conditions and the following disclaimer. 1311695Sache * 2. Redistributions in binary form must reproduce the above copyright 1411695Sache * notice, this list of conditions and the following disclaimer in the 1511695Sache * documentation and/or other materials provided with the distribution. 1611695Sache * 3. All advertising materials mentioning features or use of this software 1711695Sache * must display the following acknowledgement: 1811695Sache * This product includes software developed by the University of 1911695Sache * California, Berkeley and its contributors. 2011695Sache * 4. Neither the name of the University nor the names of its contributors 2111695Sache * may be used to endorse or promote products derived from this software 2211695Sache * without specific prior written permission. 2311695Sache * 2411695Sache * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2511695Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2611695Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2711695Sache * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2811695Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2911695Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3011695Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3111695Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3211695Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3311695Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3411695Sache * SUCH DAMAGE. 3511695Sache */ 3611695Sache 3792986Sobrien#include <sys/cdefs.h> 3892986Sobrien__FBSDID("$FreeBSD: head/lib/libc/locale/runetype.c 150065 2005-09-12 19:52:42Z stefanf $"); 3992986Sobrien 40150065Sstefanf#include <ctype.h> 413050Sache#include <stdio.h> 42132820Stjr#include <runetype.h> 433050Sache 443050Sacheunsigned long 45142653Sphantom___runetype(__ct_rune_t c) 463050Sache{ 47129065Stjr size_t lim; 48130961Stjr _RuneRange *rr = &_CurrentRuneLocale->__runetype_ext; 49129065Stjr _RuneEntry *base, *re; 503050Sache 5114811Sache if (c < 0 || c == EOF) 5214811Sache return(0L); 5312022Sache 54129065Stjr /* Binary search -- see bsearch.c for explanation. */ 55130961Stjr base = rr->__ranges; 56130961Stjr for (lim = rr->__nranges; lim != 0; lim >>= 1) { 57129065Stjr re = base + (lim >> 1); 58130961Stjr if (re->__min <= c && c <= re->__max) { 59130961Stjr if (re->__types) 60130961Stjr return(re->__types[c - re->__min]); 613050Sache else 62130961Stjr return(re->__map); 63130961Stjr } else if (c > re->__max) { 64129065Stjr base = re + 1; 65129065Stjr lim--; 663050Sache } 673050Sache } 6861218Sache 693050Sache return(0L); 703050Sache} 71