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 5423 - (show annotations) (download) (as text)
Fri Nov 22 06:29:03 2013 UTC (10 years, 4 months ago) by doda
File MIME type: text/x-csrc
File size: 129357 byte(s)
DECCOLMでDECLRMMが解除されないのを修正。
https://sourceforge.jp/ticket/browse.php?group_id=1412&tid=31986

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