/*
 * |-----------------------------------------------------------|
 * | 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: trwctype.c,v 1.1.2.1 92/06/24 14:10:51 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 is 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.0"

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

#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	_trwctype(c,x)
register wchar_t c;
{
register int	s;
register wchar_t w;
/* start for MNLS 3.2 by Unix Pacific on Jan.18,89 */
	int i,size;
	wchar_t wchar;
/* end for MNLS 3.2 by Unix Pacific on Jan.18,89 */
	if (_mbyte < 2)
	{
		if (c < 256)
			return(((_ctype + 1)[c] & x) ? ((_ctype + 258)[c]) : c);
		else
			return(c);
	}
	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(c); 			*/
/*	w = (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(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;
/* end for MNLS 3.2 by Unix Pacific on Jan.18,89 */
	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);
}
