Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/vtterm.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2561 - (hide annotations) (download) (as text)
Mon Jul 14 08:15:10 2008 UTC (15 years, 9 months ago) by doda
Original Path: teraterm/trunk/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 69511 byte(s)
screenのVisual Bell用制御シーケンス<ESC>gを解釈するようにした。
ECMA-48やvt100,xtermのいずれの標準にも含まれないため、正式サポートとはしない。
なにか問題が出たら闇に葬ります。

1 maya 2476 /* Tera Term
2     Copyright(C) 1994-1998 T. Teranishi
3     All rights reserved. */
4    
5     /* TERATERM.EXE, VT terminal emulation */
6     #include "teraterm.h"
7     #include "tttypes.h"
8     #include <stdio.h>
9     #include <string.h>
10     #include <stdlib.h>
11     #include <mbstring.h>
12     #include <locale.h>
13    
14     #include "buffer.h"
15     #include "ttwinman.h"
16     #include "ttcommon.h"
17     #include "commlib.h"
18     #include "vtdisp.h"
19     #include "keyboard.h"
20     #include "ttlib.h"
21     #include "ttftypes.h"
22     #include "filesys.h"
23     #include "teraprn.h"
24     #include "telnet.h"
25    
26     #include "vtterm.h"
27    
28     /* Parsing modes */
29     #define ModeFirst 0
30     #define ModeESC 1
31     #define ModeDCS 2
32     #define ModeDCUserKey 3
33     #define ModeSOS 4
34     #define ModeCSI 5
35     #define ModeXS 6
36     #define ModeDLE 7
37     #define ModeCAN 8
38    
39     #define NParamMax 16
40     #define IntCharMax 5
41    
42 doda 2561 void VisualBell();
43 doda 2554
44 maya 2476 /* character attribute */
45     static TCharAttr CharAttr;
46    
47     /* various modes of VT emulation */
48     static BOOL RelativeOrgMode;
49     static BOOL ReverseColor;
50     static BOOL InsertMode;
51     static BOOL LFMode;
52     static BOOL AutoWrapMode;
53     static BOOL FocusReportMode;
54     int MouseReportMode;
55    
56     // save/restore cursor
57     typedef struct {
58     int CursorX, CursorY;
59     TCharAttr Attr;
60     int Glr[2], Gn[4]; // G0-G3, GL & GR
61     BOOL AutoWrapMode;
62     BOOL RelativeOrgMode;
63     } TStatusBuff;
64     typedef TStatusBuff *PStatusBuff;
65    
66     // status buffer for main screen & status line
67     static TStatusBuff SBuff1, SBuff2;
68    
69     static BOOL ESCFlag, JustAfterESC;
70     static BOOL KanjiIn;
71     static BOOL EUCkanaIn, EUCsupIn;
72     static int EUCcount;
73     static BOOL Special;
74    
75     static int Param[NParamMax+1];
76     static int NParam;
77     static BOOL FirstPrm;
78     static BYTE IntChar[IntCharMax+1];
79     static int ICount;
80     static BYTE Prv;
81     static int ParseMode, SavedMode;
82     static int ChangeEmu;
83    
84     /* user defined keys */
85     static BOOL WaitKeyId, WaitHi;
86    
87     /* GL, GR code group */
88     static int Glr[2];
89     /* G0, G1, G2, G3 code group */
90     static int Gn[4];
91     /* GL for single shift 2/3 */
92     static int GLtmp;
93     /* single shift 2/3 flag */
94     static BOOL SSflag;
95     /* JIS -> SJIS conversion flag */
96     static BOOL ConvJIS;
97     static WORD Kanji;
98    
99     // variables for status line mode
100     static int StatusX=0;
101     static BOOL StatusWrap=FALSE;
102     static BOOL StatusCursor=TRUE;
103     static int MainX, MainY; //cursor registers
104     static int MainTop, MainBottom; // scroll region registers
105     static BOOL MainWrap;
106     static BOOL MainCursor=TRUE;
107    
108     /* status for printer escape sequences */
109     static BOOL PrintEX = TRUE; // printing extent
110     // (TRUE: screen, FALSE: scroll region)
111     static BOOL AutoPrintMode = FALSE;
112     static BOOL PrinterMode = FALSE;
113     static BOOL DirectPrn = FALSE;
114    
115     /* User key */
116     static BYTE NewKeyStr[FuncKeyStrMax];
117     static int NewKeyId, NewKeyLen;
118    
119     static _locale_t CLocale;
120    
121     void ResetSBuffers()
122     {
123     SBuff1.CursorX = 0;
124     SBuff1.CursorY = 0;
125     SBuff1.Attr = DefCharAttr;
126     if (ts.Language==IdJapanese)
127     {
128     SBuff1.Gn[0] = IdASCII;
129     SBuff1.Gn[1] = IdKatakana;
130     SBuff1.Gn[2] = IdKatakana;
131     SBuff1.Gn[3] = IdKanji;
132     SBuff1.Glr[0] = 0;
133     if ((ts.KanjiCode==IdJIS) &&
134     (ts.JIS7Katakana==0))
135     SBuff1.Glr[1] = 2; // 8-bit katakana
136     else
137     SBuff1.Glr[1] = 3;
138     }
139     else {
140     SBuff1.Gn[0] = IdASCII;
141     SBuff1.Gn[1] = IdSpecial;
142     SBuff1.Gn[2] = IdASCII;
143     SBuff1.Gn[3] = IdASCII;
144     SBuff1.Glr[0] = 0;
145     SBuff1.Glr[1] = 0;
146     }
147     SBuff1.AutoWrapMode = TRUE;
148     SBuff1.RelativeOrgMode = FALSE;
149     // copy SBuff1 to SBuff2
150     SBuff2 = SBuff1;
151     }
152    
153     void ResetTerminal() /*reset variables but don't update screen */
154     {
155     DispReset();
156     BuffReset();
157    
158     /* Attribute */
159     CharAttr = DefCharAttr;
160     Special = FALSE;
161     BuffSetCurCharAttr(CharAttr);
162    
163     /* Various modes */
164     InsertMode = FALSE;
165     LFMode = (ts.CRSend == IdCRLF);
166     AutoWrapMode = TRUE;
167     AppliKeyMode = FALSE;
168     AppliCursorMode = FALSE;
169     RelativeOrgMode = FALSE;
170     ReverseColor = FALSE;
171     AutoRepeatMode = TRUE;
172     Send8BitMode = ts.Send8BitCtrl;
173     FocusReportMode = FALSE;
174     MouseReportMode = IdMouseTrackNone;
175    
176     CLocale = _create_locale(LC_ALL, "C");
177    
178     /* Character sets */
179     ResetCharSet();
180    
181     /* ESC flag for device control sequence */
182     ESCFlag = FALSE;
183     /* for TEK sequence */
184     JustAfterESC = FALSE;
185    
186     /* Parse mode */
187     ParseMode = ModeFirst;
188    
189     /* Clear printer mode */
190     PrinterMode = FALSE;
191    
192     // status buffers
193     ResetSBuffers();
194     }
195    
196     void ResetCharSet()
197     {
198     if (ts.Language==IdJapanese)
199     {
200     Gn[0] = IdASCII;
201     Gn[1] = IdKatakana;
202     Gn[2] = IdKatakana;
203     Gn[3] = IdKanji;
204     Glr[0] = 0;
205     if ((ts.KanjiCode==IdJIS) &&
206     (ts.JIS7Katakana==0))
207     Glr[1] = 2; // 8-bit katakana
208     else
209     Glr[1] = 3;
210     }
211     else {
212     Gn[0] = IdASCII;
213     Gn[1] = IdSpecial;
214     Gn[2] = IdASCII;
215     Gn[3] = IdASCII;
216     Glr[0] = 0;
217     Glr[1] = 0;
218     cv.SendCode = IdASCII;
219     cv.SendKanjiFlag = FALSE;
220     cv.EchoCode = IdASCII;
221     cv.EchoKanjiFlag = FALSE;
222     }
223     /* Kanji flag */
224     KanjiIn = FALSE;
225     EUCkanaIn = FALSE;
226     EUCsupIn = FALSE;
227     SSflag = FALSE;
228    
229     cv.Language = ts.Language;
230     cv.CRSend = ts.CRSend;
231     cv.KanjiCodeEcho = ts.KanjiCode;
232     cv.JIS7KatakanaEcho = ts.JIS7Katakana;
233     cv.KanjiCodeSend = ts.KanjiCodeSend;
234     cv.JIS7KatakanaSend = ts.JIS7KatakanaSend;
235     cv.KanjiIn = ts.KanjiIn;
236     cv.KanjiOut = ts.KanjiOut;
237     }
238    
239     void ResetKeypadMode(BOOL DisabledModeOnly)
240     {
241     if (!DisabledModeOnly || ts.DisableAppKeypad) AppliKeyMode = FALSE;
242     if (!DisabledModeOnly || ts.DisableAppCursor) AppliCursorMode = FALSE;
243     }
244    
245     void MoveToMainScreen()
246     {
247     StatusX = CursorX;
248     StatusWrap = Wrap;
249     StatusCursor = IsCaretEnabled();
250    
251     CursorTop = MainTop;
252     CursorBottom = MainBottom;
253     Wrap = MainWrap;
254     DispEnableCaret(MainCursor);
255     MoveCursor(MainX,MainY); // move to main screen
256     }
257    
258     void MoveToStatusLine()
259     {
260     MainX = CursorX;
261     MainY = CursorY;
262     MainTop = CursorTop;
263     MainBottom = CursorBottom;
264     MainWrap = Wrap;
265     MainCursor = IsCaretEnabled();
266    
267     DispEnableCaret(StatusCursor);
268     MoveCursor(StatusX,NumOfLines-1); // move to status line
269     CursorTop = NumOfLines-1;
270     CursorBottom = CursorTop;
271     Wrap = StatusWrap;
272     }
273    
274     void HideStatusLine()
275     {
276     if ((StatusLine>0) &&
277     (CursorY==NumOfLines-1))
278     MoveToMainScreen();
279     StatusX = 0;
280     StatusWrap = FALSE;
281     StatusCursor = TRUE;
282     ShowStatusLine(0); //hide
283     }
284    
285     void ChangeTerminalSize(int Nx, int Ny)
286     {
287     BuffChangeTerminalSize(Nx,Ny);
288     StatusX = 0;
289     MainX = 0;
290     MainY = 0;
291     MainTop = 0;
292     MainBottom = NumOfColumns-1;
293     }
294    
295     void BackSpace()
296     {
297     if (CursorX == 0)
298     {
299     if ((CursorY>0) &&
300     ((ts.TermFlag & TF_BACKWRAP)!=0))
301     {
302     MoveCursor(NumOfColumns-1,CursorY-1);
303     // if (cv.HLogBuf!=0) Log1Byte(BS);
304     // (2005.2.20 yutaka)
305     if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
306     }
307     }
308     else if (CursorX > 0)
309     {
310     MoveCursor(CursorX-1,CursorY);
311     // if (cv.HLogBuf!=0) Log1Byte(BS);
312     // (2005.2.20 yutaka)
313     if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
314     }
315     }
316    
317     void CarriageReturn(BOOL logFlag)
318     {
319     #ifndef NO_COPYLINE_FIX
320     if (!ts.EnableContinuedLineCopy || logFlag)
321     #endif /* NO_COPYLINE_FIX */
322     if (cv.HLogBuf!=0) Log1Byte(CR);
323    
324     if (CursorX>0)
325     MoveCursor(0,CursorY);
326     }
327    
328     void LineFeed(BYTE b, BOOL logFlag)
329     {
330     /* for auto print mode */
331     if ((AutoPrintMode) &&
332     (b>=LF) && (b<=FF))
333     BuffDumpCurrentLine(b);
334    
335     #ifndef NO_COPYLINE_FIX
336     if (!ts.EnableContinuedLineCopy || logFlag)
337     #endif /* NO_COPYLINE_FIX */
338     if (cv.HLogBuf!=0) Log1Byte(LF);
339    
340     if (CursorY < CursorBottom)
341     MoveCursor(CursorX,CursorY+1);
342     else if (CursorY == CursorBottom) BuffScrollNLines(1);
343     else if (CursorY < NumOfLines-StatusLine-1)
344     MoveCursor(CursorX,CursorY+1);
345    
346     if (LFMode) CarriageReturn(logFlag);
347     }
348    
349     void Tab()
350     {
351     if (Wrap && !ts.VTCompatTab) {
352     CarriageReturn(FALSE);
353     LineFeed(LF,FALSE);
354     #ifndef NO_COPYLINE_FIX
355     if (ts.EnableContinuedLineCopy) {
356     SetLineContinued();
357     }
358     #endif /* NO_COPYLINE_FIX */
359     Wrap = FALSE;
360     }
361 doda 2553 CursorForwardTab(1, AutoWrapMode);
362 maya 2476 if (cv.HLogBuf!=0) Log1Byte(HT);
363     }
364    
365     void PutChar(BYTE b)
366     {
367     BOOL SpecialNew;
368     TCharAttr CharAttrTmp;
369    
370     CharAttrTmp = CharAttr;
371    
372     if (PrinterMode) { // printer mode
373     WriteToPrnFile(b,TRUE);
374     return;
375     }
376    
377     if (Wrap)
378     {
379     CarriageReturn(FALSE);
380     LineFeed(LF,FALSE);
381     #ifndef NO_COPYLINE_FIX
382     CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0;
383     #endif /* NO_COPYLINE_FIX */
384     }
385    
386     // if (cv.HLogBuf!=0) Log1Byte(b);
387     // (2005.2.20 yutaka)
388     if (ts.LogTypePlainText) {
389     if (__isascii(b) && !isprint(b)) {
390     // ASCII�������A���\�������������O�����������B
391     } else {
392     if (cv.HLogBuf!=0) Log1Byte(b);
393     }
394     } else {
395     if (cv.HLogBuf!=0) Log1Byte(b);
396     }
397    
398     Wrap = FALSE;
399    
400     SpecialNew = FALSE;
401     if ((b>0x5F) && (b<0x80))
402     {
403     if (SSflag)
404     SpecialNew = (Gn[GLtmp]==IdSpecial);
405     else
406     SpecialNew = (Gn[Glr[0]]==IdSpecial);
407     }
408     else if (b>0xDF)
409     {
410     if (SSflag)
411     SpecialNew = (Gn[GLtmp]==IdSpecial);
412     else
413     SpecialNew = (Gn[Glr[1]]==IdSpecial);
414     }
415    
416     if (SpecialNew != Special)
417     {
418     UpdateStr();
419     Special = SpecialNew;
420     }
421    
422     if (Special)
423     {
424     b = b & 0x7F;
425     CharAttrTmp.Attr |= AttrSpecial;
426     }
427     else
428     CharAttrTmp.Attr |= CharAttr.Attr;
429    
430     BuffPutChar(b, CharAttrTmp, InsertMode);
431    
432     if (CursorX < NumOfColumns-1)
433     MoveRight();
434     else {
435     UpdateStr();
436     Wrap = AutoWrapMode;
437     }
438     }
439    
440 doda 2491 void PutDecSp(BYTE b)
441     {
442     TCharAttr CharAttrTmp;
443 maya 2476
444 doda 2491 CharAttrTmp = CharAttr;
445    
446     if (PrinterMode) { // printer mode
447     WriteToPrnFile(b, TRUE);
448     return;
449     }
450    
451     if (Wrap) {
452     CarriageReturn(FALSE);
453     LineFeed(LF, FALSE);
454     #ifndef NO_COPYLINE_FIX
455     CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0;
456     #endif /* NO_COPYLINE_FIX */
457     }
458    
459     if (cv.HLogBuf!=0) Log1Byte(b);
460     /*
461     if (ts.LogTypePlainText && __isascii(b) && !isprint(b)) {
462     // ASCII�������A���\�������������O�����������B
463     } else {
464     if (cv.HLogBuf!=0) Log1Byte(b);
465     }
466     */
467    
468     Wrap = FALSE;
469    
470     if (!Special) {
471     UpdateStr();
472     Special = TRUE;
473     }
474    
475     CharAttrTmp.Attr |= AttrSpecial;
476     BuffPutChar(b, CharAttrTmp, InsertMode);
477    
478     if (CursorX < NumOfColumns-1)
479     MoveRight();
480     else {
481     UpdateStr();
482     Wrap = AutoWrapMode;
483     }
484     }
485    
486 maya 2476 void PutKanji(BYTE b)
487     {
488     #ifndef NO_COPYLINE_FIX
489     TCharAttr CharAttrTmp;
490    
491     CharAttrTmp = CharAttr;
492     #endif /* NO_COPYLINE_FIX */
493     Kanji = Kanji + b;
494    
495     if (PrinterMode && DirectPrn)
496     {
497     WriteToPrnFile(HIBYTE(Kanji),FALSE);
498     WriteToPrnFile(LOBYTE(Kanji),TRUE);
499     return;
500     }
501    
502     if (ConvJIS)
503     Kanji = JIS2SJIS((WORD)(Kanji & 0x7f7f));
504    
505     if (PrinterMode) { // printer mode
506     WriteToPrnFile(HIBYTE(Kanji),FALSE);
507     WriteToPrnFile(LOBYTE(Kanji),TRUE);
508     return;
509     }
510    
511     if (Wrap)
512     {
513     CarriageReturn(FALSE);
514     LineFeed(LF,FALSE);
515     #ifndef NO_COPYLINE_FIX
516     if (ts.EnableContinuedLineCopy)
517     CharAttrTmp.Attr |= AttrLineContinued;
518     #endif /* NO_COPYLINE_FIX */
519     }
520     else if (CursorX > NumOfColumns-2)
521     if (AutoWrapMode)
522     {
523     #ifndef NO_COPYLINE_FIX
524     if (ts.EnableContinuedLineCopy)
525     {
526     CharAttrTmp.Attr |= AttrLineContinued;
527     if (CursorX == NumOfColumns-1)
528     BuffPutChar(0x20, CharAttr, FALSE);
529     }
530     #endif /* NO_COPYLINE_FIX */
531     CarriageReturn(FALSE);
532     LineFeed(LF,FALSE);
533     }
534     else return;
535    
536     Wrap = FALSE;
537    
538     if (cv.HLogBuf!=0)
539     {
540     Log1Byte(HIBYTE(Kanji));
541     Log1Byte(LOBYTE(Kanji));
542     }
543    
544     if (Special)
545     {
546     UpdateStr();
547     Special = FALSE;
548     }
549 doda 2484
550 maya 2476 #ifndef NO_COPYLINE_FIX
551     BuffPutKanji(Kanji, CharAttrTmp, InsertMode);
552     #else
553     BuffPutKanji(Kanji, CharAttr, InsertMode);
554     #endif /* NO_COPYLINE_FIX */
555    
556     if (CursorX < NumOfColumns-2)
557     {
558     MoveRight();
559     MoveRight();
560     }
561     else {
562     UpdateStr();
563     Wrap = AutoWrapMode;
564     }
565     }
566    
567     void PutDebugChar(BYTE b)
568     {
569     InsertMode = FALSE;
570     AutoWrapMode = TRUE;
571    
572     if ((b & 0x80) == 0x80)
573     {
574     UpdateStr();
575     CharAttr.Attr = AttrReverse;
576     b = b & 0x7f;
577     }
578    
579     if (b<=US)
580     {
581     PutChar('^');
582     PutChar((char)(b+0x40));
583     }
584     else if (b==DEL)
585     {
586     PutChar('<');
587     PutChar('D');
588     PutChar('E');
589     PutChar('L');
590     PutChar('>');
591     }
592     else
593     PutChar(b);
594    
595     if (CharAttr.Attr != AttrDefault)
596     {
597     UpdateStr();
598     CharAttr.Attr = AttrDefault;
599     }
600     }
601    
602     void PrnParseControl(BYTE b) // printer mode
603     {
604     switch (b) {
605     case NUL: return;
606     case SO:
607     if (! DirectPrn)
608     {
609     if ((ts.Language==IdJapanese) &&
610     (ts.KanjiCode==IdJIS) &&
611     (ts.JIS7Katakana==1) &&
612     ((ts.TermFlag & TF_FIXEDJIS)!=0))
613     Gn[1] = IdKatakana;
614     Glr[0] = 1; /* LS1 */
615     return;
616     }
617     break;
618     case SI:
619     if (! DirectPrn)
620     {
621     Glr[0] = 0; /* LS0 */
622     return;
623     }
624     break;
625     case DC1:
626     case DC3: return;
627     case ESC:
628     ICount = 0;
629     JustAfterESC = TRUE;
630     ParseMode = ModeESC;
631     WriteToPrnFile(0,TRUE); // flush prn buff
632     return;
633     case CSI:
634     if ((ts.TerminalID<IdVT220J) ||
635     ((ts.TermFlag & TF_ACCEPT8BITCTRL)==0))
636     {
637     PutChar(b); /* Disp C1 char in VT100 mode */
638     return;
639     }
640     ICount = 0;
641     FirstPrm = TRUE;
642     NParam = 1;
643     Param[1] = -1;
644     Prv = 0;
645     ParseMode = ModeCSI;
646     WriteToPrnFile(0,TRUE); // flush prn buff
647     WriteToPrnFile(b,FALSE);
648     return;
649     }
650     /* send the uninterpreted character to printer */
651     WriteToPrnFile(b,TRUE);
652     }
653    
654     void ParseControl(BYTE b)
655     {
656     if (PrinterMode) { // printer mode
657     PrnParseControl(b);
658     return;
659     }
660    
661     if (b>=0x80) /* C1 char */
662     {
663     /* English mode */
664     if (ts.Language==IdEnglish)
665     {
666     if ((ts.TerminalID<IdVT220J) ||
667     ((ts.TermFlag & TF_ACCEPT8BITCTRL)==0))
668     {
669     PutChar(b); /* Disp C1 char in VT100 mode */
670     return;
671     }
672     }
673     else { /* Japanese mode */
674     if ((ts.TermFlag & TF_ACCEPT8BITCTRL)==0)
675     return; /* ignore C1 char */
676     /* C1 chars are interpreted as C0 chars in VT100 mode */
677     if (ts.TerminalID<IdVT220J)
678     b = b & 0x7F;
679     }
680     }
681     switch (b) {
682     /* C0 group */
683     case ENQ:
684     CommBinaryOut(&cv,&(ts.Answerback[0]),ts.AnswerbackLen);
685     break;
686     case BEL:
687 doda 2554 switch (ts.Beep) {
688     case IdBeepOff:
689     /* nothing to do */
690     break;
691     case IdBeepOn:
692     MessageBeep(0);
693     break;
694     case IdBeepVisual:
695 doda 2561 VisualBell();
696 doda 2554 break;
697     }
698 maya 2476 break;
699     case BS: BackSpace(); break;
700     case HT: Tab(); break;
701    
702     case LF:
703     // ���M�������s�R�[�h�� LF ���������A�T�[�o���� LF ���������������������������A
704     // CR+LF���������������������B
705     // cf. http://www.neocom.ca/forum/viewtopic.php?t=216
706     // (2007.1.21 yutaka)
707     if (ts.CRReceive == IdLF) {
708     CarriageReturn(TRUE);
709     LineFeed(b, TRUE);
710     break;
711     }
712    
713     case VT: LineFeed(b,TRUE); break;
714    
715     case FF:
716     if ((ts.AutoWinSwitch>0) && JustAfterESC)
717     {
718     CommInsert1Byte(&cv,b);
719     CommInsert1Byte(&cv,ESC);
720     ChangeEmu = IdTEK; /* Enter TEK Mode */
721     }
722     else
723     LineFeed(b,TRUE);
724     break;
725     case CR:
726     CarriageReturn(TRUE);
727     if (ts.CRReceive==IdCRLF)
728     CommInsert1Byte(&cv,LF);
729     break;
730     case SO:
731     if ((ts.Language==IdJapanese) &&
732     (ts.KanjiCode==IdJIS) &&
733     (ts.JIS7Katakana==1) &&
734     ((ts.TermFlag & TF_FIXEDJIS)!=0))
735     Gn[1] = IdKatakana;
736    
737     Glr[0] = 1; /* LS1 */
738     break;
739     case SI: Glr[0] = 0; break; /* LS0 */
740     case DLE:
741     if ((ts.FTFlag & FT_BPAUTO)!=0)
742     ParseMode = ModeDLE; /* Auto B-Plus activation */
743     break;
744     case CAN:
745     if ((ts.FTFlag & FT_ZAUTO)!=0)
746     ParseMode = ModeCAN; /* Auto ZMODEM activation */
747     // else if (ts.AutoWinSwitch>0)
748     // ChangeEmu = IdTEK; /* Enter TEK Mode */
749     else
750     ParseMode = ModeFirst;
751     break;
752     case SUB: ParseMode = ModeFirst; break;
753     case ESC:
754     ICount = 0;
755     JustAfterESC = TRUE;
756     ParseMode = ModeESC;
757     break;
758     case FS:
759     case GS:
760     case RS:
761     case US:
762     if (ts.AutoWinSwitch>0)
763     {
764     CommInsert1Byte(&cv,b);
765     ChangeEmu = IdTEK; /* Enter TEK Mode */
766     }
767     break;
768    
769     /* C1 char */
770     case IND: LineFeed(0,TRUE); break;
771     case NEL:
772     LineFeed(0,TRUE);
773     CarriageReturn(TRUE);
774     break;
775     case HTS: SetTabStop(); break;
776     case RI: CursorUpWithScroll(); break;
777     case SS2:
778     GLtmp = 2;
779     SSflag = TRUE;
780     break;
781     case SS3:
782     GLtmp = 3;
783     SSflag = TRUE;
784     break;
785     case DCS:
786     SavedMode = ParseMode;
787     ESCFlag = FALSE;
788     NParam = 1;
789     Param[1] = -1;
790     ParseMode = ModeDCS;
791     break;
792     case SOS:
793     SavedMode = ParseMode;
794     ESCFlag = FALSE;
795     ParseMode = ModeSOS;
796     break;
797     case CSI:
798     ICount = 0;
799     FirstPrm = TRUE;
800     NParam = 1;
801     Param[1] = -1;
802     Prv = 0;
803     ParseMode = ModeCSI;
804     break;
805     case OSC:
806     Param[1] = 0;
807     ParseMode = ModeXS;
808     break;
809     case PM:
810     case APC:
811     SavedMode = ParseMode;
812     ESCFlag = FALSE;
813     ParseMode = ModeSOS;
814     break;
815     }
816     }
817    
818     void SaveCursor()
819     {
820     int i;
821     PStatusBuff Buff;
822    
823     if ((StatusLine>0) &&
824     (CursorY==NumOfLines-1))
825     Buff = &SBuff2; // for status line
826     else
827     Buff = &SBuff1; // for main screen
828    
829     Buff->CursorX = CursorX;
830     Buff->CursorY = CursorY;
831     Buff->Attr = CharAttr;
832     Buff->Glr[0] = Glr[0];
833     Buff->Glr[1] = Glr[1];
834     for (i=0 ; i<=3; i++)
835     Buff->Gn[i] = Gn[i];
836     Buff->AutoWrapMode = AutoWrapMode;
837     Buff->RelativeOrgMode = RelativeOrgMode;
838     }
839    
840     void RestoreCursor()
841     {
842     int i;
843     PStatusBuff Buff;
844     UpdateStr();
845    
846     if ((StatusLine>0) &&
847     (CursorY==NumOfLines-1))
848     Buff = &SBuff2; // for status line
849     else
850     Buff = &SBuff1; // for main screen
851    
852     if (Buff->CursorX > NumOfColumns-1)
853     Buff->CursorX = NumOfColumns-1;
854     if (Buff->CursorY > NumOfLines-1-StatusLine)
855     Buff->CursorY = NumOfLines-1-StatusLine;
856     MoveCursor(Buff->CursorX,Buff->CursorY);
857     CharAttr = Buff->Attr;
858     Glr[0] = Buff->Glr[0];
859     Glr[1] = Buff->Glr[1];
860     for (i=0 ; i<=3; i++)
861     Gn[i] = Buff->Gn[i];
862     AutoWrapMode = Buff->AutoWrapMode;
863     RelativeOrgMode = Buff->RelativeOrgMode;
864     }
865    
866     void AnswerTerminalType()
867     {
868     char Tmp[31];
869    
870     if (ts.TerminalID<IdVT320)
871     strncpy_s(Tmp, sizeof(Tmp),"\033[?", _TRUNCATE);
872     else
873     strncpy_s(Tmp, sizeof(Tmp),"\233?", _TRUNCATE);
874    
875     switch (ts.TerminalID) {
876     case IdVT100:
877     strncat_s(Tmp,sizeof(Tmp),"1;2",_TRUNCATE);
878     break;
879     case IdVT100J:
880     strncat_s(Tmp,sizeof(Tmp),"5;2",_TRUNCATE);
881     break;
882     case IdVT101:
883     strncat_s(Tmp,sizeof(Tmp),"1;0",_TRUNCATE);
884     break;
885     case IdVT102:
886     strncat_s(Tmp,sizeof(Tmp),"6",_TRUNCATE);
887     break;
888     case IdVT102J:
889     strncat_s(Tmp,sizeof(Tmp),"15",_TRUNCATE);
890     break;
891     case IdVT220J:
892     strncat_s(Tmp,sizeof(Tmp),"62;1;2;5;6;7;8",_TRUNCATE);
893     break;
894     case IdVT282:
895     strncat_s(Tmp,sizeof(Tmp),"62;1;2;4;5;6;7;8;10;11",_TRUNCATE);
896     break;
897     case IdVT320:
898     strncat_s(Tmp,sizeof(Tmp),"63;1;2;6;7;8",_TRUNCATE);
899     break;
900     case IdVT382:
901     strncat_s(Tmp,sizeof(Tmp),"63;1;2;4;5;6;7;8;10;15",_TRUNCATE);
902     break;
903     }
904     strncat_s(Tmp,sizeof(Tmp),"c",_TRUNCATE);
905    
906     CommBinaryOut(&cv,Tmp,strlen(Tmp)); /* Report terminal ID */
907     }
908    
909     void ESCSpace(BYTE b)
910     {
911     switch (b) {
912     case 'F': Send8BitMode = FALSE; break; // S7C1T
913     case 'G': Send8BitMode = TRUE; break; // S8C1T
914     }
915     }
916    
917     void ESCSharp(BYTE b)
918     {
919     switch (b) {
920     case '8': /* Fill screen with "E" */
921     BuffUpdateScroll();
922     BuffFillWithE();
923     MoveCursor(0,0);
924     ParseMode = ModeFirst;
925     break;
926     }
927     }
928    
929     /* select double byte code set */
930     void ESCDBCSSelect(BYTE b)
931     {
932     int Dist;
933    
934     if (ts.Language!=IdJapanese) return;
935    
936     switch (ICount) {
937     case 1:
938     if ((b=='@') || (b=='B'))
939     {
940     Gn[0] = IdKanji; /* Kanji -> G0 */
941     if ((ts.TermFlag & TF_AUTOINVOKE)!=0)
942     Glr[0] = 0; /* G0->GL */
943     }
944     break;
945     case 2:
946     /* Second intermediate char must be
947     '(' or ')' or '*' or '+'. */
948     Dist = (IntChar[2]-'(') & 3; /* G0 - G3 */
949     if ((b=='1') || (b=='3') ||
950     (b=='@') || (b=='B'))
951     {
952     Gn[Dist] = IdKanji; /* Kanji -> G0-3 */
953     if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
954     (Dist==0))
955     Glr[0] = 0; /* G0->GL */
956     }
957     break;
958     }
959 doda 2484 }
960 maya 2476
961     void ESCSelectCode(BYTE b)
962     {
963     switch (b) {
964     case '0':
965     if (ts.AutoWinSwitch>0)
966     ChangeEmu = IdTEK; /* enter TEK mode */
967     break;
968     }
969     }
970    
971     /* select single byte code set */
972     void ESCSBCSSelect(BYTE b)
973     {
974     int Dist;
975    
976     /* Intermediate char must be
977     '(' or ')' or '*' or '+'. */
978     Dist = (IntChar[1]-'(') & 3; /* G0 - G3 */
979    
980     switch (b) {
981     case '0': Gn[Dist] = IdSpecial; break;
982     case '<': Gn[Dist] = IdASCII; break;
983     case '>': Gn[Dist] = IdASCII; break;
984     case 'B': Gn[Dist] = IdASCII; break;
985     case 'H': Gn[Dist] = IdASCII; break;
986     case 'I':
987     if (ts.Language==IdJapanese)
988     Gn[Dist] = IdKatakana;
989     break;
990     case 'J': Gn[Dist] = IdASCII; break;
991     }
992    
993     if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
994     (Dist==0))
995     Glr[0] = 0; /* G0->GL */
996     }
997    
998     void PrnParseEscape(BYTE b) // printer mode
999     {
1000     int i;
1001    
1002     ParseMode = ModeFirst;
1003     switch (ICount) {
1004     /* no intermediate char */
1005     case 0:
1006     switch (b) {
1007     case '[': /* CSI */
1008     ICount = 0;
1009     FirstPrm = TRUE;
1010     NParam = 1;
1011     Param[1] = -1;
1012     Prv = 0;
1013     WriteToPrnFile(ESC,FALSE);
1014     WriteToPrnFile('[',FALSE);
1015     ParseMode = ModeCSI;
1016     return;
1017     } /* end of case Icount=0 */
1018     break;
1019     /* one intermediate char */
1020     case 1:
1021     switch (IntChar[1]) {
1022     case '$':
1023     if (! DirectPrn)
1024     {
1025     ESCDBCSSelect(b);
1026     return;
1027     }
1028     break;
1029     case '(':
1030     case ')':
1031     case '*':
1032     case '+':
1033     if (! DirectPrn)
1034     {
1035     ESCSBCSSelect(b);
1036     return;
1037     }
1038     break;
1039     }
1040     break;
1041     /* two intermediate char */
1042     case 2:
1043     if ((! DirectPrn) &&
1044     (IntChar[1]=='$') &&
1045     ('('<=IntChar[2]) &&
1046     (IntChar[2]<='+'))
1047     {
1048     ESCDBCSSelect(b);
1049     return;
1050     }
1051     break;
1052     }
1053     // send the uninterpreted sequence to printer
1054     WriteToPrnFile(ESC,FALSE);
1055     for (i=1; i<=ICount; i++)
1056     WriteToPrnFile(IntChar[i],FALSE);
1057     WriteToPrnFile(b,TRUE);
1058     }
1059    
1060     void ParseEscape(BYTE b) /* b is the final char */
1061     {
1062     if (PrinterMode) { // printer mode
1063     PrnParseEscape(b);
1064     return;
1065     }
1066    
1067     switch (ICount) {
1068     /* no intermediate char */
1069     case 0:
1070     switch (b) {
1071     case '7': SaveCursor(); break;
1072     case '8': RestoreCursor(); break;
1073     case '=': AppliKeyMode = TRUE; break;
1074     case '>': AppliKeyMode = FALSE; break;
1075     case 'D': /* IND */
1076     LineFeed(0,TRUE);
1077     break;
1078     case 'E': /* NEL */
1079     MoveCursor(0,CursorY);
1080     LineFeed(0,TRUE);
1081     break;
1082     case 'H': /* HTS */
1083     SetTabStop();
1084     break;
1085     case 'M': /* RI */
1086     CursorUpWithScroll();
1087     break;
1088     case 'N': /* SS2 */
1089     GLtmp = 2;
1090     SSflag = TRUE;
1091     break;
1092     case 'O': /* SS3 */
1093     GLtmp = 3;
1094     SSflag = TRUE;
1095     break;
1096     case 'P': /* DCS */
1097     SavedMode = ParseMode;
1098     ESCFlag = FALSE;
1099     NParam = 1;
1100     Param[1] = -1;
1101     ParseMode = ModeDCS;
1102     return;
1103     case 'X': /* SOS */
1104     SavedMode = ParseMode;
1105     ESCFlag = FALSE;
1106     ParseMode = ModeSOS;
1107     return;
1108     case 'Z': AnswerTerminalType(); break;
1109     case '[': /* CSI */
1110     ICount = 0;
1111     FirstPrm = TRUE;
1112     NParam = 1;
1113     Param[1] = -1;
1114     Prv = 0;
1115     ParseMode = ModeCSI;
1116     return;
1117     case '\\': break; /* ST */
1118     case ']': /* XTERM sequence (OSC) */
1119     NParam = 1;
1120     Param[1] = 0;
1121     ParseMode = ModeXS;
1122 doda 2484 return;
1123 maya 2476 case '^':
1124     case '_': /* PM, APC */
1125     SavedMode = ParseMode;
1126     ESCFlag = FALSE;
1127     ParseMode = ModeSOS;
1128     return;
1129     case 'c': /* Hardware reset */
1130     HideStatusLine();
1131     ResetTerminal();
1132     ClearUserKey();
1133     ClearBuffer();
1134     if (ts.PortType==IdSerial) // reset serial port
1135     CommResetSerial(&ts, &cv, TRUE);
1136     break;
1137 doda 2561 case 'g': /* Visual Bell (screen original?) */
1138     VisualBell();
1139     break;
1140 maya 2476 case 'n': Glr[0] = 2; break; /* LS2 */
1141     case 'o': Glr[0] = 3; break; /* LS3 */
1142     case '|': Glr[1] = 3; break; /* LS3R */
1143     case '}': Glr[1] = 2; break; /* LS2R */
1144     case '~': Glr[1] = 1; break; /* LS1R */
1145     } /* end of case Icount=0 */
1146     break;
1147     /* one intermediate char */
1148     case 1:
1149     switch (IntChar[1]) {
1150     case ' ': ESCSpace(b); break;
1151     case '#': ESCSharp(b); break;
1152     case '$': ESCDBCSSelect(b); break;
1153     case '%': break;
1154     case '(':
1155     case ')':
1156     case '*':
1157     case '+':
1158     ESCSBCSSelect(b);
1159     break;
1160     }
1161     break;
1162     /* two intermediate char */
1163     case 2:
1164     if ((IntChar[1]=='$') &&
1165     ('('<=IntChar[2]) &&
1166     (IntChar[2]<='+'))
1167     ESCDBCSSelect(b);
1168     else if ((IntChar[1]=='%') &&
1169     (IntChar[2]=='!'))
1170     ESCSelectCode(b);
1171     break;
1172     }
1173     ParseMode = ModeFirst;
1174     }
1175    
1176     void EscapeSequence(BYTE b)
1177     {
1178     if (b<=US)
1179     ParseControl(b);
1180     else if ((b>=0x20) && (b<=0x2F))
1181     {
1182     if (ICount<IntCharMax) ICount++;
1183     IntChar[ICount] = b;
1184     }
1185     else if ((b>=0x30) && (b<=0x7E))
1186     ParseEscape(b);
1187     else if ((b>=0x80) && (b<=0x9F))
1188     ParseControl(b);
1189    
1190     JustAfterESC = FALSE;
1191     }
1192    
1193     void CSInsertCharacter()
1194     {
1195     // Insert space characters at cursor
1196     int Count;
1197    
1198     BuffUpdateScroll();
1199     if (Param[1]<1) Param[1] = 1;
1200     Count = Param[1];
1201     BuffInsertSpace(Count);
1202     }
1203    
1204     void CSCursorUp()
1205     {
1206     if (Param[1]<1) Param[1] = 1;
1207    
1208     if (CursorY >= CursorTop)
1209     {
1210     if (CursorY-Param[1] > CursorTop)
1211     MoveCursor(CursorX,CursorY-Param[1]);
1212     else
1213     MoveCursor(CursorX,CursorTop);
1214     }
1215     else {
1216     if (CursorY > 0)
1217     MoveCursor(CursorX,CursorY-Param[1]);
1218     else
1219     MoveCursor(CursorX,0);
1220     }
1221     }
1222    
1223     void CSCursorUp1()
1224     {
1225     MoveCursor(0,CursorY);
1226     CSCursorUp();
1227     }
1228    
1229     void CSCursorDown()
1230     {
1231     if (Param[1]<1) Param[1] = 1;
1232    
1233     if (CursorY <= CursorBottom)
1234     {
1235     if (CursorY+Param[1] < CursorBottom)
1236     MoveCursor(CursorX,CursorY+Param[1]);
1237     else
1238     MoveCursor(CursorX,CursorBottom);
1239     }
1240     else {
1241     if (CursorY < NumOfLines-StatusLine-1)
1242     MoveCursor(CursorX,CursorY+Param[1]);
1243     else
1244     MoveCursor(CursorX,NumOfLines-StatusLine);
1245     }
1246     }
1247    
1248     void CSCursorDown1()
1249     {
1250     MoveCursor(0,CursorY);
1251     CSCursorDown();
1252     }
1253    
1254     void CSScreenErase()
1255     {
1256     if (Param[1] == -1) Param[1] = 0;
1257     BuffUpdateScroll();
1258     switch (Param[1]) {
1259     case 0:
1260     // <ESC>[H(Cursor in left upper corner)�������J�[�\�������������w�������������A
1261     // <ESC>[J��<ESC>[2J�����������������A�����������A���s�o�b�t�@���X�N���[���A�E�g
1262     // �����������������B(2005.5.29 yutaka)
1263 yutakapon 2498 // �R���t�B�O���[�V�������������������������������B(2008.5.3 yutaka)
1264     if (ts.ScrollWindowClearScreen &&
1265     (CursorX == 0 && CursorY == 0)) {
1266 maya 2476 // Erase screen (scroll out)
1267     BuffClearScreen();
1268     UpdateWindow(HVTWin);
1269    
1270     } else {
1271     // Erase characters from cursor to the end of screen
1272     BuffEraseCurToEnd();
1273     }
1274     break;
1275    
1276     case 1:
1277     // Erase characters from home to cursor
1278     BuffEraseHomeToCur();
1279     break;
1280    
1281     case 2:
1282     // Erase screen (scroll out)
1283     BuffClearScreen();
1284     UpdateWindow(HVTWin);
1285     break;
1286     }
1287     }
1288    
1289     void CSInsertLine()
1290     {
1291     // Insert lines at current position
1292     int Count, YEnd;
1293    
1294     if (CursorY < CursorTop) return;
1295     if (CursorY > CursorBottom) return;
1296     if (Param[1]<1) Param[1] = 1;
1297     Count = Param[1];
1298    
1299     YEnd = CursorBottom;
1300     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1301     if (Count > YEnd+1 - CursorY) Count = YEnd+1 - CursorY;
1302    
1303     BuffInsertLines(Count,YEnd);
1304     }
1305    
1306     void CSLineErase()
1307     {
1308     if (Param[1] == -1) Param[1] = 0;
1309     BuffUpdateScroll();
1310     switch (Param[1]) {
1311     /* erase char from cursor to end of line */
1312     case 0:
1313     BuffEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1314     break;
1315     /* erase char from start of line to cursor */
1316     case 1:
1317     BuffEraseCharsInLine(0,CursorX+1);
1318     break;
1319     /* erase entire line */
1320     case 2:
1321     BuffEraseCharsInLine(0,NumOfColumns);
1322     break;
1323     }
1324     }
1325    
1326     void CSDeleteNLines()
1327     // Delete lines from current line
1328     {
1329     int Count, YEnd;
1330    
1331     if (CursorY < CursorTop) return;
1332     if (CursorY > CursorBottom) return;
1333     Count = Param[1];
1334     if (Count<1) Count = 1;
1335    
1336     YEnd = CursorBottom;
1337     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1338     if (Count > YEnd+1-CursorY) Count = YEnd+1-CursorY;
1339     BuffDeleteLines(Count,YEnd);
1340     }
1341    
1342     void CSDeleteCharacter()
1343     {
1344     // Delete characters in current line from cursor
1345    
1346     if (Param[1]<1) Param[1] = 1;
1347     BuffUpdateScroll();
1348     BuffDeleteChars(Param[1]);
1349     }
1350    
1351     void CSEraseCharacter()
1352     {
1353     if (Param[1]<1) Param[1] = 1;
1354     BuffUpdateScroll();
1355     BuffEraseChars(Param[1]);
1356     }
1357    
1358     void CSScrollUP()
1359     {
1360     if (Param[1]<1) Param[1] = 1;
1361     BuffUpdateScroll();
1362     BuffRegionScrollUpNLines(Param[1]);
1363     }
1364    
1365     void CSScrollDown()
1366     {
1367     if (Param[1]<1) Param[1] = 1;
1368     BuffUpdateScroll();
1369     BuffRegionScrollDownNLines(Param[1]);
1370     }
1371    
1372 doda 2553 void CSForwardTab()
1373 doda 2551 {
1374     if (Param[1]<1) Param[1] = 1;
1375 doda 2553 CursorForwardTab(Param[1], AutoWrapMode);
1376 doda 2551 }
1377    
1378 doda 2553 void CSBackwardTab()
1379     {
1380     if (Param[1]<1) Param[1] = 1;
1381     CursorBackwardTab(Param[1]);
1382     }
1383    
1384 maya 2476 void CSMoveToColumnN()
1385     {
1386     if (Param[1]<1) Param[1] = 1;
1387     Param[1]--;
1388     if (Param[1] < 0) Param[1] = 0;
1389     if (Param[1] > NumOfColumns-1) Param[1] = NumOfColumns-1;
1390     MoveCursor(Param[1],CursorY);
1391     }
1392    
1393     void CSCursorRight()
1394     {
1395     if (Param[1]<1) Param[1] = 1;
1396     if (CursorX + Param[1] > NumOfColumns-1)
1397     MoveCursor(NumOfColumns-1,CursorY);
1398     else
1399     MoveCursor(CursorX+Param[1],CursorY);
1400     }
1401    
1402     void CSCursorLeft()
1403     {
1404     if (Param[1]<1) Param[1] = 1;
1405     if (CursorX-Param[1] < 0)
1406     MoveCursor(0,CursorY);
1407     else
1408     MoveCursor(CursorX-Param[1],CursorY);
1409     }
1410    
1411     void CSMoveToLineN()
1412     {
1413     if (Param[1]<1) Param[1] = 1;
1414     if (RelativeOrgMode)
1415     {
1416     if (CursorTop+Param[1]-1 > CursorBottom)
1417     MoveCursor(CursorX,CursorBottom);
1418     else
1419     MoveCursor(CursorX,CursorTop+Param[1]-1);
1420     }
1421     else {
1422     if (Param[1] > NumOfLines-StatusLine)
1423     MoveCursor(CursorX,NumOfLines-1-StatusLine);
1424     else
1425     MoveCursor(CursorX,Param[1]-1);
1426     }
1427     }
1428    
1429     void CSMoveToXY()
1430     {
1431     int NewX, NewY;
1432    
1433     if (Param[1]<1) Param[1] = 1;
1434     if ((NParam < 2) || (Param[2]<1)) Param[2] = 1;
1435     NewX = Param[2] - 1;
1436     if (NewX > NumOfColumns-1) NewX = NumOfColumns-1;
1437    
1438     if ((StatusLine>0) && (CursorY==NumOfLines-1))
1439     NewY = CursorY;
1440     else if (RelativeOrgMode)
1441     {
1442     NewY = CursorTop + Param[1] - 1;
1443     if (NewY > CursorBottom) NewY = CursorBottom;
1444     }
1445     else {
1446     NewY = Param[1] - 1;
1447     if (NewY > NumOfLines-1-StatusLine)
1448     NewY = NumOfLines-1-StatusLine;
1449     }
1450     MoveCursor(NewX,NewY);
1451     }
1452    
1453     void CSDeleteTabStop()
1454     {
1455     if (Param[1]==-1) Param[1] = 0;
1456     ClearTabStop(Param[1]);
1457     }
1458    
1459     void CS_h_Mode()
1460     {
1461     switch (Param[1]) {
1462     case 2: KeybEnabled = FALSE; break;
1463     case 4: InsertMode = TRUE; break;
1464     case 12:
1465     ts.LocalEcho = 0;
1466     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1467     TelChangeEcho();
1468     break;
1469     case 20:
1470     LFMode = TRUE;
1471     ts.CRSend = IdCRLF;
1472     cv.CRSend = IdCRLF;
1473     break;
1474     }
1475     }
1476    
1477     void CS_i_Mode()
1478     {
1479     if (Param[1]==-1) Param[1] = 0;
1480     switch (Param[1]) {
1481     /* print screen */
1482     // PrintEX -- TRUE: print screen
1483     // FALSE: scroll region
1484     case 0: BuffPrint(! PrintEX); break;
1485     /* printer controller mode off */
1486     case 4: break; /* See PrnParseCS() */
1487     /* printer controller mode on */
1488     case 5:
1489     if (! AutoPrintMode)
1490     OpenPrnFile();
1491     DirectPrn = (ts.PrnDev[0]!=0);
1492     PrinterMode = TRUE;
1493     break;
1494     }
1495     }
1496    
1497     void CS_l_Mode()
1498     {
1499     switch (Param[1]) {
1500     case 2: KeybEnabled = TRUE; break;
1501     case 4: InsertMode = FALSE; break;
1502     case 12:
1503     ts.LocalEcho = 1;
1504     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1505     TelChangeEcho();
1506     break;
1507     case 20:
1508     LFMode = FALSE;
1509     ts.CRSend = IdCR;
1510     cv.CRSend = IdCR;
1511     break;
1512     }
1513     }
1514    
1515     void CS_n_Mode()
1516     {
1517     char Report[16];
1518     int Y;
1519    
1520     switch (Param[1]) {
1521     case 5:
1522     if (Send8BitMode)
1523     CommBinaryOut(&cv,"\2330n",3); /* Device Status Report -> Ready */
1524     else
1525     CommBinaryOut(&cv,"\033[0n",4); /* Device Status Report -> Ready */
1526     break;
1527     case 6:
1528     /* Cursor Position Report */
1529     Y = CursorY+1;
1530     if ((StatusLine>0) &&
1531     (Y==NumOfLines))
1532     Y = 1;
1533     if (Send8BitMode)
1534     _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\233%u;%uR", CLocale, Y, CursorX+1);
1535     else
1536     _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\033[%u;%uR", CLocale, Y, CursorX+1);
1537     CommBinaryOut(&cv,Report,strlen(Report));
1538     break;
1539     }
1540     }
1541    
1542     void CSSetAttr()
1543     {
1544     int i, P;
1545    
1546     UpdateStr();
1547     for (i=1 ; i<=NParam ; i++)
1548     {
1549     P = Param[i];
1550     if (P<0) P = 0;
1551     switch (P) {
1552     case 0: /* Clear all */
1553     CharAttr = DefCharAttr;
1554     BuffSetCurCharAttr(CharAttr);
1555     break;
1556    
1557     case 1: /* Bold */
1558     CharAttr.Attr |= AttrBold;
1559     BuffSetCurCharAttr(CharAttr);
1560     break;
1561    
1562     case 4: /* Under line */
1563     CharAttr.Attr |= AttrUnder;
1564     BuffSetCurCharAttr(CharAttr);
1565     break;
1566    
1567     case 5: /* Blink */
1568     CharAttr.Attr |= AttrBlink;
1569     BuffSetCurCharAttr(CharAttr);
1570     break;
1571    
1572     case 7: /* Reverse */
1573     CharAttr.Attr |= AttrReverse;
1574     BuffSetCurCharAttr(CharAttr);
1575     break;
1576    
1577     case 22: /* Bold off */
1578     CharAttr.Attr &= ~ AttrBold;
1579     BuffSetCurCharAttr(CharAttr);
1580     break;
1581    
1582     case 24: /* Under line off */
1583     CharAttr.Attr &= ~ AttrUnder;
1584     BuffSetCurCharAttr(CharAttr);
1585     break;
1586    
1587     case 25: /* Blink off */
1588     CharAttr.Attr &= ~ AttrBlink;
1589     BuffSetCurCharAttr(CharAttr);
1590     break;
1591    
1592     case 27: /* Reverse off */
1593     CharAttr.Attr &= ~ AttrReverse;
1594     BuffSetCurCharAttr(CharAttr);
1595     break;
1596    
1597     case 30:
1598     case 31:
1599     case 32:
1600     case 33:
1601     case 34:
1602     case 35:
1603     case 36:
1604     case 37: /* text color */
1605     CharAttr.Attr2 |= Attr2Fore;
1606     CharAttr.Fore = P - 30;
1607     BuffSetCurCharAttr(CharAttr);
1608     break;
1609    
1610     case 38: /* text color (256color mode) */
1611     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1612     i++;
1613     if (i < NParam) {
1614     P = Param[++i];
1615     if (P<0) {
1616     P = 0;
1617     }
1618     CharAttr.Attr2 |= Attr2Fore;
1619     CharAttr.Fore = P;
1620     BuffSetCurCharAttr(CharAttr);
1621     }
1622     }
1623     break;
1624    
1625     case 39: /* Reset text color */
1626     CharAttr.Attr2 &= ~ Attr2Fore;
1627     CharAttr.Fore = AttrDefaultFG;
1628     BuffSetCurCharAttr(CharAttr);
1629     break;
1630    
1631     case 40:
1632     case 41:
1633     case 42:
1634     case 43:
1635     case 44:
1636     case 45:
1637     case 46:
1638     case 47: /* Back color */
1639     CharAttr.Attr2 |= Attr2Back;
1640     CharAttr.Back = P - 40;
1641     BuffSetCurCharAttr(CharAttr);
1642     break;
1643    
1644     case 48: /* Back color (256color mode) */
1645     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1646     i++;
1647     if (i < NParam) {
1648     P = Param[++i];
1649     if (P<0) {
1650     P = 0;
1651     }
1652     CharAttr.Attr2 |= Attr2Back;
1653     CharAttr.Back = P;
1654     BuffSetCurCharAttr(CharAttr);
1655     }
1656     }
1657     break;
1658    
1659     case 49: /* Reset back color */
1660     CharAttr.Attr2 &= ~ Attr2Back;
1661     CharAttr.Back = AttrDefaultBG;
1662     BuffSetCurCharAttr(CharAttr);
1663     break;
1664    
1665     case 90:
1666     case 91:
1667     case 92:
1668     case 93:
1669     case 94:
1670     case 95:
1671     case 96:
1672     case 97: /* aixterm style text color */
1673     if (ts.ColorFlag & CF_AIXTERM16) {
1674     CharAttr.Attr2 |= Attr2Fore;
1675     CharAttr.Fore = P - 90 + 8;
1676     BuffSetCurCharAttr(CharAttr);
1677     }
1678     break;
1679    
1680     case 100:
1681     if (! (ts.ColorFlag & CF_AIXTERM16)) {
1682     /* Reset text and back color */
1683     CharAttr.Attr2 &= ~ (Attr2Fore | Attr2Back);
1684     CharAttr.Fore = AttrDefaultFG;
1685     CharAttr.Back = AttrDefaultBG;
1686     BuffSetCurCharAttr(CharAttr);
1687     break;
1688     }
1689     /* fall through to aixterm style back color */
1690    
1691     case 101:
1692     case 102:
1693     case 103:
1694     case 104:
1695     case 105:
1696     case 106:
1697     case 107: /* aixterm style back color */
1698     if (ts.ColorFlag & CF_AIXTERM16) {
1699     CharAttr.Attr2 |= Attr2Back;
1700     CharAttr.Back = P - 100 + 8;
1701     BuffSetCurCharAttr(CharAttr);
1702     }
1703     break;
1704     }
1705     }
1706     }
1707    
1708     void CSSetScrollRegion()
1709     {
1710     if ((StatusLine>0) &&
1711     (CursorY==NumOfLines-1))
1712     {
1713     MoveCursor(0,CursorY);
1714     return;
1715     }
1716 doda 2484 if (Param[1]<1) Param[1] =1;
1717 maya 2476 if ((NParam < 2) | (Param[2]<1))
1718     Param[2] = NumOfLines-StatusLine;
1719     Param[1]--;
1720     Param[2]--;
1721     if (Param[1] > NumOfLines-1-StatusLine)
1722     Param[1] = NumOfLines-1-StatusLine;
1723     if (Param[2] > NumOfLines-1-StatusLine)
1724     Param[2] = NumOfLines-1-StatusLine;
1725     if (Param[1] >= Param[2]) return;
1726     CursorTop = Param[1];
1727     CursorBottom = Param[2];
1728     if (RelativeOrgMode) MoveCursor(0,CursorTop);
1729     else MoveCursor(0,0);
1730     }
1731    
1732     void CSSunSequence() /* Sun terminal private sequences */
1733     {
1734     char Report[16];
1735    
1736     switch (Param[1]) {
1737     case 8: /* set terminal size */
1738     if ((Param[2]<=1) || (NParam<2)) Param[2] = 24;
1739     if ((Param[3]<=1) || (NParam<3)) Param[3] = 80;
1740     ChangeTerminalSize(Param[3],Param[2]);
1741     break;
1742     case 14: /* get window size??? */
1743     /* this is not actual window size */
1744     if (Send8BitMode)
1745     CommBinaryOut(&cv,"\2334;640;480t",11);
1746     else
1747     CommBinaryOut(&cv,"\033[4;640;480t",12);
1748     break;
1749     case 18: /* get terminal size */
1750     if (Send8BitMode)
1751     _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\2338;%u;%u;t", CLocale, NumOfLines-StatusLine, NumOfColumns);
1752     else
1753     _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\033[8;%u;%u;t", CLocale, NumOfLines-StatusLine, NumOfColumns);
1754     CommBinaryOut(&cv,Report,strlen(Report));
1755     break;
1756     }
1757     }
1758    
1759     void CSGT(BYTE b)
1760     {
1761     switch (b) {
1762     case 'c': /* second terminal report */
1763     if (Send8BitMode)
1764     CommBinaryOut(&cv,"\233>32;10;2c",11); /* VT382 */
1765     else
1766     CommBinaryOut(&cv,"\033[>32;10;2c",11); /* VT382 */
1767     break;
1768     case 'J':
1769     if (Param[1]==3) // IO-8256 terminal
1770     {
1771     if (Param[2]<1) Param[2]=1;
1772     if (Param[3]<1) Param[3]=1;
1773     if (Param[4]<1) Param[4]=1;
1774     if (Param[5]<1) Param[5]=1;
1775     BuffEraseBox(Param[3]-1,Param[2]-1,
1776     Param[5]-1,Param[4]-1);
1777     }
1778     break;
1779     case 'K':
1780     if ((NParam>=2) && (Param[1]==5))
1781     { // IO-8256 terminal
1782     switch (Param[2]) {
1783     case 3:
1784     case 4:
1785     case 5:
1786     case 6:
1787     BuffDrawLine(CharAttr, Param[2], Param[3]);
1788     break;
1789     case 12:
1790     /* Text color */
1791     if ((Param[3]>=0) && (Param[3]<=7))
1792     {
1793     switch (Param[3]) {
1794     case 3: CharAttr.Fore = IdBlue; break;
1795     case 4: CharAttr.Fore = IdCyan; break;
1796     case 5: CharAttr.Fore = IdYellow; break;
1797     case 6: CharAttr.Fore = IdMagenta; break;
1798     default: CharAttr.Fore = Param[3]; break;
1799     }
1800     CharAttr.Attr2 |= Attr2Fore;
1801     BuffSetCurCharAttr(CharAttr);
1802     }
1803     break;
1804     }
1805     }
1806     else if (Param[1]==3)
1807     {// IO-8256 terminal
1808     if (Param[2]<1) Param[2] = 1;
1809     if (Param[3]<1) Param[2] = 1;
1810     BuffEraseCharsInLine(Param[2]-1,Param[3]-Param[2]+1);
1811     }
1812     break;
1813     }
1814     }
1815    
1816     void CSQExchangeColor()
1817     {
1818     COLORREF ColorRef;
1819    
1820     BuffUpdateScroll();
1821    
1822     ColorRef = ts.VTColor[0];
1823     ts.VTColor[0] = ts.VTColor[1];
1824     ts.VTColor[1] = ColorRef;
1825     #ifdef ALPHABLEND_TYPE2
1826     BGInitialize();
1827     #endif
1828     DispChangeBackground();
1829 doda 2554 UpdateWindow(HVTWin);
1830 maya 2476 }
1831    
1832     void CSQ_h_Mode()
1833     {
1834     int i;
1835    
1836     for (i = 1 ; i<=NParam ; i++)
1837     switch (Param[i]) {
1838     case 1: AppliCursorMode = TRUE; break;
1839     case 3:
1840     ChangeTerminalSize(132,NumOfLines-StatusLine);
1841     break;
1842     case 5:
1843     if (ReverseColor) return;
1844     ReverseColor = TRUE;
1845     /* Exchange text/back color */
1846     CSQExchangeColor();
1847     break;
1848     case 6:
1849     if ((StatusLine>0) &&
1850     (CursorY==NumOfLines-1))
1851     MoveCursor(0,CursorY);
1852     else {
1853     RelativeOrgMode = TRUE;
1854     MoveCursor(0,CursorTop);
1855     }
1856     break;
1857     case 7: AutoWrapMode = TRUE; break;
1858     case 8: AutoRepeatMode = TRUE; break;
1859     case 9:
1860     if (ts.MouseEventTracking)
1861     MouseReportMode = IdMouseTrackX10;
1862     break;
1863     case 19: PrintEX = TRUE; break;
1864     case 25: DispEnableCaret(TRUE); break; // cursor on
1865     case 38:
1866     if (ts.AutoWinSwitch>0)
1867     ChangeEmu = IdTEK; /* Enter TEK Mode */
1868     break;
1869     case 59:
1870     if (ts.Language==IdJapanese)
1871     { /* kanji terminal */
1872     Gn[0] = IdASCII;
1873     Gn[1] = IdKatakana;
1874     Gn[2] = IdKatakana;
1875     Gn[3] = IdKanji;
1876     Glr[0] = 0;
1877     if ((ts.KanjiCode==IdJIS) &&
1878     (ts.JIS7Katakana==0))
1879     Glr[1] = 2; // 8-bit katakana
1880     else
1881     Glr[1] = 3;
1882     }
1883     break;
1884     case 66: AppliKeyMode = TRUE; break;
1885     case 67: ts.BSKey = IdBS; break;
1886     case 1000:
1887     if (ts.MouseEventTracking)
1888     MouseReportMode = IdMouseTrackVT200;
1889     break;
1890     case 1001:
1891     if (ts.MouseEventTracking)
1892     MouseReportMode = IdMouseTrackVT200Hl;
1893     break;
1894     case 1002:
1895     if (ts.MouseEventTracking)
1896     MouseReportMode = IdMouseTrackBtnEvent;
1897     break;
1898     case 1003:
1899     if (ts.MouseEventTracking)
1900     MouseReportMode = IdMouseTrackAllEvent;
1901     break;
1902     case 1004:
1903     if (ts.MouseEventTracking)
1904     FocusReportMode = TRUE;
1905     break;
1906     }
1907     }
1908    
1909     void CSQ_i_Mode()
1910     {
1911     if (Param[1]==-1) Param[1] = 0;
1912     switch (Param[1]) {
1913     case 1:
1914     OpenPrnFile();
1915     BuffDumpCurrentLine(LF);
1916     if (! AutoPrintMode)
1917     ClosePrnFile();
1918     break;
1919     /* auto print mode off */
1920     case 4:
1921     if (AutoPrintMode)
1922     {
1923     ClosePrnFile();
1924     AutoPrintMode = FALSE;
1925     }
1926     break;
1927     /* auto print mode on */
1928     case 5:
1929     if (! AutoPrintMode)
1930     {
1931     OpenPrnFile();
1932     AutoPrintMode = TRUE;
1933     }
1934     break;
1935     }
1936     }
1937    
1938     void CSQ_l_Mode()
1939     {
1940     int i;
1941    
1942     for (i = 1 ; i <= NParam ; i++)
1943     switch (Param[i]) {
1944     case 1: AppliCursorMode = FALSE; break;
1945     case 3:
1946     ChangeTerminalSize(80,NumOfLines-StatusLine);
1947     break;
1948     case 5:
1949     if (! ReverseColor) return;
1950     ReverseColor = FALSE;
1951     /* Exchange text/back color */
1952     CSQExchangeColor();
1953     break;
1954     case 6:
1955     if ((StatusLine>0) &&
1956     (CursorY==NumOfLines-1))
1957     MoveCursor(0,CursorY);
1958     else {
1959     RelativeOrgMode = FALSE;
1960     MoveCursor(0,0);
1961     }
1962     break;
1963     case 7: AutoWrapMode = FALSE; break;
1964     case 8: AutoRepeatMode = FALSE; break;
1965     case 9: MouseReportMode = IdMouseTrackNone; break;
1966     case 19: PrintEX = FALSE; break;
1967     case 25: DispEnableCaret(FALSE); break; // cursor off
1968     case 59:
1969     if (ts.Language==IdJapanese)
1970     { /* katakana terminal */
1971     Gn[0] = IdASCII;
1972     Gn[1] = IdKatakana;
1973     Gn[2] = IdKatakana;
1974     Gn[3] = IdKanji;
1975     Glr[0] = 0;
1976     if ((ts.KanjiCode==IdJIS) &&
1977     (ts.JIS7Katakana==0))
1978     Glr[1] = 2; // 8-bit katakana
1979     else
1980     Glr[1] = 3;
1981     }
1982     break;
1983     case 66: AppliKeyMode = FALSE; break;
1984     case 67: ts.BSKey = IdDEL; break;
1985     case 1000:
1986     case 1001:
1987     case 1002:
1988     case 1003: MouseReportMode = IdMouseTrackNone; break;
1989     case 1004: FocusReportMode = FALSE; break;
1990     }
1991     }
1992    
1993     void CSQ_n_Mode()
1994     {
1995     }
1996    
1997     void CSQuest(BYTE b)
1998     {
1999     switch (b) {
2000 doda 2484 case 'K': CSLineErase(); break;
2001 maya 2476 case 'h': CSQ_h_Mode(); break;
2002     case 'i': CSQ_i_Mode(); break;
2003     case 'l': CSQ_l_Mode(); break;
2004     case 'n': CSQ_n_Mode(); break;
2005     }
2006     }
2007    
2008     void SoftReset()
2009     // called by software-reset escape sequence handler
2010     {
2011     UpdateStr();
2012     AutoRepeatMode = TRUE;
2013     DispEnableCaret(TRUE); // cursor on
2014     InsertMode = FALSE;
2015     RelativeOrgMode = FALSE;
2016     AppliKeyMode = FALSE;
2017     AppliCursorMode = FALSE;
2018     if ((StatusLine>0) &&
2019     (CursorY == NumOfLines-1))
2020     MoveToMainScreen();
2021     CursorTop = 0;
2022     CursorBottom = NumOfLines-1-StatusLine;
2023     ResetCharSet();
2024    
2025     Send8BitMode = ts.Send8BitCtrl;
2026    
2027     /* Attribute */
2028     CharAttr = DefCharAttr;
2029     Special = FALSE;
2030     BuffSetCurCharAttr(CharAttr);
2031    
2032     // status buffers
2033     ResetSBuffers();
2034     }
2035    
2036     void CSExc(BYTE b)
2037     {
2038     switch (b) {
2039     case 'p':
2040     /* Software reset */
2041     SoftReset();
2042     break;
2043     }
2044     }
2045    
2046     void CSDouble(BYTE b)
2047     {
2048     switch (b) {
2049     case 'p':
2050     /* Select terminal mode (software reset) */
2051     SoftReset();
2052     if (NParam > 0) {
2053     switch (Param[1]) {
2054     case 61: // VT100 Mode
2055     Send8BitMode = FALSE; break;
2056     case 62: // VT200 Mode
2057     case 63: // VT300 Mode
2058     case 64: // VT400 Mode
2059     if (NParam > 1 && Param[2] == 1)
2060     Send8BitMode = FALSE;
2061     else
2062     Send8BitMode = TRUE;
2063     break;
2064     }
2065     }
2066     break;
2067     }
2068     }
2069    
2070     void CSDol(BYTE b)
2071     {
2072     switch (b) {
2073     case '}':
2074     if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2075     if (StatusLine==0) return;
2076     if ((Param[1]<1) && (CursorY==NumOfLines-1))
2077     MoveToMainScreen();
2078     else if ((Param[1]==1) && (CursorY<NumOfLines-1))
2079     MoveToStatusLine();
2080     break;
2081     case '~':
2082     if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2083     if (Param[1]<=1)
2084     HideStatusLine();
2085     else if ((StatusLine==0) && (Param[1]==2))
2086     ShowStatusLine(1); // show
2087     break;
2088     }
2089     }
2090    
2091     void PrnParseCS(BYTE b) // printer mode
2092     {
2093     ParseMode = ModeFirst;
2094     switch (ICount) {
2095     /* no intermediate char */
2096     case 0:
2097     switch (Prv) {
2098     /* no private parameter */
2099     case 0:
2100     switch (b) {
2101     case 'i':
2102     if (Param[1]==4)
2103     {
2104     PrinterMode = FALSE;
2105     // clear prn buff
2106     WriteToPrnFile(0,FALSE);
2107     if (! AutoPrintMode)
2108     ClosePrnFile();
2109     return;
2110     }
2111     break;
2112     } /* of case Prv=0 */
2113     break;
2114     }
2115     break;
2116     /* one intermediate char */
2117     case 1: break;
2118     } /* of case Icount */
2119    
2120     WriteToPrnFile(b,TRUE);
2121     }
2122    
2123     void ParseCS(BYTE b) /* b is the final char */
2124     {
2125     if (PrinterMode) { // printer mode
2126     PrnParseCS(b);
2127     return;
2128     }
2129    
2130     switch (ICount) {
2131     /* no intermediate char */
2132     case 0:
2133     switch (Prv) {
2134     /* no private parameter */
2135     case 0:
2136     switch (b) {
2137     case '@': CSInsertCharacter(); break;
2138     case 'A': CSCursorUp(); break;
2139     case 'B': CSCursorDown(); break;
2140     case 'C': CSCursorRight(); break;
2141     case 'D': CSCursorLeft(); break;
2142     case 'E': CSCursorDown1(); break;
2143     case 'F': CSCursorUp1(); break;
2144     case 'G': CSMoveToColumnN(); break;
2145     case 'H': CSMoveToXY(); break;
2146 doda 2553 case 'I': CSForwardTab(); break; // CHT
2147 maya 2476 case 'J': CSScreenErase(); break;
2148     case 'K': CSLineErase(); break;
2149     case 'L': CSInsertLine(); break;
2150     case 'M': CSDeleteNLines(); break;
2151     case 'P': CSDeleteCharacter(); break;
2152     case 'S': CSScrollUP(); break; // SU
2153     case 'T': CSScrollDown(); break; // SD
2154     case 'X': CSEraseCharacter(); break;
2155 doda 2553 case 'Z': CSBackwardTab(); break; // CBT
2156 maya 2476 case '`': CSMoveToColumnN(); break;
2157     case 'a': CSCursorRight(); break;
2158     case 'c': AnswerTerminalType(); break;
2159     case 'd': CSMoveToLineN(); break;
2160     case 'e': CSCursorUp(); break;
2161     case 'f': CSMoveToXY(); break;
2162     case 'g': CSDeleteTabStop(); break;
2163     case 'h': CS_h_Mode(); break;
2164     case 'i': CS_i_Mode(); break;
2165     case 'l': CS_l_Mode(); break;
2166     case 'm': CSSetAttr(); break;
2167     case 'n': CS_n_Mode(); break;
2168     case 'r': CSSetScrollRegion(); break;
2169     case 's': SaveCursor(); break;
2170     case 't': CSSunSequence(); break;
2171     case 'u': RestoreCursor(); break;
2172     } /* of case Prv=0 */
2173     break;
2174     /* private parameter = '>' */
2175     case '>': CSGT(b); break;
2176     /* private parameter = '?' */
2177     case '?': CSQuest(b); break;
2178     }
2179     break;
2180     /* one intermediate char */
2181     case 1:
2182     switch (IntChar[1]) {
2183     /* intermediate char = '!' */
2184     case '!': CSExc(b); break;
2185     /* intermediate char = '"' */
2186     case '"': CSDouble(b); break;
2187     /* intermediate char = '$' */
2188     case '$': CSDol(b); break;
2189     }
2190     break;
2191     } /* of case Icount */
2192    
2193     ParseMode = ModeFirst;
2194     }
2195    
2196     void ControlSequence(BYTE b)
2197     {
2198     if ((b<=US) || (b>=0x80) && (b<=0x9F))
2199     ParseControl(b); /* ctrl char */
2200     else if ((b>=0x40) && (b<=0x7E))
2201     ParseCS(b); /* terminate char */
2202     else {
2203     if (PrinterMode)
2204     WriteToPrnFile(b,FALSE);
2205    
2206     if ((b>=0x20) && (b<=0x2F))
2207     { /* intermediate char */
2208     if (ICount<IntCharMax) ICount++;
2209     IntChar[ICount] = b;
2210     }
2211     else if ((b>=0x30) && (b<=0x39))
2212     {
2213     if (Param[NParam] < 0)
2214 doda 2484 Param[NParam] = 0;
2215 maya 2476 if (Param[NParam]<1000)
2216     Param[NParam] = Param[NParam]*10 + b - 0x30;
2217     }
2218     else if (b==0x3B)
2219     {
2220     if (NParam < NParamMax)
2221     {
2222     NParam++;
2223     Param[NParam] = -1;
2224     }
2225     }
2226     else if ((b>=0x3C) && (b<=0x3F))
2227     { /* private char */
2228     if (FirstPrm) Prv = b;
2229     }
2230     }
2231     FirstPrm = FALSE;
2232     }
2233    
2234     void DeviceControl(BYTE b)
2235     {
2236 doda 2528 if (ESCFlag && (b=='\\') || (b==ST && ts.KanjiCode!=IdSJIS))
2237 maya 2476 {
2238     ESCFlag = FALSE;
2239     ParseMode = SavedMode;
2240     return;
2241     }
2242    
2243     if (b==ESC)
2244     {
2245     ESCFlag = TRUE;
2246     return;
2247     }
2248     else ESCFlag = FALSE;
2249    
2250 doda 2487 if (b<=US)
2251 maya 2476 ParseControl(b);
2252     else if ((b>=0x30) && (b<=0x39))
2253     {
2254 doda 2484 if (Param[NParam] < 0) Param[NParam] = 0;
2255 maya 2476 if (Param[NParam]<1000)
2256     Param[NParam] = Param[NParam]*10 + b - 0x30;
2257     }
2258     else if (b==0x3B)
2259     {
2260     if (NParam < NParamMax)
2261     {
2262     NParam++;
2263     Param[NParam] = -1;
2264     }
2265     }
2266     else if ((b>=0x40) && (b<=0x7E))
2267     {
2268     if (b=='|')
2269     {
2270     ParseMode = ModeDCUserKey;
2271     if (Param[1] < 1) ClearUserKey();
2272     WaitKeyId = TRUE;
2273     NewKeyId = 0;
2274     }
2275     else ParseMode = ModeSOS;
2276     }
2277     }
2278    
2279     void DCUserKey(BYTE b)
2280     {
2281 doda 2528 if (ESCFlag && (b=='\\') || (b==ST && ts.KanjiCode!=IdSJIS))
2282 maya 2476 {
2283     if (! WaitKeyId) DefineUserKey(NewKeyId,NewKeyStr,NewKeyLen);
2284     ESCFlag = FALSE;
2285     ParseMode = SavedMode;
2286     return;
2287     }
2288    
2289     if (b==ESC)
2290     {
2291     ESCFlag = TRUE;
2292     return;
2293     }
2294     else ESCFlag = FALSE;
2295    
2296     if (WaitKeyId)
2297     {
2298     if ((b>=0x30) && (b<=0x39))
2299     {
2300     if (NewKeyId<1000)
2301     NewKeyId = NewKeyId*10 + b - 0x30;
2302     }
2303     else if (b==0x2F)
2304     {
2305     WaitKeyId = FALSE;
2306     WaitHi = TRUE;
2307     NewKeyLen = 0;
2308     }
2309     }
2310     else {
2311     if (b==0x3B)
2312     {
2313     DefineUserKey(NewKeyId,NewKeyStr,NewKeyLen);
2314     WaitKeyId = TRUE;
2315     NewKeyId = 0;
2316     }
2317     else {
2318     if (NewKeyLen < FuncKeyStrMax)
2319     {
2320     if (WaitHi)
2321     {
2322     NewKeyStr[NewKeyLen] = ConvHexChar(b) << 4;
2323     WaitHi = FALSE;
2324     }
2325     else {
2326     NewKeyStr[NewKeyLen] = NewKeyStr[NewKeyLen] +
2327     ConvHexChar(b);
2328     WaitHi = TRUE;
2329     NewKeyLen++;
2330     }
2331     }
2332     }
2333     }
2334     }
2335    
2336     void IgnoreString(BYTE b)
2337     {
2338 doda 2528 if ((ESCFlag && (b=='\\')) ||
2339     (b<=US && b!=ESC && b!=HT) ||
2340     (b==ST && ts.KanjiCode!=IdSJIS))
2341 maya 2476 ParseMode = SavedMode;
2342    
2343     if (b==ESC) ESCFlag = TRUE;
2344     else ESCFlag = FALSE;
2345     }
2346    
2347     BOOL XsParseColor(char *colspec, COLORREF *color)
2348     {
2349 doda 2486 unsigned int r, g, b;
2350 doda 2484 // double dr, dg, db;
2351 maya 2476
2352 doda 2484 r = g = b = 255;
2353 maya 2476
2354 doda 2484 if (colspec == NULL || color == NULL) {
2355     return FALSE;
2356     }
2357 maya 2476
2358 doda 2484 if (_strnicmp(colspec, "rgb:", 4) == 0) {
2359     switch (strlen(colspec)) {
2360     case 9: // rgb:R/G/B
2361     if (sscanf(colspec, "rgb:%1x/%1x/%1x", &r, &g, &b) != 3) {
2362     return FALSE;
2363     }
2364     r *= 17; g *= 17; b *= 17;
2365     break;
2366     case 12: // rgb:RR/GG/BB
2367     if (sscanf(colspec, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3) {
2368     return FALSE;
2369     }
2370     break;
2371     case 15: // rgb:RRR/GGG/BBB
2372     if (sscanf(colspec, "rgb:%3x/%3x/%3x", &r, &g, &b) != 3) {
2373     return FALSE;
2374     }
2375     r >>= 4; g >>= 4; b >>= 4;
2376     break;
2377     case 18: // rgb:RRRR/GGGG/BBBB
2378     if (sscanf(colspec, "rgb:%4x/%4x/%4x", &r, &g, &b) != 3) {
2379     return FALSE;
2380     }
2381     r >>= 8; g >>= 8; b >>= 8;
2382     break;
2383     default:
2384     return FALSE;
2385     }
2386 maya 2476 }
2387 doda 2484 // else if (_strnicmp(colspec, "rgbi:", 5) == 0) {
2388     // ; /* nothing to do */
2389     // }
2390     else if (colspec[0] == '#') {
2391     switch (strlen(colspec)) {
2392     case 4: // #RGB
2393     if (sscanf(colspec, "#%1x%1x%1x", &r, &g, &b) != 3) {
2394     return FALSE;
2395     }
2396     r <<= 4; g <<= 4; b <<= 4;
2397     break;
2398     case 7: // #RRGGBB
2399     if (sscanf(colspec, "#%2x%2x%2x", &r, &g, &b) != 3) {
2400     return FALSE;
2401     }
2402     break;
2403     case 10: // #RRRGGGBBB
2404     if (sscanf(colspec, "#%3x%3x%3x", &r, &g, &b) != 3) {
2405     return FALSE;
2406     }
2407     r >>= 4; g >>= 4; b >>= 4;
2408     break;
2409     case 13: // #RRRRGGGGBBBB
2410     if (sscanf(colspec, "#%4x%4x%4x", &r, &g, &b) != 3) {
2411     return FALSE;
2412     }
2413     r >>= 8; g >>= 8; b >>= 8;
2414     break;
2415     default:
2416     return FALSE;
2417     }
2418 maya 2476 }
2419 doda 2484 else {
2420     return FALSE;
2421 maya 2476 }
2422 doda 2484
2423 doda 2486 if (r > 255 || g > 255 || b > 255) {
2424 doda 2484 return FALSE;
2425 maya 2476 }
2426    
2427 doda 2484 *color = RGB(r, g, b);
2428     return TRUE;
2429 maya 2476 }
2430    
2431     #define ModeXsFirst 1
2432     #define ModeXsString 2
2433     #define ModeXsColorNum 3
2434     #define ModeXsColorSpec 4
2435     #define ModeXsEsc 5
2436     void XSequence(BYTE b)
2437     {
2438 doda 2484 static BYTE XsParseMode = ModeXsFirst, PrevMode;
2439     static char StrBuff[sizeof(ts.Title)];
2440 doda 2486 static unsigned int ColorNumber, StrLen;
2441 doda 2484 COLORREF color;
2442 maya 2476
2443 doda 2484 switch (XsParseMode) {
2444     case ModeXsFirst:
2445     if (isdigit(b)) {
2446     if (Param[1] < 1000) {
2447     Param[1] = Param[1]*10 + b - '0';
2448     }
2449     }
2450     else if (b == ';') {
2451     StrBuff[0] = '\0';
2452     StrLen = 0;
2453     if (Param[1] == 4) {
2454     ColorNumber = 0;
2455     XsParseMode = ModeXsColorNum;
2456     }
2457     else {
2458     XsParseMode = ModeXsString;
2459     }
2460     }
2461     else {
2462     ParseMode = ModeFirst;
2463     }
2464     break;
2465     case ModeXsString:
2466 doda 2528 if ((b==ST && ts.KanjiCode!=IdSJIS) || b==BEL) { /* String Terminator */
2467 doda 2484 StrBuff[StrLen] = '\0';
2468     switch (Param[1]) {
2469     case 0: /* Change window title and icon name */
2470     case 1: /* Change icon name */
2471     case 2: /* Change window title */
2472 doda 2558 if (ts.RemoteTitleChanging) {
2473     strncpy_s(ts.Title, sizeof(ts.Title), StrBuff, _TRUNCATE);
2474     // (2006.6.15 maya) �^�C�g�����n����������SJIS������
2475     ConvertToCP932(ts.Title, sizeof(ts.Title));
2476     ChangeTitle();
2477     }
2478 doda 2484 break;
2479     default:
2480     /* nothing to do */;
2481     }
2482     ParseMode = ModeFirst;
2483     XsParseMode = ModeXsFirst;
2484     }
2485     else if (b == ESC) { /* Escape */
2486     PrevMode = ModeXsString;
2487     XsParseMode = ModeXsEsc;
2488     }
2489     else if (b <= US) { /* Other control character -- invalid sequence */
2490     ParseMode = ModeFirst;
2491     XsParseMode = ModeXsFirst;
2492     }
2493     else if (StrLen < sizeof(StrBuff) - 1) {
2494     StrBuff[StrLen++] = b;
2495     }
2496     break;
2497     case ModeXsColorNum:
2498     if (isdigit(b)) {
2499     ColorNumber = ColorNumber*10 + b - '0';
2500     }
2501     else if (b == ';') {
2502     XsParseMode = ModeXsColorSpec;
2503     StrBuff[0] = '\0';
2504     StrLen = 0;
2505     }
2506     else {
2507     ParseMode = ModeFirst;
2508     XsParseMode = ModeXsFirst;
2509     }
2510     break;
2511     case ModeXsColorSpec:
2512 doda 2528 if ((b==ST && ts.KanjiCode!=IdSJIS) || b==BEL) { /* String Terminator */
2513 doda 2484 StrBuff[StrLen] = '\0';
2514 doda 2486 if ((ts.ColorFlag & CF_XTERM256) && ColorNumber <= 255) {
2515 doda 2484 if (strcmp(StrBuff, "?") == 0) {
2516     color = DispGetANSIColor(ColorNumber);
2517     if (Send8BitMode) {
2518     _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2519     "\2354;%d;rgb:%02x/%02x/%02x\234", CLocale, ColorNumber,
2520     GetRValue(color), GetGValue(color), GetBValue(color));
2521     }
2522     else {
2523     _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2524     "\033]4;%d;rgb:%02x/%02x/%02x\033\\", CLocale, ColorNumber,
2525     GetRValue(color), GetGValue(color), GetBValue(color));
2526     }
2527     ParseMode = ModeFirst;
2528     XsParseMode = ModeXsFirst;
2529     CommBinaryOut(&cv, StrBuff, strlen(StrBuff));
2530     break;
2531     }
2532     else if (XsParseColor(StrBuff, &color)) {
2533     DispSetANSIColor(ColorNumber, color);
2534     }
2535     }
2536     ParseMode = ModeFirst;
2537     XsParseMode = ModeXsFirst;
2538     }
2539     else if (b == ESC) {
2540     PrevMode = ModeXsColorSpec;
2541     XsParseMode = ModeXsEsc;
2542     }
2543     else if (b <= US) { /* Other control character -- invalid sequence */
2544     ParseMode = ModeFirst;
2545     XsParseMode = ModeXsFirst;
2546     }
2547     else if (b == ';') {
2548 doda 2486 if ((ts.ColorFlag & CF_XTERM256) && ColorNumber <= 255) {
2549 doda 2484 if (strcmp(StrBuff, "?") == 0) {
2550     color = DispGetANSIColor(ColorNumber);
2551     if (Send8BitMode) {
2552     _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2553     "\2354;%d;rgb:%02x/%02x/%02x\234", CLocale, ColorNumber,
2554     GetRValue(color), GetGValue(color), GetBValue(color));
2555     }
2556     else {
2557     _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2558     "\033]4;%d;rgb:%02x/%02x/%02x\033\\", CLocale, ColorNumber,
2559     GetRValue(color), GetGValue(color), GetBValue(color));
2560     }
2561     XsParseMode = ModeXsColorNum;
2562     CommBinaryOut(&cv, StrBuff, strlen(StrBuff));
2563     }
2564     else if (XsParseColor(StrBuff, &color)) {
2565     DispSetANSIColor(ColorNumber, color);
2566     }
2567     }
2568     ColorNumber = 0;
2569     StrBuff[0] = '\0';
2570     StrLen = 0;
2571     XsParseMode = ModeXsColorNum;
2572     }
2573     else if (StrLen < sizeof(StrBuff) - 1) {
2574     StrBuff[StrLen++] = b;
2575     }
2576     break;
2577     case ModeXsEsc:
2578     if (b == '\\') { /* String Terminator */
2579     XsParseMode = PrevMode;
2580 doda 2528 // XSequence(ST);
2581     XSequence(BEL);
2582 doda 2484 }
2583     else { /* Other character -- invalid sequence */
2584     ParseMode = ModeFirst;
2585     XsParseMode = ModeXsFirst;
2586     }
2587     break;
2588     // default:
2589     // ParseMode = ModeFirst;
2590     // XsParseMode = ModeXsFirst;
2591 maya 2476 }
2592     }
2593    
2594     void DLESeen(BYTE b)
2595     {
2596     ParseMode = ModeFirst;
2597     if (((ts.FTFlag & FT_BPAUTO)!=0) && (b=='B'))
2598     BPStart(IdBPAuto); /* Auto B-Plus activation */
2599     ChangeEmu = -1;
2600     }
2601    
2602     void CANSeen(BYTE b)
2603     {
2604     ParseMode = ModeFirst;
2605     if (((ts.FTFlag & FT_ZAUTO)!=0) && (b=='B'))
2606     ZMODEMStart(IdZAuto); /* Auto ZMODEM activation */
2607     ChangeEmu = -1;
2608     }
2609    
2610     BOOL CheckKanji(BYTE b)
2611     {
2612     BOOL Check;
2613    
2614     if (ts.Language!=IdJapanese) return FALSE;
2615    
2616     ConvJIS = FALSE;
2617    
2618     if (ts.KanjiCode==IdSJIS<