Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/charset.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10760 - (hide annotations) (download) (as text)
Mon Jun 12 15:20:40 2023 UTC (9 months, 4 weeks ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/charset.c
File MIME type: text/x-csrc
File size: 17449 byte(s)
各モジュール間APIをUnicode版のみを使用するようにした

- buffer.c 内 BuffPutChar() -> BuffPutUnicode()
- vtterm.c 内 PutChar() -> PutU32()
1 zmatsuo 10755 /*
2     * (C) 2023- TeraTerm Project
3     * All rights reserved.
4     *
5     * Redistribution and use in source and binary forms, with or without
6     * modification, are permitted provided that the following conditions
7     * are met:
8     *
9     * 1. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     * 2. Redistributions in binary form must reproduce the above copyright
12     * notice, this list of conditions and the following disclaimer in the
13     * documentation and/or other materials provided with the distribution.
14     * 3. The name of the author may not be used to endorse or promote products
15     * derived from this software without specific prior written permission.
16     *
17     * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27     */
28    
29     #include "teraterm.h"
30     #include "tttypes.h"
31     #include <stdio.h>
32     #include <string.h>
33     #if !defined(_CRTDBG_MAP_ALLOC)
34     #define _CRTDBG_MAP_ALLOC
35     #endif
36     #include <stdlib.h>
37     #include <crtdbg.h>
38     #include <assert.h>
39    
40     #include "buffer.h" // for Wrap
41     #include "ttwinman.h"
42     #include "codeconv.h"
43     #include "unicode.h"
44     #include "language.h" // for JIS2SJIS()
45    
46     #include "charset.h"
47    
48     static BOOL KanjiIn; // TRUE = MBCS��1byte�������M��������
49     static BOOL EUCkanaIn, EUCsupIn;
50     static int EUCcount;
51     #if 0
52     static BOOL Special;
53     #endif
54    
55     /* GL for single shift 2/3 */
56     static int GLtmp;
57     /* single shift 2/3 flag */
58     static BOOL SSflag;
59     /* JIS -> SJIS conversion flag */
60     static BOOL ConvJIS;
61     static WORD Kanji;
62     BOOL Fallbacked;
63    
64     typedef struct {
65     /* GL, GR code group */
66     int Glr[2];
67     /* G0, G1, G2, G3 code group */
68     int Gn[4];
69     } VttermKanjiWork;
70    
71     static VttermKanjiWork KanjiWork;
72    
73 zmatsuo 10760 // Unicode�x�[�X����������
74     static void PutChar(BYTE b)
75     {
76     PutU32(b);
77     }
78 zmatsuo 10755
79     /**
80     * ISO2022�p���[�N������������
81     */
82     static void CharSetInit2(VttermKanjiWork *w)
83     {
84     if (ts.Language==IdJapanese) {
85     w->Gn[0] = IdASCII;
86     w->Gn[1] = IdKatakana;
87     w->Gn[2] = IdKatakana;
88     w->Gn[3] = IdKanji;
89     w->Glr[0] = 0;
90     if ((ts.KanjiCode==IdJIS) && (ts.JIS7Katakana==0))
91     w->Glr[1] = 2; // 8-bit katakana
92     else
93     w->Glr[1] = 3;
94     }
95     else {
96     w->Gn[0] = IdASCII;
97     w->Gn[1] = IdSpecial;
98     w->Gn[2] = IdASCII;
99     w->Gn[3] = IdASCII;
100     w->Glr[0] = 0;
101     w->Glr[1] = 0;
102     }
103     }
104    
105     /**
106     * �������A���[�N������������
107     */
108     void CharSetInit(void)
109     {
110     CharSetInit2(&KanjiWork);
111     SSflag = FALSE;
112    
113     KanjiIn = FALSE;
114     EUCkanaIn = FALSE;
115     EUCsupIn = FALSE;
116     ConvJIS = FALSE;
117     Fallbacked = FALSE;
118     }
119    
120     /**
121     * 1byte���`�F�b�N
122     */
123     static BOOL CheckFirstByte(BYTE b, int lang, int kanji_code)
124     {
125     switch (lang) {
126     case IdKorean:
127     return __ismbblead(b, 51949);
128     case IdChinese:
129     if (kanji_code == IdCnGB2312) {
130     return __ismbblead(b, 936);
131     }
132     else if (ts.KanjiCode == IdCnBig5) {
133     return __ismbblead(b, 950);
134     }
135     break;
136     default:
137     assert(FALSE);
138     break;
139     }
140     assert(FALSE);
141     return FALSE;
142     }
143     /**
144     * ts.Language == IdJapanese ��
145     * 1byte���`�F�b�N
146     */
147     static BOOL CheckKanji(BYTE b)
148     {
149     VttermKanjiWork *w = &KanjiWork;
150     BOOL Check;
151    
152     if (ts.Language!=IdJapanese)
153     return FALSE;
154    
155     ConvJIS = FALSE;
156    
157     if (ts.KanjiCode==IdSJIS ||
158     (ts.FallbackToCP932 && ts.KanjiCode==IdUTF8)) {
159 zmatsuo 10759 if (((0x80<b) && (b<0xa0)) || ((0xdf<b) && (b<0xfd))) {
160 zmatsuo 10755 Fallbacked = TRUE;
161     return TRUE; // SJIS kanji
162     }
163     if ((0xa1<=b) && (b<=0xdf)) {
164     return FALSE; // SJIS katakana
165     }
166     }
167    
168     if ((b>=0x21) && (b<=0x7e)) {
169     Check = (w->Gn[w->Glr[0]] == IdKanji);
170     ConvJIS = Check;
171     }
172     else if ((b>=0xA1) && (b<=0xFE)) {
173     Check = (w->Gn[w->Glr[1]] == IdKanji);
174     if (ts.KanjiCode==IdEUC) {
175     Check = TRUE;
176     }
177     else if (ts.KanjiCode==IdJIS && ((ts.TermFlag & TF_FIXEDJIS)!=0) && (ts.JIS7Katakana==0)) {
178     Check = FALSE; // 8-bit katakana
179     }
180     ConvJIS = Check;
181     }
182     else {
183     Check = FALSE;
184     }
185    
186     return Check;
187     }
188    
189     static BOOL ParseFirstJP(BYTE b)
190     // returns TRUE if b is processed
191     // (actually allways returns TRUE)
192     {
193     VttermKanjiWork *w = &KanjiWork;
194     if (KanjiIn) {
195 zmatsuo 10759 if (((! ConvJIS) && (0x3F<b) && (b<0xFD)) ||
196     (ConvJIS && ( ((0x20<b) && (b<0x7f)) ||
197     ((0xa0<b) && (b<0xff)) )) )
198 zmatsuo 10755 {
199 zmatsuo 10758 unsigned long u32;
200     Kanji = Kanji + b;
201     if (ConvJIS) {
202     // JIS -> Shift_JIS(CP932)
203     Kanji = JIS2SJIS((WORD)(Kanji & 0x7f7f));
204     }
205     u32 = CP932ToUTF32(Kanji);
206     PutU32(u32);
207 zmatsuo 10755 KanjiIn = FALSE;
208     return TRUE;
209     }
210     else if ((ts.TermFlag & TF_CTRLINKANJI)==0) {
211     KanjiIn = FALSE;
212     }
213     else if ((b==CR) && Wrap) {
214     CarriageReturn(FALSE);
215     LineFeed(LF,FALSE);
216     Wrap = FALSE;
217     }
218     }
219    
220     if (SSflag) {
221     if (w->Gn[GLtmp] == IdKanji) {
222     Kanji = b << 8;
223     KanjiIn = TRUE;
224     SSflag = FALSE;
225     return TRUE;
226     }
227     else if (w->Gn[GLtmp] == IdKatakana) {
228     b = b | 0x80;
229     }
230    
231     PutChar(b);
232     SSflag = FALSE;
233     return TRUE;
234     }
235    
236     if ((!EUCsupIn) && (!EUCkanaIn) && (!KanjiIn) && CheckKanji(b)) {
237     Kanji = b << 8;
238     KanjiIn = TRUE;
239     return TRUE;
240     }
241    
242     if (b<=US) {
243     ParseControl(b);
244     }
245     else if (b==0x20) {
246     PutChar(b);
247     }
248     else if ((b>=0x21) && (b<=0x7E)) {
249     if (EUCsupIn) {
250     EUCcount--;
251     EUCsupIn = (EUCcount==0);
252     return TRUE;
253     }
254    
255     if ((w->Gn[w->Glr[0]] == IdKatakana) || EUCkanaIn) {
256     b = b | 0x80;
257     EUCkanaIn = FALSE;
258     {
259     // b��sjis�����p�J�^�J�i
260     unsigned long u32 = CP932ToUTF32(b);
261     PutU32(u32);
262     }
263     return TRUE;
264     }
265     PutChar(b);
266     }
267     else if (b==0x7f) {
268     return TRUE;
269     }
270     else if ((b>=0x80) && (b<=0x8D)) {
271     ParseControl(b);
272     }
273     else if (b==0x8E) { // SS2
274     switch (ts.KanjiCode) {
275     case IdEUC:
276     if (ts.ISO2022Flag & ISO2022_SS2) {
277     EUCkanaIn = TRUE;
278     }
279     break;
280     case IdUTF8:
281     PutChar('?');
282     break;
283     default:
284     ParseControl(b);
285     }
286     }
287     else if (b==0x8F) { // SS3
288     switch (ts.KanjiCode) {
289     case IdEUC:
290     if (ts.ISO2022Flag & ISO2022_SS3) {
291     EUCcount = 2;
292     EUCsupIn = TRUE;
293     }
294     break;
295     case IdUTF8:
296     PutChar('?');
297     break;
298     default:
299     ParseControl(b);
300     }
301     }
302     else if ((b>=0x90) && (b<=0x9F)) {
303     ParseControl(b);
304     }
305     else if (b==0xA0) {
306     PutChar(0x20);
307     }
308     else if ((b>=0xA1) && (b<=0xFE)) {
309     if (EUCsupIn) {
310     EUCcount--;
311     EUCsupIn = (EUCcount==0);
312     return TRUE;
313     }
314    
315     if ((w->Gn[w->Glr[1]] != IdASCII) ||
316 zmatsuo 10759 ((ts.KanjiCode==IdEUC) && EUCkanaIn) ||
317 zmatsuo 10755 (ts.KanjiCode==IdSJIS) ||
318 zmatsuo 10759 ((ts.KanjiCode==IdJIS) &&
319     (ts.JIS7Katakana==0) &&
320     ((ts.TermFlag & TF_FIXEDJIS)!=0))) {
321 zmatsuo 10755 // b��sjis�����p�J�^�J�i
322     unsigned long u32 = CP932ToUTF32(b);
323     PutU32(u32);
324     } else {
325     if (w->Gn[w->Glr[1]] == IdASCII) {
326     b = b & 0x7f;
327     }
328     PutChar(b);
329     }
330     EUCkanaIn = FALSE;
331     }
332     else {
333     PutChar(b);
334     }
335    
336     return TRUE;
337     }
338    
339     static BOOL ParseFirstKR(BYTE b)
340     // returns TRUE if b is processed
341     // (actually allways returns TRUE)
342     {
343     VttermKanjiWork *w = &KanjiWork;
344     if (KanjiIn) {
345 zmatsuo 10759 if (((0x41<=b) && (b<=0x5A)) ||
346     ((0x61<=b) && (b<=0x7A)) ||
347     ((0x81<=b) && (b<=0xFE)))
348 zmatsuo 10755 {
349 zmatsuo 10758 unsigned long u32 = 0;
350     if (ts.KanjiCode == IdKoreanCP51949) {
351     // CP51949
352     Kanji = Kanji + b;
353     u32 = MBCP_UTF32(Kanji, 51949);
354     }
355     else {
356     assert(FALSE);
357     }
358     PutU32(u32);
359 zmatsuo 10755 KanjiIn = FALSE;
360     return TRUE;
361     }
362     else if ((ts.TermFlag & TF_CTRLINKANJI)==0) {
363     KanjiIn = FALSE;
364     }
365     else if ((b==CR) && Wrap) {
366     CarriageReturn(FALSE);
367     LineFeed(LF,FALSE);
368     Wrap = FALSE;
369     }
370     }
371    
372     if ((!KanjiIn) && CheckFirstByte(b, ts.Language, ts.KanjiCode)) {
373     Kanji = b << 8;
374     KanjiIn = TRUE;
375     return TRUE;
376     }
377    
378     if (b<=US) {
379     ParseControl(b);
380     }
381     else if (b==0x20) {
382     PutChar(b);
383     }
384     else if ((b>=0x21) && (b<=0x7E)) {
385     // if (Gn[Glr[0]] == IdKatakana) {
386     // b = b | 0x80;
387     // }
388     PutChar(b);
389     }
390     else if (b==0x7f) {
391     return TRUE;
392     }
393     else if ((0x80<=b) && (b<=0x9F)) {
394     ParseControl(b);
395     }
396     else if (b==0xA0) {
397     PutChar(0x20);
398     }
399     else if ((b>=0xA1) && (b<=0xFE)) {
400     if (w->Gn[w->Glr[1]] == IdASCII) {
401     b = b & 0x7f;
402     }
403     PutChar(b);
404     }
405     else {
406     PutChar(b);
407     }
408    
409     return TRUE;
410     }
411    
412     static BOOL ParseFirstCn(BYTE b)
413     // returns TRUE if b is processed
414     // (actually allways returns TRUE)
415     {
416     VttermKanjiWork *w = &KanjiWork;
417     if (KanjiIn) {
418     // TODO
419 zmatsuo 10759 if (((0x40<=b) && (b<=0x7e)) ||
420     ((0xa1<=b) && (b<=0xFE)))
421 zmatsuo 10755 {
422 zmatsuo 10758 unsigned long u32 = 0;
423     Kanji = Kanji + b;
424     if (ts.KanjiCode == IdCnGB2312) {
425     // CP936 GB2312
426     u32 = MBCP_UTF32(Kanji, 936);
427     }
428     else if (ts.KanjiCode == IdCnBig5) {
429     // CP950 Big5
430     u32 = MBCP_UTF32(Kanji, 950);
431     }
432     else {
433     assert(FALSE);
434     }
435     PutU32(u32);
436 zmatsuo 10755 KanjiIn = FALSE;
437     return TRUE;
438     }
439     else if ((ts.TermFlag & TF_CTRLINKANJI)==0) {
440     KanjiIn = FALSE;
441     }
442     else if ((b==CR) && Wrap) {
443     CarriageReturn(FALSE);
444     LineFeed(LF,FALSE);
445     Wrap = FALSE;
446     }
447     }
448    
449     if ((!KanjiIn) && CheckFirstByte(b, ts.Language, ts.KanjiCode)) {
450     Kanji = b << 8;
451     KanjiIn = TRUE;
452     return TRUE;
453     }
454    
455     if (b<=US) {
456     ParseControl(b);
457     }
458     else if (b==0x20) {
459     PutChar(b);
460     }
461     else if ((b>=0x21) && (b<=0x7E)) {
462     // if (Gn[Glr[0]] == IdKatakana) {
463     // b = b | 0x80;
464     // }
465     PutChar(b);
466     }
467     else if (b==0x7f) {
468     return TRUE;
469     }
470     else if ((0x80<=b) && (b<=0x9F)) {
471     ParseControl(b);
472     }
473     else if (b==0xA0) {
474     PutChar(0x20);
475     }
476     else if ((b>=0xA1) && (b<=0xFE)) {
477     if (w->Gn[w->Glr[1]] == IdASCII) {
478     b = b & 0x7f;
479     }
480     PutChar(b);
481     }
482     else {
483     PutChar(b);
484     }
485    
486     return TRUE;
487     }
488    
489     static void ParseASCII(BYTE b)
490     {
491     if (SSflag) {
492     PutChar(b);
493     SSflag = FALSE;
494     return;
495     }
496    
497     if (b<=US) {
498     ParseControl(b);
499     } else if ((b>=0x20) && (b<=0x7E)) {
500 zmatsuo 10760 PutU32(b);
501 zmatsuo 10755 } else if ((b==0x8E) || (b==0x8F)) {
502     PutChar('?');
503     } else if ((b>=0x80) && (b<=0x9F)) {
504     ParseControl(b);
505     } else if (b>=0xA0) {
506 zmatsuo 10760 PutU32(b);
507 zmatsuo 10755 }
508     }
509    
510     // UTF-8�����M�f�[�^����������
511     // returns TRUE if b is processed
512     // (actually allways returns TRUE)
513     static BOOL ParseFirstUTF8(BYTE b)
514     {
515     static BYTE buf[4];
516     static int count = 0;
517    
518     unsigned int code;
519     int i;
520    
521     if (ts.FallbackToCP932 && Fallbacked) {
522     return ParseFirstJP(b);
523     }
524    
525     // UTF-8�G���R�[�h
526     // Unicode 1byte, 2byte, 3byte, 4byte
527     // U+0000 ... U+007f 0x00 .. 0x7f
528     // U+0080 ... U+07ff 0xc2 .. 0xdf, 0x80 .. 0xbf
529     // U+0800 ... U+ffff 0xe0 .. 0xef, 0x80 .. 0xbf, 0x80 .. 0xbf
530     // U+10000 ... U+10ffff 0xf0 .. 0xf4, 0x80 .. 0xbf, 0x80 .. 0xbf, 0x80 .. 0xbf
531     // UTF-8���f�R�[�h������������
532     // - 1byte��
533     // - C1(0x80 - 0x9f)
534     // - 0xa0 - 0xc1
535     // - 0xf5 - 0xff
536     // - 2byte�����~
537     // - 0x00 - 0x7f
538     // - 0xc0 - 0xff
539    
540     // 1byte(7bit)
541     if (count == 0) {
542     if ((b & 0x80) == 0x00) {
543     // 1byte(7bit)
544     // 0x7f����, �������A���������o��
545     ParseASCII(b);
546     return TRUE;
547     }
548     if ((b & 0x40) == 0x00 || b >= 0xf6 ) {
549     // UTF-8��1byte���o���������R�[�h�������A���������o��
550     // 0x40 = 0b1011_1111, 0b10xx_xxxx������bit�p�^�[��������������
551     // 0xf6 ���������� U+10FFFF��������������
552     PutU32(b);
553     return TRUE;
554     }
555     // 1byte������
556     buf[count++] = b;
557     return TRUE;
558     }
559    
560     // 2byte(11bit)
561     if ((buf[0] & 0xe0) == 0xc0) {
562     code = 0;
563     if((b & 0xc0) == 0x80) {
564     // 5bit + 6bit
565     code = ((buf[0] & 0x1f) << 6) | (b & 0x3f);
566     if (code < 0x80) {
567     // 11bit�g����7bit���������AUTF-8���������\��
568     code = 0;
569     }
570     }
571     if (code == 0){
572     // ���������o��
573     PutU32(buf[0]);
574     PutU32(b);
575     count = 0;
576     return TRUE;
577     }
578     else {
579     PutU32(code);
580     count = 0;
581     return TRUE;
582     }
583     }
584    
585     // 2byte�����~����
586     buf[count++] = b;
587    
588     // 3byte(16bit)
589     if ((buf[0] & 0xf0) == 0xe0) {
590     if(count < 3) {
591     return TRUE;
592     }
593     code = 0;
594     if ((buf[1] & 0xc0) == 0x80 && (buf[2] & 0xc0) == 0x80) {
595     // 4bit + 6bit + 6bit
596     code = ((buf[0] & 0xf) << 12);
597     code |= ((buf[1] & 0x3f) << 6);
598     code |= ((buf[2] & 0x3f));
599     if (code < 0x800) {
600     // 16bit�g����11bit�����������AUTF-8���������\��
601     code = 0;
602     }
603     }
604     if (code == 0) {
605     // ���������o��
606     PutU32(buf[0]);
607     PutU32(buf[1]);
608     PutU32(buf[2]);
609     count = 0;
610     return TRUE;
611     } else {
612     PutU32(code);
613     count = 0;
614     return TRUE;
615     }
616     }
617    
618     // 4byte(21bit)
619     if ((buf[0] & 0xf8) == 0xf0) {
620     if(count < 4) {
621     return TRUE;
622     }
623     code = 0;
624     if ((buf[1] & 0xc0) == 0x80 && (buf[2] & 0xc0) == 0x80 && (buf[3] & 0xc0) == 0x80) {
625     // 3bit + 6bit + 6bit + 6bit
626     code = ((buf[0] & 0x07) << 18);
627     code |= ((buf[1] & 0x3f) << 12);
628     code |= ((buf[2] & 0x3f) << 6);
629     code |= (buf[3] & 0x3f);
630     if (code < 0x10000) {
631     // 21bit�g����16bit�����������AUTF-8���������\��
632     code = 0;
633     }
634     }
635     if (code == 0) {
636     // ���������o��
637     PutU32(buf[0]);
638     PutU32(buf[1]);
639     PutU32(buf[2]);
640     PutU32(buf[3]);
641     count = 0;
642     return TRUE;
643     } else {
644     PutU32(code);
645     count = 0;
646     return TRUE;
647     }
648     }
649    
650     // ��������������
651     assert(FALSE);
652    
653     for (i = 0; i < count; i++) {
654     ParseASCII(buf[i]);
655     }
656     count = 0;
657     return TRUE;
658     }
659    
660     static BOOL ParseFirstRus(BYTE b)
661     // returns if b is processed
662     {
663 zmatsuo 10756 // CP1251������
664     BYTE c = RussConv(ts.KanjiCode, IdWindows, b);
665     // CP1251->Unicode
666     unsigned long u32 = MBCP_UTF32(c, 1251);
667     PutU32(u32);
668     return TRUE;
669 zmatsuo 10755 }
670    
671     static BOOL ParseEnglish(BYTE b)
672     {
673     unsigned short u16 = 0;
674     int part = KanjiCodeToISO8859Part(ts.KanjiCode);
675     int r = UnicodeFromISO8859(part, b, &u16);
676     if (r == 0) {
677     return FALSE;
678     }
679     if (u16 < 0x100) {
680     ParseASCII((BYTE)u16);
681     }
682     else {
683     PutU32(u16);
684     }
685     return TRUE;
686     }
687    
688     void ParseFirst(BYTE b) {
689     switch (ts.Language) {
690     case IdUtf8:
691     ParseFirstUTF8(b);
692     return;
693    
694     case IdJapanese:
695     switch (ts.KanjiCode) {
696     case IdUTF8:
697     if (ParseFirstUTF8(b)) {
698     return;
699     }
700     break;
701     default:
702     if (ParseFirstJP(b)) {
703     return;
704     }
705     }
706     break;
707    
708     case IdKorean:
709     switch (ts.KanjiCode) {
710     case IdUTF8:
711     if (ParseFirstUTF8(b)) {
712     return;
713     }
714     break;
715     default:
716     if (ParseFirstKR(b)) {
717     return;
718     }
719     }
720     break;
721    
722     case IdRussian:
723     if (ParseFirstRus(b)) {
724     return;
725     }
726     break;
727    
728     case IdChinese:
729     switch (ts.KanjiCode) {
730     case IdUTF8:
731     if (ParseFirstUTF8(b)) {
732     return;
733     }
734     break;
735     default:
736     if (ParseFirstCn(b)) {
737     return;
738     }
739     }
740     break;
741     case IdEnglish: {
742     if (ParseEnglish(b)) {
743     return;
744     }
745     break;
746     }
747     }
748    
749     if (SSflag) {
750     PutChar(b);
751     SSflag = FALSE;
752     return;
753     }
754    
755     if (b<=US)
756     ParseControl(b);
757     else if ((b>=0x20) && (b<=0x7E))
758     PutChar(b);
759     else if ((b>=0x80) && (b<=0x9F))
760     ParseControl(b);
761     else if (b>=0xA0)
762     PutChar(b);
763     }
764    
765     /**
766     * �w��(Designate)
767     *
768     * @param Gn 0/1/2/3 = G0/G1/G2/G3
769     * @param codeset IdASCII 0
770     * IdKatakana 1
771     * IdKanji 2
772     * IdSpecial 3
773     */
774     void CharSet2022Designate(int gn, int cs)
775     {
776     VttermKanjiWork *w = &KanjiWork;
777     w->Gn[gn] = cs;
778     }
779    
780     /**
781     * �����o��(Invoke)
782     * @param glr 0/1 = GL/GR (Locking shift�������L��)
783     * @param gn 0/1/2/3 = G0/G1/G2/G3
784     * @param single_shift FALSE Locking shift
785     * TRUE Single shift
786     */
787     void CharSet2022Invoke(int glr, int gn, BOOL single_shift)
788     {
789     VttermKanjiWork *w = &KanjiWork;
790     if (single_shift == FALSE) {
791     // Locking shift
792     w->Glr[glr] = gn;
793     }
794     else {
795     // Single shift
796     GLtmp = gn;
797     SSflag = TRUE;
798     }
799     }
800    
801     /**
802     * DEC�����t�H���g(Tera Special font)
803     * 0140(0x60) ... 0176(0x7f) ���r�����A�T�C������������
804 zmatsuo 10760 * (0xe0) ... (0xff) ��?
805 zmatsuo 10755 * <ESC>(0 �������������G�X�P�[�v�V�[�P���X�����`
806     * about/emulations.html
807     *
808     * @param b �R�[�h
809 zmatsuo 10760 * @retval TRUE IdSpecial
810     * @retval FALSE IdSpecial��������
811 zmatsuo 10755 */
812     BOOL CharSetIsSpecial(BYTE b)
813     {
814     VttermKanjiWork *w = &KanjiWork;
815     BOOL SpecialNew = FALSE;
816    
817     if ((b>0x5F) && (b<0x80)) {
818     if (SSflag)
819     SpecialNew = (w->Gn[GLtmp]==IdSpecial);
820     else
821     SpecialNew = (w->Gn[w->Glr[0]]==IdSpecial);
822     }
823     else if (b>0xDF) {
824     if (SSflag)
825     SpecialNew = (w->Gn[GLtmp]==IdSpecial);
826     else
827     SpecialNew = (w->Gn[w->Glr[1]]==IdSpecial);
828     }
829    
830     return SpecialNew;
831     }
832    
833     static void CharSetSaveStateLow(CharSetState *state, const VttermKanjiWork *w)
834     {
835     int i;
836     state->infos[0] = w->Glr[0];
837     state->infos[1] = w->Glr[1];
838     for (i=0 ; i<=3; i++) {
839     state->infos[2 + i] = w->Gn[i];
840     }
841     }
842    
843     /**
844     * ��������������
845     */
846     void CharSetSaveState(CharSetState *state)
847     {
848     VttermKanjiWork *w = &KanjiWork;
849     CharSetSaveStateLow(state, w);
850     }
851    
852     /**
853     * ���������A����
854     */
855     void CharSetLoadState(const CharSetState *state)
856     {
857     VttermKanjiWork *w = &KanjiWork;
858     int i;
859     w->Glr[0] = state->infos[0];
860     w->Glr[1] = state->infos[1];
861     for (i=0 ; i<=3; i++) {
862     w->Gn[i] = state->infos[2 + i];
863     }
864     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26