/*
 * |-----------------------------------------------------------|
 * | 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: scrwidth.c,v 1.1.2.1 92/06/24 14:10:54 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 modified by AT&T Unix Pacific for MNLS 3.2 on Jan.19,89 */
#ident	"@(#)libw-port:wmisc/scrwidth.c 2.0 AT&T-UP"

#include	<libw.h>
#include	<ctype.h>
/* start for MNLS 3.2 by AT&T UP  Jan.18,1989 */
#define eucw1 _ctype[514]	/* EUC width for code set 1 */
#define eucw2 _ctype[515]	/* EUC width for code set 2 */
#define eucw3 _ctype[516]	/* EUC width for code set 3 */
/* end for MNLS 3.2 */
#define scrw1 _ctype[517]
#define scrw2 _ctype[518]
#define scrw3 _ctype[519]
#define multibyte (_ctype[520]>1)
#define	EUCMASK	0x8080
#define P00	0x0000		/* Code Set 0 */
#define P11	0x8080		/* Code Set 1 */
#define P01	0x0080		/* Code Set 2 */
#define P10	0x8000		/* Code Set 3 */

/* start for MNLS 3.2 by AT&T UP  Jan.18,1989 */
/*
 *	The followings are for 4 bytes of multi-byte code definition.
 */
#define F_EUCMASK 0x30000000	/* mask bit for 32 bits */
#define F_P00     0x00000000	/* Code Set 0 for 4 bytes code */
#define F_P11     0x30000000	/* Code Set 1 for 4 bytes code */
#define F_P01     0x10000000	/* Code Set 2 for 4 bytes code */
#define F_P10     0x20000000	/* Code Set 3 for 4 bytes code */
/* end for MNLS 3.2 */
int scrwidth(c)
wchar_t c;
{
/* start for MNLS 3.2 by AT&T UP  Jan.18,1989 */
	short pcw;	/* process code width */
/* end for MNLS 3.2 */
	if(!wisprint(c))
		return(0);
/* start for MNLS 3.2 by AT&T UP  Jan.18,1989 */
/*	return(!multibyte || c <= 0177 ? 1 : (c & P11) == P11 ? scrw1 :	*/
/*		(c & P01) ? scrw2 : scrw3); 				*/
	/*
	 *	check process code width with _ctype[]
	 */
	if ( eucw1 > sizeof(unsigned short ) ||
	     eucw2 > sizeof(unsigned short ) ||
	     eucw3 > sizeof(unsigned short ))
		pcw = sizeof(unsigned long);	/* 32 bits process code */
	else
		pcw = sizeof(unsigned short);	/* 16 bits process code */

	if (pcw > sizeof(unsigned short)) {
		return(!multibyte || c <= 0177 ? 1 : (c & F_P11) == F_P11 ? scrw1 :
			(c & F_P01) ? scrw2 : scrw3);
	} else {

		return(!multibyte || c <= 0177 ? 1 : (c & P11) == P11 ? scrw1 :
			(c & P01) ? scrw2 : scrw3);
	}
/* end for MNLS 3.2 */
}
