/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1990 MIPS Computer Systems, Inc.            |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 52.227-7013.   |
 * |         MIPS Computer Systems, Inc.                       |
 * |         928 Arques Avenue                                 |
 * |         Sunnyvale, CA 94086                               |
 * |-----------------------------------------------------------|
 */
#ident	"$Header: iswctype.c,v 1.1.2.1 92/06/24 14:10:47 marker Exp $"

/*	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.	*/

/*	This module was created for NLS on Nov 02 '87		*/
/* This module is modified by AT&T Unix Pacific for MNLS 3.2 on Jan.18,89 */

#ident	"@(#)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]	
/* start for MNLS 3.2 by Unix Pacific on Jan.18,89 */
#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
/* end for MNLS 3.2 by Unix Pacific on Jan.18,89 */

extern	int	_lflag;
extern	struct	_wctype *_wcptr[];
wchar_t	_ctmp_;
unsigned _iswctype(c,x)
register wchar_t c;
register int	x;
{
register int	s;
/* start for MNLS 3.2 by Unix Pacific on Jan.18,89 */
	int i,size;
	wchar_t w;
/* end for MNLS 3.2 by Unix Pacific on Jan.18,89 */
	if (_mbyte < 2)
	{
		/*
		 * cswidth 1,0,0
		 */
		return((c & ~0xff) ? 0: (_ctype[c+1]&x));
	}
	if (_lflag == 0)
		_loadtab();
/* start for MNLS 3.2 by Unix Pacific on Jan.18,89 */
/*	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;
/* end for MNLS 3.2 by Unix Pacific on Jan.18,89 */
	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]]);
}
