plan9fox/sys/include/ape/ctype.h
Ori Bernstein ec533a1ad8 ape/ctype.h: add isblank, fix functions (thanks staalmannen)
Our ctype.h mistakenly ommitted isblank. Add it in.

While we're here, the make the 'isfoo()' functions
are broken: they're offsetting into the array, and
don't work with negative character values.

Sync the function bodies with the macros, and make
them produce correct results.
2020-08-29 11:09:20 -07:00

59 lines
1.7 KiB
C

#ifndef __CTYPE
#define __CTYPE
#pragma lib "/$M/lib/ape/libap.a"
#ifdef __cplusplus
extern "C" {
#endif
extern int isalnum(int);
extern int isalpha(int);
extern int isblank(int);
extern int iscntrl(int);
extern int isdigit(int);
extern int isgraph(int);
extern int islower(int);
extern int isprint(int);
extern int ispunct(int);
extern int isspace(int);
extern int isupper(int);
extern int isxdigit(int);
extern int tolower(int);
extern int toupper(int);
#ifdef __cplusplus
}
#endif
enum
{
_ISupper = 01, /* UPPERCASE. */
_ISlower = 02, /* lowercase. */
_ISdigit = 04, /* Numeric. */
_ISspace = 010, /* Whitespace. */
_ISpunct = 020, /* Punctuation. */
_IScntrl = 040, /* Control character. */
_ISblank = 0100, /* Blank (usually SPC and TAB). */
_ISxdigit = 0200, /* Hexadecimal numeric. */
};
extern unsigned char _ctype[];
#define isalnum(c) (_ctype[(unsigned char)(c)]&(_ISupper|_ISlower|_ISdigit))
#define isalpha(c) (_ctype[(unsigned char)(c)]&(_ISupper|_ISlower))
#define isblank(c) (_ctype[(unsigned char)(c)]&_ISblank)
#define iscntrl(c) (_ctype[(unsigned char)(c)]&_IScntrl)
#define isdigit(c) (_ctype[(unsigned char)(c)]&_ISdigit)
#define isgraph(c) (_ctype[(unsigned char)(c)]&(_ISpunct|_ISupper|_ISlower|_ISdigit))
#define islower(c) (_ctype[(unsigned char)(c)]&_ISlower)
#define isprint(c) (_ctype[(unsigned char)(c)]&(_ISpunct|_ISupper|_ISlower|_ISdigit|_ISblank))
#define ispunct(c) (_ctype[(unsigned char)(c)]&_ISpunct)
#define isspace(c) (_ctype[(unsigned char)(c)]&_ISspace)
#define isupper(c) (_ctype[(unsigned char)(c)]&_ISupper)
#define isxdigit(c) (_ctype[(unsigned char)(c)]&_ISxdigit)
#ifdef _BSD_EXTENSION
#define isascii(c) (((unsigned int)(c))<0x80)
#define toascii( c ) ((unsigned)(c) & 0x007f)
#endif
#endif /* __CTYPE */