Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/teraterm/teraterm/vtterm.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5320 - (show annotations) (download) (as text)
Thu Jun 13 05:05:08 2013 UTC (10 years, 10 months ago) by doda
File MIME type: text/x-csrc
File size: 127397 byte(s)
DECRQM 制御シーケンスに対応

1 /* 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 #include <ctype.h>
14
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 #include "ttime.h"
27 #include "clipboar.h"
28
29 #include "vtterm.h"
30
31 void ParseFirst(BYTE b);
32
33 #define MAPSIZE(x) (sizeof(x)/sizeof((x)[0]))
34 #define Accept8BitCtrl ((VTlevel >= 2) && (ts.TermFlag & TF_ACCEPT8BITCTRL))
35
36 /* Parsing modes */
37 #define ModeFirst 0
38 #define ModeESC 1
39 #define ModeDCS 2
40 #define ModeDCUserKey 3
41 #define ModeSOS 4
42 #define ModeCSI 5
43 #define ModeXS 6
44 #define ModeDLE 7
45 #define ModeCAN 8
46
47 #define NParamMax 16
48 #define NSParamMax 16
49 #define IntCharMax 5
50
51 /* DEC Locator Flag */
52 #define DecLocatorOneShot 1
53 #define DecLocatorPixel 2
54 #define DecLocatorButtonDown 4
55 #define DecLocatorButtonUp 8
56 #define DecLocatorFiltered 16
57
58 void RingBell(int type);
59 void VisualBell();
60 BOOL DecLocatorReport(int Event, int Button);
61
62 /* character attribute */
63 static TCharAttr CharAttr;
64
65 /* various modes of VT emulation */
66 static BOOL RelativeOrgMode;
67 static BOOL InsertMode;
68 static BOOL LFMode;
69 static BOOL AutoWrapMode;
70 static BOOL FocusReportMode;
71 static BOOL AltScr;
72 BOOL BracketedPaste;
73
74 static int VTlevel;
75
76 BOOL AcceptWheelToCursor;
77
78 // save/restore cursor
79 typedef struct {
80 int CursorX, CursorY;
81 TCharAttr Attr;
82 int Glr[2], Gn[4]; // G0-G3, GL & GR
83 BOOL AutoWrapMode;
84 BOOL RelativeOrgMode;
85 } TStatusBuff;
86 typedef TStatusBuff *PStatusBuff;
87
88 // currently only used for AUTO CR/LF receive mode
89 BYTE PrevCharacter;
90 BOOL PrevCRorLFGeneratedCRLF; // indicates that previous CR or LF really generated a CR+LF
91
92 // status buffer for main screen & status line
93 static TStatusBuff SBuff1, SBuff2, SBuff3;
94
95 static BOOL ESCFlag, JustAfterESC;
96 static BOOL KanjiIn;
97 static BOOL EUCkanaIn, EUCsupIn;
98 static int EUCcount;
99 static BOOL Special;
100
101 static int Param[NParamMax+1];
102 static int SubParam[NParamMax+1][NSParamMax+1];
103 static int NParam, NSParam[NParamMax+1];
104 static BOOL FirstPrm;
105 static BYTE IntChar[IntCharMax+1];
106 static int ICount;
107 static BYTE Prv;
108 static int ParseMode;
109 static int ChangeEmu;
110
111 typedef struct tstack {
112 char *title;
113 struct tstack *next;
114 } TStack;
115 typedef TStack *PTStack;
116 PTStack TitleStack = NULL;
117
118 /* user defined keys */
119 static BOOL WaitKeyId, WaitHi;
120
121 /* GL, GR code group */
122 static int Glr[2];
123 /* G0, G1, G2, G3 code group */
124 static int Gn[4];
125 /* GL for single shift 2/3 */
126 static int GLtmp;
127 /* single shift 2/3 flag */
128 static BOOL SSflag;
129 /* JIS -> SJIS conversion flag */
130 static BOOL ConvJIS;
131 static WORD Kanji;
132
133 // variables for status line mode
134 static int StatusX=0;
135 static BOOL StatusWrap=FALSE;
136 static BOOL StatusCursor=TRUE;
137 static int MainX, MainY; //cursor registers
138 static int MainTop, MainBottom; // scroll region registers
139 static BOOL MainWrap;
140 static BOOL MainCursor=TRUE;
141
142 /* status for printer escape sequences */
143 static BOOL PrintEX = TRUE; // printing extent
144 // (TRUE: screen, FALSE: scroll region)
145 static BOOL AutoPrintMode = FALSE;
146 static BOOL PrinterMode = FALSE;
147 static BOOL DirectPrn = FALSE;
148
149 /* User key */
150 static BYTE NewKeyStr[FuncKeyStrMax];
151 static int NewKeyId, NewKeyLen;
152
153 /* Mouse Report */
154 int MouseReportMode;
155 int MouseReportExtMode;
156 unsigned int DecLocatorFlag;
157 int LastX, LastY;
158 int ButtonStat;
159 int FilterTop, FilterBottom, FilterLeft, FilterRight;
160
161 /* IME Status */
162 BOOL IMEstat;
163
164 /* Beep over-used */
165 static DWORD BeepStartTime = 0;
166 static DWORD BeepSuppressTime = 0;
167 static DWORD BeepOverUsedCount = 0;
168
169 /* OSC String buffer */
170 #define MAXOSCBUFFSIZE 4096
171 static char *OSCStrBuff;
172 static unsigned int OSCStrBuffSize;
173
174 static _locale_t CLocale = NULL;
175
176 void ClearParams()
177 {
178 ICount = 0;
179 NParam = 1;
180 NSParam[1] = 0;
181 Param[1] = 0;
182 Prv = 0;
183 }
184
185 void ResetSBuffer(PStatusBuff sbuff)
186 {
187 sbuff->CursorX = 0;
188 sbuff->CursorY = 0;
189 sbuff->Attr = DefCharAttr;
190 if (ts.Language==IdJapanese)
191 {
192 sbuff->Gn[0] = IdASCII;
193 sbuff->Gn[1] = IdKatakana;
194 sbuff->Gn[2] = IdKatakana;
195 sbuff->Gn[3] = IdKanji;
196 sbuff->Glr[0] = 0;
197 if ((ts.KanjiCode==IdJIS) &&
198 (ts.JIS7Katakana==0))
199 sbuff->Glr[1] = 2; // 8-bit katakana
200 else
201 sbuff->Glr[1] = 3;
202 }
203 else {
204 sbuff->Gn[0] = IdASCII;
205 sbuff->Gn[1] = IdSpecial;
206 sbuff->Gn[2] = IdASCII;
207 sbuff->Gn[3] = IdASCII;
208 sbuff->Glr[0] = 0;
209 sbuff->Glr[1] = 0;
210 }
211 sbuff->AutoWrapMode = TRUE;
212 sbuff->RelativeOrgMode = FALSE;
213 }
214
215 void ResetAllSBuffers()
216 {
217 ResetSBuffer(&SBuff1);
218 // copy SBuff1 to SBuff2
219 SBuff2 = SBuff1;
220 SBuff3 = SBuff1;
221 }
222
223 void ResetCurSBuffer()
224 {
225 PStatusBuff Buff;
226
227 if (AltScr) {
228 Buff = &SBuff3; // Alternate screen buffer
229 }
230 else {
231 Buff = &SBuff1; // Normal screen buffer
232 }
233 ResetSBuffer(Buff);
234 SBuff2 = *Buff;
235 }
236
237 void ResetTerminal() /*reset variables but don't update screen */
238 {
239 DispReset();
240 BuffReset();
241
242 /* Attribute */
243 CharAttr = DefCharAttr;
244 Special = FALSE;
245 BuffSetCurCharAttr(CharAttr);
246
247 /* Various modes */
248 InsertMode = FALSE;
249 LFMode = (ts.CRSend == IdCRLF);
250 AutoWrapMode = TRUE;
251 AppliKeyMode = FALSE;
252 AppliCursorMode = FALSE;
253 AppliEscapeMode = FALSE;
254 AcceptWheelToCursor = ts.TranslateWheelToCursor;
255 RelativeOrgMode = FALSE;
256 ts.ColorFlag &= ~CF_REVERSEVIDEO;
257 AutoRepeatMode = TRUE;
258 FocusReportMode = FALSE;
259 MouseReportMode = IdMouseTrackNone;
260 MouseReportExtMode = IdMouseTrackExtNone;
261 DecLocatorFlag = 0;
262
263 ChangeTerminalID();
264
265 LastX = 0;
266 LastY = 0;
267 ButtonStat = 0;
268
269 if (CLocale == NULL) {
270 CLocale = _create_locale(LC_ALL, "C");
271 }
272
273 /* Character sets */
274 ResetCharSet();
275
276 /* ESC flag for device control sequence */
277 ESCFlag = FALSE;
278 /* for TEK sequence */
279 JustAfterESC = FALSE;
280
281 /* Parse mode */
282 ParseMode = ModeFirst;
283
284 /* Clear printer mode */
285 PrinterMode = FALSE;
286
287 // status buffers
288 ResetAllSBuffers();
289
290 // Alternate Screen Buffer
291 AltScr = FALSE;
292
293 // Bracketed Paste Mode
294 BracketedPaste = FALSE;
295
296 // Saved IME Status
297 IMEstat = FALSE;
298
299 // previous received character
300 PrevCharacter = -1; // none
301 PrevCRorLFGeneratedCRLF = FALSE;
302
303 // Beep over-used
304 BeepStartTime = GetTickCount();
305 BeepSuppressTime = BeepStartTime - ts.BeepSuppressTime * 1000;
306 BeepStartTime -= (ts.BeepOverUsedTime * 1000);
307 BeepOverUsedCount = ts.BeepOverUsedCount;
308 }
309
310 void ResetCharSet()
311 {
312 if (ts.Language==IdJapanese)
313 {
314 Gn[0] = IdASCII;
315 Gn[1] = IdKatakana;
316 Gn[2] = IdKatakana;
317 Gn[3] = IdKanji;
318 Glr[0] = 0;
319 if ((ts.KanjiCode==IdJIS) &&
320 (ts.JIS7Katakana==0))
321 Glr[1] = 2; // 8-bit katakana
322 else
323 Glr[1] = 3;
324 }
325 else {
326 Gn[0] = IdASCII;
327 Gn[1] = IdSpecial;
328 Gn[2] = IdASCII;
329 Gn[3] = IdASCII;
330 Glr[0] = 0;
331 Glr[1] = 0;
332 cv.SendCode = IdASCII;
333 cv.SendKanjiFlag = FALSE;
334 cv.EchoCode = IdASCII;
335 cv.EchoKanjiFlag = FALSE;
336 }
337 /* Kanji flag */
338 KanjiIn = FALSE;
339 EUCkanaIn = FALSE;
340 EUCsupIn = FALSE;
341 SSflag = FALSE;
342
343 cv.Language = ts.Language;
344 cv.CRSend = ts.CRSend;
345 cv.KanjiCodeEcho = ts.KanjiCode;
346 cv.JIS7KatakanaEcho = ts.JIS7Katakana;
347 cv.KanjiCodeSend = ts.KanjiCodeSend;
348 cv.JIS7KatakanaSend = ts.JIS7KatakanaSend;
349 cv.KanjiIn = ts.KanjiIn;
350 cv.KanjiOut = ts.KanjiOut;
351 }
352
353 void ResetKeypadMode(BOOL DisabledModeOnly)
354 {
355 if (!DisabledModeOnly || ts.DisableAppKeypad) AppliKeyMode = FALSE;
356 if (!DisabledModeOnly || ts.DisableAppCursor) AppliCursorMode = FALSE;
357 }
358
359 void MoveToMainScreen()
360 {
361 StatusX = CursorX;
362 StatusWrap = Wrap;
363 StatusCursor = IsCaretEnabled();
364
365 CursorTop = MainTop;
366 CursorBottom = MainBottom;
367 Wrap = MainWrap;
368 DispEnableCaret(MainCursor);
369 MoveCursor(MainX,MainY); // move to main screen
370 }
371
372 void MoveToStatusLine()
373 {
374 MainX = CursorX;
375 MainY = CursorY;
376 MainTop = CursorTop;
377 MainBottom = CursorBottom;
378 MainWrap = Wrap;
379 MainCursor = IsCaretEnabled();
380
381 DispEnableCaret(StatusCursor);
382 MoveCursor(StatusX,NumOfLines-1); // move to status line
383 CursorTop = NumOfLines-1;
384 CursorBottom = CursorTop;
385 Wrap = StatusWrap;
386 }
387
388 void HideStatusLine()
389 {
390 if ((StatusLine>0) &&
391 (CursorY==NumOfLines-1))
392 MoveToMainScreen();
393 StatusX = 0;
394 StatusWrap = FALSE;
395 StatusCursor = TRUE;
396 ShowStatusLine(0); //hide
397 }
398
399 void ChangeTerminalSize(int Nx, int Ny)
400 {
401 BuffChangeTerminalSize(Nx,Ny);
402 StatusX = 0;
403 MainX = 0;
404 MainY = 0;
405 MainTop = 0;
406 MainBottom = NumOfColumns-1;
407 }
408
409 void SendCSIstr(char *str, int len) {
410 int l;
411
412 if (str == NULL || len < 0)
413 return;
414
415 if (len == 0) {
416 l = strlen(str);
417 }
418 else {
419 l = len;
420 }
421
422 if (Send8BitMode)
423 CommBinaryOut(&cv,"\233", 1);
424 else
425 CommBinaryOut(&cv,"\033[", 2);
426
427 CommBinaryOut(&cv, str, l);
428 }
429
430 void SendOSCstr(char *str, int len) {
431 int l;
432
433 if (str == NULL || len < 0)
434 return;
435
436 if (len == 0) {
437 l = strlen(str);
438 }
439 else {
440 l = len;
441 }
442
443 if (Send8BitMode) {
444 CommBinaryOut(&cv,"\235", 1);
445 CommBinaryOut(&cv, str, l);
446 CommBinaryOut(&cv,"\234", 1);
447 }
448 else {
449 CommBinaryOut(&cv,"\033]", 2);
450 CommBinaryOut(&cv, str, l);
451 CommBinaryOut(&cv,"\033\\", 2);
452 }
453
454 }
455
456 void SendDCSstr(char *str, int len) {
457 int l;
458
459 if (str == NULL || len < 0)
460 return;
461
462 if (len == 0) {
463 l = strlen(str);
464 }
465 else {
466 l = len;
467 }
468
469 if (Send8BitMode) {
470 CommBinaryOut(&cv,"\220", 1);
471 CommBinaryOut(&cv, str, l);
472 CommBinaryOut(&cv,"\234", 1);
473 }
474 else {
475 CommBinaryOut(&cv,"\033P", 2);
476 CommBinaryOut(&cv, str, l);
477 CommBinaryOut(&cv,"\033\\", 2);
478 }
479
480 }
481
482 void BackSpace()
483 {
484 if (CursorX == 0)
485 {
486 if ((CursorY>0) &&
487 ((ts.TermFlag & TF_BACKWRAP)!=0))
488 {
489 MoveCursor(NumOfColumns-1,CursorY-1);
490 // if (cv.HLogBuf!=0) Log1Byte(BS);
491 // (2005.2.20 yutaka)
492 if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
493 }
494 }
495 else if (CursorX > 0)
496 {
497 MoveCursor(CursorX-1,CursorY);
498 // if (cv.HLogBuf!=0) Log1Byte(BS);
499 // (2005.2.20 yutaka)
500 if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
501 }
502 }
503
504 void CarriageReturn(BOOL logFlag)
505 {
506 #ifndef NO_COPYLINE_FIX
507 if (!ts.EnableContinuedLineCopy || logFlag)
508 #endif /* NO_COPYLINE_FIX */
509 if (cv.HLogBuf!=0) Log1Byte(CR);
510
511 if (CursorX>0)
512 MoveCursor(0,CursorY);
513 }
514
515 void LineFeed(BYTE b, BOOL logFlag)
516 {
517 /* for auto print mode */
518 if ((AutoPrintMode) &&
519 (b>=LF) && (b<=FF))
520 BuffDumpCurrentLine(b);
521
522 #ifndef NO_COPYLINE_FIX
523 if (!ts.EnableContinuedLineCopy || logFlag)
524 #endif /* NO_COPYLINE_FIX */
525 if (cv.HLogBuf!=0) Log1Byte(LF);
526
527 if (CursorY < CursorBottom)
528 MoveCursor(CursorX,CursorY+1);
529 else if (CursorY == CursorBottom) BuffScrollNLines(1);
530 else if (CursorY < NumOfLines-StatusLine-1)
531 MoveCursor(CursorX,CursorY+1);
532
533 #ifndef NO_COPYLINE_FIX
534 ClearLineContinued();
535 #endif /* NO_COPYLINE_FIX */
536
537 if (LFMode) CarriageReturn(logFlag);
538 }
539
540 void Tab()
541 {
542 if (Wrap && !ts.VTCompatTab) {
543 CarriageReturn(FALSE);
544 LineFeed(LF,FALSE);
545 #ifndef NO_COPYLINE_FIX
546 if (ts.EnableContinuedLineCopy) {
547 SetLineContinued();
548 }
549 #endif /* NO_COPYLINE_FIX */
550 Wrap = FALSE;
551 }
552 CursorForwardTab(1, AutoWrapMode);
553 if (cv.HLogBuf!=0) Log1Byte(HT);
554 }
555
556 void PutChar(BYTE b)
557 {
558 BOOL SpecialNew;
559 TCharAttr CharAttrTmp;
560
561 CharAttrTmp = CharAttr;
562
563 if (PrinterMode) { // printer mode
564 WriteToPrnFile(b,TRUE);
565 return;
566 }
567
568 if (Wrap)
569 {
570 CarriageReturn(FALSE);
571 LineFeed(LF,FALSE);
572 #ifndef NO_COPYLINE_FIX
573 CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0;
574 #endif /* NO_COPYLINE_FIX */
575 }
576
577 // if (cv.HLogBuf!=0) Log1Byte(b);
578 // (2005.2.20 yutaka)
579 if (ts.LogTypePlainText) {
580 if (__isascii(b) && !isprint(b)) {
581 // ASCII�������A���\�������������O�����������B
582 } else {
583 if (cv.HLogBuf!=0) Log1Byte(b);
584 }
585 } else {
586 if (cv.HLogBuf!=0) Log1Byte(b);
587 }
588
589 Wrap = FALSE;
590
591 SpecialNew = FALSE;
592 if ((b>0x5F) && (b<0x80))
593 {
594 if (SSflag)
595 SpecialNew = (Gn[GLtmp]==IdSpecial);
596 else
597 SpecialNew = (Gn[Glr[0]]==IdSpecial);
598 }
599 else if (b>0xDF)
600 {
601 if (SSflag)
602 SpecialNew = (Gn[GLtmp]==IdSpecial);
603 else
604 SpecialNew = (Gn[Glr[1]]==IdSpecial);
605 }
606
607 if (SpecialNew != Special)
608 {
609 UpdateStr();
610 Special = SpecialNew;
611 }
612
613 if (Special)
614 {
615 b = b & 0x7F;
616 CharAttrTmp.Attr |= AttrSpecial;
617 }
618 else
619 CharAttrTmp.Attr |= CharAttr.Attr;
620
621 BuffPutChar(b, CharAttrTmp, InsertMode);
622
623 if (CursorX < NumOfColumns-1)
624 MoveRight();
625 else {
626 UpdateStr();
627 Wrap = AutoWrapMode;
628 }
629 }
630
631 void PutDecSp(BYTE b)
632 {
633 TCharAttr CharAttrTmp;
634
635 CharAttrTmp = CharAttr;
636
637 if (PrinterMode) { // printer mode
638 WriteToPrnFile(b, TRUE);
639 return;
640 }
641
642 if (Wrap) {
643 CarriageReturn(FALSE);
644 LineFeed(LF, FALSE);
645 #ifndef NO_COPYLINE_FIX
646 CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0;
647 #endif /* NO_COPYLINE_FIX */
648 }
649
650 if (cv.HLogBuf!=0) Log1Byte(b);
651 /*
652 if (ts.LogTypePlainText && __isascii(b) && !isprint(b)) {
653 // ASCII�������A���\�������������O�����������B
654 } else {
655 if (cv.HLogBuf!=0) Log1Byte(b);
656 }
657 */
658
659 Wrap = FALSE;
660
661 if (!Special) {
662 UpdateStr();
663 Special = TRUE;
664 }
665
666 CharAttrTmp.Attr |= AttrSpecial;
667 BuffPutChar(b, CharAttrTmp, InsertMode);
668
669 if (CursorX < NumOfColumns-1)
670 MoveRight();
671 else {
672 UpdateStr();
673 Wrap = AutoWrapMode;
674 }
675 }
676
677 void PutKanji(BYTE b)
678 {
679 #ifndef NO_COPYLINE_FIX
680 TCharAttr CharAttrTmp;
681
682 CharAttrTmp = CharAttr;
683 #endif /* NO_COPYLINE_FIX */
684 Kanji = Kanji + b;
685
686 if (PrinterMode && DirectPrn)
687 {
688 WriteToPrnFile(HIBYTE(Kanji),FALSE);
689 WriteToPrnFile(LOBYTE(Kanji),TRUE);
690 return;
691 }
692
693 if (ConvJIS)
694 Kanji = JIS2SJIS((WORD)(Kanji & 0x7f7f));
695
696 if (PrinterMode) { // printer mode
697 WriteToPrnFile(HIBYTE(Kanji),FALSE);
698 WriteToPrnFile(LOBYTE(Kanji),TRUE);
699 return;
700 }
701
702 if (Wrap)
703 {
704 CarriageReturn(FALSE);
705 LineFeed(LF,FALSE);
706 #ifndef NO_COPYLINE_FIX
707 if (ts.EnableContinuedLineCopy)
708 CharAttrTmp.Attr |= AttrLineContinued;
709 #endif /* NO_COPYLINE_FIX */
710 }
711 else if (CursorX > NumOfColumns-2)
712 if (AutoWrapMode)
713 {
714 #ifndef NO_COPYLINE_FIX
715 if (ts.EnableContinuedLineCopy)
716 {
717 CharAttrTmp.Attr |= AttrLineContinued;
718 if (CursorX == NumOfColumns-1)
719 BuffPutChar(0x20, CharAttr, FALSE);
720 }
721 #endif /* NO_COPYLINE_FIX */
722 CarriageReturn(FALSE);
723 LineFeed(LF,FALSE);
724 }
725 else return;
726
727 Wrap = FALSE;
728
729 if (cv.HLogBuf!=0)
730 {
731 Log1Byte(HIBYTE(Kanji));
732 Log1Byte(LOBYTE(Kanji));
733 }
734
735 if (Special)
736 {
737 UpdateStr();
738 Special = FALSE;
739 }
740
741 #ifndef NO_COPYLINE_FIX
742 BuffPutKanji(Kanji, CharAttrTmp, InsertMode);
743 #else
744 BuffPutKanji(Kanji, CharAttr, InsertMode);
745 #endif /* NO_COPYLINE_FIX */
746
747 if (CursorX < NumOfColumns-2)
748 {
749 MoveRight();
750 MoveRight();
751 }
752 else {
753 UpdateStr();
754 Wrap = AutoWrapMode;
755 }
756 }
757
758 void PutDebugChar(BYTE b)
759 {
760 static BYTE buff[3];
761 int i = 0;
762
763 if (DebugFlag!=DEBUG_FLAG_NONE) {
764 InsertMode = FALSE;
765 AutoWrapMode = TRUE;
766
767 if (DebugFlag==DEBUG_FLAG_HEXD) {
768 _snprintf(buff,3,"%02X",(unsigned int) b);
769
770 for (;i<2;i++)
771 PutChar(buff[i]);
772 PutChar(' ');
773 }
774 else if (DebugFlag==DEBUG_FLAG_NORM) {
775
776 if ((b & 0x80) == 0x80)
777 {
778 UpdateStr();
779 CharAttr.Attr = AttrReverse;
780 b = b & 0x7f;
781 }
782
783 if (b<=US)
784 {
785 PutChar('^');
786 PutChar((char)(b+0x40));
787 }
788 else if (b==DEL)
789 {
790 PutChar('<');
791 PutChar('D');
792 PutChar('E');
793 PutChar('L');
794 PutChar('>');
795 }
796 else
797 PutChar(b);
798 }
799
800 if (CharAttr.Attr != AttrDefault)
801 {
802 UpdateStr();
803 CharAttr.Attr = AttrDefault;
804 }
805 }
806 }
807
808 void PrnParseControl(BYTE b) // printer mode
809 {
810 switch (b) {
811 case NUL: return;
812 case SO:
813 if (! DirectPrn)
814 {
815 if ((ts.Language==IdJapanese) &&
816 (ts.KanjiCode==IdJIS) &&
817 (ts.JIS7Katakana==1) &&
818 ((ts.TermFlag & TF_FIXEDJIS)!=0))
819 Gn[1] = IdKatakana;
820 Glr[0] = 1; /* LS1 */
821 return;
822 }
823 break;
824 case SI:
825 if (! DirectPrn)
826 {
827 Glr[0] = 0; /* LS0 */
828 return;
829 }
830 break;
831 case DC1:
832 case DC3: return;
833 case ESC:
834 ICount = 0;
835 JustAfterESC = TRUE;
836 ParseMode = ModeESC;
837 WriteToPrnFile(0,TRUE); // flush prn buff
838 return;
839 case CSI:
840 if (! Accept8BitCtrl) {
841 PutChar(b); /* Disp C1 char in VT100 mode */
842 return;
843 }
844 ClearParams();
845 FirstPrm = TRUE;
846 ParseMode = ModeCSI;
847 WriteToPrnFile(0,TRUE); // flush prn buff
848 WriteToPrnFile(b,FALSE);
849 return;
850 }
851 /* send the uninterpreted character to printer */
852 WriteToPrnFile(b,TRUE);
853 }
854
855 void ParseControl(BYTE b)
856 {
857 if (PrinterMode) { // printer mode
858 PrnParseControl(b);
859 return;
860 }
861
862 if (b>=0x80) /* C1 char */
863 {
864 /* English mode */
865 if (ts.Language==IdEnglish)
866 {
867 if (!Accept8BitCtrl) {
868 PutChar(b); /* Disp C1 char in VT100 mode */
869 return;
870 }
871 }
872 else { /* Japanese mode */
873 if ((ts.TermFlag & TF_ACCEPT8BITCTRL)==0)
874 return; /* ignore C1 char */
875 /* C1 chars are interpreted as C0 chars in VT100 mode */
876 if (VTlevel < 2)
877 b = b & 0x7F;
878 }
879 }
880 switch (b) {
881 /* C0 group */
882 case ENQ:
883 CommBinaryOut(&cv,&(ts.Answerback[0]),ts.AnswerbackLen);
884 break;
885 case BEL:
886 if (ts.Beep != IdBeepOff) {
887 RingBell(ts.Beep);
888 }
889 break;
890 case BS: BackSpace(); break;
891 case HT: Tab(); break;
892
893 case LF:
894 if (ts.CRReceive == IdLF) {
895 // ���M�������s�R�[�h�� LF ���������A�T�[�o���� LF ���������������������������A
896 // CR+LF���������������������B
897 // cf. http://www.neocom.ca/forum/viewtopic.php?t=216
898 // (2007.1.21 yutaka)
899 CarriageReturn(TRUE);
900 LineFeed(b, TRUE);
901 break;
902 }
903 else if (ts.CRReceive == IdAUTO) {
904 // 9th Apr 2012: AUTO CR/LF mode (tentner)
905 // a CR or LF will generated a CR+LF, if the next character is the opposite, it will be ignored
906 if(PrevCharacter != CR || !PrevCRorLFGeneratedCRLF) {
907 CarriageReturn(TRUE);
908 LineFeed(b, TRUE);
909 PrevCRorLFGeneratedCRLF = TRUE;
910 }
911 else {
912 PrevCRorLFGeneratedCRLF = FALSE;
913 }
914 break;
915 }
916
917 case VT: LineFeed(b,TRUE); break;
918
919 case FF:
920 if ((ts.AutoWinSwitch>0) && JustAfterESC)
921 {
922 CommInsert1Byte(&cv,b);
923 CommInsert1Byte(&cv,ESC);
924 ChangeEmu = IdTEK; /* Enter TEK Mode */
925 }
926 else
927 LineFeed(b,TRUE);
928 break;
929 case CR:
930 if (ts.CRReceive == IdAUTO) {
931 // 9th Apr 2012: AUTO CR/LF mode (tentner)
932 // a CR or LF will generated a CR+LF, if the next character is the opposite, it will be ignored
933 if(PrevCharacter != LF || !PrevCRorLFGeneratedCRLF) {
934 CarriageReturn(TRUE);
935 LineFeed(b, TRUE);
936 PrevCRorLFGeneratedCRLF = TRUE;
937 }
938 else {
939 PrevCRorLFGeneratedCRLF = FALSE;
940 }
941 }
942 else {
943 CarriageReturn(TRUE);
944 if (ts.CRReceive==IdCRLF) {
945 CommInsert1Byte(&cv,LF);
946 }
947 }
948 break;
949 case SO:
950 if ((ts.Language==IdJapanese) &&
951 (ts.KanjiCode==IdJIS) &&
952 (ts.JIS7Katakana==1) &&
953 ((ts.TermFlag & TF_FIXEDJIS)!=0))
954 Gn[1] = IdKatakana;
955
956 Glr[0] = 1; /* LS1 */
957 break;
958 case SI: Glr[0] = 0; break; /* LS0 */
959 case DLE:
960 if ((ts.FTFlag & FT_BPAUTO)!=0)
961 ParseMode = ModeDLE; /* Auto B-Plus activation */
962 break;
963 case CAN:
964 if ((ts.FTFlag & FT_ZAUTO)!=0)
965 ParseMode = ModeCAN; /* Auto ZMODEM activation */
966 // else if (ts.AutoWinSwitch>0)
967 // ChangeEmu = IdTEK; /* Enter TEK Mode */
968 else
969 ParseMode = ModeFirst;
970 break;
971 case SUB: ParseMode = ModeFirst; break;
972 case ESC:
973 ICount = 0;
974 JustAfterESC = TRUE;
975 ParseMode = ModeESC;
976 break;
977 case FS:
978 case GS:
979 case RS:
980 case US:
981 if (ts.AutoWinSwitch>0)
982 {
983 CommInsert1Byte(&cv,b);
984 ChangeEmu = IdTEK; /* Enter TEK Mode */
985 }
986 break;
987
988 /* C1 char */
989 case IND: LineFeed(0,TRUE); break;
990 case NEL:
991 LineFeed(0,TRUE);
992 CarriageReturn(TRUE);
993 break;
994 case HTS: if (ts.TabStopFlag & TABF_HTS8) SetTabStop(); break;
995 case RI: CursorUpWithScroll(); break;
996 case SS2:
997 GLtmp = 2;
998 SSflag = TRUE;
999 break;
1000 case SS3:
1001 GLtmp = 3;
1002 SSflag = TRUE;
1003 break;
1004 case DCS:
1005 ClearParams();
1006 ESCFlag = FALSE;
1007 ParseMode = ModeDCS;
1008 break;
1009 case SOS:
1010 ESCFlag = FALSE;
1011 ParseMode = ModeSOS;
1012 break;
1013 case CSI:
1014 ClearParams();
1015 FirstPrm = TRUE;
1016 ParseMode = ModeCSI;
1017 break;
1018 case OSC:
1019 ClearParams();
1020 ParseMode = ModeXS;
1021 break;
1022 case PM:
1023 case APC:
1024 ESCFlag = FALSE;
1025 ParseMode = ModeSOS;
1026 break;
1027 }
1028 }
1029
1030 void SaveCursor()
1031 {
1032 int i;
1033 PStatusBuff Buff;
1034
1035 if ((StatusLine>0) &&
1036 (CursorY==NumOfLines-1))
1037 Buff = &SBuff2; // for status line
1038 else if (AltScr)
1039 Buff = &SBuff3; // for alternate screen
1040 else
1041 Buff = &SBuff1; // for main screen
1042
1043 Buff->CursorX = CursorX;
1044 Buff->CursorY = CursorY;
1045 Buff->Attr = CharAttr;
1046 Buff->Glr[0] = Glr[0];
1047 Buff->Glr[1] = Glr[1];
1048 for (i=0 ; i<=3; i++)
1049 Buff->Gn[i] = Gn[i];
1050 Buff->AutoWrapMode = AutoWrapMode;
1051 Buff->RelativeOrgMode = RelativeOrgMode;
1052 }
1053
1054 void RestoreCursor()
1055 {
1056 int i;
1057 PStatusBuff Buff;
1058 UpdateStr();
1059
1060 if ((StatusLine>0) &&
1061 (CursorY==NumOfLines-1))
1062 Buff = &SBuff2; // for status line
1063 else if (AltScr)
1064 Buff = &SBuff3; // for alternate screen
1065 else
1066 Buff = &SBuff1; // for main screen
1067
1068 if (Buff->CursorX > NumOfColumns-1)
1069 Buff->CursorX = NumOfColumns-1;
1070 if (Buff->CursorY > NumOfLines-1-StatusLine)
1071 Buff->CursorY = NumOfLines-1-StatusLine;
1072 MoveCursor(Buff->CursorX,Buff->CursorY);
1073 CharAttr = Buff->Attr;
1074 Glr[0] = Buff->Glr[0];
1075 Glr[1] = Buff->Glr[1];
1076 for (i=0 ; i<=3; i++)
1077 Gn[i] = Buff->Gn[i];
1078 AutoWrapMode = Buff->AutoWrapMode;
1079 RelativeOrgMode = Buff->RelativeOrgMode;
1080 }
1081
1082 void AnswerTerminalType()
1083 {
1084 char Tmp[50];
1085
1086 if (ts.TerminalID<IdVT320 || !Send8BitMode)
1087 strncpy_s(Tmp, sizeof(Tmp),"\033[?", _TRUNCATE);
1088 else
1089 strncpy_s(Tmp, sizeof(Tmp),"\233?", _TRUNCATE);
1090
1091 switch (ts.TerminalID) {
1092 case IdVT100:
1093 strncat_s(Tmp,sizeof(Tmp),"1;2",_TRUNCATE);
1094 break;
1095 case IdVT100J:
1096 strncat_s(Tmp,sizeof(Tmp),"5;2",_TRUNCATE);
1097 break;
1098 case IdVT101:
1099 strncat_s(Tmp,sizeof(Tmp),"1;0",_TRUNCATE);
1100 break;
1101 case IdVT102:
1102 strncat_s(Tmp,sizeof(Tmp),"6",_TRUNCATE);
1103 break;
1104 case IdVT102J:
1105 strncat_s(Tmp,sizeof(Tmp),"15",_TRUNCATE);
1106 break;
1107 case IdVT220J:
1108 strncat_s(Tmp,sizeof(Tmp),"62;1;2;5;6;7;8",_TRUNCATE);
1109 break;
1110 case IdVT282:
1111 strncat_s(Tmp,sizeof(Tmp),"62;1;2;4;5;6;7;8;10;11",_TRUNCATE);
1112 break;
1113 case IdVT320:
1114 strncat_s(Tmp,sizeof(Tmp),"63;1;2;6;7;8",_TRUNCATE);
1115 break;
1116 case IdVT382:
1117 strncat_s(Tmp,sizeof(Tmp),"63;1;2;4;5;6;7;8;10;15",_TRUNCATE);
1118 break;
1119 case IdVT420:
1120 strncat_s(Tmp,sizeof(Tmp),"64;1;2;7;8;9;15;18;21",_TRUNCATE);
1121 break;
1122 case IdVT520:
1123 strncat_s(Tmp,sizeof(Tmp),"65;1;2;7;8;9;12;18;19;21;23;24;42;44;45;46",_TRUNCATE);
1124 break;
1125 case IdVT525:
1126 strncat_s(Tmp,sizeof(Tmp),"65;1;2;7;9;12;18;19;21;22;23;24;42;44;45;46",_TRUNCATE);
1127 break;
1128 }
1129 strncat_s(Tmp,sizeof(Tmp),"c",_TRUNCATE);
1130
1131 CommBinaryOut(&cv,Tmp,strlen(Tmp)); /* Report terminal ID */
1132 }
1133
1134 void ESCSpace(BYTE b)
1135 {
1136 switch (b) {
1137 case 'F': // S7C1T
1138 Send8BitMode = FALSE;
1139 break;
1140 case 'G': // S8C1T
1141 if (VTlevel >= 2) {
1142 Send8BitMode = TRUE;
1143 }
1144 break;
1145 }
1146 }
1147
1148 void ESCSharp(BYTE b)
1149 {
1150 switch (b) {
1151 case '8': /* Fill screen with "E" (DECALN) */
1152 BuffUpdateScroll();
1153 BuffFillWithE();
1154 CursorTop = 0;
1155 CursorBottom = NumOfLines-1-StatusLine;
1156 MoveCursor(0,0);
1157 ParseMode = ModeFirst;
1158 break;
1159 }
1160 }
1161
1162 /* select double byte code set */
1163 void ESCDBCSSelect(BYTE b)
1164 {
1165 int Dist;
1166
1167 if (ts.Language!=IdJapanese) return;
1168
1169 switch (ICount) {
1170 case 1:
1171 if ((b=='@') || (b=='B'))
1172 {
1173 Gn[0] = IdKanji; /* Kanji -> G0 */
1174 if ((ts.TermFlag & TF_AUTOINVOKE)!=0)
1175 Glr[0] = 0; /* G0->GL */
1176 }
1177 break;
1178 case 2:
1179 /* Second intermediate char must be
1180 '(' or ')' or '*' or '+'. */
1181 Dist = (IntChar[2]-'(') & 3; /* G0 - G3 */
1182 if ((b=='1') || (b=='3') ||
1183 (b=='@') || (b=='B'))
1184 {
1185 Gn[Dist] = IdKanji; /* Kanji -> G0-3 */
1186 if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
1187 (Dist==0))
1188 Glr[0] = 0; /* G0->GL */
1189 }
1190 break;
1191 }
1192 }
1193
1194 void ESCSelectCode(BYTE b)
1195 {
1196 switch (b) {
1197 case '0':
1198 if (ts.AutoWinSwitch>0)
1199 ChangeEmu = IdTEK; /* enter TEK mode */
1200 break;
1201 }
1202 }
1203
1204 /* select single byte code set */
1205 void ESCSBCSSelect(BYTE b)
1206 {
1207 int Dist;
1208
1209 /* Intermediate char must be
1210 '(' or ')' or '*' or '+'. */
1211 Dist = (IntChar[1]-'(') & 3; /* G0 - G3 */
1212
1213 switch (b) {
1214 case '0': Gn[Dist] = IdSpecial; break;
1215 case '<': Gn[Dist] = IdASCII; break;
1216 case '>': Gn[Dist] = IdASCII; break;
1217 case 'A': Gn[Dist] = IdASCII; break;
1218 case 'B': Gn[Dist] = IdASCII; break;
1219 case 'H': Gn[Dist] = IdASCII; break;
1220 case 'I':
1221 if (ts.Language==IdJapanese)
1222 Gn[Dist] = IdKatakana;
1223 break;
1224 case 'J': Gn[Dist] = IdASCII; break;
1225 }
1226
1227 if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
1228 (Dist==0))
1229 Glr[0] = 0; /* G0->GL */
1230 }
1231
1232 void PrnParseEscape(BYTE b) // printer mode
1233 {
1234 int i;
1235
1236 ParseMode = ModeFirst;
1237 switch (ICount) {
1238 /* no intermediate char */
1239 case 0:
1240 switch (b) {
1241 case '[': /* CSI */
1242 ClearParams();
1243 FirstPrm = TRUE;
1244 WriteToPrnFile(ESC,FALSE);
1245 WriteToPrnFile('[',FALSE);
1246 ParseMode = ModeCSI;
1247 return;
1248 } /* end of case Icount=0 */
1249 break;
1250 /* one intermediate char */
1251 case 1:
1252 switch (IntChar[1]) {
1253 case '$':
1254 if (! DirectPrn)
1255 {
1256 ESCDBCSSelect(b);
1257 return;
1258 }
1259 break;
1260 case '(':
1261 case ')':
1262 case '*':
1263 case '+':
1264 if (! DirectPrn)
1265 {
1266 ESCSBCSSelect(b);
1267 return;
1268 }
1269 break;
1270 }
1271 break;
1272 /* two intermediate char */
1273 case 2:
1274 if ((! DirectPrn) &&
1275 (IntChar[1]=='$') &&
1276 ('('<=IntChar[2]) &&
1277 (IntChar[2]<='+'))
1278 {
1279 ESCDBCSSelect(b);
1280 return;
1281 }
1282 break;
1283 }
1284 // send the uninterpreted sequence to printer
1285 WriteToPrnFile(ESC,FALSE);
1286 for (i=1; i<=ICount; i++)
1287 WriteToPrnFile(IntChar[i],FALSE);
1288 WriteToPrnFile(b,TRUE);
1289 }
1290
1291 void ParseEscape(BYTE b) /* b is the final char */
1292 {
1293 if (PrinterMode) { // printer mode
1294 PrnParseEscape(b);
1295 return;
1296 }
1297
1298 switch (ICount) {
1299 /* no intermediate char */
1300 case 0:
1301 switch (b) {
1302 case '6': // DECBI
1303 if (CursorX == 0) {
1304 BuffScrollRight(1);
1305 }
1306 else {
1307 CursorX--;
1308 }
1309 case '7': SaveCursor(); break;
1310 case '8': RestoreCursor(); break;
1311 case '9': // DECFI
1312 if (CursorX == NumOfColumns-1) {
1313 BuffScrollLeft(1);
1314 }
1315 else {
1316 CursorX++;
1317 }
1318 case '=': AppliKeyMode = TRUE; break;
1319 case '>': AppliKeyMode = FALSE; break;
1320 case 'D': /* IND */
1321 LineFeed(0,TRUE);
1322 break;
1323 case 'E': /* NEL */
1324 MoveCursor(0,CursorY);
1325 LineFeed(0,TRUE);
1326 break;
1327 case 'H': /* HTS */
1328 if (ts.TabStopFlag & TABF_HTS7) SetTabStop();
1329 break;
1330 case 'M': /* RI */
1331 CursorUpWithScroll();
1332 break;
1333 case 'N': /* SS2 */
1334 GLtmp = 2;
1335 SSflag = TRUE;
1336 break;
1337 case 'O': /* SS3 */
1338 GLtmp = 3;
1339 SSflag = TRUE;
1340 break;
1341 case 'P': /* DCS */
1342 ClearParams();
1343 ESCFlag = FALSE;
1344 ParseMode = ModeDCS;
1345 return;
1346 case 'X': /* SOS */
1347 ESCFlag = FALSE;
1348 ParseMode = ModeSOS;
1349 return;
1350 case 'Z': /* DECID */
1351 AnswerTerminalType();
1352 break;
1353 case '[': /* CSI */
1354 ClearParams();
1355 FirstPrm = TRUE;
1356 ParseMode = ModeCSI;
1357 return;
1358 case '\\': break; /* ST */
1359 case ']': /* XTERM sequence (OSC) */
1360 ClearParams();
1361 ParseMode = ModeXS;
1362 return;
1363 case '^':
1364 case '_': /* PM, APC */
1365 ESCFlag = FALSE;
1366 ParseMode = ModeSOS;
1367 return;
1368 case 'c': /* Hardware reset */
1369 HideStatusLine();
1370 ResetTerminal();
1371 ClearUserKey();
1372 ClearBuffer();
1373 if (ts.PortType==IdSerial) // reset serial port
1374 CommResetSerial(&ts, &cv, TRUE);
1375 break;
1376 case 'g': /* Visual Bell (screen original?) */
1377 RingBell(IdBeepVisual);
1378 break;
1379 case 'n': Glr[0] = 2; break; /* LS2 */
1380 case 'o': Glr[0] = 3; break; /* LS3 */
1381 case '|': Glr[1] = 3; break; /* LS3R */
1382 case '}': Glr[1] = 2; break; /* LS2R */
1383 case '~': Glr[1] = 1; break; /* LS1R */
1384 } /* end of case Icount=0 */
1385 break;
1386 /* one intermediate char */
1387 case 1:
1388 switch (IntChar[1]) {
1389 case ' ': ESCSpace(b); break;
1390 case '#': ESCSharp(b); break;
1391 case '$': ESCDBCSSelect(b); break;
1392 case '%': break;
1393 case '(':
1394 case ')':
1395 case '*':
1396 case '+':
1397 ESCSBCSSelect(b);
1398 break;
1399 }
1400 break;
1401 /* two intermediate char */
1402 case 2:
1403 if ((IntChar[1]=='$') &&
1404 ('('<=IntChar[2]) &&
1405 (IntChar[2]<='+'))
1406 ESCDBCSSelect(b);
1407 else if ((IntChar[1]=='%') &&
1408 (IntChar[2]=='!'))
1409 ESCSelectCode(b);
1410 break;
1411 }
1412 ParseMode = ModeFirst;
1413 }
1414
1415 void EscapeSequence(BYTE b)
1416 {
1417 if (b<=US)
1418 ParseControl(b);
1419 else if ((b>=0x20) && (b<=0x2F))
1420 {
1421 if (ICount<IntCharMax) ICount++;
1422 IntChar[ICount] = b;
1423 }
1424 else if ((b>=0x30) && (b<=0x7E))
1425 ParseEscape(b);
1426 else if ((b>=0x80) && (b<=0x9F))
1427 ParseControl(b);
1428 else if (b>=0xA0) {
1429 ParseMode=ModeFirst;
1430 ParseFirst(b);
1431 }
1432
1433 JustAfterESC = FALSE;
1434 }
1435
1436 void CSInsertCharacter()
1437 {
1438 // Insert space characters at cursor
1439 int Count;
1440
1441 BuffUpdateScroll();
1442 if (Param[1]<1) Param[1] = 1;
1443 Count = Param[1];
1444 BuffInsertSpace(Count);
1445 }
1446
1447 void CSCursorUp()
1448 {
1449 if (Param[1]<1) Param[1] = 1;
1450
1451 if (CursorY >= CursorTop)
1452 {
1453 if (CursorY-Param[1] > CursorTop)
1454 MoveCursor(CursorX,CursorY-Param[1]);
1455 else
1456 MoveCursor(CursorX,CursorTop);
1457 }
1458 else {
1459 if (CursorY > 0)
1460 MoveCursor(CursorX,CursorY-Param[1]);
1461 else
1462 MoveCursor(CursorX,0);
1463 }
1464 }
1465
1466 void CSCursorUp1()
1467 {
1468 MoveCursor(0,CursorY);
1469 CSCursorUp();
1470 }
1471
1472 void CSCursorDown()
1473 {
1474 if (Param[1]<1) Param[1] = 1;
1475
1476 if (CursorY <= CursorBottom)
1477 {
1478 if (CursorY+Param[1] < CursorBottom)
1479 MoveCursor(CursorX,CursorY+Param[1]);
1480 else
1481 MoveCursor(CursorX,CursorBottom);
1482 }
1483 else {
1484 if (CursorY < NumOfLines-StatusLine-1)
1485 MoveCursor(CursorX,CursorY+Param[1]);
1486 else
1487 MoveCursor(CursorX,NumOfLines-StatusLine);
1488 }
1489 }
1490
1491 void CSCursorDown1()
1492 {
1493 MoveCursor(0,CursorY);
1494 CSCursorDown();
1495 }
1496
1497 void CSScreenErase()
1498 {
1499 BuffUpdateScroll();
1500 switch (Param[1]) {
1501 case 0:
1502 // <ESC>[H(Cursor in left upper corner)�������J�[�\�������������w�������������A
1503 // <ESC>[J��<ESC>[2J�����������������A�����������A���s�o�b�t�@���X�N���[���A�E�g
1504 // �����������������B(2005.5.29 yutaka)
1505 // �R���t�B�O���[�V�������������������������������B(2008.5.3 yutaka)
1506 if (ts.ScrollWindowClearScreen &&
1507 (CursorX == 0 && CursorY == 0)) {
1508 // Erase screen (scroll out)
1509 BuffClearScreen();
1510 UpdateWindow(HVTWin);
1511
1512 } else {
1513 // Erase characters from cursor to the end of screen
1514 BuffEraseCurToEnd();
1515 }
1516 break;
1517
1518 case 1:
1519 // Erase characters from home to cursor
1520 BuffEraseHomeToCur();
1521 break;
1522
1523 case 2:
1524 // Erase screen (scroll out)
1525 BuffClearScreen();
1526 UpdateWindow(HVTWin);
1527 break;
1528 }
1529 }
1530
1531 void CSQSelScreenErase()
1532 {
1533 BuffUpdateScroll();
1534 switch (Param[1]) {
1535 case 0:
1536 // Erase characters from cursor to end
1537 BuffSelectedEraseCurToEnd();
1538 break;
1539
1540 case 1:
1541 // Erase characters from home to cursor
1542 BuffSelectedEraseHomeToCur();
1543 break;
1544
1545 case 2:
1546 // Erase entire screen
1547 BuffSelectedEraseScreen();
1548 break;
1549 }
1550 }
1551
1552 void CSInsertLine()
1553 {
1554 // Insert lines at current position
1555 int Count, YEnd;
1556
1557 if (CursorY < CursorTop) return;
1558 if (CursorY > CursorBottom) return;
1559 if (Param[1]<1) Param[1] = 1;
1560 Count = Param[1];
1561
1562 YEnd = CursorBottom;
1563 if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1564 if (Count > YEnd+1 - CursorY) Count = YEnd+1 - CursorY;
1565
1566 BuffInsertLines(Count,YEnd);
1567 }
1568
1569 void CSLineErase()
1570 {
1571 BuffUpdateScroll();
1572 switch (Param[1]) {
1573 /* erase char from cursor to end of line */
1574 case 0:
1575 BuffEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1576 break;
1577 /* erase char from start of line to cursor */
1578 case 1:
1579 BuffEraseCharsInLine(0,CursorX+1);
1580 break;
1581 /* erase entire line */
1582 case 2:
1583 BuffEraseCharsInLine(0,NumOfColumns);
1584 break;
1585 }
1586 }
1587
1588 void CSQSelLineErase()
1589 {
1590 BuffUpdateScroll();
1591 switch (Param[1]) {
1592 /* erase char from cursor to end of line */
1593 case 0:
1594 BuffSelectedEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1595 break;
1596 /* erase char from start of line to cursor */
1597 case 1:
1598 BuffSelectedEraseCharsInLine(0,CursorX+1);
1599 break;
1600 /* erase entire line */
1601 case 2:
1602 BuffSelectedEraseCharsInLine(0,NumOfColumns);
1603 break;
1604 }
1605 }
1606
1607 void CSDeleteNLines()
1608 // Delete lines from current line
1609 {
1610 int Count, YEnd;
1611
1612 if (CursorY < CursorTop) return;
1613 if (CursorY > CursorBottom) return;
1614 Count = Param[1];
1615 if (Count<1) Count = 1;
1616
1617 YEnd = CursorBottom;
1618 if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1619 if (Count > YEnd+1-CursorY) Count = YEnd+1-CursorY;
1620 BuffDeleteLines(Count,YEnd);
1621 }
1622
1623 void CSDeleteCharacter()
1624 {
1625 // Delete characters in current line from cursor
1626
1627 if (Param[1]<1) Param[1] = 1;
1628 BuffUpdateScroll();
1629 BuffDeleteChars(Param[1]);
1630 }
1631
1632 void CSEraseCharacter()
1633 {
1634 if (Param[1]<1) Param[1] = 1;
1635 BuffUpdateScroll();
1636 BuffEraseChars(Param[1]);
1637 }
1638
1639 void CSScrollUP()
1640 {
1641 if (Param[1]<1) Param[1] = 1;
1642 BuffUpdateScroll();
1643 BuffRegionScrollUpNLines(Param[1]);
1644 }
1645
1646 void CSScrollDown()
1647 {
1648 if (Param[1]<1) Param[1] = 1;
1649 BuffUpdateScroll();
1650 BuffRegionScrollDownNLines(Param[1]);
1651 }
1652
1653 void CSForwardTab()
1654 {
1655 if (Param[1]<1) Param[1] = 1;
1656 CursorForwardTab(Param[1], AutoWrapMode);
1657 }
1658
1659 void CSBackwardTab()
1660 {
1661 if (Param[1]<1) Param[1] = 1;
1662 CursorBackwardTab(Param[1]);
1663 }
1664
1665 void CSMoveToColumnN()
1666 {
1667 if (Param[1]<1) Param[1] = 1;
1668 Param[1]--;
1669 if (Param[1] > NumOfColumns-1) Param[1] = NumOfColumns-1;
1670 MoveCursor(Param[1],CursorY);
1671 }
1672
1673 void CSCursorRight()
1674 {
1675 if (Param[1]<1) Param[1] = 1;
1676 if (CursorX + Param[1] > NumOfColumns-1)
1677 MoveCursor(NumOfColumns-1,CursorY);
1678 else
1679 MoveCursor(CursorX+Param[1],CursorY);
1680 }
1681
1682 void CSCursorLeft()
1683 {
1684 if (Param[1]<1) Param[1] = 1;
1685 if (CursorX-Param[1] < 0)
1686 MoveCursor(0,CursorY);
1687 else
1688 MoveCursor(CursorX-Param[1],CursorY);
1689 }
1690
1691 void CSMoveToLineN()
1692 {
1693 if (Param[1]<1) Param[1] = 1;
1694 if (RelativeOrgMode)
1695 {
1696 if (CursorTop+Param[1]-1 > CursorBottom)
1697 MoveCursor(CursorX,CursorBottom);
1698 else
1699 MoveCursor(CursorX,CursorTop+Param[1]-1);
1700 }
1701 else {
1702 if (Param[1] > NumOfLines-StatusLine)
1703 MoveCursor(CursorX,NumOfLines-1-StatusLine);
1704 else
1705 MoveCursor(CursorX,Param[1]-1);
1706 }
1707 }
1708
1709 void CSMoveToXY()
1710 {
1711 int NewX, NewY;
1712
1713 if (Param[1]<1) Param[1] = 1;
1714 if ((NParam < 2) || (Param[2]<1)) Param[2] = 1;
1715 NewX = Param[2] - 1;
1716 if (NewX > NumOfColumns-1) NewX = NumOfColumns-1;
1717
1718 if ((StatusLine>0) && (CursorY==NumOfLines-1))
1719 NewY = CursorY;
1720 else if (RelativeOrgMode)
1721 {
1722 NewY = CursorTop + Param[1] - 1;
1723 if (NewY > CursorBottom) NewY = CursorBottom;
1724 }
1725 else {
1726 NewY = Param[1] - 1;
1727 if (NewY > NumOfLines-1-StatusLine)
1728 NewY = NumOfLines-1-StatusLine;
1729 }
1730 MoveCursor(NewX,NewY);
1731 }
1732
1733 void CSDeleteTabStop()
1734 {
1735 ClearTabStop(Param[1]);
1736 }
1737
1738 void CS_h_Mode() // SM
1739 {
1740 switch (Param[1]) {
1741 case 2: // KAM
1742 KeybEnabled = FALSE; break;
1743 case 4: // IRM
1744 InsertMode = TRUE; break;
1745 case 12: // SRM
1746 ts.LocalEcho = 0;
1747 if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1748 TelChangeEcho();
1749 break;
1750 case 20: // LF/NL
1751 LFMode = TRUE;
1752 ts.CRSend = IdCRLF;
1753 cv.CRSend = IdCRLF;
1754 break;
1755 case 33: // WYSTCURM
1756 if (ts.WindowFlag & WF_CURSORCHANGE) {
1757 ts.NonblinkingCursor = TRUE;
1758 ChangeCaret();
1759 }
1760 break;
1761 case 34: // WYULCURM
1762 if (ts.WindowFlag & WF_CURSORCHANGE) {
1763 ts.CursorShape = IdHCur;
1764 ChangeCaret();
1765 }
1766 break;
1767 }
1768 }
1769
1770 void CS_i_Mode() // MC
1771 {
1772 switch (Param[1]) {
1773 /* print screen */
1774 // PrintEX -- TRUE: print screen
1775 // FALSE: scroll region
1776 case 0:
1777 if (ts.TermFlag&TF_PRINTERCTRL) {
1778 BuffPrint(! PrintEX);
1779 }
1780 break;
1781 /* printer controller mode off */
1782 case 4: break; /* See PrnParseCS() */
1783 /* printer controller mode on */
1784 case 5:
1785 if (ts.TermFlag&TF_PRINTERCTRL) {
1786 if (! AutoPrintMode)
1787 OpenPrnFile();
1788 DirectPrn = (ts.PrnDev[0]!=0);
1789 PrinterMode = TRUE;
1790 }
1791 break;
1792 }
1793 }
1794
1795 void CS_l_Mode() // RM
1796 {
1797 switch (Param[1]) {
1798 case 2: // KAM
1799 KeybEnabled = TRUE; break;
1800 case 4: // IRM
1801 InsertMode = FALSE; break;
1802 case 12: // SRM
1803 ts.LocalEcho = 1;
1804 if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1805 TelChangeEcho();
1806 break;
1807 case 20: // LF/NL
1808 LFMode = FALSE;
1809 ts.CRSend = IdCR;
1810 cv.CRSend = IdCR;
1811 break;
1812 case 33: // WYSTCURM
1813 if (ts.WindowFlag & WF_CURSORCHANGE) {
1814 ts.NonblinkingCursor = FALSE;
1815 ChangeCaret();
1816 }
1817 break;
1818 case 34: // WYULCURM
1819 if (ts.WindowFlag & WF_CURSORCHANGE) {
1820 ts.CursorShape = IdBlkCur;
1821 ChangeCaret();
1822 }
1823 break;
1824 }
1825 }
1826
1827 void CS_n_Mode() // DSR
1828 {
1829 char Report[16];
1830 int Y, len;
1831
1832 switch (Param[1]) {
1833 case 5:
1834 /* Device Status Report -> Ready */
1835 SendCSIstr("0n", 0);
1836 break;
1837 case 6:
1838 /* Cursor Position Report */
1839 Y = CursorY+1;
1840 if ((StatusLine>0) &&
1841 (Y==NumOfLines))
1842 Y = 1;
1843 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%u;%uR", CLocale, Y, CursorX+1);
1844 SendCSIstr(Report, len);
1845 break;
1846 }
1847 }
1848
1849 void ParseSGRParams(PCharAttr attr, PCharAttr mask, int start)
1850 {
1851 int i, j, P, r, g, b, color;
1852 TCharAttr dummy;
1853
1854 if (mask == NULL) {
1855 mask = &dummy;
1856 }
1857
1858 for (i=start ; i<=NParam ; i++)
1859 {
1860 P = Param[i];
1861 switch (P) {
1862 case 0: /* Clear all */
1863 attr->Attr = DefCharAttr.Attr;
1864 attr->Attr2 = DefCharAttr.Attr2 | (attr->Attr2&Attr2Protect);
1865 attr->Fore = DefCharAttr.Fore;
1866 attr->Back = DefCharAttr.Back;
1867 mask->Attr = AttrSgrMask;
1868 mask->Attr2 = Attr2ColorMask;
1869 break;
1870
1871 case 1: /* Bold */
1872 attr->Attr |= AttrBold;
1873 mask->Attr |= AttrBold;
1874 break;
1875
1876 case 4: /* Under line */
1877 attr->Attr |= AttrUnder;
1878 mask->Attr |= AttrUnder;
1879 break;
1880
1881 case 5: /* Blink */
1882 attr->Attr |= AttrBlink;
1883 mask->Attr |= AttrBlink;
1884 break;
1885
1886 case 7: /* Reverse */
1887 attr->Attr |= AttrReverse;
1888 mask->Attr |= AttrReverse;
1889 break;
1890
1891 case 22: /* Bold off */
1892 attr->Attr &= ~ AttrBold;
1893 mask->Attr |= AttrBold;
1894 break;
1895
1896 case 24: /* Under line off */
1897 attr->Attr &= ~ AttrUnder;
1898 mask->Attr |= AttrUnder;
1899 break;
1900
1901 case 25: /* Blink off */
1902 attr->Attr &= ~ AttrBlink;
1903 mask->Attr |= AttrBlink;
1904 break;
1905
1906 case 27: /* Reverse off */
1907 attr->Attr &= ~ AttrReverse;
1908 mask->Attr |= AttrReverse;
1909 break;
1910
1911 case 30:
1912 case 31:
1913 case 32:
1914 case 33:
1915 case 34:
1916 case 35:
1917 case 36:
1918 case 37: /* text color */
1919 attr->Attr2 |= Attr2Fore;
1920 mask->Attr2 |= Attr2Fore;
1921 attr->Fore = P - 30;
1922 break;
1923
1924 case 38: /* text color (256color mode) */
1925 if (ts.ColorFlag & CF_XTERM256) {
1926 /*
1927 * Change foreground color. accept following formats.
1928 *
1929 * 38 ; 2 ; r ; g ; b
1930 * 38 ; 2 : r : g : b
1931 * 38 : 2 : r : g : b
1932 * 38 ; 5 ; idx
1933 * 38 ; 5 : idx
1934 * 38 : 5 : idx
1935 *
1936 */
1937 color = -1;
1938 j = 0;
1939 if (NSParam[i] > 0) {
1940 P = SubParam[i][1];
1941 j++;
1942 }
1943 else if (i < NParam) {
1944 P = Param[i+1];
1945 if (P == 2 || P == 5) {
1946 i++;
1947 }
1948 }
1949 switch (P) {
1950 case 2:
1951 r = g = b = 0;
1952 if (NSParam[i] > 0) {
1953 if (j < NSParam[i]) {
1954 r = SubParam[i][++j];
1955 if (j < NSParam[i]) {
1956 g = SubParam[i][++j];
1957 }
1958 if (j < NSParam[i]) {
1959 b = SubParam[i][++j];
1960 }
1961 color = DispFindClosestColor(r, g, b);
1962 }
1963 }
1964 else if (i < NParam && NSParam[i+1] > 0) {
1965 r = Param[++i];
1966 g = SubParam[i][1];
1967 if (NSParam[i] > 1) {
1968 b = SubParam[i][2];
1969 }
1970 color = DispFindClosestColor(r, g, b);
1971 }
1972 else if (i+2 < NParam) {
1973 r = Param[++i];
1974 g = Param[++i];
1975 b = Param[++i];
1976 color = DispFindClosestColor(r, g, b);
1977 }
1978 break;
1979 case 5:
1980 if (NSParam[i] > 0) {
1981 if (j < NSParam[i]) {
1982 color = SubParam[i][++j];
1983 }
1984 }
1985 else if (i < NParam) {
1986 color = Param[++i];
1987 }
1988 break;
1989 }
1990 if (color >= 0 && color < 256) {
1991 attr->Attr2 |= Attr2Fore;
1992 mask->Attr2 |= Attr2Fore;
1993 attr->Fore = color;
1994 }
1995 }
1996 break;
1997
1998 case 39: /* Reset text color */
1999 attr->Attr2 &= ~ Attr2Fore;
2000 mask->Attr2 |= Attr2Fore;
2001 attr->Fore = AttrDefaultFG;
2002 break;
2003
2004 case 40:
2005 case 41:
2006 case 42:
2007 case 43:
2008 case 44:
2009 case 45:
2010 case 46:
2011 case 47: /* Back color */
2012 attr->Attr2 |= Attr2Back;
2013 mask->Attr2 |= Attr2Back;
2014 attr->Back = P - 40;
2015 break;
2016
2017 case 48: /* Back color (256color mode) */
2018 if (ts.ColorFlag & CF_XTERM256) {
2019 color = -1;
2020 j = 0;
2021 if (NSParam[i] > 0) {
2022 P = SubParam[i][1];
2023 j++;
2024 }
2025 else if (i < NParam) {
2026 P = Param[i+1];
2027 if (P == 2 || P == 5) {
2028 i++;
2029 }
2030 }
2031 switch (P) {
2032 case 2:
2033 r = g = b = 0;
2034 if (NSParam[i] > 0) {
2035 if (j < NSParam[i]) {
2036 r = SubParam[i][++j];
2037 if (j < NSParam[i]) {
2038 g = SubParam[i][++j];
2039 }
2040 if (j < NSParam[i]) {
2041 b = SubParam[i][++j];
2042 }
2043 color = DispFindClosestColor(r, g, b);
2044 }
2045 }
2046 else if (i < NParam && NSParam[i+1] > 0) {
2047 r = Param[++i];
2048 g = SubParam[i][1];
2049 if (NSParam[i] > 1) {
2050 b = SubParam[i][2];
2051 }
2052 color = DispFindClosestColor(r, g, b);
2053 }
2054 else if (i+2 < NParam) {
2055 r = Param[++i];
2056 g = Param[++i];
2057 b = Param[++i];
2058 color = DispFindClosestColor(r, g, b);
2059 }
2060 break;
2061 case 5:
2062 if (NSParam[i] > 0) {
2063 if (j < NSParam[i]) {
2064 color = SubParam[i][++j];
2065 }
2066 }
2067 else if (i < NParam) {
2068 color = Param[++i];
2069 }
2070 break;
2071 }
2072 if (color >= 0 && color < 256) {
2073 attr->Attr2 |= Attr2Back;
2074 mask->Attr2 |= Attr2Back;
2075 attr->Back = color;
2076 }
2077 }
2078 break;
2079
2080 case 49: /* Reset back color */
2081 attr->Attr2 &= ~ Attr2Back;
2082 mask->Attr2 |= Attr2Back;
2083 attr->Back = AttrDefaultBG;
2084 break;
2085
2086 case 90:
2087 case 91:
2088 case 92:
2089 case 93:
2090 case 94:
2091 case 95:
2092 case 96:
2093 case 97: /* aixterm style text color */
2094 if (ts.ColorFlag & CF_AIXTERM16) {
2095 attr->Attr2 |= Attr2Fore;
2096 mask->Attr2 |= Attr2Fore;
2097 attr->Fore = P - 90 + 8;
2098 }
2099 break;
2100
2101 case 100:
2102 if (! (ts.ColorFlag & CF_AIXTERM16)) {
2103 /* Reset text and back color */
2104 attr->Attr2 &= ~ (Attr2Fore | Attr2Back);
2105 mask->Attr2 |= Attr2ColorMask;
2106 attr->Fore = AttrDefaultFG;
2107 attr->Back = AttrDefaultBG;
2108 break;
2109 }
2110 /* fall through to aixterm style back color */
2111
2112 case 101:
2113 case 102:
2114 case 103:
2115 case 104:
2116 case 105:
2117 case 106:
2118 case 107: /* aixterm style back color */
2119 if (ts.ColorFlag & CF_AIXTERM16) {
2120 attr->Attr2 |= Attr2Back;
2121 mask->Attr2 |= Attr2Back;
2122 attr->Back = P - 100 + 8;
2123 }
2124 break;
2125 }
2126 }
2127 }
2128
2129 void CSSetAttr() // SGR
2130 {
2131 UpdateStr();
2132 ParseSGRParams(&CharAttr, NULL, 1);
2133 BuffSetCurCharAttr(CharAttr);
2134 }
2135
2136 void CSSetScrollRegion()
2137 {
2138 if ((StatusLine>0) &&
2139 (CursorY==NumOfLines-1))
2140 {
2141 MoveCursor(0,CursorY);
2142 return;
2143 }
2144 if (Param[1]<1) Param[1] =1;
2145 if ((NParam < 2) | (Param[2]<1))
2146 Param[2] = NumOfLines-StatusLine;
2147 Param[1]--;
2148 Param[2]--;
2149 if (Param[1] > NumOfLines-1-StatusLine)
2150 Param[1] = NumOfLines-1-StatusLine;
2151 if (Param[2] > NumOfLines-1-StatusLine)
2152 Param[2] = NumOfLines-1-StatusLine;
2153 if (Param[1] >= Param[2]) return;
2154 CursorTop = Param[1];
2155 CursorBottom = Param[2];
2156 if (RelativeOrgMode) MoveCursor(0,CursorTop);
2157 else MoveCursor(0,0);
2158 }
2159
2160 void CSSunSequence() /* Sun terminal private sequences */
2161 {
2162 int x, y, len;
2163 char Report[TitleBuffSize*2+10];
2164 PTStack t;
2165
2166 switch (Param[1]) {
2167 case 1: // De-iconify window
2168 if (ts.WindowFlag & WF_WINDOWCHANGE)
2169 DispShowWindow(WINDOW_RESTORE);
2170 break;
2171 case 2: // Iconify window
2172 if (ts.WindowFlag & WF_WINDOWCHANGE)
2173 DispShowWindow(WINDOW_MINIMIZE);
2174 break;
2175 case 3: // set window position
2176 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2177 if (NParam < 2) Param[2] = 0;
2178 if (NParam < 3) Param[3] = 0;
2179 DispMoveWindow(Param[2], Param[3]);
2180 }
2181 break;
2182 case 4: // set window size
2183 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2184 if (NParam < 2) Param[2] = 0;
2185 if (NParam < 3) Param[3] = 0;
2186 DispResizeWin(Param[3], Param[2]);
2187 }
2188 break;
2189 case 5: // Raise window
2190 if (ts.WindowFlag & WF_WINDOWCHANGE)
2191 DispShowWindow(WINDOW_RAISE);
2192 break;
2193 case 6: // Lower window
2194 if (ts.WindowFlag & WF_WINDOWCHANGE)
2195 DispShowWindow(WINDOW_LOWER);
2196 break;
2197 case 7: // Refresh window
2198 if (ts.WindowFlag & WF_WINDOWCHANGE)
2199 DispShowWindow(WINDOW_REFRESH);
2200 break;
2201 case 8: /* set terminal size */
2202 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2203 if ((Param[2]<=1) || (NParam<2)) Param[2] = 24;
2204 if ((Param[3]<=1) || (NParam<3)) Param[3] = 80;
2205 ChangeTerminalSize(Param[3],Param[2]);
2206 }
2207 break;
2208 case 9: // Maximize/Restore window
2209 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2210 if (NParam < 2 || Param[2] == 0) {
2211 DispShowWindow(WINDOW_RESTORE);
2212 }
2213 else if (Param[2] == 1) {
2214 DispShowWindow(WINDOW_MAXIMIZE);
2215 }
2216 }
2217 break;
2218 case 11: // Report window state
2219 if (ts.WindowFlag & WF_WINDOWREPORT) {
2220 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%dt", CLocale, DispWindowIconified()?2:1);
2221 SendCSIstr(Report, len);
2222 }
2223 break;
2224 case 13: // Report window position
2225 if (ts.WindowFlag & WF_WINDOWREPORT) {
2226 DispGetWindowPos(&x, &y);
2227 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "3;%u;%ut", CLocale, (unsigned int)x, (unsigned int)y);
2228 SendCSIstr(Report, len);
2229 }
2230 break;
2231 case 14: /* get window size */
2232 if (ts.WindowFlag & WF_WINDOWREPORT) {
2233 DispGetWindowSize(&x, &y);
2234 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "4;%d;%dt", CLocale, y, x);
2235 SendCSIstr(Report, len);
2236 }
2237 break;
2238 case 18: /* get terminal size */
2239 if (ts.WindowFlag & WF_WINDOWREPORT) {
2240 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "8;%u;%ut", CLocale,
2241 NumOfLines-StatusLine, NumOfColumns);
2242 SendCSIstr(Report, len);
2243 }
2244 break;
2245 case 19: // Report display size (character)
2246 if (ts.WindowFlag & WF_WINDOWREPORT) {
2247 DispGetRootWinSize(&x, &y);
2248 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "9;%d;%dt", CLocale, y, x);
2249 SendCSIstr(Report, len);
2250 }
2251 break;
2252 case 20: // Report icon label
2253 switch (ts.WindowFlag & WF_TITLEREPORT) {
2254 case IdTitleReportIgnore:
2255 // nothing to do
2256 break;
2257 case IdTitleReportAccept:
2258 switch (ts.AcceptTitleChangeRequest) {
2259 case IdTitleChangeRequestOff:
2260 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2261 break;
2262 case IdTitleChangeRequestAhead:
2263 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, cv.TitleRemote, ts.Title);
2264 break;
2265 case IdTitleChangeRequestLast:
2266 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, ts.Title, cv.TitleRemote);
2267 break;
2268 default:
2269 if (cv.TitleRemote[0] == 0) {
2270 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2271 }
2272 else {
2273 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, cv.TitleRemote);
2274 }
2275 }
2276 SendOSCstr(Report, len);
2277 break;
2278 default: // IdTitleReportEmpty:
2279 SendOSCstr("L", 0);
2280 break;
2281 }
2282 break;
2283 case 21: // Report window title
2284 switch (ts.WindowFlag & WF_TITLEREPORT) {
2285 case IdTitleReportIgnore:
2286 // nothing to do
2287 break;
2288 case IdTitleReportAccept:
2289 switch (ts.AcceptTitleChangeRequest) {
2290 case IdTitleChangeRequestOff:
2291 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2292 break;
2293 case IdTitleChangeRequestAhead:
2294 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, cv.TitleRemote, ts.Title);
2295 break;
2296 case IdTitleChangeRequestLast:
2297 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, ts.Title, cv.TitleRemote);
2298 break;
2299 default:
2300 if (cv.TitleRemote[0] == 0) {
2301 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2302 }
2303 else {
2304 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, cv.TitleRemote);
2305 }
2306 }
2307 SendOSCstr(Report, len);
2308 break;
2309 default: // IdTitleReportEmpty:
2310 SendOSCstr("l", 0);
2311 break;
2312 }
2313 break;
2314 case 22: // Push Title
2315 if (NParam < 2) {
2316 Param[2] = 0;
2317 }
2318 switch (Param[2]) {
2319 case 0:
2320 case 1:
2321 case 2:
2322 if (ts.AcceptTitleChangeRequest && (t=malloc(sizeof(TStack))) != NULL) {
2323 if ((t->title = _strdup(cv.TitleRemote)) != NULL) {
2324 t->next = TitleStack;
2325 TitleStack = t;
2326 }
2327 else {
2328 free(t);
2329 }
2330 }
2331 break;
2332 }
2333 break;
2334 case 23: // Pop Title
2335 if (NParam < 2) {
2336 Param[2] = 0;
2337 }
2338 switch (Param[2]) {
2339 case 0:
2340 case 1:
2341 case 2:
2342 if (ts.AcceptTitleChangeRequest && TitleStack != NULL) {
2343 t = TitleStack;
2344 TitleStack = t->next;
2345 strncpy_s(cv.TitleRemote, sizeof(cv.TitleRemote), t->title, _TRUNCATE);
2346 ChangeTitle();
2347 free(t->title);
2348 free(t);
2349 }
2350 break;
2351 }
2352 }
2353 }
2354
2355 void CSLT(BYTE b)
2356 {
2357 switch (b) {
2358 case 'r':
2359 if (CanUseIME()) {
2360 SetIMEOpenStatus(IMEstat);
2361 }
2362 break;
2363
2364 case 's':
2365 if (CanUseIME()) {
2366 IMEstat = GetIMEOpenStatus();
2367 }
2368 break;
2369
2370 case 't':
2371 if (CanUseIME()) {
2372 SetIMEOpenStatus(Param[1] == 1);
2373 }
2374 break;
2375 }
2376 }
2377
2378 void CSEQ(BYTE b)
2379 {
2380 char Report[16];
2381 int len;
2382
2383 switch (b) {
2384 case 'c': /* Tertiary terminal report (Tertiary DA) */
2385 if (Param[1] < 1) {
2386 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "!|%8s", CLocale, ts.TerminalUID);
2387 SendDCSstr(Report, len);
2388 }
2389 break;
2390 }
2391 }
2392
2393 void CSGT(BYTE b)
2394 {
2395 switch (b) {
2396 case 'c': /* second terminal report (Secondary DA) */
2397 if (Param[1] < 1) {
2398 SendCSIstr(">32;100;2c", 0); /* VT382 */
2399 }
2400 break;
2401 case 'J': // IO-8256 terminal
2402 if (Param[1]==3) {
2403 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
2404 if (Param[3] < 1 || NParam < 3) Param[3] = 1;
2405 if (Param[4] < 1 || NParam < 4) Param[4] = NumOfLines-StatusLine;
2406 if (Param[5] < 1 || NParam < 5) Param[5] = NumOfColumns;
2407 BuffEraseBox(Param[3]-1, Param[2]-1, Param[5]-1, Param[4]-1);
2408 }
2409 break;
2410 case 'K': // IO-8256 terminal
2411 switch (Param[1]) {
2412 case 3:
2413 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
2414 if (Param[3] < 1 || NParam < 3) Param[3] = 1;
2415 BuffEraseCharsInLine(Param[2]-1, Param[3]-Param[2]+1);
2416 break;
2417 case 5:
2418 if (NParam < 2) Param[2] = 0;
2419 if (NParam < 3) Param[3] = 0;
2420 switch (Param[2]) {
2421 case 3:
2422 case 4:
2423 case 5:
2424 case 6: // Draw Line
2425 BuffDrawLine(CharAttr, Param[2], Param[3]);
2426 break;
2427
2428 case 12: // Text color
2429 if ((Param[3]>=0) && (Param[3]<=7)) {
2430 switch (Param[3]) {
2431 case 3: CharAttr.Fore = IdBlue; break;
2432 case 4: CharAttr.Fore = IdCyan; break;
2433 case 5: CharAttr.Fore = IdYellow; break;
2434 case 6: CharAttr.Fore = IdMagenta; break;
2435 default: CharAttr.Fore = Param[3]; break;
2436 }
2437 CharAttr.Attr2 |= Attr2Fore;
2438 BuffSetCurCharAttr(CharAttr);
2439 }
2440 break;
2441 }
2442 break;
2443 }
2444 break;
2445 }
2446 }
2447
2448 void CSQExchangeColor() // DECSCNM / Visual Bell
2449 {
2450 COLORREF ColorRef;
2451
2452 BuffUpdateScroll();
2453
2454 if (ts.ColorFlag & CF_REVERSECOLOR) {
2455 ColorRef = ts.VTColor[0];
2456 ts.VTColor[0] = ts.VTReverseColor[0];
2457 ts.VTReverseColor[0] = ColorRef;
2458 ColorRef = ts.VTColor[1];
2459 ts.VTColor[1] = ts.VTReverseColor[1];
2460 ts.VTReverseColor[1] = ColorRef;
2461 }
2462 else {
2463 ColorRef = ts.VTColor[0];
2464 ts.VTColor[0] = ts.VTColor[1];
2465 ts.VTColor[1] = ColorRef;
2466 }
2467
2468 ColorRef = ts.VTBoldColor[0];
2469 ts.VTBoldColor[0] = ts.VTBoldColor[1];
2470 ts.VTBoldColor[1] = ColorRef;
2471
2472 ColorRef = ts.VTBlinkColor[0];
2473 ts.VTBlinkColor[0] = ts.VTBlinkColor[1];
2474 ts.VTBlinkColor[1] = ColorRef;
2475
2476 ColorRef = ts.URLColor[0];
2477 ts.URLColor[0] = ts.URLColor[1];
2478 ts.URLColor[1] = ColorRef;
2479
2480 ts.ColorFlag ^= CF_REVERSEVIDEO;
2481
2482 #ifdef ALPHABLEND_TYPE2
2483 BGExchangeColor();
2484 #endif
2485 DispChangeBackground();
2486 UpdateWindow(HVTWin);
2487 }
2488
2489 void CSQChangeColumnMode(int width) // DECCOLM
2490 {
2491 ChangeTerminalSize(width, NumOfLines-StatusLine);
2492 if ((ts.TermFlag & TF_CLEARONRESIZE) == 0) {
2493 MoveCursor(0, 0);
2494 BuffClearScreen();
2495 UpdateWindow(HVTWin);
2496 }
2497 }
2498
2499 void CSQ_h_Mode() // DECSET
2500 {
2501 int i;
2502
2503 for (i = 1 ; i<=NParam ; i++)
2504 switch (Param[i]) {
2505 case 1: AppliCursorMode = TRUE; break; // DECCKM
2506 case 3: CSQChangeColumnMode(132); break; // DECCOLM
2507 case 5: /* Reverse Video (DECSCNM) */
2508 if (!(ts.ColorFlag & CF_REVERSEVIDEO))
2509 CSQExchangeColor(); /* Exchange text/back color */
2510 break;
2511 case 6: // DECOM
2512 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2513 MoveCursor(0,CursorY);
2514 else {
2515 RelativeOrgMode = TRUE;
2516 MoveCursor(0,CursorTop);
2517 }
2518 break;
2519 case 7: AutoWrapMode = TRUE; break; // DECAWM
2520 case 8: AutoRepeatMode = TRUE; break; // DECARM
2521 case 9: /* X10 Mouse Tracking */
2522 if (ts.MouseEventTracking)
2523 MouseReportMode = IdMouseTrackX10;
2524 break;
2525 case 12: /* att610 cursor blinking */
2526 if (ts.WindowFlag & WF_CURSORCHANGE) {
2527 ts.NonblinkingCursor = FALSE;
2528 ChangeCaret();
2529 }
2530 break;
2531 case 19: PrintEX = TRUE; break; // DECPEX
2532 case 25: DispEnableCaret(TRUE); break; // cursor on (DECTCEM)
2533 case 38: // DECTEK
2534 if (ts.AutoWinSwitch>0)
2535 ChangeEmu = IdTEK; /* Enter TEK Mode */
2536 break;
2537 case 47: // Alternate Screen Buffer
2538 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2539 BuffSaveScreen();
2540 AltScr = TRUE;
2541 }
2542 break;
2543 case 59:
2544 if (ts.Language==IdJapanese)
2545 { /* kanji terminal */
2546 Gn[0] = IdASCII;
2547 Gn[1] = IdKatakana;
2548 Gn[2] = IdKatakana;
2549 Gn[3] = IdKanji;
2550 Glr[0] = 0;
2551 if ((ts.KanjiCode==IdJIS) &&
2552 (ts.JIS7Katakana==0))
2553 Glr[1] = 2; // 8-bit katakana
2554 else
2555 Glr[1] = 3;
2556 }
2557 break;
2558 case 66: AppliKeyMode = TRUE; break; // DECNKM
2559 case 67: ts.BSKey = IdBS; break; // DECBKM
2560 case 1000: // Mouse Tracking
2561 if (ts.MouseEventTracking)
2562 MouseReportMode = IdMouseTrackVT200;
2563 break;
2564 case 1001: // Hilite Mouse Tracking
2565 if (ts.MouseEventTracking)
2566 MouseReportMode = IdMouseTrackVT200Hl;
2567 break;
2568 case 1002: // Button-Event Mouse Tracking
2569 if (ts.MouseEventTracking)
2570 MouseReportMode = IdMouseTrackBtnEvent;
2571 break;
2572 case 1003: // Any-Event Mouse Tracking
2573 if (ts.MouseEventTracking)
2574 MouseReportMode = IdMouseTrackAllEvent;
2575 break;
2576 case 1004: // Focus Report
2577 if (ts.MouseEventTracking)
2578 FocusReportMode = TRUE;
2579 break;
2580 case 1005: // Extended Mouse Tracking (UTF-8)
2581 if (ts.MouseEventTracking)
2582 MouseReportExtMode = IdMouseTrackExtUTF8;
2583 break;
2584 case 1006: // Extended Mouse Tracking (SGR)
2585 if (ts.MouseEventTracking)
2586 MouseReportExtMode = IdMouseTrackExtSGR;
2587 break;
2588 case 1015: // Extended Mouse Tracking (rxvt-unicode)
2589 if (ts.MouseEventTracking)
2590 MouseReportExtMode = IdMouseTrackExtURXVT;
2591 break;
2592 case 1047: // Alternate Screen Buffer
2593 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2594 BuffSaveScreen();
2595 AltScr = TRUE;
2596 }
2597 break;
2598 case 1048: // Save Cursor Position (Alternate Screen Buffer)
2599 if (ts.TermFlag & TF_ALTSCR) {
2600 SaveCursor();
2601 }
2602 break;
2603 case 1049: // Alternate Screen Buffer
2604 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2605 SaveCursor();
2606 BuffSaveScreen();
2607 BuffClearScreen();
2608 AltScr = TRUE;
2609 }
2610 break;
2611 case 2004: // Bracketed Paste Mode
2612 BracketedPaste = TRUE;
2613 break;
2614 case 7727: // mintty Application Escape Mode
2615 AppliEscapeMode = TRUE;
2616 break;
2617 case 7786: // Wheel to Cursor translation
2618 if (ts.TranslateWheelToCursor) {
2619 AcceptWheelToCursor = TRUE;
2620 }
2621 break;
2622 case 14001: // NetTerm mouse mode
2623 if (ts.MouseEventTracking)
2624 MouseReportMode = IdMouseTrackNetTerm;
2625 break;
2626 }
2627 }
2628
2629 void CSQ_i_Mode() // DECMC
2630 {
2631 switch (Param[1]) {
2632 case 1:
2633 if (ts.TermFlag&TF_PRINTERCTRL) {
2634 OpenPrnFile();
2635 BuffDumpCurrentLine(LF);
2636 if (! AutoPrintMode)
2637 ClosePrnFile();
2638 }
2639 break;
2640 /* auto print mode off */
2641 case 4:
2642 if (AutoPrintMode)
2643 {
2644 ClosePrnFile();
2645 AutoPrintMode = FALSE;
2646 }
2647 break;
2648 /* auto print mode on */
2649 case 5:
2650 if (ts.TermFlag&TF_PRINTERCTRL) {
2651 if (! AutoPrintMode)
2652 {
2653 OpenPrnFile();
2654 AutoPrintMode = TRUE;
2655 }
2656 }
2657 break;
2658 }
2659 }
2660
2661 void CSQ_l_Mode() // DECRST
2662 {
2663 int i;
2664
2665 for (i = 1 ; i <= NParam ; i++)
2666 switch (Param[i]) {
2667 case 1: AppliCursorMode = FALSE; break; // DECCKM
2668 case 3: CSQChangeColumnMode(80); break; // DECCOLM
2669 case 5: /* Normal Video (DECSCNM) */
2670 if (ts.ColorFlag & CF_REVERSEVIDEO)
2671 CSQExchangeColor(); /* Exchange text/back color */
2672 break;
2673 case 6: // DECOM
2674 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2675 MoveCursor(0,CursorY);
2676 else {
2677 RelativeOrgMode = FALSE;
2678 MoveCursor(0,0);
2679 }
2680 break;
2681 case 7: AutoWrapMode = FALSE; break; // DECAWM
2682 case 8: AutoRepeatMode = FALSE; break; // DECARM
2683 case 9: MouseReportMode = IdMouseTrackNone; break; /* X10 Mouse Tracking */
2684 case 12: /* att610 cursor blinking */
2685 if (ts.WindowFlag & WF_CURSORCHANGE) {
2686 ts.NonblinkingCursor = TRUE;
2687 ChangeCaret();
2688 }
2689 break;
2690 case 19: PrintEX = FALSE; break; // DECPEX
2691 case 25: DispEnableCaret(FALSE); break; // cursor off (DECTCEM)
2692 case 47: // Alternate Screen Buffer
2693 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2694 BuffRestoreScreen();
2695 AltScr = FALSE;
2696 }
2697 break;
2698 case 59:
2699 if (ts.Language==IdJapanese)
2700 { /* katakana terminal */
2701 Gn[0] = IdASCII;
2702 Gn[1] = IdKatakana;
2703 Gn[2] = IdKatakana;
2704 Gn[3] = IdKanji;
2705 Glr[0] = 0;
2706 if ((ts.KanjiCode==IdJIS) &&
2707 (ts.JIS7Katakana==0))
2708 Glr[1] = 2; // 8-bit katakana
2709 else
2710 Glr[1] = 3;
2711 }
2712 break;
2713 case 66: AppliKeyMode = FALSE; break; // DECNKM
2714 case 67: ts.BSKey = IdDEL; break; // DECBKM
2715 case 1000: // Mouse Tracking
2716 case 1001: // Hilite Mouse Tracking
2717 case 1002: // Button-Event Mouse Tracking
2718 case 1003: // Any-Event Mouse Tracking
2719 MouseReportMode = IdMouseTrackNone;
2720 break;
2721 case 1004: // Focus Report
2722 FocusReportMode = FALSE;
2723 break;
2724 case 1005: // Extended Mouse Tracking (UTF-8)
2725 case 1006: // Extended Mouse Tracking (SGR)
2726 case 1015: // Extended Mouse Tracking (rxvt-unicode)
2727 MouseReportExtMode = IdMouseTrackExtNone;
2728 break;
2729 case 1047: // Alternate Screen Buffer
2730 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2731 BuffClearScreen();
2732 BuffRestoreScreen();
2733 AltScr = FALSE;
2734 }
2735 break;
2736 case 1048: // Save Cursor Position (Alternate Screen Buffer)
2737 if (ts.TermFlag & TF_ALTSCR) {
2738 RestoreCursor();
2739 }
2740 break;
2741 case 1049: // Alternate Screen Buffer
2742 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2743 BuffClearScreen();
2744 BuffRestoreScreen();
2745 AltScr = FALSE;
2746 RestoreCursor();
2747 }
2748 break;
2749 case 2004: // Bracketed Paste Mode
2750 BracketedPaste = FALSE;
2751 break;
2752 case 7727: // mintty Application Escape Mode
2753 AppliEscapeMode = FALSE;
2754 break;
2755 case 7786: // Wheel to Cursor translation
2756 AcceptWheelToCursor = FALSE;
2757 break;
2758 case 14001: // NetTerm mouse mode
2759 MouseReportMode = IdMouseTrackNone;
2760 break;
2761 }
2762 }
2763
2764 void CSQ_n_Mode() // DECDSR
2765 {
2766 switch (Param[1]) {
2767 case 53:
2768 case 55:
2769 /* Locator Device Status Report -> Ready */
2770 SendCSIstr("?50n", 0);
2771 break;
2772 }
2773 }
2774
2775 void CSQuest(BYTE b)
2776 {
2777 switch (b) {
2778 case 'J': CSQSelScreenErase(); break; // DECSED
2779 case 'K': CSQSelLineErase(); break; // DECSEL
2780 case 'h': CSQ_h_Mode(); break; // DECSET
2781 case 'i': CSQ_i_Mode(); break; // DECMC
2782 case 'l': CSQ_l_Mode(); break; // DECRST
2783 case 'n': CSQ_n_Mode(); break; // DECDSR
2784 }
2785 }
2786
2787 void SoftReset()
2788 // called by software-reset escape sequence handler
2789 {
2790 UpdateStr();
2791 AutoRepeatMode = TRUE;
2792 DispEnableCaret(TRUE); // cursor on
2793 InsertMode = FALSE;
2794 RelativeOrgMode = FALSE;
2795 AppliKeyMode = FALSE;
2796 AppliCursorMode = FALSE;
2797 AppliEscapeMode = FALSE;
2798 AcceptWheelToCursor = ts.TranslateWheelToCursor;
2799 if ((StatusLine>0) &&
2800 (CursorY == NumOfLines-1))
2801 MoveToMainScreen();
2802 CursorTop = 0;
2803 CursorBottom = NumOfLines-1-StatusLine;
2804 ResetCharSet();
2805
2806 /* Attribute */
2807 CharAttr = DefCharAttr;
2808 Special = FALSE;
2809 BuffSetCurCharAttr(CharAttr);
2810
2811 // status buffers
2812 ResetCurSBuffer();
2813
2814 // Saved IME status
2815 IMEstat = FALSE;
2816 }
2817
2818 void CSExc(BYTE b)
2819 {
2820 switch (b) {
2821 case 'p':
2822 /* Software reset */
2823 SoftReset();
2824 break;
2825 }
2826 }
2827
2828 void CSDouble(BYTE b)
2829 {
2830 switch (b) {
2831 case 'p': // DECSCL
2832 /* Select terminal mode (software reset) */
2833 SoftReset();
2834 if (NParam > 0) {
2835 ChangeTerminalID();
2836 if (Param[1] >= 61 && Param[1] <= 65) {
2837 if (VTlevel > Param[1] - 60) {
2838 VTlevel = Param[1] - 60;
2839 }
2840 }
2841 else {
2842 VTlevel = 1;
2843 }
2844
2845 if (VTlevel < 2 || (NParam > 1 && Param[2] == 1))
2846 Send8BitMode = FALSE;
2847 else
2848 Send8BitMode = TRUE;
2849 }
2850 break;
2851
2852 case 'q': // DECSCA
2853 switch (Param[1]) {
2854 case 0:
2855 case 2:
2856 CharAttr.Attr2 &= ~Attr2Protect;
2857 BuffSetCurCharAttr(CharAttr);
2858 break;
2859 case 1:
2860 CharAttr.Attr2 |= Attr2Protect;
2861 BuffSetCurCharAttr(CharAttr);
2862 break;
2863 default:
2864 /* nothing to do */
2865 break;
2866 }
2867 break;
2868 }
2869 }
2870
2871 void CSDolRequestMode()
2872 {
2873 char buff[256];
2874 char *pp;
2875 int len, resp = 0;
2876
2877 if (NParam == 0)
2878 Param[1] = 0;
2879
2880 switch (Prv) {
2881 case 0: /* ANSI Mode */
2882 resp = 4;
2883 pp = "";
2884 switch (Param[1]) {
2885 case 2: // KAM
2886 if (KeybEnabled)
2887 resp = 2;
2888 else
2889 resp = 1;
2890 break;
2891 case 4: // IRM
2892 if (InsertMode)
2893 resp = 1;
2894 else
2895 resp = 2;
2896 break;
2897 case 12: // SRM
2898 if (ts.LocalEcho)
2899 resp = 2;
2900 else
2901 resp = 1;
2902 break;
2903 case 20: // LNM
2904 if (LFMode)
2905 resp = 1;
2906 else
2907 resp = 2;
2908 break;
2909 case 33: // WYSTCURM
2910 if (ts.NonblinkingCursor)
2911 resp = 1;
2912 else
2913 resp = 2;
2914 if ((ts.WindowFlag & WF_CURSORCHANGE) == 0)
2915 resp += 2;
2916 break;
2917 case 34: // WYULCURM
2918 if (ts.CursorShape == IdHCur)
2919 resp = 1;
2920 else
2921 resp = 2;
2922 if ((ts.WindowFlag & WF_CURSORCHANGE) == 0)
2923 resp += 2;
2924 break;
2925 }
2926 break;
2927
2928 case '?': /* DEC Mode */
2929 pp = "?";
2930 switch (Param[1]) {
2931 case 1: // DECCKM
2932 if (AppliCursorMode)
2933 resp = 1;
2934 else
2935 resp = 2;
2936 break;
2937 case 3: // DECCOLM
2938 if (NumOfColumns == 132)
2939 resp = 1;
2940 else
2941 resp = 2;
2942 break;
2943 case 5: // DECSCNM
2944 if (ts.ColorFlag & CF_REVERSEVIDEO)
2945 resp = 1;
2946 else
2947 resp = 2;
2948 break;
2949 case 6: // DECOM
2950 if (RelativeOrgMode)
2951 resp = 1;
2952 else
2953 resp = 2;
2954 break;
2955 case 7: // DECAWM
2956 if (AutoWrapMode)
2957 resp = 1;
2958 else
2959 resp = 2;
2960 break;
2961 case 8: // DECARM
2962 if (AutoRepeatMode)
2963 resp = 1;
2964 else
2965 resp = 2;
2966 break;
2967 case 9: // XT_MSE_X10 -- X10 Mouse Tracking
2968 if (!ts.MouseEventTracking)
2969 resp = 4;
2970 else if (MouseReportMode == IdMouseTrackX10)
2971 resp = 1;
2972 else
2973 resp = 2;
2974 break;
2975 case 12: // XT_CBLINK -- att610 cursor blinking
2976 if (ts.NonblinkingCursor)
2977 resp = 2;
2978 else
2979 resp = 1;
2980 if ((ts.WindowFlag & WF_CURSORCHANGE) == 0)
2981 resp += 2;
2982 break;
2983 case 19: // DECPEX
2984 if (PrintEX)
2985 resp = 1;
2986 else
2987 resp = 2;
2988 break;
2989 case 25: // DECTCEM
2990 if (IsCaretEnabled())
2991 resp = 1;
2992 else
2993 resp = 2;
2994 break;
2995 case 38: // DECTEK
2996 resp = 4;
2997 break;
2998 case 47: // XT_ALTSCRN -- Alternate Screen / (DECGRPM)
2999 if ((ts.TermFlag & TF_ALTSCR) == 0)
3000 resp = 4;
3001 else if (AltScr)
3002 resp = 1;
3003 else
3004 resp = 2;
3005 break;
3006 case 59: // DECKKDM
3007 if (ts.Language!=IdJapanese)
3008 resp = 0;
3009 else if ((ts.KanjiCode == IdJIS) && (!ts.JIS7Katakana))
3010 resp = 4;
3011 else
3012 resp = 3;
3013 break;
3014 case 66: // DECNKM
3015 if (AppliKeyMode)
3016 resp = 1;
3017 else
3018 resp = 2;
3019 break;
3020 case 67: // DECBKM
3021 if (ts.BSKey==IdBS)
3022 resp = 1;
3023 else
3024 resp = 2;
3025 break;
3026 case 1000: // XT_MSE_X11
3027 if (!ts.MouseEventTracking)
3028 resp = 4;
3029 else if (MouseReportMode == IdMouseTrackVT200)
3030 resp = 1;
3031 else
3032 resp = 2;
3033 break;
3034 case 1001: // XT_MSE_HL
3035 #if 0
3036 if (!ts.MouseEventTracking)
3037 resp = 4;
3038 else if (MouseReportMode == IdMouseTrackVT200Hl)
3039 resp = 1;
3040 else
3041 resp = 2;
3042 #else
3043 resp = 4;
3044 #endif
3045 break;
3046 case 1002: // XT_MSE_BTN
3047 if (!ts.MouseEventTracking)
3048 resp = 4;
3049 else if (MouseReportMode == IdMouseTrackBtnEvent)
3050 resp = 1;
3051 else
3052 resp = 2;
3053 break;
3054 case 1003: // XT_MSE_ANY
3055 if (!ts.MouseEventTracking)
3056 resp = 4;
3057 else if (MouseReportMode == IdMouseTrackAllEvent)
3058 resp = 1;
3059 else
3060 resp = 2;
3061 break;
3062 case 1004: // XT_MSE_WIN
3063 if (!ts.MouseEventTracking)
3064 resp = 4;
3065 else if (FocusReportMode)
3066 resp = 1;
3067 else
3068 resp = 2;
3069 break;
3070 case 1005: // XT_MSE_UTF
3071 if (!ts.MouseEventTracking)
3072 resp = 4;
3073 else if (MouseReportExtMode == IdMouseTrackExtUTF8)
3074 resp = 1;
3075 else
3076 resp = 2;
3077 break;
3078 case 1006: // XT_MSE_SGR
3079 if (!ts.MouseEventTracking)
3080 resp = 4;
3081 else if (MouseReportExtMode == IdMouseTrackExtSGR)
3082 resp = 1;
3083 else
3084 resp = 2;
3085 break;
3086 case 1015: // urxvt-style extended mouse tracking
3087 if (!ts.MouseEventTracking)
3088 resp = 4;
3089 else if (MouseReportExtMode == IdMouseTrackExtURXVT)
3090 resp = 1;
3091 else
3092 resp = 2;
3093 break;
3094 case 1047: // XT_ALTS_47
3095 if ((ts.TermFlag & TF_ALTSCR) == 0)
3096 resp = 4;
3097 else if (AltScr)
3098 resp = 1;
3099 else
3100 resp = 2;
3101 break;
3102 case 1048:
3103 if ((ts.TermFlag & TF_ALTSCR) == 0)
3104 resp = 4;
3105 else
3106 resp = 1;
3107 break;
3108 case 1049: // XT_EXTSCRN
3109 if ((ts.TermFlag & TF_ALTSCR) == 0)
3110 resp = 4;
3111 else if (AltScr)
3112 resp = 1;
3113 else
3114 resp = 2;
3115 break;
3116 case 2004: // RL_BRACKET
3117 if (BracketedPaste)
3118 resp = 1;
3119 else
3120 resp = 2;
3121 break;
3122 case 7727: // MinTTY Application Escape Mode
3123 if (AppliEscapeMode)
3124 resp = 1;
3125 else
3126 resp = 2;
3127 break;
3128 case 7786: // MinTTY Mousewheel reporting
3129 if (!ts.TranslateWheelToCursor)
3130 resp = 4;
3131 else if (AcceptWheelToCursor)
3132 resp = 1;
3133 else
3134 resp = 2;
3135 break;
3136 case 14001: // NetTerm Mouse Reporting (TT)
3137 if (!ts.MouseEventTracking)
3138 resp = 4;
3139 else if (MouseReportMode == IdMouseTrackNetTerm)
3140 resp = 1;
3141 else
3142 resp = 2;
3143 break;
3144 }
3145 break;
3146 }
3147
3148 len = _snprintf_s(buff, sizeof(buff), _TRUNCATE, "%s%d;%d$y", pp, Param[1], resp);
3149 SendCSIstr(buff, len);
3150 }
3151
3152 void CSDol(BYTE b)
3153 {
3154 TCharAttr attr, mask;
3155 attr = DefCharAttr;
3156 mask = DefCharAttr;
3157
3158 switch (b) {
3159 case 'p': // DECRQM
3160 CSDolRequestMode();
3161 break;
3162 case 'r': // DECCARA
3163 case 't': // DECRARA
3164 if (Param[1] < 1 || NParam < 1) Param[1] = 1;
3165 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
3166 if (Param[3] < 1 || NParam < 3) Param[3] = NumOfLines-StatusLine;
3167 if (Param[4] < 1 || NParam < 4) Param[4] = NumOfColumns;
3168 if (Param[1] <= Param[3] && Param[2] <= Param[4]) {
3169 if (RelativeOrgMode) {
3170 Param[1] += CursorTop;
3171 if (Param[1] > CursorBottom) {
3172 Param[1] = CursorBottom + 1;
3173 }
3174 Param[3] += CursorTop;
3175 if (Param[3] > CursorBottom) {
3176 Param[3] = CursorBottom + 1;
3177 }
3178 }
3179 }
3180 ParseSGRParams(&attr, &mask, 5);
3181 if (b == 'r') { // DECCARA
3182 attr.Attr &= AttrSgrMask;
3183 mask.Attr &= AttrSgrMask;
3184 attr.Attr2 &= Attr2ColorMask;
3185 mask.Attr2 &= Attr2ColorMask;
3186 BuffChangeAttrBox(Param[2]-1, Param[1]-1, Param[4]-1, Param[3]-1, &attr, &mask);
3187 }
3188 else { // DECRARA
3189 attr.Attr &= AttrSgrMask;
3190 BuffChangeAttrBox(Param[2]-1, Param[1]-1, Param[4]-1, Param[3]-1, &attr, NULL);
3191 }
3192 break;
3193 case 'v': // DECCRA
3194 if (Param[1] < 1 || NParam < 1) Param[1] = 1;
3195 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
3196 if (Param[3] < 1 || NParam < 3) Param[3] = NumOfLines-StatusLine;
3197 if (Param[4] < 1 || NParam < 4) Param[4] = NumOfColumns;
3198 if (Param[5] < 1 || NParam < 5) Param[5] = 1;
3199 if (Param[6] < 1 || NParam < 6) Param[6] = 1;
3200 if (Param[7] < 1 || NParam < 7) Param[7] = 1;
3201 if (Param[8] < 1 || NParam < 8) Param[8] = 1;
3202 if (Param[1] <= Param[3] && Param[2] <= Param[4]) {
3203 if (RelativeOrgMode) {
3204 Param[1] += CursorTop;
3205 if (Param[1] > CursorBottom) {
3206 Param[1] = CursorBottom + 1;
3207 }
3208 Param[3] += CursorTop;
3209 if (Param[3] > CursorBottom) {
3210 Param[3] = CursorBottom + 1;
3211 }
3212 Param[6] += CursorTop;
3213 if (Param[6] > CursorBottom) {
3214 Param[6] = CursorBottom + 1;
3215 }
3216 if (Param[6] + Param[3] - Param[1] > CursorBottom) {
3217 Param[3] = Param[1] + CursorBottom - Param[6] + 1;
3218 }
3219 }
3220 BuffCopyBox(Param[2], Param[1], Param[4], Param[3], Param[5], Param[7], Param[6], Param[8]);
3221 }
3222 break;
3223 case 'x': // DECFRA
3224 if (NParam < 1 || Param[1] < 32 || (Param[1] > 127 && Param[1] < 160) || Param[1] > 255) {
3225 return;
3226 }
3227 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
3228 if (Param[3] < 1 || NParam < 3) Param[3] = 1;
3229 if (Param[4] < 1 || NParam < 4) Param[4] = NumOfLines-StatusLine;
3230 if (Param[5] < 1 || NParam < 5) Param[5] = NumOfColumns;
3231 if (Param[2] > Param[4] || Param[3] > Param[5]) {
3232 return;
3233 }
3234 if (RelativeOrgMode) {
3235 Param[2] += CursorTop;
3236 if (Param[2] > CursorBottom) {
3237 Param[2] = CursorBottom + 1;
3238 }
3239 Param[4] += CursorTop;
3240 if (Param[4] > CursorBottom) {
3241 Param[4] = CursorBottom + 1;
3242 }
3243 }
3244 BuffFillBox(Param[1], Param[3]-1, Param[2]-1, Param[5]-1, Param[4]-1);
3245 break;
3246
3247 case 'z': // DECERA
3248 case '{': // DECSERA
3249 if (Param[1] < 1 || NParam < 1) Param[1]=1;
3250 if (Param[2] < 1 || NParam < 2) Param[2]=1;
3251 if (Param[3] < 1 || NParam < 3) Param[3]=NumOfLines-StatusLine;
3252 if (Param[4] < 1 || NParam < 4) Param[4]=NumOfColumns;
3253 if (RelativeOrgMode) {
3254 Param[1] += CursorTop;
3255 if (Param[1] > CursorBottom) {
3256 Param[1] = CursorBottom + 1;
3257 }
3258 Param[3] += CursorTop;
3259 if (Param[3] > CursorBottom) {
3260 Param[3] = CursorBottom + 1;
3261 }
3262 }
3263 if (b == 'z') {
3264 BuffEraseBox(Param[2]-1, Param[1]-1, Param[4]-1, Param[3]-1);
3265 }
3266 else {
3267 BuffSelectiveEraseBox(Param[2]-1, Param[1]-1, Param[4]-1, Param[3]-1);
3268 }
3269 break;
3270
3271 case '}': // DECSASD
3272 if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
3273 if (StatusLine==0) return;
3274 if ((Param[1]<1) && (CursorY==NumOfLines-1))
3275 MoveToMainScreen();
3276 else if ((Param[1]==1) && (CursorY<NumOfLines-1))
3277 MoveToStatusLine();
3278 break;
3279 case '~': // DECSSDT
3280 if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
3281 if (Param[1]<=1)
3282 HideStatusLine();
3283 else if ((StatusLine==0) && (Param[1]==2))
3284 ShowStatusLine(1); // show
3285 break;
3286 }
3287 }
3288
3289 void CSQDol(BYTE b)
3290 {
3291 switch (b) {
3292 case 'p':
3293 CSDolRequestMode();
3294 break;
3295 }
3296 }
3297
3298 void CSQuote(BYTE b)
3299 {
3300 int i, x, y;
3301 switch (b) {
3302 case 'w': // Enable Filter Rectangle (DECEFR)
3303 if (MouseReportMode == IdMouseTrackDECELR) {
3304 if (DecLocatorFlag & DecLocatorPixel) {
3305 x = LastX + 1;
3306 y = LastY + 1;
3307 }
3308 else {
3309 DispConvWinToScreen(LastX, LastY, &x, &y, NULL);
3310 x++;
3311 y++;
3312 }
3313 FilterTop = (NParam<1 || Param[1]<1)? y : Param[1];
3314 FilterLeft = (NParam<2 || Param[2]<1)? x : Param[2];
3315 FilterBottom = (NParam<3 || Param[3]<1)? y : Param[3];
3316 FilterRight = (NParam<4 || Param[4]<1)? x : Param[4];
3317 if (FilterTop > FilterBottom) {
3318 i = FilterTop; FilterTop = FilterBottom