/*
 *			c t y p e . c
 */

/*)LIBRARY
*/

#ifdef	DOCUMENTATION

title	ctype	Character Classification Type Table
index		Character classification type table

internal

synopsis
	.s.nf
	#include <ctype.h>
	.s.f
Description

	This module contains the bit-mask table
	for the is... and to... functions.

Bugs

	No provisions are made for national letters.
	Maintainers should note that source for a test program is included.

	is...() functions assume that EOF is a control character.

#endif


/*
 * Warning -- this presupposes contiguous storage allocation
 */

#include	<ctype.h>
#define	_CS	(_C | _S)
#define	_BS	(_B | _S)
#define	_DX	(_D | _X)
#define	_UX	(_U | _X)
#define	_LX	(_L | _X)

static char	__ctype_eof = 0;		/* _ctype_[EOF]		*/
char		_ctype_[] = {
	 _C,  _C,  _C,  _C,
			     _C,  _C,  _C,  _C,	/* 000-007		*/
	 _C, _CS, _CS, _CS,
			    _CS, _CS,  _C,  _C,	/* 010-017 \b\n\t\f\r	*/
	 _C,  _C,  _C,  _C,
			     _C,  _C,  _C,  _C,	/* 020-027		*/
	 _C,  _C,  _C,  _C,
			     _C,  _C,  _C,  _C,	/* 030-037		*/
	_BS,  _P,  _P,  _P,
			     _P,  _P,  _P,  _P,	/* 040-047  !"#$%&'	*/
	 _P,  _P,  _P,  _P,
			     _P,  _P,  _P,  _P,	/* 050-057 ()*+,-./	*/
	_DX, _DX, _DX, _DX,
			    _DX, _DX, _DX, _DX,	/* 060-067 01234567	*/
	_DX, _DX,  _P,  _P,
			     _P,  _P,  _P,  _P,	/* 070-077 89:;<=>?	*/
	 _P, _UX, _UX, _UX,
			    _UX, _UX,  _UX, _U,	/* 100-107 @ABCDEFG	*/
	 _U,  _U,  _U,  _U,
			     _U,  _U,  _U,  _U,	/* 110-117 HIJKLMNO	*/
	 _U,  _U,  _U,  _U,
			     _U,  _U,  _U,  _U,	/* 120-127 PQRSTUVW	*/
	 _U,  _U,  _U,  _P,
			     _P,  _P,  _P,  _P,	/* 130-137 XYZ[\]^_	*/
	 _P, _LX, _LX, _LX,
			    _LX, _LX, _LX,  _L,	/* 140-147 `abcdefg	*/
	 _L,  _L,  _L,  _L,
			     _L,  _L,  _L,  _L,	/* 150-157 hijklmno	*/
	 _L,  _L,  _L,  _L,
			     _L,  _L,  _L,  _L,	/* 160-167 pqrstuvw	*/
	 _L,  _L,  _L,  _P,
			     _P,  _P,  _P,  _C,	/* 170-177 xyz{|}	*/
};


#ifdef	TESTING
/*
 *		istest.c -- is....() test program
 *		Decus C only (assumes is... are functions, not macros)
 */
#include <stdio.h>

typedef struct info {
	char	*name;
	int	(*func)();
} INFO;
extern int	isalnum(), isalpha(), isascii(), iscntrl(), isdigit();
extern int	isgraph(), islower(), isprint(), ispunct(), isspace();
extern int	isupper(), isxdigit();

INFO	database[] = {
	"isalnum",	isalnum,	"isalpha",	isalpha,
	"isascii",	isascii,	"iscntrl",	iscntrl,
	"isdigit",	isdigit,	"isgraph",	isgraph,
	"islower",	islower,	"isupper",	isupper,
	"isprint",	isprint,	"ispunct",	ispunct,
	"isspace",	isspace,	"isupper",	isupper,
	"isxdigit",	isxdigit,	NULL,		NULL,
};
main() {
	register int	from;
	register int	i;
	int		to;
	register INFO	*ip;
	for (from = 0; from < 0200; from = to) {
		to = from + 040;
		printf("\t");
		for (i = from; i < to; i++) {
			if (i < ' ' || i >= 0200)
				printf("%02o", i);
			else if (i == 0177)
				printf(" DEL");
			else	printf("%c", i);
		}
		for (ip = database; ip->func != NULL; ip++) {
			range(from, to, ip->name, ip->func);
		}
		printf("\n");
	}
	for (ip = database; ip->func != NULL; ip++)
		range(EOF, EOF+1, ip->name, ip->func);
}

range(from, to, name, func)
int		from, to;
char		*name;
int		(*func)();
{
	register int	i;

	printf("\n%s\t", name);
	for (i = from; i < to; i++) {
		if (i < 040 || i >= 0177)
			printf("%2d", (*func)(i) != 0);
		else	printf("%1d", (*func)(i) != 0);
	}
}
#endif
