/*
 *	ctype.h		Character classification and conversion
 */

#ifndef _CTYPE_H
#define _CTYPE_H

#ifndef _COMPILER_H
#include <compiler.h>
#endif

extern	unsigned char	*_ctype;

#define	_CTc	0x01		/* control character */
#define	_CTd	0x02		/* numeric digit */
#define	_CTu	0x04		/* upper case */
#define	_CTl	0x08		/* lower case */
#define	_CTs	0x10		/* whitespace */
#define	_CTp	0x20		/* punctuation */
#define	_CTx	0x40		/* hexadecimal */

#define	isalnum(c)	(_ctype[c]&(_CTu|_CTl|_CTd))
#define	isalpha(c)	(_ctype[c]&(_CTu|_CTl))
#define	isascii(c)	!((c)&~0x7F)
#define	iscntrl(c)	(_ctype[c]&_CTc)
#define	isdigit(c)	(_ctype[c]&_CTd)
#define	isgraph(c)	!(_ctype[c]&(_CTc|_CTs))
#define	islower(c)	(_ctype[c]&_CTl)
#define	isprint(c)	!(_ctype[c]&_CTc)
#define	ispunct(c)	(_ctype[c]&_CTp)
#define	isspace(c)	(_ctype[c]&_CTs)
#define	isupper(c)	(_ctype[c]&_CTu)
#define	isxdigit(c)	(_ctype[c]&_CTx)
#define iswhite(c)	isspace(c)

#define	_toupper(c)	((c)^0x20)
#define	_tolower(c)	((c)^0x20)
#define	toascii(c)	((c)&0x7F)

#ifdef __GNUC__
/* use safe versions */

#if 0 /* do not define, these are routines in ctype.c as they should be */
#define	toupper(c) \
    ({typedef _tc = (c);  \
	_tc _c = (c);     \
	    islower(_c) ? (_c^0x20) : _c; })
#define	tolower(c)  \
    ({typedef _tc = (c);  \
        _tc _c = (c);     \
	    isupper(_c) ? (_c^0x20) : _c; })
#endif /* 0 */

#define toint(c)    \
    ({typedef _tc = (c);  \
        _tc _c = (c);     \
	    (_c <= '9') ? (_c - '0') : (toupper(_c) - 'A'); })
#define isodigit(c) \
    ({typedef _tc = (c);   \
	_tc _c = (c);      \
	    (_c >='0') && (_c<='7'); })
#define iscymf(c)   \
    ({typedef _tc = (c);   \
	_tc _c = (c);      \
	    isalpha(_c) || (_c == '_'); })
#define iscym(c)    \
    ({typedef _tc = (c);   \
	_tc _c = (c);      \
	    isalnum(_c) || (_c == '_'); })

#else /* you know what */

#if 0 /* see above */
#define	toupper(c)	(islower(c) ? (c)^0x20 : (c))
#define	tolower(c)	(isupper(c) ? (c)^0x20 : (c))
#endif

#define toint(c)	( (c) <= '9' ? (c) - '0' : toupper(c) - 'A' )
#define isodigit(c)	( (c)>='0' && (c)<='7' )
#define iscymf(c)	(isalpha(c) || ((c) == '_') )
#define iscym(c)	(isalnum(c) || ((c) == '_') )

#endif /* __GNUC__ */

__EXTERN int	toupper	__PROTO((int));
__EXTERN int 	tolower	__PROTO((int));

#endif /* _CTYPE_H */
