Esempio n. 1
0
/*
 * Big5 ---> MIC
 */
static void
big52mic(const unsigned char *big5, unsigned char *p, int len)
{
	unsigned short c1;
	unsigned short big5buf,
				cnsBuf;
	unsigned char lc;
	int			l;

	while (len > 0)
	{
		c1 = *big5;
		if (!IS_HIGHBIT_SET(c1))
		{
			/* ASCII */
			if (c1 == 0)
				report_invalid_encoding(PG_BIG5,
										(const char *) big5, len);
			*p++ = c1;
			big5++;
			len--;
			continue;
		}
		l = pg_encoding_verifymb(PG_BIG5, (const char *) big5, len);
		if (l < 0)
			report_invalid_encoding(PG_BIG5,
									(const char *) big5, len);
		big5buf = (c1 << 8) | big5[1];
		cnsBuf = BIG5toCNS(big5buf, &lc);
		if (lc != 0)
		{
			if (lc == LC_CNS11643_3 || lc == LC_CNS11643_4)
			{
				*p++ = 0x9d;	/* LCPRV2 */
			}
			*p++ = lc;			/* Plane No. */
			*p++ = (cnsBuf >> 8) & 0x00ff;
			*p++ = cnsBuf & 0x00ff;
		}
		else
			report_untranslatable_char(PG_BIG5, PG_MULE_INTERNAL,
									   (const char *) big5, len);
		big5 += l;
		len -= l;
	}
Esempio n. 2
0
public void EncodeHz( i_str_t *istr, int head, int tail,
		     byte codingSystem, boolean_t binary )
{
  int idx, attr;
  ic_t ic;
  byte cset;
  boolean_t asciiMode = TRUE;

  for( idx = head ; idx < tail ; idx++ ){
    cset = istr[ idx ].charset;
    ic = istr[ idx ].c;
    attr = (int)istr[ idx ].attr << 8;
    if( BIG5 == cset )
      ic = BIG5toCNS( ic, &cset );
#ifndef MSDOS /* IF NOT DEFINED */
    else if( UNICODE == cset )
      ic = UNItoGB( ic, &cset );
#endif /* MSDOS */
    if( cset < PSEUDO ){
      if( ASCII == cset ){
	if( FALSE == asciiMode ){
	  asciiMode = TRUE;
	  EncodeAddChar( attr, (ic_t)'~' );
	  EncodeAddChar( attr, (ic_t)'}' );
	}
	EncodeAddChar( attr, ic );
	if( (ic_t)'~' == ic )
	  EncodeAddChar( attr, (ic_t)'~' );
      } else if( GB2312 == cset ){
	if( TRUE == asciiMode ){
	  asciiMode = FALSE;
	  EncodeAddChar( attr, '~' );
	  EncodeAddChar( attr, '{' );
	}
	EncodeAddChar( attr, MakeByte1( ic ) );
	EncodeAddChar( attr, MakeByte2( ic ) );
      } else {
	if( FALSE == EncodeAddInvalid( attr, ic, cset ) )
	  break;
      }
    } else if( FALSE == EncodeAddPseudo( attr, ic, cset, binary ) ){
      break;
    }
  }
}
Esempio n. 3
0
public void EncodeEUCjp( i_str_t *istr, int head, int tail,
			byte codingSystem, boolean_t binary )
{
  int idx, attr;
  ic_t ic;
  byte cset, g0, g1, g2, g3;

  g0 = cTable[ (int)codingSystem ].state.cset[ G0 ];
  g1 = cTable[ (int)codingSystem ].state.cset[ G1 ];
  g2 = cTable[ (int)codingSystem ].state.cset[ G2 ];
  g3 = cTable[ (int)codingSystem ].state.cset[ G3 ];

  for( idx = head ; idx < tail ; idx++ ){
    cset = istr[ idx ].charset;
    ic = istr[ idx ].c;
    attr = (int)istr[ idx ].attr << 8;
    if( BIG5 == cset )
      ic = BIG5toCNS( ic, &cset );
#ifndef MSDOS /* IF NOT DEFINED */
    else if( UNICODE == cset ){
      switch( codingSystem ){
      case EUC_CHINA: ic = UNItoGB( ic, &cset ); break;
      case EUC_JAPAN: ic = UNItoJIS( ic, &cset ); break;
      case EUC_KOREA: ic = UNItoKSC( ic, &cset ); break;
      case EUC_TAIWAN:ic = UNItoCNS( ic, &cset ); break;
      default: ic = UNItoJIS( ic, &cset );
      }
    }
#endif /* MSDOS */
    if( cset < PSEUDO ){
      if( g0 == cset ){
	if( TRUE == iTable[ (int)cset ].multi ){
	  EncodeAddChar( attr, MakeByte1( ic ) );
	  EncodeAddChar( attr, MakeByte2( ic ) );
	} else {
	  EncodeAddChar( attr, ic );
	}
	continue;
      } else if( C6226 == cset && EUC_JAPAN == codingSystem ){
	/* Japanese alternative g1 set */
      } else if( g1 == cset ){
      } else if( EUC_TAIWAN == codingSystem
		&& ( cset >= CNS_2 && cset <= CNS_7 ) ){
	EncodeAddChar( attr, SS2 );
	EncodeAddChar( attr, ( cset - CNS_1 ) + 0xa1 );
      } else if( g2 == cset ){
	EncodeAddChar( attr, SS2 );
      } else if( g3 == cset ){
	EncodeAddChar( attr, SS3 );
      } else {
        if( FALSE == EncodeAddInvalid( attr, ic, cset ) )
          break;
        else
          continue;
      }
      if( TRUE == iTable[ (int)cset ].multi ){
	EncodeAddChar( attr, 0x80 | MakeByte1( ic ) );
	EncodeAddChar( attr, 0x80 | MakeByte2( ic ) );
      } else {
	EncodeAddChar( attr, 0x80 | ic );
      }
    } else if( FALSE == EncodeAddPseudo( attr, ic, cset, binary ) ){
      break;
    }
  }
}