/************************************************************************
 * This program is Copyright (C) 1986 by Jonathan Payne.  JOVE is       *
 * provided to you without charge, and with no warranty.  You may give  *
 * away copies of JOVE, including sources, provided that this notice is *
 * included in all the files.                                           *
 ************************************************************************/

#ifndef _CTYPE_H_
#define _CTYPE_H_

#ifndef TUNED
#   include "tune.h"
#endif

#ifdef _CTYPE_C_
RCS_H(ctype, "$Id: ctype.h,v 14.32 1993/04/09 00:46:26 tom Exp tom $")
#endif

/* The code in this file was snarfed from ctype.h and modified for JOVE. */

#if (BPC == 7)
#   define _Uc
#else
#   define _Uc	_UC_
#endif

#define	_U	01
#define	_L	02
#define	_N	04
#define _P	010
#define _C	020
#define _S	040
#define _Op	0100
#define _Cl	0200

extern int	ModeMask;

/*
 * Support for selectable character set tables;
 * enabled with compile-time option SELECTABLE (pun intended)
 */
#ifdef SELECTABLE
#   define Const
#else
#   define Const const
#endif

extern Const char
#if (BPC > 7)
		CaseEquiv[],
#endif
		CharTable[],
		UpcTable[],
		LocTable[],
		WordTable[];

#ifndef _CTYPE_C_
#   undef Const
#endif

#define iswhite(c)	(isspace(c))
#define isword(c)	(WordTable[_Uc(c)]&ModeMask)
#define	isalpha(c)	(CharTable[_Uc(c)]&(_U|_L))
#define	isupper(c)	(CharTable[_Uc(c)]&_U)
#define	islower(c)	(CharTable[_Uc(c)]&_L)
#define	isdigit(c)	(CharTable[_Uc(c)]&_N)
#define	isspace(c)	(CharTable[_Uc(c)]&_S)
#define ispunct(c)	(CharTable[_Uc(c)]&_P)
#define toupper(c)	(UpcTable[_Uc(c)])
#define tolower(c)	(LocTable[_Uc(c)])
#if (BPC == 7)				/* use 7-bits character set... */
#   define toascii(c)	((c)&0177)
#else					/* ...and 8-bits chars for others */
#   define toascii(c)	_UC_(c)
#endif
#define isctrl(c)	(CharTable[toascii(c)]&_C)
#define isopenp(c)	(CharTable[toascii(c)]&_Op)
#define isclosep(c)	(CharTable[toascii(c)]&_Cl)
#define isoctal(c)	((unsigned)((c)-'0') < 8)
#define ishex(c)	(isdigit(c)||(unsigned)(toupper(c)-'A') < 6)
#define has_syntax(c,s)	(CharTable[_Uc(c)]&(s))
#if (BPC == 7)
#   define CEquiv(c)	tolower(c)
#else
#   define CEquiv(c)	CaseEquiv[_Uc(c)]
#endif

#define SET_TABLE(x)	(ModeMask=(1<<(x)))

#define WITH_TABLE(x)	\
{			\
	int _push=ModeMask;	\
	SET_TABLE(x);

#define END_TABLE()	\
	ModeMask=_push;	\
}

	/* check if input key is a printable character */
#define printable(c)	((c)<0200 && has_syntax(c,_U|_L|_N|_P))

/* Abbreviations for FUNDAMENTAL, TEXT, CMODE, LISPMODE bitmasks */
#define F	(1<<FUNDAMENTAL)
#define T	(1<<TEXT)
#define C	(1<<CMODE)
#define L	if_LISP(1<<LISPMODE)
#define P	if_PERL(1<<PERLMODE)
#define ALL	(F|T|C|L|P)

#ifdef SELECTABLE
#   define NCTABLES	4	/* number of tables to define */

void	set_char_tables __(( const char * const *_(new_char_tables),
			     int _(offset), int _(size),
			     const char * const *_(new_accent_table),
			     const char *_(new_name) ));
#endif

#endif /* _CTYPE_H_ */

/*======================================================================
 * $Log: ctype.h,v $
 * Revision 14.32  1993/04/09  00:46:26  tom
 * (CEquiv): fix 7-bit definition for `case-sensitive case-insensitivity'.
 *
 * Revision 14.31  1993/02/13  00:47:04  tom
 * move definition of Cequiv() here (from "re.h").
 *
 * Revision 14.30  1993/01/26  17:53:27  tom
 * cleanup whitespace.
 *
 * Revision 14.28  1992/10/05  13:25:07  tom
 * convert to "port{ansi,defs}.h" conventions.
 *
 * Revision 14.26  1992/08/26  23:56:40  tom
 * some typographic changes; add RCS directives.
 *
 */
