/* $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: trwctype.c 1.2 90/04/21 $@(#)libw-port:iswctype.c 2.0"

/*
	_tuwctype(c) converts lower-case character to upper-case 
*/

#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	_trwctype(c,x)
register wchar_t c;
{
register int	s;
register wchar_t w;
	int i,size;
	wchar_t wchar;
	if (_mbyte < 2)
	{
		if (c < 256)
			return(((_ctype + 1)[c] & x) ? ((_ctype + 258)[c]) : c);
		else
			return(c);
	}
	if (_lflag == 0)
		_loadtab();
	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(c);
	/*
	 *	pick up the 7 bits data from c
	 */
	for (i = 0,wchar = 0; size--; i++)
		wchar |= ((c & (MASK << (8 * i))) >> (1 * i));	
	w = wchar;
	if (_wcptr[s] == 0 || _wcptr[s]->code == 0 ||
	    w < _wcptr[s]->cmin || w > _wcptr[s]->cmax)
		return(c);
	return(_iswctype(c,x) ? _wcptr[s]->code[w - _wcptr[s]->cmin] : c);
}
