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 5410 - (show annotations) (download) (as text)
Thu Oct 31 10:27:07 2013 UTC (10 years, 5 months ago) by doda
File MIME type: text/x-csrc
File size: 129332 byte(s)
OSC文字列用バッファの最大値を設定できるようにした。

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