/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1988 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "codeset.h"
#include "mbextern.h"
#include "iso2022.h"
/*
* Keep state informations
*/
struct state {
};
{-1, 0}, {-1, 0}, {-1, 0}, {01, 0}
};
void _savestates(void); /* save states */
void _restorestates(void); /* restore states */
void _initializestates(void);/* Initialize states */
/*
* Variables for wc*tomb*()
*/
/*
* mbtowc - subroutine for most iso codeset sequences
*/
int
{
unsigned char ch;
unsigned char *us = (unsigned char *)s;
int length = 0;
int len = 0;
int mask;
int i;
/*
* initialize _g0_stuff
*/
}
/*
* get character and proceed
*/
loop:
switch (ch) { /* get a character */
/* escape sequence or locking shifts */
case ESC: /* escape sequence */
switch (ch) {
/* DESIGNATE */
case 0x24: /* designate */
switch (ch) {
case 0x28: case 0x29:
case 0x2A: case 0x2B:
case 0x2D: case 0x2E:
case 0x2F:
/* Skip intermidiates */
do {
return (-1); /* error */
if (tch == 0x28)
i = G0;
i = G1;
i = G2;
else /* (tch == 0x2B || tch == 0x2F) */
i = G3;
/* updates state info */
goto loop;
break;
default:
/* This is an illegal sequence */
return (-1);
break;
}
break;
case 0x28: /* designate */
case 0x29: case 0x2A: case 0x2B:
case 0x2D: case 0x2E: case 0x2F:
/* Skip intermidiates */
do {
return (-1); /* error */
if (tch == 0x28)
i = G0;
i = G1;
i = G2;
else /* (tch == 0x2B || tch == 0x2F) */
i = G3;
/* updates state info */
goto loop;
break;
/* LOCKING SHIFTS */
case LS1R: /* locking shift LS1R */;
_currentG1 = G1;
goto loop;
break;
case LS2: /* locking shift LS2 */
_currentG0 = G2;
goto loop;
break;
case LS2R: /* locking shift LS2R */
_currentG1 = G2;
goto loop;
break;
case LS3: /* locking shift LS3 */
_currentG0 = G3;
goto loop;
break;
case LS3R: /* locking shift LS3R */
_currentG1 = G3;
goto loop;
break;
/* CONTROL FUNCTIONS */
case 0x21: /* C0 sets */
case 0x22: /* C1 sets */
do {
return (-1); /* error */
goto loop;
break;
/* SINGLE SHIFT for 7bit environment */
case SS2_7B: /* Single shift SS2 for 7bits */
case SS3_7B: /* Single shoft SS3 for 7bits */
else
goto loop;
break;
default: /* should be an error */
return (-1);
break;
}
/* locking shifts */
case LS0:
_currentG0 = G0;
goto loop;
break;
case LS1:
_currentG0 = G1;
goto loop;
break;
/* Single shift SS3 and SS2 for 8bits */
case SS2_8B:
case SS3_8B:
else
goto loop;
break;
/* This character is not any special character/
* It does not change any state.
* Goto where it generates wide character.
*/
default:
/*
* Use this ch to generate pwc.
*/
if (ch == 0) { /* end of string or 0 */
wide = 0;
mask = 0;
goto gen_wide;
}
break;
}
/*
* Generate pwc here.
* The information here is
* current state and length. If the length is two, you need to
* read one more character.
*/
switch (gen_wide_state) {
case USE_STATE:
/* current mode is G1 mode */
if (++length > n) return (-1);
}
else {
}
}
else {
/* current mode is G0 mode */
if (++length > n) return (-1);
}
else {
}
}
break;
case USE_SS2:
if (++length > n) return (-1);
}
else {
}
break;
case USE_SS3:
if (++length > n) return (-1);
}
else {
}
break;
default:
/* shoult be internal error */
return (-1);
break;
}
return (length);
}
/*
* mbstowcs()
*/
{
int ret1;
int accsum = 0;
/*
* If pwcs == 0, do nothing.
*/
if (pwcs == 0)
return (0);
/*
* States things
*/
_savestates(); _initializestates();
while (accsum < n) {
if (ret1 < 0)
return (-1); /* error */
if (pwcs == 0)
*pwcs = 0;
/*
* Restore states
*/
return (accsum);
}
s = s + ret1; /* increment the pointer */
++accsum;
}
/*
* Restore states
*/
return (accsum);
}
/*
* wctomb -
*/
int
{
unsigned char ch;
unsigned char *us = (unsigned char *)s;
int length = 0;
int len = 0;
unsigned short mode;
unsigned char *bp;
int csize, i;
int n = MMB_CUR_MAX;
/*
* If pwc is 0, do this first.
*/
if (pwc == 0) {
if (s != 0) {
*s = 0;
return (1);
}
else {
return (0);
}
}
csize = 1;
else
csize = 2;
length = 0;
#ifdef DDDebug
printf ("7b ");
else
printf ("8b ");
switch (mode) {
case G0MASK:
printf ("G0"); break;
case G1MASK:
printf ("G1"); break;
case G2MASK:
printf ("G2"); break;
case G3MASK:
printf ("G3"); break;
default:
printf ("XXXX"); break;
}
#endif
switch (_my_env) {
case BIT7ENV: /* 7 bit environment */
switch (mode) {
case G0MASK:
_currentOUT = G0;
if (csize == 2) {
/*
* Emit escape sequences
*/
*bp++ = 0x24;
*bp++ = 0x28;
length += 4;
}
else {
/*
* Emit escape sequences
*/
*bp++ = 0x28;
length += 3;
}
++length;
}
if (csize == 1) {
++length;
}
else {
++length;
++length;
}
break;
case G1MASK:
_currentOUT = G1;
if (csize == 2) {
/*
* Emit escape sequences
*/
*bp++ = 0x24;
*bp++ = 0x29;
length += 4;
}
else {
/*
* Emit escape sequences
*/
*bp++ = 0x29;
length += 3;
}
++length;
}
if (csize == 1) {
++length;
}
else {
++length;
++length;
}
break;
case G2MASK:
_currentOUT = G2;
if (csize == 2) {
/*
* Emit escape sequences
*/
*bp++ = 0x24;
*bp++ = 0x2A;
length += 4;
}
else {
/*
* Emit escape sequences
*/
*bp++ = 0x2A;
length += 3;
}
length += 2;
}
if (csize == 1) {
++length;
}
else {
++length;
++length;
}
break;
case G3MASK:
_currentOUT = G3;
if (csize == 2) {
/*
* Emit escape sequences
*/
*bp++ = 0x24;
*bp++ = 0x2B;
length += 4;
}
else {
/*
* Emit escape sequences
*/
*bp++ = 0x2B;
length += 3;
}
length += 2;
}
if (csize == 1) {
++length;
}
else {
++length;
++length;
}
break;
}
break;
case BIT8ENV: /* 8 bit environment */
switch (mode) {
case G0MASK:
_currentOUT = G0;
if (csize == 2) {
/*
* Emit escape sequences
*/
*bp++ = 0x24;
*bp++ = 0x28;
length += 4;
}
else {
/*
* Emit escape sequences
*/
*bp++ = 0x28;
length += 3;
}
++length;
}
if (csize == 1) {
++length;
}
else {
++length;
++length;
}
break;
case G1MASK:
_currentOUT = G1;
if (csize == 2) {
/*
* Emit escape sequences
*/
*bp++ = 0x24;
*bp++ = 0x29;
length += 4;
}
else {
/*
* Emit escape sequences
*/
*bp++ = 0x29;
length += 3;
}
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) {
++length;
}
else {
++length;
++length;
}
break;
case G2MASK:
_currentOUT = G2;
if (csize == 2) {
/*
* Emit escape sequences
*/
*bp++ = 0x24;
*bp++ = 0x2A;
length += 4;
}
else {
/*
* Emit escape sequences
*/
*bp++ = 0x2A;
length += 3;
}
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) {
++length;
}
else {
++length;
++length;
}
break;
case G3MASK:
_currentOUT = G3;
if (csize == 2) {
/*
* Emit escape sequences
*/
*bp++ = 0x24;
*bp++ = 0x2B;
length += 4;
}
else {
/*
* Emit escape sequences
*/
*bp++ = 0x2B;
length += 3;
}
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) {
++length;
}
else {
++length;
++length;
}
break;
}
break;
default: /* Should never happens */
return (-1);
break;
}
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 (")\n");
#endif
return (length);
}
/*
* wcstombs
*/
{
int acclen = 0;
int ret1;
int i;
if (n < 0)
return (-1);
/*
* Initialize State
*/
_savestates(); _initializestates();
while (acclen < n) {
/*
* end of string ?
*/
*s = 0;
/*
* restore states
*/
return (acclen);
}
/*
* Error ?
*/
if (ret1 < 0)
return (-1);
for (i = 0; i < ret1; i++)
*s++ = buf[i];
++pwcs;
}
/*
* restore states
*/
/*
* return the length
*/
return (acclen);
}
/*
* Supplementary routines
*/
void
_initializestates(void)
{
_currentG0 = G0;
_currentG1 = G1;
_currentOUT = G0;
prevcsize = 1;
}
static char SAVED_currentG0;
static char SAVED_currentG1;
void
_savestates(void)
{
}
void
_restorestates(void)
{
}