9 /**********************************************************************
13 **********************************************************************/
14 extern void (*outascii
)(), (*outkanji
)(), (*outgaiji
)(), (*outkana
)();
16 /*---------------------------------------------------------------------
19 ---------------------------------------------------------------------*/
20 void Kcc_outsjis(ddd
, c1
, c2
)
26 c
= c1
* 2 - (c1
<= 0x9f ? 0x00e1 : (c1
< 0xf0 ? 0x0161 : 0x01bf));
28 c2
= c2
- (c2
> 0x7f ? 0x20 : 0x1f);
33 (*(c1
<= 0xef ? outkanji
: outgaiji
))(ddd
, c
, c2
);
36 /*---------------------------------------------------------------------
39 ---------------------------------------------------------------------*/
40 unsigned Kcc_out(ddd
, str
, len
, code
, outcode
, inmode
, insi
, inso
, innj
, ingj
)
43 register unsigned code
;
45 unsigned long *insi
, *inso
, *innj
, *ingj
;
51 for (s
= str
; s
< str
+ len
; s
+= i
) {
53 switch (*(u_char
*) s
) {
57 if (Kcc_compare("$B", s
+ 1) || Kcc_compare("$@", s
+ 1)) {
58 *inmode
= M_KANJI
; /* kanji */
59 *insi
|= bitflag(((u_char
*) s
)[2]);
61 } else if (Kcc_compare("&@\033$B", s
+ 1)) {
62 *inmode
= M_KANJI
; /* kanji 1990 */
63 *innj
|= bitflag('B');
65 } else if (Kcc_compare("(B", s
+ 1) || Kcc_compare("(J", s
+ 1) ||
66 Kcc_compare("(H", s
+ 1)) {
67 *inmode
= M_ASCII
; /* kanji end */
68 *inso
|= bitflag(((u_char
*) s
)[2]);
70 } else if (Kcc_compare("(I", s
+ 1)) {
71 *inmode
= M_ESCI
; /* "ESC(I" */
72 *inso
|= bitflag('I');
74 } else if (Kcc_compare("$(D", s
+ 1)) {
75 *inmode
= M_GAIJI
; /* gaiji */
76 *ingj
|= bitflag('D');
83 if (*inmode
== M_ASCII
) {
90 if (*inmode
== M_SO
) {
96 if (*inmode
!= M_ASCII
) {
97 if (0x20 < ((u_char
*) s
)[0] && ((u_char
*) s
)[0] < 0x7f)
100 (*outkanji
)(ddd
, ((u_char
*) s
)[0], ((u_char
*) s
)[1] & 0x7f);
104 (*outgaiji
)(ddd
, ((u_char
*) s
)[0], ((u_char
*) s
)[1] & 0x7f);
109 (*outkana
)(ddd
, ((u_char
*) s
)[0]);
114 } else if (((u_char
*) s
)[0] & 0x80) {
115 if (code
& (EUC
| DEC
)) {
119 if (0xa0 < ((u_char
*) s
)[0] &&
120 ((u_char
*) s
)[0] < 0xff) {
121 if (!(((u_char
*) s
)[1] & 0x80) && code
& DEC
) {
125 code
&= ~EUC
; /* definitely DEC */
126 (*outgaiji
)(ddd
, ((u_char
*) s
)[0] & 0x7f, ((u_char
*) s
)[1]);
129 * EUC code set 1 (kanji), DEC kanji:
131 (*outkanji
)(ddd
, ((u_char
*) s
)[0] & 0x7f, ((u_char
*) s
)[1] & 0x7f);
132 } else if (((u_char
*) s
)[0] == SS2
&& code
& EUC
&&
133 0xa0 < ((u_char
*) s
)[1] &&
134 ((u_char
*) s
)[1] < 0xff) {
136 * EUC code set 2 (hankaku kana):
138 code
&= ~DEC
; /* probably EUC */
139 (*outkana
)(ddd
, ((u_char
*) s
)[1] & 0x7f);
140 } else if (((u_char
*) s
)[0] == SS3
&& code
& EUC
&&
141 0xa0 < ((u_char
*) s
)[1] &&
142 ((u_char
*) s
)[1] < 0xff &&
143 0xa0 < ((u_char
*) s
)[2] &&
144 ((u_char
*) s
)[2] < 0xff) {
146 * EUC code set 3 (gaiji):
148 code
&= ~DEC
; /* probably EUC */
149 (*outgaiji
)(ddd
, ((u_char
*) s
)[1] & 0x7f, ((u_char
*) s
)[2] & 0x7f);
154 * Control character (C1):
156 if (outcode
!= SJIS
&& (outcode
!= EUC
||
157 (((u_char
*) s
)[0] != SS2
&&
158 ((u_char
*) s
)[0] != SS3
)))
159 **ddd
= ((u_char
*) s
)[0]; (*ddd
)++;
164 } else if (code
& (SJIS
| JIS8
)) {
168 if (!(code
& SJIS
) || (0xa0 < ((u_char
*) s
)[0] &&
169 ((u_char
*) s
)[0] < 0xe0))
173 (*outkana
)(ddd
, ((u_char
*) s
)[0] & 0x7f);
178 code
&= ~JIS8
; /* definitely shift-JIS */
179 Kcc_outsjis(ddd
, ((u_char
*) s
)[0], ((u_char
*) s
)[1]);
185 (*outascii
)(ddd
, ((u_char
*) s
)[0]);