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 4700 - (hide annotations) (download) (as text)
Tue Nov 1 10:24:23 2011 UTC (12 years, 5 months ago) by doda
File MIME type: text/x-csrc
File size: 106285 byte(s)
リモートからのクリップボードアクセス (OSC 52) に対応した。

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