/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
*/

/*	Copyright (c) 1988 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/


#ident	"$Header: iswctype.c 1.2 90/04/21 $@(#)libw-port:iswctype.c 2.1"

/*
	_iswctype(c,x) returns true if 'c' is classified x
*/

#include <ctype.h>
#include <widec.h>
#include <wctype.h>
#define	_mbyte	_ctype[520]	
#define eucw1	_ctype[514]	/* length of code set 1 */
#define eucw2	_ctype[515]	/* length of code set 2 */
#define eucw3	_ctype[516]	/* length of code set 3 */
#define MASK	0x7f

extern	int	_lflag;
extern	struct	_wctype *_wcptr[];
wchar_t	_ctmp_;
unsigned _iswctype(c,x)
register wchar_t c;
register int	x;
{
register int	s;
	int i,size;
	wchar_t w;
	if (_mbyte < 2)
	{
		/*
		 * cswidth 1,0,0
		 */
		return((c&0xff00) == 0x0000 ? (_ctype[c+1]&x) : 0);
	}
	if (_lflag == 0)
		_loadtab();
/*	if (iscodeset1(c)) 			*/
/*		s=0; 				*/
/*	else if (iscodeset2(c)) 		*/
/*		s=1; 				*/
/*	else if (iscodeset3(c)) 		*/
/*		s=2; 				*/
/*	else 					*/
/*		return(0); 			*/
/*	c = (c & 0x7f) | ((c & 0x7f00) >> 1); 	*/
	if (iscodeset1(c)) {
		s=0;
		size = eucw1;	/* length of code set 1 */
	} else if (iscodeset2(c)) {
		s=1;
		size = eucw2;	/* length of code set 2 */
	} else if (iscodeset3(c)) {
		s=2;
		size = eucw3;	/* length of code set 3 */
	} else
		return(0);
	/*
	 *	pick up the 7 bits data from c
	 */
	for (i = 0,w = 0; size--; i++)
		w |= ((c & (MASK << (8 * i))) >> (1 * i));	
	c = w;
	if (_wcptr[s] == 0 || _wcptr[s]->index == 0 ||
	    c < _wcptr[s]->tmin || c > _wcptr[s]->tmax)
		return(0);
	return(x & _wcptr[s]->type[_wcptr[s]->index[c-_wcptr[s]->tmin]]);
}
