shithub: scc

Download patch

ref: c4c303869381a1d06b5877e6a32e5bf016cb4531
parent: c68d4e43cd22c18199c1b5ea7468e3d9b5b2ad97
author: Quentin Rameau <quinq@fifth.space>
date: Fri Feb 17 12:50:25 EST 2017

[libc] Implement ctype function-style

--- a/libc/src/ctype.c
+++ b/libc/src/ctype.c
@@ -1,6 +1,7 @@
-
 #include <ctype.h>
 
+#ifdef __USE_MACROS
+
 unsigned char _ctype[255] = {
 	_C,_C,_C,_C,_C,_C,_C,_C,                        /* 0-7 */
 	_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C,         /* 8-15 */
@@ -19,3 +20,93 @@
 	_L,_L,_L,_L,_L,_L,_L,_L,                        /* 112-119 */
 	_L,_L,_L,_P,_P,_P,_P,_C,                        /* 120-127 */
 };
+
+#else
+
+int
+isblank(int c)
+{
+	return (c == ' ') || (c == '\t');
+}
+
+int
+iscntrl(int c)
+{
+	return (unsigned)c < ' ' || c == 0x7f;
+}
+
+int
+isdigit(int c)
+{
+	return (unsigned)c - '0' < 10;
+}
+
+int
+islower(int c)
+{
+	return (unsigned)c - 'a' < 26;
+}
+
+int
+isupper(int c)
+{
+	return (unsigned)c - 'A' < 26;
+}
+
+int
+isprint(int c)
+{
+	return (unsigned)c - ' ' < 95;
+}
+
+int
+isspace(int c)
+{
+	return (c == ' ') || ((unsigned)c - '\t' < 5);
+}
+
+int
+isxdigit(int c)
+{
+	return isdigit(c) ||
+	       ((unsigned)c - 'a' < 6) ||
+	       ((unsigned)c - 'A' < 6);
+}
+
+int
+isgraph(int c)
+{
+	return isprint(c) && c != ' ';
+}
+
+int
+isalpha(int c)
+{
+	return islower(c) || isupper(c);
+}
+
+int
+isalnum(int c)
+{
+	return isalpha(c) || isdigit(c);
+}
+
+int
+ispunct(int c)
+{
+	return isprint(c) && !isspace(c) && !isalnum(c);
+}
+
+int
+tolower(int c)
+{
+	return (isupper(c) ? (unsigned)c + ' ' : c);
+}
+
+int
+toupper(int c)
+{
+	return (islower(c) ? (unsigned)c - ' ' : c);
+}
+
+#endif // __USE_MACROS