toupper.c revision 129065
184865Sobrien/*- 2218822Sdim * Copyright (c) 1993 3218822Sdim * The Regents of the University of California. All rights reserved. 484865Sobrien * 584865Sobrien * This code is derived from software contributed to Berkeley by 684865Sobrien * Paul Borman at Krystal Technologies. 784865Sobrien * 884865Sobrien * Redistribution and use in source and binary forms, with or without 984865Sobrien * modification, are permitted provided that the following conditions 1084865Sobrien * are met: 1184865Sobrien * 1. Redistributions of source code must retain the above copyright 1284865Sobrien * notice, this list of conditions and the following disclaimer. 1384865Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1484865Sobrien * notice, this list of conditions and the following disclaimer in the 1584865Sobrien * documentation and/or other materials provided with the distribution. 1684865Sobrien * 3. All advertising materials mentioning features or use of this software 1784865Sobrien * must display the following acknowledgement: 1884865Sobrien * This product includes software developed by the University of 1984865Sobrien * California, Berkeley and its contributors. 20218822Sdim * 4. Neither the name of the University nor the names of its contributors 21218822Sdim * may be used to endorse or promote products derived from this software 2284865Sobrien * without specific prior written permission. 23104834Sobrien * 24104834Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2584865Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2684865Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2784865Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2884865Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2984865Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3084865Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3189857Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3284865Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3384865Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3489857Sobrien * SUCH DAMAGE. 3584865Sobrien */ 3684865Sobrien 37130561Sobrien#include <sys/cdefs.h> 38130561Sobrien__FBSDID("$FreeBSD: head/lib/libc/locale/toupper.c 129065 2004-05-09 13:04:49Z tjr $"); 39130561Sobrien 40130561Sobrien#include <stdio.h> 41130561Sobrien#include <rune.h> 42130561Sobrien 43130561Sobrien__ct_rune_t 44130561Sobrien___toupper(c) 45130561Sobrien __ct_rune_t c; 46130561Sobrien{ 47130561Sobrien size_t lim; 48130561Sobrien _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext; 49130561Sobrien _RuneEntry *base, *re; 50130561Sobrien 51130561Sobrien if (c < 0 || c == EOF) 52130561Sobrien return(c); 53130561Sobrien 54130561Sobrien /* Binary search -- see bsearch.c for explanation. */ 55130561Sobrien base = rr->ranges; 56130561Sobrien for (lim = rr->nranges; lim != 0; lim >>= 1) { 57130561Sobrien re = base + (lim >> 1); 5884865Sobrien if (re->min <= c && c <= re->max) 5984865Sobrien return (re->map + c - re->min); 6084865Sobrien else if (c > re->max) { 6184865Sobrien base = re + 1; 6284865Sobrien lim--; 6384865Sobrien } 6484865Sobrien } 6584865Sobrien 6684865Sobrien return(c); 6784865Sobrien} 6884865Sobrien