⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iso.multibyte.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
		case G0MASK:			if (_currentOUT != G0 || prevcsize != csize) {				 _currentOUT = G0;				if (csize == 2) {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x24;					 *bp++ = 0x28;					 *bp++ = FINAL;					 length += 4;				}				else {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x28;					 *bp++ = FINAL;					 length += 3;				}				*bp++ = SI;				++length;			}			if (csize == 1) {				*bp++ = pwc & 0x007f;				++length;			}			else {				*bp++ = (pwc & 0x7f00) >> 8;				++length;				*bp++ = pwc & 0x007f;				++length;			}			break;		case G1MASK:			if (_currentOUT != G1 || prevcsize != csize) {				 _currentOUT = G1;				if (csize == 2) {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x24;					 *bp++ = 0x29;					 *bp++ = FINAL;					 length += 4;				}				else {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x29;					 *bp++ = FINAL;					 length += 3;				}				*bp++ = SO;				++length;			}			if (csize == 1) {				*bp++ = pwc & 0x007f;				++length;			}			else {				*bp++ = (pwc & 0x7f00) >> 8;				++length;				*bp++ = pwc & 0x007f;				++length;			}			break;		case G2MASK:			if (_currentOUT != G2 || prevcsize != csize) {				 _currentOUT = G2;				if (csize == 2) {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x24;					 *bp++ = 0x2A;					 *bp++ = FINAL;					 length += 4;				}				else {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x2A;					 *bp++ = FINAL;					 length += 3;				}				*bp++ = ESC; *bp++ = LS2;				length += 2;			}			if (csize == 1) {				*bp++ = pwc & 0x007f;				++length;			}			else {				*bp++ = (pwc & 0x7f00) >> 8;				++length;				*bp++ = pwc & 0x007f;				++length;			}			break;		case G3MASK:			if (_currentOUT != G3 || prevcsize != csize) {				 _currentOUT = G3;				if (csize == 2) {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x24;					 *bp++ = 0x2B;					 *bp++ = FINAL;					 length += 4;				}				else {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x2B;					 *bp++ = FINAL;					 length += 3;				}				*bp++ = ESC; *bp++ = LS3;				length += 2;			}			if (csize == 1) {				*bp++ = pwc & 0x007f;				++length;			}			else {				*bp++ = (pwc & 0x7f00) >> 8;				++length;				*bp++ = pwc & 0x007f;				++length;			}			break;		}		break;	case BIT8ENV:	/* 8 bit environment */		switch (mode) {		case G0MASK:			if (_currentOUT != G0 || prevcsize != csize) {				_currentOUT = G0;				if (csize == 2) {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x24;					 *bp++ = 0x28;					 *bp++ = FINAL;					 length += 4;				}				else {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x28;					 *bp++ = FINAL;					 length += 3;				}				*bp++ = LS0;				++length;			}			if (csize == 1) {				*bp++ = pwc & 0x007f;				++length;			}			else {				*bp++ = (pwc & 0x7f00) >> 8;				++length;				*bp++ = pwc & 0x007f;				++length;			}			break;		case G1MASK:			if (_currentOUT != G1 || prevcsize != csize) {				_currentOUT = G1;				if (csize == 2) {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x24;					 *bp++ = 0x29;					 *bp++ = FINAL;					 length += 4;				}				else {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x29;					 *bp++ = FINAL;					 length += 3;				}				*bp++ = ESC; *bp++ = LS1R;				length += 2;			}			/*			 * If state is G1 or G2, or G3, assume that			 * this is 8bit characters. To do this more			 * accurately, wide character needs to be			 * larger than 16 bits to keep more information.			 */			pwc |= 0x8080;			if (csize == 1) {				*bp++ = pwc & 0x00ff;				++length;			}			else {				*bp++ = (pwc & 0xff00) >> 8;				++length;				*bp++ = pwc & 0x00ff;				++length;			}			break;		case G2MASK:			if (_currentOUT != G2 || prevcsize != csize) {				_currentOUT = G2;				if (csize == 2) {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x24;					 *bp++ = 0x2A;					 *bp++ = FINAL;					 length += 4;				}				else {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x2A;					 *bp++ = FINAL;					 length += 3;				}				*bp++ = ESC; *bp++ = LS2R;				length += 2;			}			/*			 * If state is G1 or G2, or G3, assume that			 * this is 8bit characters. To do this more			 * accurately, wide character needs to be			 * larger than 16 bits to keep more information.			 */			pwc |= 0x8080;			if (csize == 1) {				*bp++ = pwc & 0x00ff;				++length;			}			else {				*bp++ = (pwc & 0xff00) >> 8;				++length;				*bp++ = pwc & 0x00ff;				++length;			}			break;		case G3MASK:			if (_currentOUT != G3 || prevcsize != csize) {				_currentOUT = G3;				if (csize == 2) {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x24;					 *bp++ = 0x2B;					 *bp++ = FINAL;					 length += 4;				}				else {					/*					 * Emit escape sequences					 */					 *bp++ = ESC;					 *bp++ = 0x2B;					 *bp++ = FINAL;					 length += 3;				}				*bp++ = ESC; *bp++ = LS3R;				length += 2;			}			/*			 * If state is G1 or G2, or G3, assume that			 * this is 8bit characters. To do this more			 * accurately, wide character needs to be			 * larger than 16 bits to keep more information.			 */			pwc |= 0x8080;			if (csize == 1) {				*bp++ = pwc & 0x00ff;				++length;			}			else {				*bp++ = (pwc & 0xff00) >> 8;				++length;				*bp++ = pwc & 0x00ff;				++length;			}			break;		}		break;	default:	/* Should never happens */		return (-1);		break;	}	prevcsize = csize;		if (length > n) {		return (-1);	/* buffer too small */	}	for (i = 0; i < length; i++) {		*s++ = buf[i];	}#ifdef DDDebug	printf ("\t(");	for (i = 0; i < length; i++) {		printf ("%x,", buf[i]);	}	printf (")\n");#endif	return (length);}/* * wcstombs */size_t_wcstombs_iso(s, pwcs, n)	char *s;	wchar_t *pwcs;	int n;{	int acclen = 0;	char buf[MMB_CUR_MAX];	int ret1;	int i;	if (n < 0)		return (-1);	/*	 * Initialize State	 */	 _savestates(); _initializestates();	 while (acclen < n) {		ret1 = _wctomb_iso (buf, *pwcs);		/*		 * end of string ?		 */		if (ret1 == 1 && buf[0] == 0) {			*s = 0;			/*			 * restore states			 */			_restorestates();			return (acclen);		}		/*		 * Error ?		 */		if (ret1 < 0)			return (-1);		acclen += ret1;		for (i = 0; i < ret1; i++)			*s++ = buf[i];		++pwcs;	 }	/*	 * restore states	 */	_restorestates();	 /*	  * return the length	  */	 return (acclen);}/* * Supplementary routines */int_initializestates(){	_currentG0 = G0;	_currentG1 = G1;	_des_states[G0].width = -1;	/* This makes it Initialize */	_currentOUT = G0;	prevcsize = 1;}static char SAVED_currentG0;static char SAVED_currentG1;static struct state SAVED_des_states[NUM_OF_STATES];static struct state SAVED_Invoked_G0, SAVED_Invoked_G1;static char SAVED_currentOUT = G0; /* G0, G1, G2 or G3 */static SAVED_prevcsize = 1;int_savestates(){	SAVED_currentG0 = _currentG0;	SAVED_currentG1 = _currentG1;	SAVED_des_states[G0] = _des_states[G0];	SAVED_des_states[G1] = _des_states[G1];	SAVED_des_states[G2] = _des_states[G2];	SAVED_des_states[G3] = _des_states[G3];	SAVED_Invoked_G0 = Invoked_G0;	SAVED_Invoked_G1 = Invoked_G1;	SAVED_currentOUT = _currentOUT;	SAVED_prevcsize = prevcsize;}int _restorestates(){	_currentG0 = SAVED_currentG0;	_currentG1 = SAVED_currentG1;	_des_states[G0] = SAVED_des_states[G0];	_des_states[G1] = SAVED_des_states[G1];	_des_states[G2] = SAVED_des_states[G2];	_des_states[G3] = SAVED_des_states[G3];	Invoked_G0 = SAVED_Invoked_G0;	Invoked_G1 = SAVED_Invoked_G1;	_currentOUT = SAVED_currentOUT;	prevcsize = SAVED_prevcsize;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -