4
* All rights reserved. Copyright (C) 1996 by NARITA Tomio.
5
* $Id: shiftjis.c,v 1.6 2003/11/13 03:08:19 nrt Exp $
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
private void msk2jis( byte *c )
40
c1 = ( c1 << 1 ) - 0x0160; /* 63-94 ku */
42
c1 = ( c1 << 1 ) - 0x00e0; /* 01-62 ku */
45
c2 -= 0x007e; /* even ku */
58
public void DecodeShiftJis( state_t *state, byte codingSystem )
61
byte c[ ICHAR_WIDTH ];
67
if( FALSE == DecodeEscape( state ) )
70
DecodeAddTab( state->attr );
71
else if( SO == ch ) /* LS1 for 8bit */
72
state->gset[ GL ] = G1;
73
else if( SI == ch ) /* LS0 for 8bit */
74
state->gset[ GL ] = G0;
78
DecodeAddControl( ch );
80
if( NULL != state->sset ){
81
if( FALSE == DecodeAddShifted( state, ch ) )
85
} else if( 0x80 & ch ){
86
if( IsShiftJisByte1( ch ) ){
92
if( !IsGraphicChar94( c[ 0 ] ) || !IsGraphicChar94( c[ 1 ] ) ){
93
DecodeAddControl( ch );
96
} else if( IsKatakana( 0x7f & ch ) ){
100
DecodeAddControl( ch );
107
charset = CSET( G0 );
108
if( !IsGraphicChar( charset, ch ) ){
110
DecodeAddSpace( state->attr );
112
DecodeAddControl( ch );
115
} else if( X0201KANA == charset && !IsKatakana( ch ) ){
116
DecodeAddControl( ch );
120
if( TRUE == iTable[ (int)charset ].multi ){
123
if( !IsGraphicChar( charset, ch ) )
128
DecodeAddChar( charset, c, state->attr );
133
private void jis2msk( byte *c )
140
if( 0 == ( c1 & 0x0001 ) )
141
c2 += 0x007e; /* even ku */
143
if( c2 >= 0x0060 ) /* odd ku */
150
c1 = ( ( c1 - 0x005f ) >> 1 ) + 0x00e0; /* 63-94 ku */
152
c1 = ( ( c1 - 0x0021 ) >> 1 ) + 0x0081; /* 01-62 ku */
158
public void EncodeShiftJis( i_str_t *istr, int head, int tail,
159
byte codingSystem, boolean_t binary )
165
for( idx = head ; idx < tail ; idx++ ){
166
cset = istr[ idx ].charset;
168
attr = (int)istr[ idx ].attr << 8;
169
#ifndef MSDOS /* IF NOT DEFINED */
170
if( UNICODE == cset )
171
ic = UNItoJIS( ic, &cset );
175
EncodeAddChar( attr, ic );
176
} else if( X0208 == cset || C6226 == cset ){
177
sj[ 0 ] = MakeByte1( ic );
178
sj[ 1 ] = MakeByte2( ic );
180
EncodeAddChar( attr, sj[ 0 ] );
181
EncodeAddChar( attr, sj[ 1 ] );
182
} else if( X0201KANA == cset ){
183
EncodeAddChar( attr, 0x80 | ic );
185
if( FALSE == EncodeAddInvalid( attr, ic, cset ) )
188
} else if( FALSE == EncodeAddPseudo( attr, ic, cset, binary ) ){