scc

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

commit fbda8879666e4144c62bcab1bd6530dac1ea09c0
parent 69a0a3e07aee3304446942c49527d65ebc5f7c85
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 25 Sep 2017 10:47:12 +0100

[libc] Add macro definitions for tolower() and toupper()

The library is not thread safe in a lot of different places, and it
doesn't try to be thread safe because it will require a more complex
design, out of the scope of this simple library. For this reason
it is not a problem to use a global static variable.

Diffstat:
Mlib/c/include/ctype.h | 4++++
Mlib/c/src/ctype.c | 2++
2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/lib/c/include/ctype.h b/lib/c/include/ctype.h @@ -28,6 +28,7 @@ extern int toupper(int c); #define _SP 0x80 /* hard space (0x20) */ extern unsigned char __ctype[]; +extern int __ctmp; #define isalnum(c) ((__ctype+1)[(c)] & (_U|_L|_D)) #define isalpha(c) ((__ctype+1)[(c)] & (_U|_L)) @@ -41,6 +42,9 @@ extern unsigned char __ctype[]; #define isupper(c) ((__ctype+1)[(c)] & (_U)) #define isxdigit(c) ((__ctype+1)[(c)] & (_D|_X)) +#define tolower(c) ((__ctmp=c, isupper(__ctmp) ? __ctmp | 0x20 : __ctmp)) +#define toupper(c) ((__ctmp=c, islower(__ctmp) ? __ctmp & ~0x20 : __ctmp)) + #define isascii(c) ((unsigned)(c)<=0x7f) #endif diff --git a/lib/c/src/ctype.c b/lib/c/src/ctype.c @@ -2,6 +2,8 @@ #include <ctype.h> #undef ctype +int __ctmp; + /* __ctype is shifted by one to match EOF */ unsigned char __ctype[257] = { 0, /* EOF */