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 6173 - (show annotations) (download) (as text)
Mon Nov 30 09:30:33 2015 UTC (8 years, 4 months ago) by doda
File MIME type: text/x-csrc
File size: 131728 byte(s)
インデント修正。

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