xref: /freebsd/lib/libc/locale/tolower.c (revision 350a3d3e48232a1040bc3ae87865be85fb5e39de)
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 ___tolower(c)
422f04ec53SAndrey A. Chernov 	_BSD_RUNE_T_ c;
432f04ec53SAndrey A. Chernov {
442f04ec53SAndrey A. Chernov 	int x;
452f04ec53SAndrey A. Chernov 	_RuneRange *rr = &_CurrentRuneLocale->maplower_ext;
462f04ec53SAndrey A. Chernov 	_RuneEntry *re = rr->ranges;
472f04ec53SAndrey A. Chernov 
482f04ec53SAndrey A. Chernov 	if (c == EOF)
492f04ec53SAndrey A. Chernov 		return(EOF);
502f04ec53SAndrey A. Chernov 	for (x = 0; x < rr->nranges; ++x, ++re) {
512f04ec53SAndrey A. Chernov 		if (c < re->min)
522f04ec53SAndrey A. Chernov 			return(c);
532f04ec53SAndrey A. Chernov 		if (c <= re->max)
542f04ec53SAndrey A. Chernov 			return(re->map + c - re->min);
552f04ec53SAndrey A. Chernov 	}
562f04ec53SAndrey A. Chernov 	return(c);
572f04ec53SAndrey A. Chernov }
582f04ec53SAndrey A. Chernov 
592f04ec53SAndrey A. Chernov 
60