From 3b81d48f27e024a113ec63bdfa0b762808d5291c Mon Sep 17 00:00:00 2001
From: Eric Andersen <andersen@codepoet.org>
Date: Tue, 17 Oct 2000 21:23:48 +0000
Subject: Fix up ctype.h

---
 libc/misc/Makefile       |   6 +-
 libc/misc/ctype/Makefile |  14 +++--
 libc/misc/ctype/ctype.c  | 142 +++++++++++++++++++++++++++++++----------------
 3 files changed, 108 insertions(+), 54 deletions(-)

(limited to 'libc')

diff --git a/libc/misc/Makefile b/libc/misc/Makefile
index 30c92fcf8..eb3dfd84d 100644
--- a/libc/misc/Makefile
+++ b/libc/misc/Makefile
@@ -21,7 +21,11 @@
 # respective copyright holders.
 
 
-DIRS = assert crypt ctype fnmatch glob internals lsearch regex shm time
+DIRS = assert crypt fnmatch glob internals lsearch regex shm time
+
+ifeq ($(USE_CTYPE_C_FUNCTIONS),true)
+    DIRS+=ctype
+endif
 
 all: libc.a
 
diff --git a/libc/misc/ctype/Makefile b/libc/misc/ctype/Makefile
index 216855544..128881f28 100644
--- a/libc/misc/ctype/Makefile
+++ b/libc/misc/ctype/Makefile
@@ -24,17 +24,21 @@ TOPDIR=../../
 include $(TOPDIR)Rules.mak
 LIBC=$(TOPDIR)libc.a
 
-CSRC=ctype.c
-COBJS=$(patsubst %.c,%.o, $(CSRC))
-OBJS=$(COBJS)
-
-all: $(OBJS) $(LIBC)
+MSRC=ctype.c
+MOBJ= isalnum.o isalpha.o isascii.o iscntrl.o isdigit.o isgraph.o \
+	islower.o isprint.o ispunct.o isspace.o isupper.o isxdigit.o \
+	isxlower.o isxupper.o toascii.o tolower.o toupper.o 
+OBJS=$(MOBJ)
+all: $(MOBJ) $(LIBC)
 
 $(LIBC): ar-target
 
 ar-target: $(OBJS)
 	$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
 
+$(MOBJ): $(MSRC)
+	$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+
 $(OBJS): Makefile
 
 clean:
diff --git a/libc/misc/ctype/ctype.c b/libc/misc/ctype/ctype.c
index 689ea50aa..78e1f8891 100644
--- a/libc/misc/ctype/ctype.c
+++ b/libc/misc/ctype/ctype.c
@@ -1,67 +1,113 @@
-/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
- * This file is part of the Linux-8086 C library and is distributed
+/* ctype.c	
+ * Character classification and conversion
+ * Copyright (C) 2000 Lineo, Inc.
+ * Written by Erik Andersen
+ * This file is part of the uC-Libc C library and is distributed
  * under the GNU Library General Public License.
  */
 
-/*
- *  CTYPE.C	Character classification and conversion
- */
-
 #include <ctype.h>
 
-#undef	toupper
-#undef	tolower
+int
+isalnum( int c )
+{
+    return (isalpha(c) || isdigit(c));
+}
 
