summaryrefslogtreecommitdiff
path: root/libc/ctype
diff options
context:
space:
mode:
authorProjectRevoTPP <projectrevotpp@hotmail.com>2017-12-20 16:34:35 -0500
committerProjectRevoTPP <projectrevotpp@hotmail.com>2017-12-20 16:34:35 -0500
commit48ef7704c03e7e554c05de01bf8d1d70c16cb6f4 (patch)
tree34d52513de6c903b4f52ef87d885c73472daf469 /libc/ctype
parentf49e7cbb33e6e27b0ce5eb35244d7241c800a7c1 (diff)
add libc building to agbcc.
Diffstat (limited to 'libc/ctype')
-rw-r--r--libc/ctype/_tolower.c9
-rw-r--r--libc/ctype/_toupper.c9
-rw-r--r--libc/ctype/ctype_.c62
-rw-r--r--libc/ctype/isalnum.c46
-rw-r--r--libc/ctype/isalpha.c44
-rw-r--r--libc/ctype/isascii.c43
-rw-r--r--libc/ctype/iscntrl.c48
-rw-r--r--libc/ctype/isdigit.c43
-rw-r--r--libc/ctype/islower.c43
-rw-r--r--libc/ctype/isprint.c60
-rw-r--r--libc/ctype/ispunct.c46
-rw-r--r--libc/ctype/isspace.c44
-rw-r--r--libc/ctype/isupper.c43
-rw-r--r--libc/ctype/isxdigit.c45
-rw-r--r--libc/ctype/toascii.c41
-rw-r--r--libc/ctype/tolower.c55
-rw-r--r--libc/ctype/toupper.c54
17 files changed, 735 insertions, 0 deletions
diff --git a/libc/ctype/_tolower.c b/libc/ctype/_tolower.c
new file mode 100644
index 0000000..968dcf7
--- /dev/null
+++ b/libc/ctype/_tolower.c
@@ -0,0 +1,9 @@
+#include <_ansi.h>
+#include <ctype.h>
+
+#undef _tolower
+int
+_DEFUN(_tolower,(c),int c)
+{
+ return isupper(c) ? (c) - 'A' + 'a' : c;
+}
diff --git a/libc/ctype/_toupper.c b/libc/ctype/_toupper.c
new file mode 100644
index 0000000..db4e00d
--- /dev/null
+++ b/libc/ctype/_toupper.c
@@ -0,0 +1,9 @@
+#include <_ansi.h>
+#include <ctype.h>
+
+#undef _toupper
+int
+_DEFUN(_toupper,(c),int c)
+{
+ return islower(c) ? c - 'a' + 'A' : c;
+}
diff --git a/libc/ctype/ctype_.c b/libc/ctype/ctype_.c
new file mode 100644
index 0000000..45fcaa7
--- /dev/null
+++ b/libc/ctype/ctype_.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)ctype_.c 5.6 (Berkeley) 6/1/90";
+#endif /* LIBC_SCCS and not lint */
+
+#include <ctype.h>
+
+#if defined(__CYGWIN__) || defined(__CYGWIN32__)
+_CONST char __declspec(dllexport) _ctype_[1 + 256] = {
+#else
+_CONST char _ctype_[1 + 256] = {
+#endif
+ 0,
+ _C, _C, _C, _C, _C, _C, _C, _C,
+ _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C,
+ _C, _C, _C, _C, _C, _C, _C, _C,
+ _C, _C, _C, _C, _C, _C, _C, _C,
+ _S|_B, _P, _P, _P, _P, _P, _P, _P,
+ _P, _P, _P, _P, _P, _P, _P, _P,
+ _N, _N, _N, _N, _N, _N, _N, _N,
+ _N, _N, _P, _P, _P, _P, _P, _P,
+ _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U,
+ _U, _U, _U, _U, _U, _U, _U, _U,
+ _U, _U, _U, _U, _U, _U, _U, _U,
+ _U, _U, _U, _P, _P, _P, _P, _P,
+ _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L,
+ _L, _L, _L, _L, _L, _L, _L, _L,
+ _L, _L, _L, _L, _L, _L, _L, _L,
+ _L, _L, _L, _P, _P, _P, _P, _C
+};
diff --git a/libc/ctype/isalnum.c b/libc/ctype/isalnum.c
new file mode 100644
index 0000000..7e05bd1
--- /dev/null
+++ b/libc/ctype/isalnum.c
@@ -0,0 +1,46 @@
+/*
+FUNCTION
+ <<isalnum>>---alphanumeric character predicate
+
+INDEX
+ isalnum
+
+ANSI_SYNOPSIS
+ #include <ctype.h>
+ int isalnum(int <[c]>);
+
+TRAD_SYNOPSIS
+ #include <ctype.h>
+ int isalnum(<[c]>);
+
+
+DESCRIPTION
+<<isalnum>> is a macro which classifies ASCII integer values by table
+lookup. It is a predicate returning non-zero for alphabetic or
+numeric ASCII characters, and <<0>> for other arguments. It is defined
+for all integer values.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining the macro using `<<#undef isalnum>>'.
+
+RETURNS
+<<isalnum>> returns non-zero if <[c]> is a letter (<<a>>--<<z>> or
+<<A>>--<<Z>>) or a digit (<<0>>--<<9>>).
+
+PORTABILITY
+<<isalnum>> is ANSI C.
+
+No OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <ctype.h>
+
+#undef isalnum
+
+int
+_DEFUN(isalnum,(c),int c)
+{
+ return((_ctype_ + 1)[c] & (_U|_L|_N));
+}
+
diff --git a/libc/ctype/isalpha.c b/libc/ctype/isalpha.c
new file mode 100644
index 0000000..35f14d3
--- /dev/null
+++ b/libc/ctype/isalpha.c
@@ -0,0 +1,44 @@
+/*
+FUNCTION
+ <<isalpha>>---alphabetic character predicate
+
+INDEX
+ isalpha
+
+ANSI_SYNOPSIS
+ #include <ctype.h>
+ int isalpha(int <[c]>);
+
+TRAD_SYNOPSIS
+ #include <ctype.h>
+ int isalpha(<[c]>);
+
+DESCRIPTION
+<<isalpha>> is a macro which classifies ASCII integer values by table
+lookup. It is a predicate returning non-zero when <[c]> represents an
+alphabetic ASCII character, and 0 otherwise. It is defined only when
+<<isascii>>(<[c]>) is true or <[c]> is EOF.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining the macro using `<<#undef isalpha>>'.
+
+RETURNS
+<<isalpha>> returns non-zero if <[c]> is a letter (<<A>>--<<Z>> or
+<<a>>--<<z>>).
+
+PORTABILITY
+<<isalpha>> is ANSI C.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <ctype.h>
+
+#undef isalpha
+int
+_DEFUN(isalpha,(c),int c)
+{
+ return((_ctype_ + 1)[c] & (_U|_L));
+}
+
diff --git a/libc/ctype/isascii.c b/libc/ctype/isascii.c
new file mode 100644
index 0000000..109fd3a
--- /dev/null
+++ b/libc/ctype/isascii.c
@@ -0,0 +1,43 @@
+/*
+FUNCTION
+ <<isascii>>---ASCII character predicate
+
+INDEX
+ isascii
+
+ANSI_SYNOPSIS
+ #include <ctype.h>
+ int isascii(int <[c]>);
+
+TRAD_SYNOPSIS
+ #include <ctype.h>
+ int isascii(<[c]>);
+
+DESCRIPTION
+<<isascii>> is a macro which returns non-zero when <[c]> is an ASCII
+character, and 0 otherwise. It is defined for all integer values.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining the macro using `<<#undef isascii>>'.
+
+RETURNS
+<<isascii>> returns non-zero if the low order byte of <[c]> is in the range
+0 to 127 (<<0x00>>--<<0x7F>>).
+
+PORTABILITY
+<<isascii>> is ANSI C.
+
+No supporting OS subroutines are required.
+*/
+#include <_ansi.h>
+#include <ctype.h>
+
+
+
+#undef isascii
+
+int
+_DEFUN(isascii,(c),int c)
+{
+ return c >= 0 && c< 128;
+}
diff --git a/libc/ctype/iscntrl.c b/libc/ctype/iscntrl.c
new file mode 100644
index 0000000..7b6da34
--- /dev/null
+++ b/libc/ctype/iscntrl.c
@@ -0,0 +1,48 @@
+
+/*
+FUNCTION
+ <<iscntrl>>---control character predicate
+
+INDEX
+ iscntrl
+
+ANSI_SYNOPSIS
+ #include <ctype.h>
+ int iscntrl(int <[c]>);
+
+TRAD_SYNOPSIS
+ #include <ctype.h>
+ int iscntrl(<[c]>);
+
+DESCRIPTION
+<<iscntrl>> is a macro which classifies ASCII integer values by table
+lookup. It is a predicate returning non-zero for control characters, and 0
+for other characters. It is defined only when <<isascii>>(<[c]>) is
+true or <[c]> is EOF.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining the macro using `<<#undef iscntrl>>'.
+
+RETURNS
+<<iscntrl>> returns non-zero if <[c]> is a delete character or ordinary
+control character (<<0x7F>> or <<0x00>>--<<0x1F>>).
+
+PORTABILITY
+<<iscntrl>> is ANSI C.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <ctype.h>
+
+
+
+#undef iscntrl
+int
+_DEFUN(iscntrl,(c),int c)
+{
+ return((_ctype_ + 1)[c] & _C);
+}
+
+
diff --git a/libc/ctype/isdigit.c b/libc/ctype/isdigit.c
new file mode 100644
index 0000000..5c21898
--- /dev/null
+++ b/libc/ctype/isdigit.c
@@ -0,0 +1,43 @@
+/*
+FUNCTION
+<<isdigit>>---decimal digit predicate
+
+INDEX
+isdigit
+
+ANSI_SYNOPSIS
+#include <ctype.h>
+int isdigit(int <[c]>);
+
+TRAD_SYNOPSIS
+#include <ctype.h>
+int isdigit(<[c]>);
+
+DESCRIPTION
+<<isdigit>> is a macro which classifies ASCII integer values by table
+lookup. It is a predicate returning non-zero for decimal digits, and 0 for
+other characters. It is defined only when <<isascii>>(<[c]>) is true
+or <[c]> is EOF.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining the macro using `<<#undef isdigit>>'.
+
+RETURNS
+<<isdigit>> returns non-zero if <[c]> is a decimal digit (<<0>>--<<9>>).
+
+PORTABILITY
+<<isdigit>> is ANSI C.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <ctype.h>
+
+
+#undef isdigit
+int
+_DEFUN(isdigit,(c),int c)
+{
+ return((_ctype_ + 1)[c] & _N);
+}
diff --git a/libc/ctype/islower.c b/libc/ctype/islower.c
new file mode 100644
index 0000000..81ad0bb
--- /dev/null
+++ b/libc/ctype/islower.c
@@ -0,0 +1,43 @@
+
+/*
+FUNCTION
+<<islower>>---lower-case character predicate
+
+INDEX
+islower
+
+ANSI_SYNOPSIS
+#include <ctype.h>
+int islower(int <[c]>);
+
+TRAD_SYNOPSIS
+#include <ctype.h>
+int islower(<[c]>);
+
+DESCRIPTION
+<<islower>> is a macro which classifies ASCII integer values by table
+lookup. It is a predicate returning non-zero for minuscules
+(lower-case alphabetic characters), and 0 for other characters.
+It is defined only when <<isascii>>(<[c]>) is true or <[c]> is EOF.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining the macro using `<<#undef islower>>'.
+
+RETURNS
+<<islower>> returns non-zero if <[c]> is a lower case letter (<<a>>--<<z>>).
+
+PORTABILITY
+<<islower>> is ANSI C.
+
+No supporting OS subroutines are required.
+*/
+#include <_ansi.h>
+#include <ctype.h>
+
+#undef islower
+int
+_DEFUN(islower,(c),int c)
+{
+ return((_ctype_ + 1)[c] & _L);
+}
+
diff --git a/libc/ctype/isprint.c b/libc/ctype/isprint.c
new file mode 100644
index 0000000..2ff00f4
--- /dev/null
+++ b/libc/ctype/isprint.c
@@ -0,0 +1,60 @@
+
+/*
+FUNCTION
+ <<isprint>>, <<isgraph>>---printable character predicates
+
+INDEX
+ isprint
+INDEX
+ isgraph
+
+ANSI_SYNOPSIS
+ #include <ctype.h>
+ int isprint(int <[c]>);
+ int isgraph(int <[c]>);
+
+TRAD_SYNOPSIS
+ #include <ctype.h>
+ int isprint(<[c]>);
+ int isgraph(<[c]>);
+
+
+DESCRIPTION
+<<isprint>> is a macro which classifies ASCII integer values by table
+lookup. It is a predicate returning non-zero for printable
+characters, and 0 for other character arguments.
+It is defined only when <<isascii>>(<[c]>) is true or <[c]> is EOF.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining either macro using `<<#undef isprint>>' or `<<#undef isgraph>>'.
+
+RETURNS
+<<isprint>> returns non-zero if <[c]> is a printing character,
+(<<0x20>>--<<0x7E>>).
+<<isgraph>> behaves identically to <<isprint>>, except that the space
+character (<<0x20>>) is excluded.
+
+PORTABILITY
+<<isprint>> and <<isgraph>> are ANSI C.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <ctype.h>
+
+#undef isgraph
+int
+_DEFUN(isgraph,(c),int c)
+{
+ return((_ctype_ + 1)[c] & (_P|_U|_L|_N));
+}
+
+
+#undef isprint
+int
+_DEFUN(isprint,(c),int c)
+{
+ return((_ctype_ + 1)[c] & (_P|_U|_L|_N|_B));
+}
+
diff --git a/libc/ctype/ispunct.c b/libc/ctype/ispunct.c
new file mode 100644
index 0000000..c567932
--- /dev/null
+++ b/libc/ctype/ispunct.c
@@ -0,0 +1,46 @@
+
+/*
+FUNCTION
+<<ispunct>>---punctuation character predicate
+
+INDEX
+ispunct
+
+ANSI_SYNOPSIS
+#include <ctype.h>
+int ispunct(int <[c]>);
+
+TRAD_SYNOPSIS
+#include <ctype.h>
+int ispunct(<[c]>);
+
+DESCRIPTION
+<<ispunct>> is a macro which classifies ASCII integer values by table
+lookup. It is a predicate returning non-zero for printable
+punctuation characters, and 0 for other characters. It is defined
+only when <<isascii>>(<[c]>) is true or <[c]> is EOF.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining the macro using `<<#undef ispunct>>'.
+
+RETURNS
+<<ispunct>> returns non-zero if <[c]> is a printable punctuation character
+(<<isgraph(<[c]>) && !isalnum(<[c]>)>>).
+
+PORTABILITY
+<<ispunct>> is ANSI C.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <ctype.h>
+
+
+#undef ispunct
+int
+_DEFUN(ispunct,(c),int c)
+{
+ return((_ctype_ + 1)[c] & _P);
+}
+
diff --git a/libc/ctype/isspace.c b/libc/ctype/isspace.c
new file mode 100644
index 0000000..1bc0798
--- /dev/null
+++ b/libc/ctype/isspace.c
@@ -0,0 +1,44 @@
+
+/*
+FUNCTION
+ <<isspace>>---whitespace character predicate
+
+INDEX
+ isspace
+
+ANSI_SYNOPSIS
+ #include <ctype.h>
+ int isspace(int <[c]>);
+
+TRAD_SYNOPSIS
+ #include <ctype.h>
+ int isspace(<[c]>);
+
+DESCRIPTION
+<<isspace>> is a macro which classifies ASCII integer values by table
+lookup. It is a predicate returning non-zero for whitespace
+characters, and 0 for other characters. It is defined only when <<isascii>>(<[c]>) is true or <[c]> is EOF.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining the macro using `<<#undef isspace>>'.
+
+RETURNS
+<<isspace>> returns non-zero if <[c]> is a space, tab, carriage return, new
+line, vertical tab, or formfeed (<<0x09>>--<<0x0D>>, <<0x20>>).
+
+PORTABILITY
+<<isspace>> is ANSI C.
+
+No supporting OS subroutines are required.
+*/
+#include <_ansi.h>
+#include <ctype.h>
+
+
+#undef isspace
+int
+_DEFUN(isspace,(c),int c)
+{
+ return((_ctype_ + 1)[c] & _S);
+}
+
diff --git a/libc/ctype/isupper.c b/libc/ctype/isupper.c
new file mode 100644
index 0000000..8127e25
--- /dev/null
+++ b/libc/ctype/isupper.c
@@ -0,0 +1,43 @@
+
+/*
+FUNCTION
+<<isupper>>---uppercase character predicate
+
+INDEX
+isupper
+
+ANSI_SYNOPSIS
+#include <ctype.h>
+int isupper(int <[c]>);
+
+TRAD_SYNOPSIS
+#include <ctype.h>
+int isupper(<[c]>);
+
+DESCRIPTION
+<<isupper>> is a macro which classifies ASCII integer values by table
+lookup. It is a predicate returning non-zero for upper-case letters
+(<<A>>--<<Z>>), and 0 for other characters. It is defined only when
+<<isascii>>(<[c]>) is true or <[c]> is EOF.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining the macro using `<<#undef isupper>>'.
+
+RETURNS
+<<isupper>> returns non-zero if <[c]> is a upper case letter (A-Z).
+
+PORTABILITY
+<<isupper>> is ANSI C.
+
+No supporting OS subroutines are required.
+*/
+#include <_ansi.h>
+#include <ctype.h>
+
+#undef isupper
+int
+_DEFUN(isupper,(c),int c)
+{
+ return((_ctype_ + 1)[c] & _U);
+}
+
diff --git a/libc/ctype/isxdigit.c b/libc/ctype/isxdigit.c
new file mode 100644
index 0000000..f8a035f
--- /dev/null
+++ b/libc/ctype/isxdigit.c
@@ -0,0 +1,45 @@
+
+/*
+FUNCTION
+<<isxdigit>>---hexadecimal digit predicate
+
+INDEX
+isxdigit
+
+ANSI_SYNOPSIS
+#include <ctype.h>
+int isxdigit(int <[c]>);
+
+TRAD_SYNOPSIS
+#include <ctype.h>
+int isxdigit(int <[c]>);
+
+DESCRIPTION
+<<isxdigit>> is a macro which classifies ASCII integer values by table
+lookup. It is a predicate returning non-zero for hexadecimal digits,
+and <<0>> for other characters. It is defined only when
+<<isascii>>(<[c]>) is true or <[c]> is EOF.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining the macro using `<<#undef isxdigit>>'.
+
+RETURNS
+<<isxdigit>> returns non-zero if <[c]> is a hexadecimal digit
+(<<0>>--<<9>>, <<a>>--<<f>>, or <<A>>--<<F>>).
+
+PORTABILITY
+<<isxdigit>> is ANSI C.
+
+No supporting OS subroutines are required.
+*/
+#include <_ansi.h>
+#include <ctype.h>
+
+
+#undef isxdigit
+int
+_DEFUN(isxdigit,(c),int c)
+{
+ return((_ctype_ + 1)[c] & ((_X)|(_N)));
+}
+
diff --git a/libc/ctype/toascii.c b/libc/ctype/toascii.c
new file mode 100644
index 0000000..4506f35
--- /dev/null
+++ b/libc/ctype/toascii.c
@@ -0,0 +1,41 @@
+/*
+FUNCTION
+ <<toascii>>---force integers to ASCII range
+
+INDEX
+ toascii
+
+ANSI_SYNOPSIS
+ #include <ctype.h>
+ int toascii(int <[c]>);
+
+TRAD_SYNOPSIS
+ #include <ctype.h>
+ int toascii(<[c]>);
+ int (<[c]>);
+
+DESCRIPTION
+<<toascii>> is a macro which coerces integers to the ASCII range (0--127) by zeroing any higher-order bits.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining this macro using `<<#undef toascii>>'.
+
+RETURNS
+<<toascii>> returns integers between 0 and 127.
+
+PORTABILITY
+<<toascii>> is not ANSI C.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <ctype.h>
+#undef toascii
+
+int
+_DEFUN(toascii,(c),int c)
+{
+ return (c)&0177;
+}
+
diff --git a/libc/ctype/tolower.c b/libc/ctype/tolower.c
new file mode 100644
index 0000000..e43fa6c
--- /dev/null
+++ b/libc/ctype/tolower.c
@@ -0,0 +1,55 @@
+/*
+FUNCTION
+ <<tolower>>---translate characters to lower case
+
+INDEX
+ tolower
+INDEX
+ _tolower
+
+ANSI_SYNOPSIS
+ #include <ctype.h>
+ int tolower(int <[c]>);
+ int _tolower(int <[c]>);
+
+TRAD_SYNOPSIS
+ #include <ctype.h>
+ int tolower(<[c]>);
+ int _tolower(<[c]>);
+
+
+DESCRIPTION
+<<tolower>> is a macro which converts upper-case characters to lower
+case, leaving all other characters unchanged. It is only defined when
+<[c]> is an integer in the range <<EOF>> to <<255>>.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining this macro using `<<#undef tolower>>'.
+
+<<_tolower>> performs the same conversion as <<tolower>>, but should
+only be used when <[c]> is known to be an uppercase character (<<A>>--<<Z>>).
+
+RETURNS
+<<tolower>> returns the lower-case equivalent of <[c]> when it is a
+character between <<A>> and <<Z>>, and <[c]> otherwise.
+
+<<_tolower>> returns the lower-case equivalent of <[c]> when it is a
+character between <<A>> and <<Z>>. If <[c]> is not one of these
+characters, the behaviour of <<_tolower>> is undefined.
+
+PORTABILITY
+<<tolower>> is ANSI C. <<_tolower>> is not recommended for portable
+programs.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <ctype.h>
+
+#undef tolower
+int
+_DEFUN(tolower,(c),int c)
+{
+ return isupper(c) ? (c) - 'A' + 'a' : c;
+}
diff --git a/libc/ctype/toupper.c b/libc/ctype/toupper.c
new file mode 100644
index 0000000..7977beb
--- /dev/null
+++ b/libc/ctype/toupper.c
@@ -0,0 +1,54 @@
+/*
+FUNCTION
+ <<toupper>>---translate characters to upper case
+
+INDEX
+ toupper
+INDEX
+ _toupper
+
+ANSI_SYNOPSIS
+ #include <ctype.h>
+ int toupper(int <[c]>);
+ int _toupper(int <[c]>);
+
+TRAD_SYNOPSIS
+ #include <ctype.h>
+ int toupper(<[c]>);
+ int _toupper(<[c]>);
+
+
+DESCRIPTION
+<<toupper>> is a macro which converts lower-case characters to upper
+case, leaving all other characters unchanged. It is only defined when
+<[c]> is an integer in the range <<EOF>> to <<255>>.
+
+You can use a compiled subroutine instead of the macro definition by
+undefining this macro using `<<#undef toupper>>'.
+
+<<_toupper>> performs the same conversion as <<toupper>>, but should
+only be used when <[c]> is known to be a lowercase character (<<a>>--<<z>>).
+
+RETURNS
+<<toupper>> returns the upper-case equivalent of <[c]> when it is a
+character between <<a>> and <<z>>, and <[c]> otherwise.
+
+<<_toupper>> returns the upper-case equivalent of <[c]> when it is a
+character between <<a>> and <<z>>. If <[c]> is not one of these
+characters, the behaviour of <<_toupper>> is undefined.
+
+PORTABILITY
+<<toupper>> is ANSI C. <<_toupper>> is not recommended for portable programs.
+
+No supporting OS subroutines are required.
+*/
+
+#include <_ansi.h>
+#include <ctype.h>
+
+#undef toupper
+int
+_DEFUN(toupper,(c),int c)
+{
+ return islower(c) ? c - 'a' + 'A' : c;
+}