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 10759 - (hide annotations) (download) (as text)
Mon Jun 12 15:20:30 2023 UTC (9 months, 4 weeks ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/charset.c
File MIME type: text/x-csrc
File size: 17345 byte(s)
コンパイル時警告が出ないよう修正

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

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