-unsigned char __ctype[128] = {
-	__CT_c, __CT_c, __CT_c, __CT_c,	/* 0x00..0x03 */
-	__CT_c, __CT_c, __CT_c, __CT_c,	/* 0x04..0x07 */
-	__CT_c, __CT_c | __CT_s, __CT_c | __CT_s, __CT_c | __CT_s,	/* 0x08..0x0B */
-	__CT_c | __CT_s, __CT_c | __CT_s, __CT_c, __CT_c,	/* 0x0C..0x0F */
+int
+isalpha( int c )
+{
+    return (isupper(c) || islower(c));
+}
 
-	__CT_c, __CT_c, __CT_c, __CT_c,	/* 0x10..0x13 */
-	__CT_c, __CT_c, __CT_c, __CT_c,	/* 0x14..0x17 */
-	__CT_c, __CT_c, __CT_c, __CT_c,	/* 0x18..0x1B */
-	__CT_c, __CT_c, __CT_c, __CT_c,	/* 0x1C..0x1F */
+int
+isascii( int c )
+{
+    return (c > 0 && c <= 0x7f);
+}
 
-	__CT_s, __CT_p, __CT_p, __CT_p,	/* 0x20..0x23 */
-	__CT_p, __CT_p, __CT_p, __CT_p,	/* 0x24..0x27 */
-	__CT_p, __CT_p, __CT_p, __CT_p,	/* 0x28..0x2B */
-	__CT_p, __CT_p, __CT_p, __CT_p,	/* 0x2C..0x2F */
+int
+iscntrl( int c )
+{
+    return ((c > 0) && ((c <= 0x1f) || (c == 0x7f)));
+}
 
-	__CT_d | __CT_x, __CT_d | __CT_x, __CT_d | __CT_x, __CT_d | __CT_x,	/* 0x30..0x33 */
-	__CT_d | __CT_x, __CT_d | __CT_x, __CT_d | __CT_x, __CT_d | __CT_x,	/* 0x34..0x37 */
-	__CT_d | __CT_x, __CT_d | __CT_x, __CT_p, __CT_p,	/* 0x38..0x3B */
-	__CT_p, __CT_p, __CT_p, __CT_p,	/* 0x3C..0x3F */
+int
+isdigit( int c )
+{
+    return (c >= '0' && c <= '9');
+}
 
-	__CT_p, __CT_u | __CT_x, __CT_u | __CT_x, __CT_u | __CT_x,	/* 0x40..0x43 */
-	__CT_u | __CT_x, __CT_u | __CT_x, __CT_u | __CT_x, __CT_u,	/* 0x44..0x47 */
-	__CT_u, __CT_u, __CT_u, __CT_u,	/* 0x48..0x4B */
-	__CT_u, __CT_u, __CT_u, __CT_u,	/* 0x4C..0x4F */
+int
+isgraph( int c )
+{
+    return (c != ' ' && isprint(c));
+}
 
-	__CT_u, __CT_u, __CT_u, __CT_u,	/* 0x50..0x53 */
-	__CT_u, __CT_u, __CT_u, __CT_u,	/* 0x54..0x57 */
-	__CT_u, __CT_u, __CT_u, __CT_p,	/* 0x58..0x5B */
-	__CT_p, __CT_p, __CT_p, __CT_p,	/* 0x5C..0x5F */
+int
+islower( int c )
+{
+    return (c >=  'a' && c <= 'z');
+}
 
-	__CT_p, __CT_l | __CT_x, __CT_l | __CT_x, __CT_l | __CT_x,	/* 0x60..0x63 */
-	__CT_l | __CT_x, __CT_l | __CT_x, __CT_l | __CT_x, __CT_l,	/* 0x64..0x67 */
-	__CT_l, __CT_l, __CT_l, __CT_l,	/* 0x68..0x6B */
-	__CT_l, __CT_l, __CT_l, __CT_l,	/* 0x6C..0x6F */
+int
+isprint( int c )
+{
+    return (c >= ' ' && c <= '~');
+}
 
-	__CT_l, __CT_l, __CT_l, __CT_l,	/* 0x70..0x73 */
-	__CT_l, __CT_l, __CT_l, __CT_l,	/* 0x74..0x77 */
-	__CT_l, __CT_l, __CT_l, __CT_p,	/* 0x78..0x7B */
-	__CT_p, __CT_p, __CT_p, __CT_c	/* 0x7C..0x7F */
-};
+int
+ispunct( int c )
+{
+    return ((c > ' ' && c <= '~') && !isalnum(c));
+}
 
-int toupper(c)
-int c;
+int
+isspace( int c )
 {
-	return (islower(c) ? (c ^ 0x20) : (c));
+    return (c == ' ' || c == '\f' || c == '\n' || c == '\r' ||
+	    c == '\t' || c == '\v');
 }
 
-int tolower(c)
-int c;
+int
+isupper( int c )
 {
-	return (isupper(c) ? (c ^ 0x20) : (c));
+    return (c >=  'A' && c <= 'Z');
 }
+
+int
+isxdigit( int c )
+{
+    return (isxupper(c) || isxlower(c));
+}
+
+int
+isxlower( int c )
+{
+    return (isdigit(c) || (c >= 'a' && c <= 'f'));
+}
+
+int
+isxupper( int c )
+{
+    return (isdigit(c) || (c >= 'A' && c <= 'F'));
+}
+
+int
+toascii( int c )
+{
+    return (c & 0x7f);
+}
+
+int
+tolower( int c )
+{
+    return (isupper(c) ? ( c - 'A' + 'a') : (c));
+}
+
+int
+toupper( int c )
+{
+    return (islower(c) ? (c - 'a' + 'A') : (c));
+}
+
-- 
cgit v1.2.3