SRC_C += vfprintf.c vprintf.c wait.c xitoa.c pathconf.c
SRC_C += gethostname.c sysconf.c confstr.c memccpy.c getpass.c
# ctype
-SRC_C += toupper.c tolower.c toascii.c isascii.c isalnum.c isalpha.c
-SRC_C += iscntrl.c isdigit.c isgraph.c islower.c ispunct.c isspace.c
-SRC_C += isupper.c isxdigit.c isoctal.c
+SRC_C += isalnum.c isalpha.c isascii.c isblank.c iscntrl.c isdigit.c
+SRC_C += isgraph.c islower.c isprint.c ispunct.c isspace.c isupper.c
+SRC_C += isxdigit.c
# tty layer
SRC_C += tcgetattr.c tcsetattr.c tcdrain.c tcflow.c tcflush.c
SRC_C += cfmakeraw.c cfspeed.c revoke.c
SRC_C += gethostname.c sysconf.c confstr.c memccpy.c getpass.c
SRC_C += strtol.c
# ctype
-SRC_C += toupper.c tolower.c toascii.c isascii.c isalnum.c isalpha.c
-SRC_C += iscntrl.c isdigit.c isgraph.c islower.c ispunct.c isspace.c
-SRC_C += isupper.c isxdigit.c isoctal.c
+SRC_C += isalnum.c isalpha.c isascii.c isblank.c iscntrl.c isdigit.c
+SRC_C += isgraph.c islower.c isprint.c ispunct.c isspace.c isupper.c
+SRC_C += isxdigit.c
# tty layer
SRC_C += tcgetattr.c tcsetattr.c tcdrain.c tcflow.c tcflush.c
SRC_C += cfmakeraw.c cfspeed.c revoke.c
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
+#endif
int isalnum(int c)
{
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
+#endif
int isalpha(int c)
{
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
+#endif
int isascii(int c)
{
--- /dev/null
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
+#include <stdint.h>
+#include <ctype.h>
+#include <string.h>
+#endif
+
+int isblank(int c)
+{
+ uint8_t cb = c;
+ return (cb == ' ') || (c == '\t');
+}
+
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
+#endif
int iscntrl(int c)
{
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
+#endif
int isdigit(int c)
{
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
+#endif
int isgraph(int c)
{
- return !iscntrl(c) && !isspace(c);
+ uint8_t cb = c;
+ return (c >= 33) && (c <= 126);
}
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
+#endif
int islower(int c)
{
+++ /dev/null
-#include <stdint.h>
-#include <ctype.h>
-
-int isoctal(int c)
-{
- uint8_t bc = c;
- return (bc >= '0') && (bc <= '7');
-}
-
--- /dev/null
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
+#include <stdint.h>
+#include <ctype.h>
+#include <string.h>
+#endif
+
+int isprint(int c)
+{
+ uint8_t cb = c;
+ return (cb >= 32) && (cb <= 126);
+}
+
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
+#endif
int ispunct(int c)
{
- return !iscntrl(c) && !isalpha(c) && !isspace(c);
+ return isascii(c) && !iscntrl(c) && !isalnum(c) && !isspace(c);
}
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
#include <string.h>
+#endif
int isspace(int c)
{
- return !!strchr(" \t\n\r\f\v", c);
+ return c && !!strchr(" \t\n\r\f\v", c);
}
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
+#endif
int isupper(int c)
{
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <stdint.h>
#include <ctype.h>
+#endif
int isxdigit(int c)
{
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <ctype.h>
+#endif
int tolower(int c)
{
+/* This file has a unit test in Library/test/ctype.c. If you change this file,
+ * please make sure the test still runs. */
+
+#if !defined __TESTING__
#include <ctype.h>
+#endif
int toupper(int c)
{
--- /dev/null
+/* Test for the Fuzix libc ctype library. Compares Fuzix's implementation
+ * with the system standard.
+ *
+ * Compile this with:
+ *
+ * gcc Library/tests/ctype.c -o Library/tests/ctype
+ *
+ * ...and run them. They'll moan if there's anything wrong. Note that this
+ * only tests the inline versions.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <ctype.h>
+
+typedef int (*ctype_fn)(int c);
+
+/* Import the system ctype functions under new names. */
+
+#define define_sys(n) static ctype_fn sys_##n = n
+define_sys(isalnum);
+define_sys(isalpha);
+define_sys(isascii);
+define_sys(isblank);
+define_sys(iscntrl);
+define_sys(isdigit);
+define_sys(isgraph);
+define_sys(islower);
+define_sys(isprint);
+define_sys(ispunct);
+define_sys(isspace);
+define_sys(isupper);
+define_sys(isxdigit);
+define_sys(tolower);
+define_sys(toupper);
+
+/* Now import the Fuzix ones. */
+
+#define __TESTING__
+
+#undef isalnum
+#define isalnum fuzix_isalnum
+#include "../libs/isalnum.c"
+
+#undef isalpha
+#define isalpha fuzix_isalpha
+#include "../libs/isalpha.c"
+
+#undef isascii
+#define isascii fuzix_isascii
+#include "../libs/isascii.c"
+
+#undef isblank
+#define isblank fuzix_isblank
+#include "../libs/isblank.c"
+
+#undef iscntrl
+#define iscntrl fuzix_iscntrl
+#include "../libs/iscntrl.c"
+
+#undef isdigit
+#define isdigit fuzix_isdigit
+#include "../libs/isdigit.c"
+
+#undef isgraph
+#define isgraph fuzix_isgraph
+#include "../libs/isgraph.c"
+
+#undef islower
+#define islower fuzix_islower
+#include "../libs/islower.c"
+
+#undef isprint
+#define isprint fuzix_isprint
+#include "../libs/isprint.c"
+
+#undef ispunct
+#define ispunct fuzix_ispunct
+#include "../libs/ispunct.c"
+
+#undef isspace
+#define isspace fuzix_isspace
+#include "../libs/isspace.c"
+
+#undef isupper
+#define isupper fuzix_isupper
+#include "../libs/isupper.c"
+
+#undef isxdigit
+#define isxdigit fuzix_isxdigit
+#include "../libs/isxdigit.c"
+
+#undef tolower
+#define tolower fuzix_tolower
+#include "../libs/tolower.c"
+
+#undef toupper
+#define toupper fuzix_toupper
+#include "../libs/toupper.c"
+
+static bool failed = false;
+
+static void test(int i)
+{
+ #define TEST(n) \
+ if (!!sys_##n(i) != !!fuzix_##n(i)) \
+ printf("FAIL sys_%s(%d)=%d; fuzix_%s(%d)=%d\n", \
+ #n, i, sys_##n(i), #n, i, fuzix_##n(i))
+
+ TEST(isalnum);
+ TEST(isalpha);
+ TEST(isascii);
+ TEST(isblank);
+ TEST(iscntrl);
+ TEST(isdigit);
+ TEST(isgraph);
+ TEST(islower);
+ TEST(isprint);
+ TEST(ispunct);
+ TEST(isspace);
+ 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));
+}
+
+int main(int argc, const char* argv[])
+{
+ int i;
+
+ for (i=0; i<=255; i++)
+ test(i);
+ test(EOF);
+
+ return failed ? EXIT_FAILURE : EXIT_SUCCESS;
+}
+