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 3302 - (hide annotations) (download) (as text)
Fri Apr 10 12:44:00 2009 UTC (15 years ago) by doda
File MIME type: text/x-csrc
File size: 75910 byte(s)
ウィンドウ最小化/最大化制御シーケンス(dtterm由来?)に対応。
  <CSI> Ps t
    Ps=1	最小化解除
       2	最小化
       9;0	最大化解除
       9;1	最大化

ウィンドウ位置変更もだけど、セキュリティ的には受け入れるか設定できた方がいいと思われる。

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