From 1c3b33746e896ffa3fd8cb81c6f041e9ff9449f6 Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Wed, 27 Jul 2016 15:03:34 +0200 Subject: [PATCH] added a non-wide ctypes.h --- ctype/_ctype.c | 35 +++++++++++++++++++++++++++++++++++ ctype/_ctype.h | 9 +++++++++ ctype/isASCII.cpp | 6 ++++++ ctype/isAlNum.cpp | 7 +++++++ ctype/isAlpha.cpp | 7 +++++++ ctype/isBlank.cpp | 7 +++++++ ctype/isCntrl.cpp | 7 +++++++ ctype/isDigit.cpp | 7 +++++++ ctype/isLower.cpp | 7 +++++++ ctype/isPrint.cpp | 11 +++++++++++ ctype/isPunct.cpp | 7 +++++++ ctype/isSpace.cpp | 7 +++++++ ctype/isUpper.cpp | 7 +++++++ ctype/isXDigit.cpp | 7 +++++++ ctype/toCase.cpp | 12 ++++++++++++ include/ctype.h | 23 +++++++++++++++++++++++ include/limits.h | 25 +++++++++++++++++++++++++ include/signal.h | 18 ++++++++++++++++++ 18 files changed, 209 insertions(+) create mode 100644 ctype/_ctype.c create mode 100644 ctype/_ctype.h create mode 100644 ctype/isASCII.cpp create mode 100644 ctype/isAlNum.cpp create mode 100644 ctype/isAlpha.cpp create mode 100644 ctype/isBlank.cpp create mode 100644 ctype/isCntrl.cpp create mode 100644 ctype/isDigit.cpp create mode 100644 ctype/isLower.cpp create mode 100644 ctype/isPrint.cpp create mode 100644 ctype/isPunct.cpp create mode 100644 ctype/isSpace.cpp create mode 100644 ctype/isUpper.cpp create mode 100644 ctype/isXDigit.cpp create mode 100644 ctype/toCase.cpp create mode 100644 include/ctype.h create mode 100644 include/limits.h create mode 100644 include/signal.h diff --git a/ctype/_ctype.c b/ctype/_ctype.c new file mode 100644 index 0000000..236653e --- /dev/null +++ b/ctype/_ctype.c @@ -0,0 +1,35 @@ +#include "_ctype.h" +int ascii_table[256] { + CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL, + CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL, + CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL, + CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL, + SPACE ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL , + OPEN ,CLOSE ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL , + NUMBER ,NUMBER ,NUMBER ,NUMBER ,NUMBER ,NUMBER ,NUMBER ,NUMBER , + NUMBER ,NUMBER ,SYMBOL ,SYMBOL ,OPEN ,SYMBOL ,CLOSE ,SYMBOL , + SYMBOL ,HEXNUM ,HEXNUM ,HEXNUM ,HEXNUM ,HEXNUM ,HEXNUM ,UPPER , + UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER , + UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER , + UPPER ,UPPER ,UPPER ,OPEN ,SYMBOL ,CLOSE ,SYMBOL ,SYMBOL , + SYMBOL ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER , + LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER , + LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER , + LOWER ,LOWER ,LOWER ,OPEN ,SYMBOL ,CLOSE ,SYMBOL ,CONTROL, + CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL, + CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL, + CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL, + CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL,CONTROL, + SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL , + SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL , + SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL , + SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL ,SYMBOL , + UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER , + UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER , + UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,SYMBOL , + UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,UPPER ,LOWER , + LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER , + LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER , + LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,SYMBOL , + LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER ,LOWER +}; \ No newline at end of file diff --git a/ctype/_ctype.h b/ctype/_ctype.h new file mode 100644 index 0000000..fb20572 --- /dev/null +++ b/ctype/_ctype.h @@ -0,0 +1,9 @@ +#define CONTROL 1 +#define SYMBOL 2 +#define UPPER 4 +#define LOWER 8 +#define NUMBER 16 +#define OPEN 32|SYMBOL +#define CLOSE 64|SYMBOL +#define SPACE 128 +#define HEXNUM 256|UPPER \ No newline at end of file diff --git a/ctype/isASCII.cpp b/ctype/isASCII.cpp new file mode 100644 index 0000000..f049e70 --- /dev/null +++ b/ctype/isASCII.cpp @@ -0,0 +1,6 @@ +#include +#include "_ctype.h" +extern "C" isascii(int c) { + assert(c<256); + return c >= 0 && c < 128; +} \ No newline at end of file diff --git a/ctype/isAlNum.cpp b/ctype/isAlNum.cpp new file mode 100644 index 0000000..8099dd4 --- /dev/null +++ b/ctype/isAlNum.cpp @@ -0,0 +1,7 @@ +#include +#include "_ctype.h" +#include +extern "C" int isalnum(int c) { + assert(c<256); + return ascii_table[c] & (UPPER|LOWER|NUMBER); +} \ No newline at end of file diff --git a/ctype/isAlpha.cpp b/ctype/isAlpha.cpp new file mode 100644 index 0000000..9ccfac1 --- /dev/null +++ b/ctype/isAlpha.cpp @@ -0,0 +1,7 @@ +#include +#include "_ctype.h" +#include +extern "C" isalpha(int c) { + assert(c<256); + return ascii_table[c] & (UPPER|LOWER); +} \ No newline at end of file diff --git a/ctype/isBlank.cpp b/ctype/isBlank.cpp new file mode 100644 index 0000000..06dc7d2 --- /dev/null +++ b/ctype/isBlank.cpp @@ -0,0 +1,7 @@ +#include +#include "_ctype.h" +#include +extern "C" isblank(int c) { + assert(c<256); + return (ascii_table[c] & SPACE) || (c=='\t'); +} \ No newline at end of file diff --git a/ctype/isCntrl.cpp b/ctype/isCntrl.cpp new file mode 100644 index 0000000..138f6f0 --- /dev/null +++ b/ctype/isCntrl.cpp @@ -0,0 +1,7 @@ +#include +#include "_ctype.h" +#include +extern "C" iscntrl(int c) { + assert(c<256); + return ascii_table[c] & CONTROL; +} \ No newline at end of file diff --git a/ctype/isDigit.cpp b/ctype/isDigit.cpp new file mode 100644 index 0000000..84fa650 --- /dev/null +++ b/ctype/isDigit.cpp @@ -0,0 +1,7 @@ +#include +#include "_ctype.h" +#include +extern "C" isdigit(int c) { + assert(c<256); + return ascii_table[c] & (NUMBER); +} \ No newline at end of file diff --git a/ctype/isLower.cpp b/ctype/isLower.cpp new file mode 100644 index 0000000..7312710 --- /dev/null +++ b/ctype/isLower.cpp @@ -0,0 +1,7 @@ +#include +#include "_ctype.h" +#include +extern "C" islower(int c) { + assert(c<256); + return ascii_table[c] & (LOWER); +} \ No newline at end of file diff --git a/ctype/isPrint.cpp b/ctype/isPrint.cpp new file mode 100644 index 0000000..6590076 --- /dev/null +++ b/ctype/isPrint.cpp @@ -0,0 +1,11 @@ +#include +#include "_ctype.h" +#include +extern "C" isgraph(int c) { + assert(c<256); + return ascii_table[c] & (SYMBOL|UPPER|LOWER|NUMBER); +} +extern "C" isprint(int c) { + assert(c<256); + return ascii_table[c] & (SYMBOL|UPPER|LOWER|NUMBER|SPACE); +} \ No newline at end of file diff --git a/ctype/isPunct.cpp b/ctype/isPunct.cpp new file mode 100644 index 0000000..306d44e --- /dev/null +++ b/ctype/isPunct.cpp @@ -0,0 +1,7 @@ +#include +#include "_ctype.h" +#include +extern "C" int ispunct(int c) { + assert(c<256); + return ascii_table[c] & (SYMBOL); +} \ No newline at end of file diff --git a/ctype/isSpace.cpp b/ctype/isSpace.cpp new file mode 100644 index 0000000..ab0888d --- /dev/null +++ b/ctype/isSpace.cpp @@ -0,0 +1,7 @@ +#include +#include "_ctype.h" +#include +extern "C" int isspace(int c) { + assert(c<256); + return ascii_table[c] & (SPACE); +} \ No newline at end of file diff --git a/ctype/isUpper.cpp b/ctype/isUpper.cpp new file mode 100644 index 0000000..2ac9f02 --- /dev/null +++ b/ctype/isUpper.cpp @@ -0,0 +1,7 @@ +#include +#include "_ctype.h" +#include +extern "C" int isupper(int c) { + assert(c<256); + return ascii_table[c] & (UPPER); +} \ No newline at end of file diff --git a/ctype/isXDigit.cpp b/ctype/isXDigit.cpp new file mode 100644 index 0000000..dff9ae7 --- /dev/null +++ b/ctype/isXDigit.cpp @@ -0,0 +1,7 @@ +#include +#include "_ctype.h" +#include +extern "C" int isxdigit(int c) { + assert(c<256); + return ascii_table[c] & (DIGIT|(HEXNUM^UPPER)); +} \ No newline at end of file diff --git a/ctype/toCase.cpp b/ctype/toCase.cpp new file mode 100644 index 0000000..c46cfba --- /dev/null +++ b/ctype/toCase.cpp @@ -0,0 +1,12 @@ +#include +#include "_ctype.h" +extern "C" int toupper(int c) { + if(isupper(c)) + return c; + return c+0x20; +} +extern "C" int tolower(int c) { + if(islower(c)) + return c; + return c-0x20; +} \ No newline at end of file diff --git a/include/ctype.h b/include/ctype.h new file mode 100644 index 0000000..5bc10bd --- /dev/null +++ b/include/ctype.h @@ -0,0 +1,23 @@ +#ifndef __CTYPE_H +#define __CTYPE_H +#ifdef __cplusplus +extern "C" { +#endif +int isalnum(int); +int isalpha(int); +int isascii(int); +int isblank(int); +int iscntrl(int); +int isdigit(int); +int islower(int); +int isgraph(int); +int isprint(int); +int ispunct(int); +int isspace(int); +int isupper(int); +int toupper(int); +int tolower(int); +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/include/limits.h b/include/limits.h new file mode 100644 index 0000000..6959a8a --- /dev/null +++ b/include/limits.h @@ -0,0 +1,25 @@ +#define CHAR_BIT 8 +#define SCHAR_MIN -128 +#define SCHAR_MAX 127 +#define UCHAR_MAX 255 +#define CHAR_MIN -128 +#define CHAR_MAX 127 +#define MB_LEN_MAX 6 +#define SHRT_MIN -32768 +#define SHRT_MAX 32767 +#define USHR_MAX 65535 +#define INT_MIN -2147483648 +#define INT_MAX 2147483647 +#define UINT_MAX 4294967295 +#define LLONG_MIN -9223372036854775808lli +#define LLONG_MAX 9223372036854775807lli +#define ULLONG_MAX 18446744073709551615ulli +#ifdef __LP64 +#define LONG_MIN LLONG_MIN +#define LONG_MAX LLONG_MAX +#define ULONG_MAX ULLONG_MAX +#else +#define LONG_MIN INT_MIN +#define LONG_MAX INT_MAX +#define ULONG_MAX UINT_MAX +#endif diff --git a/include/signal.h b/include/signal.h new file mode 100644 index 0000000..26d3ea2 --- /dev/null +++ b/include/signal.h @@ -0,0 +1,18 @@ +#ifndef __SIGNAL_H +#define __SIGNAL_H +#ifdef __cplusplus +extern "C" { +#endif +#define SIG_DFL &__signal_h_sig_dfl +#define SIG_ERR &__signal_h_sig_err +#define SIG_IGN &__signal_h_sig_ign +#define SIGINT 1 +#define SIGILL 2 +#define SIGABRT 3 +#define SIGFPE 4 +#define SIGSEGV 5 +#define SIGTERM 6 +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file