xref: /freebsd/lib/libc/locale/toupper.c (revision f9cbdf41)
1350a3d3eSAndrey A. Chernov /*-
2350a3d3eSAndrey A. Chernov  * Copyright (c) 1993
3350a3d3eSAndrey A. Chernov  *	The Regents of the University of California.  All rights reserved.
4350a3d3eSAndrey A. Chernov  *
5350a3d3eSAndrey A. Chernov  * This code is derived from software contributed to Berkeley by
6350a3d3eSAndrey A. Chernov  * Paul Borman at Krystal Technologies.
7350a3d3eSAndrey A. Chernov  *
8350a3d3eSAndrey A. Chernov  * Redistribution and use in source and binary forms, with or without
9350a3d3eSAndrey A. Chernov  * modification, are permitted provided that the following conditions
10350a3d3eSAndrey A. Chernov  * are met:
11350a3d3eSAndrey A. Chernov  * 1. Redistributions of source code must retain the above copyright
12350a3d3eSAndrey A. Chernov  *    notice, this list of conditions and the following disclaimer.
13350a3d3eSAndrey A. Chernov  * 2. Redistributions in binary form must reproduce the above copyright
14350a3d3eSAndrey A. Chernov  *    notice, this list of conditions and the following disclaimer in the
15350a3d3eSAndrey A. Chernov  *    documentation and/or other materials provided with the distribution.
16350a3d3eSAndrey A. Chernov  * 3. All advertising materials mentioning features or use of this software
17350a3d3eSAndrey A. Chernov  *    must display the following acknowledgement:
18350a3d3eSAndrey A. Chernov  *	This product includes software developed by the University of
19350a3d3eSAndrey A. Chernov  *	California, Berkeley and its contributors.
20350a3d3eSAndrey A. Chernov  * 4. Neither the name of the University nor the names of its contributors
21350a3d3eSAndrey A. Chernov  *    may be used to endorse or promote products derived from this software
22350a3d3eSAndrey A. Chernov  *    without specific prior written permission.
23350a3d3eSAndrey A. Chernov  *
24350a3d3eSAndrey A. Chernov  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25350a3d3eSAndrey A. Chernov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26350a3d3eSAndrey A. Chernov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27350a3d3eSAndrey A. Chernov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28350a3d3eSAndrey A. Chernov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29350a3d3eSAndrey A. Chernov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30350a3d3eSAndrey A. Chernov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31350a3d3eSAndrey A. Chernov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32350a3d3eSAndrey A. Chernov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33350a3d3eSAndrey A. Chernov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34350a3d3eSAndrey A. Chernov  * SUCH DAMAGE.
35350a3d3eSAndrey A. Chernov  */
36350a3d3eSAndrey A. Chernov 
372f04ec53SAndrey A. Chernov #include <stdio.h>
382f04ec53SAndrey A. Chernov #include <rune.h>
392f04ec53SAndrey A. Chernov 
402f04ec53SAndrey A. Chernov _BSD_RUNE_T_
412f04ec53SAndrey A. Chernov ___toupper(c)
422f04ec53SAndrey A. Chernov 	_BSD_RUNE_T_ c;
432f04ec53SAndrey A. Chernov {
44f9cbdf41SAndrey A. Chernov #ifdef XPG4
452f04ec53SAndrey A. Chernov 	int x;
462f04ec53SAndrey A. Chernov 	_RuneRange *rr = &_CurrentRuneLocale->mapupper_ext;
472f04ec53SAndrey A. Chernov 	_RuneEntry *re = rr->ranges;
48f9cbdf41SAndrey A. Chernov #endif
492f04ec53SAndrey A. Chernov 
502f04ec53SAndrey A. Chernov 	if (c == EOF)
512f04ec53SAndrey A. Chernov 		return(EOF);
52f9cbdf41SAndrey A. Chernov 	if (c < 0) {
53f9cbdf41SAndrey A. Chernov 		if (c >= -128) /* signed char */
54f9cbdf41SAndrey A. Chernov 			return(_CurrentRuneLocale->mapupper[(unsigned char)c]);
55f9cbdf41SAndrey A. Chernov 		else
56f9cbdf41SAndrey A. Chernov 			return(c);
57f9cbdf41SAndrey A. Chernov 	}
58f9cbdf41SAndrey A. Chernov #ifdef XPG4
592f04ec53SAndrey A. Chernov 	for (x = 0; x < rr->nranges; ++x, ++re) {
602f04ec53SAndrey A. Chernov 		if (c < re->min)
612f04ec53SAndrey A. Chernov 			return(c);
622f04ec53SAndrey A. Chernov 		if (c <= re->max)
632f04ec53SAndrey A. Chernov 			return(re->map + c - re->min);
642f04ec53SAndrey A. Chernov 	}
65f9cbdf41SAndrey A. Chernov #endif
662f04ec53SAndrey A. Chernov 	return(c);
672f04ec53SAndrey A. Chernov }
682f04ec53SAndrey A. Chernov 
69