1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
/*
* Copyright 1999 Justsystem Corporation, Japan.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of Justsystem Corporation
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Justsystem
* Corporation makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Author: Atsushi Irisawa
*/
#ifndef lint
static char rcsid[] = "$Id: misc.c,v 1.2 1999/08/24 09:01:09 ishisone Exp $" ;
#endif /* !lint */
#include <Xatoklib.h>
/* Page */
/*
* [$B4X?tL>(B]
* wcs2euc( )
* [$BI=Bj(B]
* WCHAR $B7?$+$i(BEUC$BJ8;zNs$X$NJQ49(B
* [$B8F=P7A<0(B]
* int wcs2euc( wchar *wbuf, int wlen, unsigned char *euc )
*
* [$B0z?t(B]
* $B7?(B : $BL>(B $B>N(B : I O : $B@b(B $BL@(B
* wchar : *wbuf : i : WCHAR $B7?J8;zNs(B
* int : wlen : i : wchar $B7?J8;zNs$ND9$5(B
* unsigned char : *euc : o : EUC $BJ8;zNs3JG<NN0h(B
*
* [$BJV$jCM(B]
* EUC $BJ8;zNs$ND9$5(B
*
* [$B;HMQ4X?t(B]
* $B$J$7(B
* [$B5!G=(B]
* wchar $B7?J8;zNs$+$i(B unsigined char $B$N(BEUC$BJ8;zNs$KJQ49$9$k!#(B
*
*/
int wcs2euc(wbuf, wlen, euc)
wchar *wbuf;
int wlen;
unsigned char *euc;
{
int i ;
int n = 0 ;
unsigned char c ;
for( i = 0 ; i < wlen ; i++ ) {
c = ( *wbuf & 0xff00 ) >> 8 ;
if ( c ) {
*euc++ = c ;
n++ ;
}
else if (( *wbuf & 0xff ) & 0x80 ) {
*euc++ = 0x8e ;
n++ ;
}
*euc++ = *wbuf & 0xff ;
wbuf++ ;
n++ ;
}
*euc = 0 ;
return n ;
}
/* Page */
/*
* [$B4X?tL>(B]
* euc2wcs( )
* [$BI=Bj(B]
* EUC$BJ8;zNs$+$i(B wchar $B7?J8;zNs$X$NJQ49(B
* [$B8F=P7A<0(B]
* int euc2wcs( unsigned char *euc, int elen, wchar *wbuf )
*
* [$B0z?t(B]
* $B7?(B : $BL>(B $B>N(B : I O : $B@b(B $BL@(B
* unsigned char : *euc : i : EUC $BJ8;zNs(B
* int : elen : i : EUC $BJ8;zNs$ND9$5(B
* wchar : *wbuf : o : wchar $B7?J8;zNs3JG<NN0h(B
*
* [$BJV$jCM(B]
* 1 : $B>o$K#1(B
*
* [$B;HMQ4X?t(B]
* $B$J$7(B
* [$B5!G=(B]
* unsigined char $B7?$N(BEUC $BJ8;zNs$r(Bwchar $B7?$KJQ49$9$k!#(B
* EUC $BJ8;zNs$K$O!"(B0x8f $B$NFCJL$J%3!<%I$,4^$^$l$F$$$k$N$G(B
* wchar $B$KJQ49$9$k;~$K8DJL=hM}$r$9$k!#(B
*/
int euc2wcs(euc, elen, wbuf)
unsigned char *euc;
int elen;
wchar *wbuf;
{
int lb = 0, hb = 0 ;
int i ;
int n = 0 ;
int isSkip ;
for( i = 0 ; i < elen ; i++ ) {
isSkip = 0 ;
if ( *euc == 0x8e ) {
euc++ ;
hb = *euc ;
lb = 0 ;
i++ ;
}
else if ( *euc & 0x80 ) {
if ( *euc == 0x8f ) {
isSkip=1 ;
}
else {
lb = *euc ;
euc++ ;
hb = *euc ;
i++ ;
}
}
else {
hb = *euc ;
lb = 0 ;
}
euc++ ;
if ( !isSkip ) {
*wbuf = (( lb << 8 ) | hb ) & 0xffff ;
wbuf++ ;
n++ ;
}
}
*wbuf = 0 ;
return n ;
}
/* End of misc.c */
|