scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 0f98deff32570e2c79e77dad7344298253b15db9
parent 38586fa8fa99443e61b7f9ae12de448cbe97a98f
Author: Quentin Rameau <quinq@fifth.space>
Date:   Sat, 18 Feb 2017 14:42:42 +0100

[libc] Add isblank

Diffstat:
libc/include/ctype.h | 7++++---
libc/src/Makefile | 7+++----
libc/src/ctype.c | 3+--
libc/src/isblank.c | 11+++++++++++
4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/libc/include/ctype.h b/libc/include/ctype.h @@ -17,7 +17,7 @@ extern int ispunct(int c); extern int tolower(int c); extern int toupper(int c); -#ifdef __USE_MACROS +#ifdef __USE_MACROS #define _U 0x01 /* upper */ #define _L 0x02 /* lower */ @@ -25,13 +25,15 @@ extern int toupper(int c); #define _C 0x08 /* cntrl */ #define _P 0x10 /* punct */ #define _S 0x20 /* white space (space/lf/tab) */ -#define _X 0x40 /* hex digit */ +#define _X 0x40 /* hex char */ #define _SP 0x80 /* hard space (0x20) */ +#define _TB 0x100 /* tabulation */ extern unsigned char _ctype[]; #define isalnum(c) (_ctype[(unsigned char) c] & (_U|_L|_D)) #define isalpha(c) (_ctype[(unsigned char) c] & (_U|_L)) +#define isblank(c) (_ctype[(unsigned char) c] & (_SP|_TB)) #define iscntrl(c) (_ctype[(unsigned char) c] & (_C)) #define isdigit(c) (_ctype[(unsigned char) c] & (_D)) #define isgraph(c) (_ctype[(unsigned char) c] & (_P|_U|_L|_D)) @@ -46,5 +48,4 @@ extern unsigned char _ctype[]; #endif - #endif diff --git a/libc/src/Makefile b/libc/src/Makefile @@ -4,10 +4,9 @@ LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \ strrchr.o strcat.o strncpy.o strncat.o strcoll.o \ memset.o memcpy.o memmove.o memcmp.o memchr.o \ - isalnum.o isalpha.o isascii.o iscntrl.o isdigit.o isgraph.o \ - islower.o isprint.o ispunct.o isspace.o isupper.o isxdigit.o \ - toupper.o tolower.o \ - setlocale.o + isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \ + isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \ + isxdigit.o toupper.o tolower.o setlocale.o all: libc.a diff --git a/libc/src/ctype.c b/libc/src/ctype.c @@ -1,9 +1,8 @@ - #include <ctype.h> 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 */ + _C,_C|_S|_TB,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ diff --git a/libc/src/isblank.c b/libc/src/isblank.c @@ -0,0 +1,11 @@ +/* See LICENSE file for copyright and license details. */ + +#define __USE_MACROS +#include <ctype.h> +#undef isblank + +int +isblank(int c) +{ + return _ctype[(unsigned char) c] & (_SP|_TB); +}