OSDN Git Service

projects clean up 1
[pinoc/pinoc.git] / pinoc_gcc / lib / c / ctype / tolower.c
1 /*
2 FUNCTION
3         <<tolower>>---translate characters to lowercase
4
5 INDEX
6         tolower
7 INDEX
8         _tolower
9
10 ANSI_SYNOPSIS
11         #include <ctype.h>
12         int tolower(int <[c]>);
13         int _tolower(int <[c]>);
14
15 TRAD_SYNOPSIS
16         #include <ctype.h>
17         int tolower(<[c]>);
18         int _tolower(<[c]>);
19
20
21 DESCRIPTION
22 <<tolower>> is a macro which converts uppercase characters to lowercase,
23 leaving all other characters unchanged.  It is only defined when
24 <[c]> is an integer in the range <<EOF>> to <<255>>.
25
26 You can use a compiled subroutine instead of the macro definition by
27 undefining this macro using `<<#undef tolower>>'.
28
29 <<_tolower>> performs the same conversion as <<tolower>>, but should
30 only be used when <[c]> is known to be an uppercase character (<<A>>--<<Z>>).
31
32 RETURNS
33 <<tolower>> returns the lowercase equivalent of <[c]> when it is a
34 character between <<A>> and <<Z>>, and <[c]> otherwise.
35
36 <<_tolower>> returns the lowercase equivalent of <[c]> when it is a
37 character between <<A>> and <<Z>>.  If <[c]> is not one of these
38 characters, the behaviour of <<_tolower>> is undefined.
39
40 PORTABILITY
41 <<tolower>> is ANSI C.  <<_tolower>> is not recommended for portable
42 programs.
43
44 No supporting OS subroutines are required.
45 */ 
46
47 #include <_ansi.h>
48 #include <ctype.h>
49 #if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS)
50 #include <limits.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <wctype.h>
54 #include <wchar.h>
55 #endif
56
57 #undef tolower
58 int
59 _DEFUN(tolower,(c),int c)
60 {
61 #if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS)
62   if ((unsigned char) c <= 0x7f) 
63     return isupper (c) ? c - 'A' + 'a' : c;
64   else if (c != EOF && MB_CUR_MAX == 1 && isupper (c))
65     {
66       char s[MB_LEN_MAX] = { c, '\0' };
67       wchar_t wc;
68       if (mbtowc (&wc, s, 1) >= 0
69           && wctomb (s, (wchar_t) towlower ((wint_t) wc)) == 1)
70         c = (unsigned char) s[0];
71     }
72   return c;
73 #else
74   return isupper(c) ? (c) - 'A' + 'a' : c;
75 #endif
76 }