#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);
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
int isalnum(int c)
{
- return isalpha(c) || isdigit(c);
+ return isdigit(c) || isalpha(c);
}
#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);
}
int isblank(int c)
{
- uint8_t cb = c;
- return (cb == ' ') || (c == '\t');
+ return ((uint8_t)c == ' ') || ((uint8_t)c == '\t');
}
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);
}
int isdigit(int c)
{
- uint8_t bc = c;
- return (bc >= '0') && (bc <= '9');
+ return ((uint8_t)c >= '0') && ((uint8_t)c <= '9');
}
int isgraph(int c)
{
- uint8_t cb = c;
- return (c >= 33) && (c <= 126);
+ return ((uint8_t)c >= 33) && ((uint8_t)c <= 126);
}
int islower(int c)
{
- uint8_t bc = c;
- return (bc >= 'a') && (bc <= 'z');
+ return ((uint8_t)c >= 'a') && ((uint8_t)c <= 'z');
}
int isprint(int c)
{
- uint8_t cb = c;
- return (cb >= 32) && (cb <= 126);
+ return ((uint8_t)c >= 32) && ((uint8_t)c <= 126);
}
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');
}
int isupper(int c)
{
- uint8_t bc = c;
- return (bc >= 'A') && (bc <= 'Z');
+ return ((uint8_t)c >= 'A') && ((uint8_t)c <= 'Z');
}
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'));
}
#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;
}
#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;
}
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[])