Did a smallification and header fix pass. Still passes the unit tests!
authorDavid Given <dg@cowlark.com>
Sat, 21 Mar 2015 22:12:01 +0000 (23:12 +0100)
committerDavid Given <dg@cowlark.com>
Sat, 21 Mar 2015 22:12:01 +0000 (23:12 +0100)
--HG--
extra : source : 49f4625dc1e0a95f94779069e144e8a2d7c4a9e3

15 files changed:
Library/include/ctype.h
Library/libs/isalnum.c
Library/libs/isascii.c
Library/libs/isblank.c
Library/libs/iscntrl.c
Library/libs/isdigit.c
Library/libs/isgraph.c
Library/libs/islower.c
Library/libs/isprint.c
Library/libs/isspace.c
Library/libs/isupper.c
Library/libs/isxdigit.c
Library/libs/tolower.c
Library/libs/toupper.c
Library/tests/ctype.c

index f217afe..c8081dd 100644 (file)
@@ -3,11 +3,11 @@
 #ifndef __CTYPE_H
 #define __CTYPE_H
 
+#include <stdint.h>
+
 extern int toupper(int c);
 extern int tolower(int c);
 
-#define toascii(c) ((c) & 0x7f)
-
 extern int isalnum(int c);
 extern int isalpha(int c);
 extern int isascii(int c);
@@ -20,10 +20,11 @@ extern int ispunct(int c);
 extern int isspace(int c);
 extern int isupper(int c);
 extern int isxdigit(int c);
-extern int isoctal(int c);
+
+#define isascii(c) (!((uint8_t)c & 0x80))
+#define toascii(c) ((c) & 0x7f)
 
 #define isdecimal isdigit
-#define isprint(c) (!iscntrl(c))
 #define _tolower tolower
 #define _toupper toupper
 
index adcd2f2..e424b9e 100644 (file)
@@ -8,5 +8,5 @@
 
 int isalnum(int c)
 {
-       return isalpha(c) || isdigit(c);
+       return isdigit(c) || isalpha(c);
 }
index d91fbfa..df5db8e 100644 (file)
@@ -4,11 +4,11 @@
 #if !defined __TESTING__
 #include <stdint.h>
 #include <ctype.h>
+#undef isascii
 #endif
 
 int isascii(int c)
 {
-       uint8_t cb = c;
-       return (cb >= 0) && (cb <= 127);
+       return !((uint8_t)c & 0x80);
 }
 
index 7def9bc..ab7edc7 100644 (file)
@@ -9,7 +9,6 @@
 
 int isblank(int c)
 {
-       uint8_t cb = c;
-       return (cb == ' ') || (c == '\t');
+       return ((uint8_t)c == ' ') || ((uint8_t)c == '\t');
 }
 
index 2987ec2..7aafbd3 100644 (file)
@@ -8,6 +8,5 @@
 
 int iscntrl(int c)
 {
-       uint8_t bc = c;
-       return ((bc >= 0) && (bc <= 31)) || (bc == 127);
+       return (((uint8_t)c >= 0) && ((uint8_t)c <= 31)) || ((uint8_t)c == 127);
 }
index 57f4e1a..91314c0 100644 (file)
@@ -8,7 +8,6 @@
 
 int isdigit(int c)
 {
-       uint8_t bc = c;
-       return (bc >= '0') && (bc <= '9');
+       return ((uint8_t)c >= '0') && ((uint8_t)c <= '9');
 }
 
index f95e942..8954cab 100644 (file)
@@ -8,7 +8,6 @@
 
 int isgraph(int c)
 {
-       uint8_t cb = c;
-       return (c >= 33) && (c <= 126);
+       return ((uint8_t)c >= 33) && ((uint8_t)c <= 126);
 }
 
index db7a5f2..38702e3 100644 (file)
@@ -8,6 +8,5 @@
 
 int islower(int c)
 {
-       uint8_t bc = c;
-       return (bc >= 'a') && (bc <= 'z');
+       return ((uint8_t)c >= 'a') && ((uint8_t)c <= 'z');
 }
