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 5735 - (show annotations) (download) (as text)
Tue Dec 9 04:09:46 2014 UTC (9 years, 4 months ago) by doda
File MIME type: text/x-csrc
File size: 134072 byte(s)
[Control] - [Reset Terminal] で OSC 10/11 で設定した色もリセットするようにした。

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