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 3774 - (hide annotations) (download) (as text)
Mon Feb 8 15:26:07 2010 UTC (14 years, 2 months ago) by doda
File MIME type: text/x-csrc
File size: 85641 byte(s)
TitleReportSequence で受け付ける値を、accept/ignore/empty に変更した。[ttssh2-devel 1623]

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