index d3f6ce3..0e72f5f 100644 (file)
@@ -9,7 +9,6 @@
 
 int isprint(int c)
 {
-       uint8_t cb = c;
-       return (cb >= 32) && (cb <= 126);
+       return ((uint8_t)c >= 32) && ((uint8_t)c <= 126);
 }
 
index f072760..7d27773 100644 (file)
@@ -9,6 +9,11 @@
 
 int isspace(int c)
 {
-       return c && !!strchr(" \t\n\r\f\v", c);
+       return ((uint8_t)c == ' ') ||
+              ((uint8_t)c == '\t') ||
+                  ((uint8_t)c == '\n') ||
+                  ((uint8_t)c == '\r') ||
+                  ((uint8_t)c == '\f') ||
+                  ((uint8_t)c == '\v');
 }
 
index 5368cad..666749a 100644 (file)
@@ -8,6 +8,5 @@
 
 int isupper(int c)
 {
-       uint8_t bc = c;
-       return (bc >= 'A') && (bc <= 'Z');
+       return ((uint8_t)c >= 'A') && ((uint8_t)c <= 'Z');
 }
index 94be6d0..2e56a7c 100644 (file)
@@ -9,7 +9,8 @@
 int isxdigit(int c)
 {
        uint8_t bc = c;
-       return isdigit(bc)
-               || ((bc >= 'a') && (bc <= 'f'))
-               || ((bc >= 'A') && (bc <= 'F'));
+       if (isdigit(bc))
+               return 1;
+       bc |= 0x20;
+       return ((bc >= 'a') && (bc <= 'f'));
 }
index 9824af5..ee1cd54 100644 (file)
@@ -3,12 +3,14 @@
 
 #if !defined __TESTING__
 #include <ctype.h>
+#include <stdint.h>
 #endif
 
 int tolower(int c)
 {
-       if (isupper(c))
-               c = c^0x20;
-       return c;
+       uint8_t cb = c;
+       if ((cb >= 'A') && (cb <= 'Z'))
+               cb ^= 0x20;
+       return cb;
 }
 
index 44badc0..75a6df3 100644 (file)
@@ -3,12 +3,14 @@
 
 #if !defined __TESTING__
 #include <ctype.h>
+#include <stdint.h>
 #endif
 
 int toupper(int c)
 {
-       if (islower(c))
-               c = c^0x20;
-       return c;
+       uint8_t cb = c;
+       if ((cb >= 'a') && (cb <= 'z'))
+               cb ^= 0x20;
+       return cb;
 }
 
index 768ea94..3b4478b 100644 (file)
@@ -124,12 +124,15 @@ static void test(int i)
        TEST(isupper);
        TEST(isxdigit);
 
-       if (sys_tolower(i) != fuzix_tolower(i))
-               printf("FAIL sys_tolower(%d)=%d; fuzix_tolower(%d)=%d\n",
-                       i, sys_tolower(i), i, fuzix_tolower(i));
-       if (sys_toupper(i) != fuzix_toupper(i))
-               printf("FAIL sys_toupper(%d)=%d; fuzix_toupper(%d)=%d\n",
-                       i, sys_toupper(i), i, fuzix_toupper(i));
+       if (i != EOF)
+       {
+               if (sys_tolower(i) != fuzix_tolower(i))
+                       printf("FAIL sys_tolower(%d)=%d; fuzix_tolower(%d)=%d\n",
+                               i, sys_tolower(i), i, fuzix_tolower(i));
+               if (sys_toupper(i) != fuzix_toupper(i))
+                       printf("FAIL sys_toupper(%d)=%d; fuzix_toupper(%d)=%d\n",
+                               i, sys_toupper(i), i, fuzix_toupper(i));
+       }
 }
 
 int main(int argc, const char* argv[])