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 5911 - (show annotations) (download) (as text)
Tue Jul 14 01:51:16 2015 UTC (8 years, 9 months ago) by doda
File MIME type: text/x-csrc
File size: 133512 byte(s)
OSC文字列のparse処理を全面的に書き換え
・主な目的は色の問い合わせへの応答の終端を問い合わせに合わせて変えるというもの
・OSC 105 ST で special color をすべてリセットするようにした
・その他にも動作が変わったものがあるかも

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 {
1444 if (ICount<IntCharMax) 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) return;
1589 if (CursorY > CursorBottom) return;
1590 if (Param[1]<1) Param[1] = 1;
1591 Count = Param[1];
1592
1593 YEnd = CursorBottom;
1594 if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1595 if (Count > YEnd+1 - CursorY) Count = YEnd+1 - CursorY;
1596
1597 BuffInsertLines(Count,YEnd);
1598 }
1599
1600 void CSLineErase()
1601 {
1602 BuffUpdateScroll();
1603 switch (Param[1]) {
1604 /* erase char from cursor to end of line */
1605 case 0:
1606 BuffEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1607 break;
1608 /* erase char from start of line to cursor */
1609 case 1:
1610 BuffEraseCharsInLine(0,CursorX+1);
1611 break;
1612 /* erase entire line */
1613 case 2:
1614 BuffEraseCharsInLine(0,NumOfColumns);
1615 break;
1616 }
1617 }
1618
1619 void CSQSelLineErase()
1620 {
1621 BuffUpdateScroll();
1622 switch (Param[1]) {
1623 /* erase char from cursor to end of line */
1624 case 0:
1625 BuffSelectedEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1626 break;
1627 /* erase char from start of line to cursor */
1628 case 1:
1629 BuffSelectedEraseCharsInLine(0,CursorX+1);
1630 break;
1631 /* erase entire line */
1632 case 2:
1633 BuffSelectedEraseCharsInLine(0,NumOfColumns);
1634 break;
1635 }
1636 }
1637
1638 void CSDeleteNLines()
1639 // Delete lines from current line
1640 {
1641 int Count, YEnd;
1642
1643 if (CursorY < CursorTop) return;
1644 if (CursorY > CursorBottom) return;
1645 Count = Param[1];
1646 if (Count<1) Count = 1;
1647
1648 YEnd = CursorBottom;
1649 if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1650 if (Count > YEnd+1-CursorY) Count = YEnd+1-CursorY;
1651 BuffDeleteLines(Count,YEnd);
1652 }
1653
1654 void CSDeleteCharacter() // DCH
1655 {
1656 // Delete characters in current line from cursor
1657
1658 if (Param[1]<1) Param[1] = 1;
1659 BuffUpdateScroll();
1660 BuffDeleteChars(Param[1]);
1661 }
1662
1663 void CSEraseCharacter() // ECH
1664 {
1665 if (Param[1]<1) Param[1] = 1;
1666 BuffUpdateScroll();
1667 BuffEraseChars(Param[1]);
1668 }
1669
1670 void CSScrollUp()
1671 {
1672 if (Param[1]<1) Param[1] = 1;
1673 BuffUpdateScroll();
1674 BuffRegionScrollUpNLines(Param[1]);
1675 }
1676
1677 void CSScrollDown()
1678 {
1679 if (Param[1]<1) Param[1] = 1;
1680 BuffUpdateScroll();
1681 BuffRegionScrollDownNLines(Param[1]);
1682 }
1683
1684 void CSForwardTab()
1685 {
1686 if (Param[1]<1) Param[1] = 1;
1687 CursorForwardTab(Param[1], AutoWrapMode);
1688 }
1689
1690 void CSBackwardTab()
1691 {
1692 if (Param[1]<1) Param[1] = 1;
1693 CursorBackwardTab(Param[1]);
1694 }
1695
1696 void CSMoveToColumnN() // CHA / HPA
1697 {
1698 if (Param[1]<1)
1699 Param[1] = 1;
1700 else if (Param[1] > NumOfColumns)
1701 Param[1] = NumOfColumns;
1702
1703 Param[1]--;
1704
1705 if (RelativeOrgMode) {
1706 if (CursorLeftM + Param[1] > CursorRightM )
1707 MoveCursor(CursorRightM, CursorY);
1708 else
1709 MoveCursor(CursorLeftM + Param[1], CursorY);
1710 }
1711 else {
1712 MoveCursor(Param[1], CursorY);
1713 }
1714 }
1715
1716 void CSCursorRight(BOOL AffectMargin) // CUF / HPR
1717 {
1718 int NewX, rightMargin;
1719
1720 if (Param[1] < 1)
1721 Param[1] = 1;
1722
1723 if (AffectMargin && CursorX <= CursorRightM)
1724 rightMargin = CursorRightM;
1725 else
1726 rightMargin = NumOfColumns-1;
1727
1728 NewX = CursorX + Param[1];
1729 if (NewX > rightMargin)
1730 NewX = rightMargin;
1731
1732 MoveCursor(NewX, CursorY);
1733 }
1734
1735 void CSCursorLeft(BOOL AffectMargin) // CUB / HPB
1736 {
1737 int NewX, leftMargin;
1738
1739 if (Param[1] < 1)
1740 Param[1] = 1;
1741
1742 if (AffectMargin && CursorX >= CursorLeftM)
1743 leftMargin = CursorLeftM;
1744 else
1745 leftMargin = 0;
1746
1747 NewX = CursorX - Param[1];
1748 if (NewX < leftMargin)
1749 NewX = leftMargin;
1750
1751 MoveCursor(NewX, CursorY);
1752 }
1753
1754 void CSMoveToLineN() // VPA
1755 {
1756 if (Param[1]<1) Param[1] = 1;
1757 if (RelativeOrgMode)
1758 {
1759 if (CursorTop+Param[1]-1 > CursorBottom)
1760 MoveCursor(CursorX,CursorBottom);
1761 else
1762 MoveCursor(CursorX,CursorTop+Param[1]-1);
1763 }
1764 else {
1765 if (Param[1] > NumOfLines-StatusLine)
1766 MoveCursor(CursorX,NumOfLines-1-StatusLine);
1767 else
1768 MoveCursor(CursorX,Param[1]-1);
1769 }
1770 }
1771
1772 void CSMoveToXY() // CUP / HVP
1773 {
1774 int NewX, NewY;
1775
1776 if (Param[1] < 1)
1777 Param[1] = 1;
1778 else if (Param[1] > NumOfLines-StatusLine)
1779 Param[1] = NumOfLines-StatusLine;
1780
1781 if ((NParam < 2) || (Param[2]<1))
1782 Param[2] = 1;
1783 else if (Param[2] > NumOfColumns)
1784 Param[2] = NumOfColumns;
1785
1786 NewY = Param[1] - 1;
1787 NewX = Param[2] - 1;
1788
1789 if (isCursorOnStatusLine)
1790 NewY = CursorY;
1791 else if (RelativeOrgMode) {
1792 NewX += CursorLeftM;
1793 if (NewX > CursorRightM)
1794 NewX = CursorRightM;
1795
1796 NewY += CursorTop;
1797 if (NewY > CursorBottom)
1798 NewY = CursorBottom;
1799 }
1800 else {
1801 NewY = Param[1] - 1;
1802 if (NewY > NumOfLines-1-StatusLine)
1803 NewY = NumOfLines-1-StatusLine;
1804 }
1805
1806 MoveCursor(NewX, NewY);
1807 }
1808
1809 void CSDeleteTabStop()
1810 {
1811 ClearTabStop(Param[1]);
1812 }
1813
1814 void CS_h_Mode() // SM
1815 {
1816 switch (Param[1]) {
1817 case 2: // KAM
1818 KeybEnabled = FALSE; break;
1819 case 4: // IRM
1820 InsertMode = TRUE; break;
1821 case 12: // SRM
1822 ts.LocalEcho = 0;
1823 if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1824 TelChangeEcho();
1825 break;
1826 case 20: // LF/NL
1827 LFMode = TRUE;
1828 ts.CRSend = IdCRLF;
1829 cv.CRSend = IdCRLF;
1830 break;
1831 case 33: // WYSTCURM
1832 if (ts.WindowFlag & WF_CURSORCHANGE) {
1833 ts.NonblinkingCursor = TRUE;
1834 ChangeCaret();
1835 }
1836 break;
1837 case 34: // WYULCURM
1838 if (ts.WindowFlag & WF_CURSORCHANGE) {
1839 ts.CursorShape = IdHCur;
1840 ChangeCaret();
1841 }
1842 break;
1843 }
1844 }
1845
1846 void CS_i_Mode() // MC
1847 {
1848 switch (Param[1]) {
1849 /* print screen */
1850 // PrintEX -- TRUE: print screen
1851 // FALSE: scroll region
1852 case 0:
1853 if (ts.TermFlag&TF_PRINTERCTRL) {
1854 BuffPrint(! PrintEX);
1855 }
1856 break;
1857 /* printer controller mode off */
1858 case 4: break; /* See PrnParseCS() */
1859 /* printer controller mode on */
1860 case 5:
1861 if (ts.TermFlag&TF_PRINTERCTRL) {
1862 if (! AutoPrintMode)
1863 OpenPrnFile();
1864 DirectPrn = (ts.PrnDev[0]!=0);
1865 PrinterMode = TRUE;
1866 }
1867 break;
1868 }
1869 }
1870
1871 void CS_l_Mode() // RM
1872 {
1873 switch (Param[1]) {
1874 case 2: // KAM
1875 KeybEnabled = TRUE; break;
1876 case 4: // IRM
1877 InsertMode = FALSE; break;
1878 case 12: // SRM
1879 ts.LocalEcho = 1;
1880 if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1881 TelChangeEcho();
1882 break;
1883 case 20: // LF/NL
1884 LFMode = FALSE;
1885 ts.CRSend = IdCR;
1886 cv.CRSend = IdCR;
1887 break;
1888 case 33: // WYSTCURM
1889 if (ts.WindowFlag & WF_CURSORCHANGE) {
1890 ts.NonblinkingCursor = FALSE;
1891 ChangeCaret();
1892 }
1893 break;
1894 case 34: // WYULCURM
1895 if (ts.WindowFlag & WF_CURSORCHANGE) {
1896 ts.CursorShape = IdBlkCur;
1897 ChangeCaret();
1898 }
1899 break;
1900 }
1901 }
1902
1903 void CS_n_Mode() // DSR
1904 {
1905 char Report[16];
1906 int X, Y, len;
1907
1908 switch (Param[1]) {
1909 case 5:
1910 /* Device Status Report -> Ready */
1911 SendCSIstr("0n", 0);
1912 break;
1913 case 6:
1914 /* Cursor Position Report */
1915 if (isCursorOnStatusLine) {
1916 X = CursorX + 1;
1917 Y = 1;
1918 }
1919 else if (RelativeOrgMode) {
1920 X = CursorX - CursorLeftM + 1;
1921 Y = CursorY - CursorTop + 1;
1922 }
1923 else {
1924 X = CursorX + 1;
1925 Y = CursorY+1;
1926 }
1927 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%u;%uR", CLocale, Y, X);
1928 SendCSIstr(Report, len);
1929 break;
1930 }
1931 }
1932
1933 void ParseSGRParams(PCharAttr attr, PCharAttr mask, int start)
1934 {
1935 int i, j, P, r, g, b, color;
1936 TCharAttr dummy;
1937
1938 if (mask == NULL) {
1939 mask = &dummy;
1940 }
1941
1942 for (i=start ; i<=NParam ; i++)
1943 {
1944 P = Param[i];
1945 switch (P) {
1946 case 0: /* Clear all */
1947 attr->Attr = DefCharAttr.Attr;
1948 attr->Attr2 = DefCharAttr.Attr2 | (attr->Attr2&Attr2Protect);
1949 attr->Fore = DefCharAttr.Fore;
1950 attr->Back = DefCharAttr.Back;
1951 mask->Attr = AttrSgrMask;
1952 mask->Attr2 = Attr2ColorMask;
1953 break;
1954
1955 case 1: /* Bold */
1956 attr->Attr |= AttrBold;
1957 mask->Attr |= AttrBold;
1958 break;
1959
1960 case 4: /* Under line */
1961 attr->Attr |= AttrUnder;
1962 mask->Attr |= AttrUnder;
1963 break;
1964
1965 case 5: /* Blink */
1966 attr->Attr |= AttrBlink;
1967 mask->Attr |= AttrBlink;
1968 break;
1969
1970 case 7: /* Reverse */
1971 attr->Attr |= AttrReverse;
1972 mask->Attr |= AttrReverse;
1973 break;
1974
1975 case 22: /* Bold off */
1976 attr->Attr &= ~ AttrBold;
1977 mask->Attr |= AttrBold;
1978 break;
1979
1980 case 24: /* Under line off */
1981 attr->Attr &= ~ AttrUnder;
1982 mask->Attr |= AttrUnder;
1983 break;
1984
1985 case 25: /* Blink off */
1986 attr->Attr &= ~ AttrBlink;
1987 mask->Attr |= AttrBlink;
1988 break;
1989
1990 case 27: /* Reverse off */
1991 attr->Attr &= ~ AttrReverse;
1992 mask->Attr |= AttrReverse;
1993 break;
1994
1995 case 30:
1996 case 31:
1997 case 32:
1998 case 33:
1999 case 34:
2000 case 35:
2001 case 36:
2002 case 37: /* text color */
2003 attr->Attr2 |= Attr2Fore;
2004 mask->Attr2 |= Attr2Fore;
2005 attr->Fore = P - 30;
2006 break;
2007
2008 case 38: /* text color (256color mode) */
2009 if (ts.ColorFlag & CF_XTERM256) {
2010 /*
2011 * Change foreground color. accept following formats.
2012 *
2013 * 38 ; 2 ; r ; g ; b
2014 * 38 ; 2 : r : g : b
2015 * 38 : 2 : r : g : b
2016 * 38 ; 5 ; idx
2017 * 38 ; 5 : idx
2018 * 38 : 5 : idx
2019 *
2020 */
2021 color = -1;
2022 j = 0;
2023 if (NSParam[i] > 0) {
2024 P = SubParam[i][1];
2025 j++;
2026 }
2027 else if (i < NParam) {
2028 P = Param[i+1];
2029 if (P == 2 || P == 5) {
2030 i++;
2031 }
2032 }
2033 switch (P) {
2034 case 2:
2035 r = g = b = 0;
2036 if (NSParam[i] > 0) {
2037 if (j < NSParam[i]) {
2038 r = SubParam[i][++j];
2039 if (j < NSParam[i]) {
2040 g = SubParam[i][++j];
2041 }
2042 if (j < NSParam[i]) {
2043 b = SubParam[i][++j];
2044 }
2045 color = DispFindClosestColor(r, g, b);
2046 }
2047 }
2048 else if (i < NParam && NSParam[i+1] > 0) {
2049 r = Param[++i];
2050 g = SubParam[i][1];
2051 if (NSParam[i] > 1) {
2052 b = SubParam[i][2];
2053 }
2054 color = DispFindClosestColor(r, g, b);
2055 }
2056 else if (i+2 < NParam) {
2057 r = Param[++i];
2058 g = Param[++i];
2059 b = Param[++i];
2060 color = DispFindClosestColor(r, g, b);
2061 }
2062 break;
2063 case 5:
2064 if (NSParam[i] > 0) {
2065 if (j < NSParam[i]) {
2066 color = SubParam[i][++j];
2067 }
2068 }
2069 else if (i < NParam) {
2070 color = Param[++i];
2071 }
2072 break;
2073 }
2074 if (color >= 0 && color < 256) {
2075 attr->Attr2 |= Attr2Fore;
2076 mask->Attr2 |= Attr2Fore;
2077 attr->Fore = color;
2078 }
2079 }
2080 break;
2081
2082 case 39: /* Reset text color */
2083 attr->Attr2 &= ~ Attr2Fore;
2084 mask->Attr2 |= Attr2Fore;
2085 attr->Fore = AttrDefaultFG;
2086 break;
2087
2088 case 40:
2089 case 41:
2090 case 42:
2091 case 43:
2092 case 44:
2093 case 45:
2094 case 46:
2095 case 47: /* Back color */
2096 attr->Attr2 |= Attr2Back;
2097 mask->Attr2 |= Attr2Back;
2098 attr->Back = P - 40;
2099 break;
2100
2101 case 48: /* Back color (256color mode) */
2102 if (ts.ColorFlag & CF_XTERM256) {
2103 color = -1;
2104 j = 0;
2105 if (NSParam[i] > 0) {
2106 P = SubParam[i][1];
2107 j++;
2108 }
2109 else if (i < NParam) {
2110 P = Param[i+1];
2111 if (P == 2 || P == 5) {
2112 i++;
2113 }
2114 }
2115 switch (P) {
2116 case 2:
2117 r = g = b = 0;
2118 if (NSParam[i] > 0) {
2119 if (j < NSParam[i]) {
2120 r = SubParam[i][++j];
2121 if (j < NSParam[i]) {
2122 g = SubParam[i][++j];
2123 }
2124 if (j < NSParam[i]) {
2125 b = SubParam[i][++j];
2126 }
2127 color = DispFindClosestColor(r, g, b);
2128 }
2129 }
2130 else if (i < NParam && NSParam[i+1] > 0) {
2131 r = Param[++i];
2132 g = SubParam[i][1];
2133 if (NSParam[i] > 1) {
2134 b = SubParam[i][2];
2135 }
2136 color = DispFindClosestColor(r, g, b);
2137 }
2138 else if (i+2 < NParam) {
2139 r = Param[++i];
2140 g = Param[++i];
2141 b = Param[++i];
2142 color = DispFindClosestColor(r, g, b);
2143 }
2144 break;
2145 case 5:
2146 if (NSParam[i] > 0) {
2147 if (j < NSParam[i]) {
2148 color = SubParam[i][++j];
2149 }
2150 }
2151 else if (i < NParam) {
2152 color = Param[++i];
2153 }
2154 break;
2155 }
2156 if (color >= 0 && color < 256) {
2157 attr->Attr2 |= Attr2Back;
2158 mask->Attr2 |= Attr2Back;
2159 attr->Back = color;
2160 }
2161 }
2162 break;
2163
2164 case 49: /* Reset back color */
2165 attr->Attr2 &= ~ Attr2Back;
2166 mask->Attr2 |= Attr2Back;
2167 attr->Back = AttrDefaultBG;
2168 break;
2169
2170 case 90:
2171 case 91:
2172 case 92:
2173 case 93:
2174 case 94:
2175 case 95:
2176 case 96:
2177 case 97: /* aixterm style text color */
2178 if (ts.ColorFlag & CF_AIXTERM16) {
2179 attr->Attr2 |= Attr2Fore;
2180 mask->Attr2 |= Attr2Fore;
2181 attr->Fore = P - 90 + 8;
2182 }
2183 break;
2184
2185 case 100:
2186 if (! (ts.ColorFlag & CF_AIXTERM16)) {
2187 /* Reset text and back color */
2188 attr->Attr2 &= ~ (Attr2Fore | Attr2Back);
2189 mask->Attr2 |= Attr2ColorMask;
2190 attr->Fore = AttrDefaultFG;
2191 attr->Back = AttrDefaultBG;
2192 break;
2193 }
2194 /* fall through to aixterm style back color */
2195
2196 case 101:
2197 case 102:
2198 case 103:
2199 case 104:
2200 case 105:
2201 case 106:
2202 case 107: /* aixterm style back color */
2203 if (ts.ColorFlag & CF_AIXTERM16) {
2204 attr->Attr2 |= Attr2Back;
2205 mask->Attr2 |= Attr2Back;
2206 attr->Back = P - 100 + 8;
2207 }
2208 break;
2209 }
2210 }
2211 }
2212
2213 void CSSetAttr() // SGR
2214 {
2215 UpdateStr();
2216 ParseSGRParams(&CharAttr, NULL, 1);
2217 BuffSetCurCharAttr(CharAttr);
2218 }
2219
2220 void CSSetScrollRegion() // DECSTBM
2221 {
2222 if (isCursorOnStatusLine) {
2223 MoveCursor(0,CursorY);
2224 return;
2225 }
2226 if (Param[1]<1) Param[1] =1;
2227 if ((NParam < 2) | (Param[2]<1))
2228 Param[2] = NumOfLines-StatusLine;
2229 Param[1]--;
2230 Param[2]--;
2231 if (Param[1] > NumOfLines-1-StatusLine)
2232 Param[1] = NumOfLines-1-StatusLine;
2233 if (Param[2] > NumOfLines-1-StatusLine)
2234 Param[2] = NumOfLines-1-StatusLine;
2235 if (Param[1] >= Param[2]) return;
2236 CursorTop = Param[1];
2237 CursorBottom = Param[2];
2238 if (RelativeOrgMode) MoveCursor(0,CursorTop);
2239 else MoveCursor(0,0);
2240 }
2241
2242 void CSSetLRScrollRegion() // DECSLRM
2243 {
2244 // if (isCursorOnStatusLine) {
2245 // MoveCursor(0,CursorY);
2246 // return;
2247 // }
2248
2249 if (Param[1] < 1)
2250 Param[1] =1;
2251 else if (Param[1] > NumOfColumns)
2252 Param[1] = NumOfColumns;
2253
2254 if (NParam < 2 || Param[2] < 1 || Param[2] > NumOfColumns)
2255 Param[2] = NumOfColumns;
2256
2257 if (Param[1] >= Param[2])
2258 return;
2259
2260 Param[1]--;
2261 Param[2]--;
2262
2263 CursorLeftM = Param[1];
2264 CursorRightM = Param[2];
2265
2266 if (RelativeOrgMode)
2267 MoveCursor(CursorLeftM, CursorTop);
2268 else
2269 MoveCursor(0, 0);
2270 }
2271
2272 void CSSunSequence() /* Sun terminal private sequences */
2273 {
2274 int x, y, len;
2275 char Report[TitleBuffSize*2+10];
2276 PTStack t;
2277
2278 switch (Param[1]) {
2279 case 1: // De-iconify window
2280 if (ts.WindowFlag & WF_WINDOWCHANGE)
2281 DispShowWindow(WINDOW_RESTORE);
2282 break;
2283 case 2: // Iconify window
2284 if (ts.WindowFlag & WF_WINDOWCHANGE)
2285 DispShowWindow(WINDOW_MINIMIZE);
2286 break;
2287 case 3: // set window position
2288 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2289 if (NParam < 2) Param[2] = 0;
2290 if (NParam < 3) Param[3] = 0;
2291 DispMoveWindow(Param[2], Param[3]);
2292 }
2293 break;
2294 case 4: // set window size
2295 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2296 if (NParam < 2) Param[2] = 0;
2297 if (NParam < 3) Param[3] = 0;
2298 DispResizeWin(Param[3], Param[2]);
2299 }
2300 break;
2301 case 5: // Raise window
2302 if (ts.WindowFlag & WF_WINDOWCHANGE)
2303 DispShowWindow(WINDOW_RAISE);
2304 break;
2305 case 6: // Lower window
2306 if (ts.WindowFlag & WF_WINDOWCHANGE)
2307 DispShowWindow(WINDOW_LOWER);
2308 break;
2309 case 7: // Refresh window
2310 if (ts.WindowFlag & WF_WINDOWCHANGE)
2311 DispShowWindow(WINDOW_REFRESH);
2312 break;
2313 case 8: /* set terminal size */
2314 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2315 if ((Param[2]<=1) || (NParam<2)) Param[2] = 24;
2316 if ((Param[3]<=1) || (NParam<3)) Param[3] = 80;
2317 ChangeTerminalSize(Param[3],Param[2]);
2318 }
2319 break;
2320 case 9: // Maximize/Restore window
2321 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2322 if (NParam < 2 || Param[2] == 0) {
2323 DispShowWindow(WINDOW_RESTORE);
2324 }
2325 else if (Param[2] == 1) {
2326 DispShowWindow(WINDOW_MAXIMIZE);
2327 }
2328 }
2329 break;
2330 case 11: // Report window state
2331 if (ts.WindowFlag & WF_WINDOWREPORT) {
2332 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%dt", CLocale, DispWindowIconified()?2:1);
2333 SendCSIstr(Report, len);
2334 }
2335 break;
2336 case 13: // Report window position
2337 if (ts.WindowFlag & WF_WINDOWREPORT) {
2338 DispGetWindowPos(&x, &y);
2339 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "3;%u;%ut", CLocale, (unsigned int)x, (unsigned int)y);
2340 SendCSIstr(Report, len);
2341 }
2342 break;
2343 case 14: /* get window size */
2344 if (ts.WindowFlag & WF_WINDOWREPORT) {
2345 DispGetWindowSize(&x, &y);
2346 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "4;%d;%dt", CLocale, y, x);
2347 SendCSIstr(Report, len);
2348 }
2349 break;
2350 case 18: /* get terminal size */
2351 if (ts.WindowFlag & WF_WINDOWREPORT) {
2352 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "8;%u;%ut", CLocale,
2353 NumOfLines-StatusLine, NumOfColumns);
2354 SendCSIstr(Report, len);
2355 }
2356 break;
2357 case 19: // Report display size (character)
2358 if (ts.WindowFlag & WF_WINDOWREPORT) {
2359 DispGetRootWinSize(&x, &y);
2360 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "9;%d;%dt", CLocale, y, x);
2361 SendCSIstr(Report, len);
2362 }
2363 break;
2364 case 20: // Report icon label
2365 switch (ts.WindowFlag & WF_TITLEREPORT) {
2366 case IdTitleReportIgnore:
2367 // nothing to do
2368 break;
2369 case IdTitleReportAccept:
2370 switch (ts.AcceptTitleChangeRequest) {
2371 case IdTitleChangeRequestOff:
2372 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2373 break;
2374 case IdTitleChangeRequestAhead:
2375 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, cv.TitleRemote, ts.Title);
2376 break;
2377 case IdTitleChangeRequestLast:
2378 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, ts.Title, cv.TitleRemote);
2379 break;
2380 default:
2381 if (cv.TitleRemote[0] == 0) {
2382 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2383 }
2384 else {
2385 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, cv.TitleRemote);
2386 }
2387 }
2388 SendOSCstr(Report, len, ST);
2389 break;
2390 default: // IdTitleReportEmpty:
2391 SendOSCstr("L", 0, ST);
2392 break;
2393 }
2394 break;
2395 case 21: // Report window title
2396 switch (ts.WindowFlag & WF_TITLEREPORT) {
2397 case IdTitleReportIgnore:
2398 // nothing to do
2399 break;
2400 case IdTitleReportAccept:
2401 switch (ts.AcceptTitleChangeRequest) {
2402 case IdTitleChangeRequestOff:
2403 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2404 break;
2405 case IdTitleChangeRequestAhead:
2406 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, cv.TitleRemote, ts.Title);
2407 break;
2408 case IdTitleChangeRequestLast:
2409 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, ts.Title, cv.TitleRemote);
2410 break;
2411 default:
2412 if (cv.TitleRemote[0] == 0) {
2413 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2414 }
2415 else {
2416 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, cv.TitleRemote);
2417 }
2418 }
2419 SendOSCstr(Report, len, ST);
2420 break;
2421 default: // IdTitleReportEmpty:
2422 SendOSCstr("l", 0, ST);
2423 break;
2424 }
2425 break;
2426 case 22: // Push Title
2427 if (NParam < 2) {
2428 Param[2] = 0;
2429 }
2430 switch (Param[2]) {
2431 case 0:
2432 case 1:
2433 case 2:
2434 if (ts.AcceptTitleChangeRequest && (t=malloc(sizeof(TStack))) != NULL) {
2435 if ((t->title = _strdup(cv.TitleRemote)) != NULL) {
2436 t->next = TitleStack;
2437 TitleStack = t;
2438 }
2439 else {
2440 free(t);
2441 }
2442 }
2443 break;
2444 }
2445 break;
2446 case 23: // Pop Title
2447 if (NParam < 2) {
2448 Param[2] = 0;
2449 }
2450 switch (Param[2]) {
2451 case 0:
2452 case 1:
2453 case 2:
2454 if (ts.AcceptTitleChangeRequest && TitleStack != NULL) {
2455 t = TitleStack;
2456 TitleStack = t->next;
2457 strncpy_s(cv.TitleRemote, sizeof(cv.TitleRemote), t->title, _TRUNCATE);
2458 ChangeTitle();
2459 free(t->title);
2460 free(t);
2461 }
2462 break;
2463 }
2464 }
2465 }
2466
2467 void CSLT(BYTE b)
2468 {
2469 switch (b) {
2470 case 'r':
2471 if (CanUseIME()) {
2472 SetIMEOpenStatus(IMEstat);
2473 }
2474 break;
2475
2476 case 's':
2477 if (CanUseIME()) {
2478 IMEstat = GetIMEOpenStatus();
2479 }
2480 break;
2481
2482 case 't':
2483 if (CanUseIME()) {
2484 SetIMEOpenStatus(Param[1] == 1);
2485 }
2486 break;
2487 }
2488 }
2489
2490 void CSEQ(BYTE b)
2491 {
2492 char Report[16];
2493 int len;
2494
2495 switch (b) {
2496 case 'c': /* Tertiary terminal report (Tertiary DA) */
2497 if (Param[1] < 1) {
2498 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "!|%8s", CLocale, ts.TerminalUID);
2499 SendDCSstr(Report, len);
2500 }
2501 break;
2502 }
2503 }
2504
2505 void CSGT(BYTE b)
2506 {
2507 switch (b) {
2508 case 'c': /* second terminal report (Secondary DA) */
2509 if (Param[1] < 1) {
2510 SendCSIstr(">32;278;0c", 0); /* VT382(>32) + xterm rev 278 */
2511 }
2512 break;
2513 case 'J': // IO-8256 terminal
2514 if (Param[1]==3) {
2515 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
2516 if (Param[3] < 1 || NParam < 3) Param[3] = 1;
2517 if (Param[4] < 1 || NParam < 4) Param[4] = NumOfLines-StatusLine;
2518 if (Param[5] < 1 || NParam < 5) Param[5] = NumOfColumns;
2519 BuffEraseBox(Param[3]-1, Param[2]-1, Param[5]-1, Param[4]-1);
2520 }
2521 break;
2522 case 'K': // IO-8256 terminal
2523 switch (Param[1]) {
2524 case 3:
2525 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
2526 if (Param[3] < 1 || NParam < 3) Param[3] = 1;
2527 BuffEraseCharsInLine(Param[2]-1, Param[3]-Param[2]+1);
2528 break;
2529 case 5:
2530 if (NParam < 2) Param[2] = 0;
2531 if (NParam < 3) Param[3] = 0;
2532 switch (Param[2]) {
2533 case 3:
2534 case 4:
2535 case 5:
2536 case 6: // Draw Line
2537 BuffDrawLine(CharAttr, Param[2], Param[3]);
2538 break;
2539
2540 case 12: // Text color
2541 if ((Param[3]>=0) && (Param[3]<=7)) {
2542 switch (Param[3]) {
2543 case 3: CharAttr.Fore = IdBlue; break;
2544 case 4: CharAttr.Fore = IdCyan; break;
2545 case 5: CharAttr.Fore = IdYellow; break;
2546 case 6: CharAttr.Fore = IdMagenta; break;
2547 default: CharAttr.Fore = Param[3]; break;
2548 }
2549 CharAttr.Attr2 |= Attr2Fore;
2550 BuffSetCurCharAttr(CharAttr);
2551 }
2552 break;
2553 }
2554 break;
2555 }
2556 break;
2557 }
2558 }
2559
2560 void CSQExchangeColor() // DECSCNM / Visual Bell
2561 {
2562 COLORREF ColorRef;
2563
2564 BuffUpdateScroll();
2565
2566 if (ts.ColorFlag & CF_REVERSECOLOR) {
2567 ColorRef = ts.VTColor[0];
2568 ts.VTColor[0] = ts.VTReverseColor[0];
2569 ts.VTReverseColor[0] = ColorRef;
2570 ColorRef = ts.VTColor[1];
2571 ts.VTColor[1] = ts.VTReverseColor[1];
2572 ts.VTReverseColor[1] = ColorRef;
2573 }
2574 else {
2575 ColorRef = ts.VTColor[0];
2576 ts.VTColor[0] = ts.VTColor[1];
2577 ts.VTColor[1] = ColorRef;
2578 }
2579
2580 ColorRef = ts.VTBoldColor[0];
2581 ts.VTBoldColor[0] = ts.VTBoldColor[1];
2582 ts.VTBoldColor[1] = ColorRef;
2583
2584 ColorRef = ts.VTBlinkColor[0];
2585 ts.VTBlinkColor[0] = ts.VTBlinkColor[1];
2586 ts.VTBlinkColor[1] = ColorRef;
2587
2588 ColorRef = ts.URLColor[0];
2589 ts.URLColor[0] = ts.URLColor[1];
2590 ts.URLColor[1] = ColorRef;
2591
2592 ts.ColorFlag ^= CF_REVERSEVIDEO;
2593
2594 #ifdef ALPHABLEND_TYPE2
2595 BGExchangeColor();
2596 #endif
2597 DispChangeBackground();
2598 UpdateWindow(HVTWin);
2599 }
2600
2601 void CSQChangeColumnMode(int width) // DECCOLM
2602 {
2603 ChangeTerminalSize(width, NumOfLines-StatusLine);
2604 if ((ts.TermFlag & TF_CLEARONRESIZE) == 0) {
2605 MoveCursor(0, 0);
2606 BuffClearScreen();
2607 UpdateWindow(HVTWin);
2608 }
2609 }
2610
2611 void CSQ_h_Mode() // DECSET
2612 {
2613 int i;
2614
2615 for (i = 1 ; i<=NParam ; i++)
2616 switch (Param[i]) {
2617 case 1: AppliCursorMode = TRUE; break; // DECCKM
2618 case 3: CSQChangeColumnMode(132); break; // DECCOLM
2619 case 5: /* Reverse Video (DECSCNM) */
2620 if (!(ts.ColorFlag & CF_REVERSEVIDEO))
2621 CSQExchangeColor(); /* Exchange text/back color */
2622 break;
2623 case 6: // DECOM
2624 if (isCursorOnStatusLine)
2625 MoveCursor(0,CursorY);
2626 else {
2627 RelativeOrgMode = TRUE;
2628 MoveCursor(0,CursorTop);
2629 }
2630 break;
2631 case 7: AutoWrapMode = TRUE; break; // DECAWM
2632 case 8: AutoRepeatMode = TRUE; break; // DECARM
2633 case 9: /* X10 Mouse Tracking */
2634 if (ts.MouseEventTracking)
2635 MouseReportMode = IdMouseTrackX10;
2636 break;
2637 case 12: /* att610 cursor blinking */
2638 if (ts.WindowFlag & WF_CURSORCHANGE) {
2639 ts.NonblinkingCursor = FALSE;
2640 ChangeCaret();
2641 }
2642 break;
2643 case 19: PrintEX = TRUE; break; // DECPEX
2644 case 25: DispEnableCaret(TRUE); break; // cursor on (DECTCEM)
2645 case 38: // DECTEK
2646 if (ts.AutoWinSwitch>0)
2647 ChangeEmu = IdTEK; /* Enter TEK Mode */
2648 break;
2649 case 47: // Alternate Screen Buffer
2650 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2651 BuffSaveScreen();
2652 AltScr = TRUE;
2653 }
2654 break;
2655 case 59:
2656 if (ts.Language==IdJapanese)
2657 { /* kanji terminal */
2658 Gn[0] = IdASCII;
2659 Gn[1] = IdKatakana;
2660 Gn[2] = IdKatakana;
2661 Gn[3] = IdKanji;
2662 Glr[0] = 0;
2663 if ((ts.KanjiCode==IdJIS) &&
2664 (ts.JIS7Katakana==0))
2665 Glr[1] = 2; // 8-bit katakana
2666 else
2667 Glr[1] = 3;
2668 }
2669 break;
2670 case 66: AppliKeyMode = TRUE; break; // DECNKM
2671 case 67: ts.BSKey = IdBS; break; // DECBKM
2672 case 69: LRMarginMode = TRUE; break; // DECLRMM (DECVSSM)
2673 case 1000: // Mouse Tracking
2674 if (ts.MouseEventTracking)
2675 MouseReportMode = IdMouseTrackVT200;
2676 break;
2677 case 1001: // Hilite Mouse Tracking
2678 if (ts.MouseEventTracking)
2679 MouseReportMode = IdMouseTrackVT200Hl;
2680 break;
2681 case 1002: // Button-Event Mouse Tracking
2682 if (ts.MouseEventTracking)
2683 MouseReportMode = IdMouseTrackBtnEvent;
2684 break;
2685 case 1003: // Any-Event Mouse Tracking
2686 if (ts.MouseEventTracking)
2687 MouseReportMode = IdMouseTrackAllEvent;
2688 break;
2689 case 1004: // Focus Report
2690 if (ts.MouseEventTracking)
2691 FocusReportMode = TRUE;
2692 break;
2693 case 1005: // Extended Mouse Tracking (UTF-8)
2694 if (ts.MouseEventTracking)
2695 MouseReportExtMode = IdMouseTrackExtUTF8;
2696 break;
2697 case 1006: // Extended Mouse Tracking (SGR)
2698 if (ts.MouseEventTracking)
2699 MouseReportExtMode = IdMouseTrackExtSGR;
2700 break;
2701 case 1015: // Extended Mouse Tracking (rxvt-unicode)
2702 if (ts.MouseEventTracking)
2703 MouseReportExtMode = IdMouseTrackExtURXVT;
2704 break;
2705 case 1047: // Alternate Screen Buffer
2706 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2707 BuffSaveScreen();
2708 AltScr = TRUE;
2709 }
2710 break;
2711 case 1048: // Save Cursor Position (Alternate Screen Buffer)
2712 if (ts.TermFlag & TF_ALTSCR) {
2713 SaveCursor();
2714 }
2715 break;
2716 case 1049: // Alternate Screen Buffer
2717 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2718 SaveCursor();
2719 BuffSaveScreen();
2720 BuffClearScreen();
2721 AltScr = TRUE;
2722 }
2723 break;
2724 case 2004: // Bracketed Paste Mode
2725 BracketedPaste = TRUE;
2726 break;
2727 case 7727: // mintty Application Escape Mode
2728 AppliEscapeMode = 1;
2729 break;
2730 case 7786: // Wheel to Cursor translation
2731 if (ts.TranslateWheelToCursor) {
2732 AcceptWheelToCursor = TRUE;
2733 }
2734 break;
2735 case 8200: // ClearThenHome
2736 ClearThenHome = TRUE;
2737 break;
2738 case 14001: // NetTerm mouse mode
2739 if (ts.MouseEventTracking)
2740 MouseReportMode = IdMouseTrackNetTerm;
2741 break;
2742 case 14002: // test Application Escape Mode 2
2743 case 14003: // test Application Escape Mode 3
2744 case 14004: // test Application Escape Mode 4
2745 AppliEscapeMode = Param[i] - 14000;
2746 break;
2747 }
2748 }
2749
2750 void CSQ_i_Mode() // DECMC
2751 {
2752 switch (Param[1]) {
2753 case 1:
2754 if (ts.TermFlag&TF_PRINTERCTRL) {
2755 OpenPrnFile();
2756 BuffDumpCurrentLine(LF);
2757 if (! AutoPrintMode)
2758 ClosePrnFile();
2759 }
2760 break;
2761 /* auto print mode off */
2762 case 4:
2763 if (AutoPrintMode)
2764 {
2765 ClosePrnFile();
2766 AutoPrintMode = FALSE;
2767 }
2768 break;
2769 /* auto print mode on */
2770 case 5:
2771 if (ts.TermFlag&TF_PRINTERCTRL) {
2772 if (! AutoPrintMode)
2773 {
2774 OpenPrnFile();
2775 AutoPrintMode = TRUE;
2776 }
2777 }
2778 break;
2779 }
2780 }
2781
2782 void CSQ_l_Mode() // DECRST
2783 {
2784 int i;
2785
2786 for (i = 1 ; i <= NParam ; i++)
2787 switch (Param[i]) {
2788 case 1: AppliCursorMode = FALSE; break; // DECCKM
2789 case 3: CSQChangeColumnMode(80); break; // DECCOLM
2790 case 5: /* Normal Video (DECSCNM) */
2791 if (ts.ColorFlag & CF_REVERSEVIDEO)
2792 CSQExchangeColor(); /* Exchange text/back color */
2793 break;
2794 case 6: // DECOM
2795 if (isCursorOnStatusLine)
2796 MoveCursor(0,CursorY);
2797 else {
2798 RelativeOrgMode = FALSE;
2799 MoveCursor(0,0);
2800 }
2801 break;
2802 case 7: AutoWrapMode = FALSE; break; // DECAWM
2803 case 8: AutoRepeatMode = FALSE; break; // DECARM
2804 case 9: MouseReportMode = IdMouseTrackNone; break; /* X10 Mouse Tracking */
2805 case 12: /* att610 cursor blinking */
2806 if (ts.WindowFlag & WF_CURSORCHANGE) {
2807 ts.NonblinkingCursor = TRUE;
2808 ChangeCaret();
2809 }
2810 break;
2811 case 19: PrintEX = FALSE; break; // DECPEX
2812 case 25: DispEnableCaret(FALSE); break; // cursor off (DECTCEM)
2813 case 47: // Alternate Screen Buffer
2814 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2815 BuffRestoreScreen();
2816 AltScr = FALSE;
2817 }
2818 break;
2819 case 59:
2820 if (ts.Language==IdJapanese)
2821 { /* katakana terminal */
2822 Gn[0] = IdASCII;
2823 Gn[1] = IdKatakana;
2824 Gn[2] = IdKatakana;
2825 Gn[3] = IdKanji;
2826 Glr[0] = 0;
2827 if ((ts.KanjiCode==IdJIS) &&
2828 (ts.JIS7Katakana==0))
2829 Glr[1] = 2; // 8-bit katakana
2830 else
2831 Glr[1] = 3;
2832 }
2833 break;
2834 case 66: AppliKeyMode = FALSE; break; // DECNKM
2835 case 67: ts.BSKey = IdDEL; break; // DECBKM
2836 case 69: // DECLRMM (DECVSSM)
2837 LRMarginMode = FALSE;
2838 CursorLeftM = 0;
2839 CursorRightM = NumOfColumns - 1;
2840 break;
2841 case 1000: // Mouse Tracking
2842 case 1001: // Hilite Mouse Tracking
2843 case 1002: // Button-Event Mouse Tracking
2844 case 1003: // Any-Event Mouse Tracking
2845 MouseReportMode = IdMouseTrackNone;
2846 break;
2847 case 1004: // Focus Report
2848 FocusReportMode = FALSE;
2849 break;
2850 case 1005: // Extended Mouse Tracking (UTF-8)
2851 case 1006: // Extended Mouse Tracking (SGR)
2852 case 1015: // Extended Mouse Tracking (rxvt-unicode)
2853 MouseReportExtMode = IdMouseTrackExtNone;
2854 break;
2855 case 1047: // Alternate Screen Buffer
2856 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2857 BuffClearScreen();
2858 BuffRestoreScreen();
2859 AltScr = FALSE;
2860 }
2861 break;
2862 case 1048: // Save Cursor Position (Alternate Screen Buffer)
2863 if (ts.TermFlag & TF_ALTSCR) {
2864 RestoreCursor();
2865 }
2866 break;
2867 case 1049: // Alternate Screen Buffer
2868 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2869 BuffClearScreen();
2870 BuffRestoreScreen();
2871 AltScr = FALSE;
2872 RestoreCursor();
2873 }
2874 break;
2875 case 2004: // Bracketed Paste Mode
2876 BracketedPaste = FALSE;
2877 break;
2878 case 7727: // mintty Application Escape Mode
2879 AppliEscapeMode = 0;
2880 break;
2881 case 7786: // Wheel to Cursor translation
2882 AcceptWheelToCursor = FALSE;
2883 break;
2884 case 8200: // ClearThenHome
2885 ClearThenHome = FALSE;
2886 break;
2887 case 14001: // NetTerm mouse mode
2888 MouseReportMode = IdMouseTrackNone;
2889 break;
2890 case 14002: // test Application Escape Mode 2
2891 case 14003: // test Application Escape Mode 3
2892 case 14004: // test Application Escape Mode 4
2893 AppliEscapeMode = 0;
2894 break;
2895 }
2896 }
2897
2898 void CSQ_n_Mode() // DECDSR
2899 {
2900 switch (Param[1]) {
2901 case 53:
2902 case 55:
2903 /* Locator Device Status Report -> Ready */
2904 SendCSIstr("?50n", 0);
2905 break;
2906 }
2907 }
2908
2909 void CSQuest(BYTE b)
2910 {
2911 switch (b) {
2912 case 'J': CSQSelScreenErase(); break; // DECSED
2913 case 'K': CSQSelLineErase(); break; // DECSEL
2914 case 'h': CSQ_h_Mode(); break; // DECSET
2915 case 'i': CSQ_i_Mode(); break; // DECMC
2916 case 'l': CSQ_l_Mode(); break; // DECRST
2917 case 'n': CSQ_n_Mode(); break; // DECDSR
2918 }
2919 }
2920
2921 void SoftReset()
2922 // called by software-reset escape sequence handler
2923 {
2924 UpdateStr();
2925 AutoRepeatMode = TRUE;
2926 DispEnableCaret(TRUE); // cursor on
2927 InsertMode = FALSE;
2928 RelativeOrgMode = FALSE;
2929 AppliKeyMode = FALSE;
2930 AppliCursorMode = FALSE;
2931 AppliEscapeMode = FALSE;
2932 AcceptWheelToCursor = ts.TranslateWheelToCursor;
2933 if (isCursorOnStatusLine)
2934 MoveToMainScreen();
2935 CursorTop = 0;
2936 CursorBottom = NumOfLines-1-StatusLine;
2937 CursorLeftM = 0;
2938 CursorRightM = NumOfColumns - 1;
2939 ResetCharSet();
2940
2941 /* Attribute */
2942 CharAttr = DefCharAttr;
2943 Special = FALSE;
2944 BuffSetCurCharAttr(CharAttr);
2945
2946 // status buffers
2947 ResetCurSBuffer();
2948
2949 // Saved IME status
2950 IMEstat = FALSE;
2951 }
2952
2953 void CSExc(BYTE b)
2954 {
2955 switch (b) {
2956 case 'p':
2957 /* Software reset */
2958 SoftReset();
2959 break;
2960 }
2961 }
2962
2963 void CSDouble(BYTE b)
2964 {
2965 switch (b) {
2966 case 'p': // DECSCL
2967 /* Select terminal mode (software reset) */
2968 SoftReset();
2969 if (NParam > 0) {
2970 ChangeTerminalID();
2971 if (Param[1] >= 61 && Param[1] <= 65) {
2972 if (VTlevel > Param[1] - 60) {
2973 VTlevel = Param[1] - 60;
2974 }
2975 }
2976 else {
2977 VTlevel = 1;
2978 }
2979
2980 if (VTlevel < 2 || (NParam > 1 && Param[2] == 1))
2981 Send8BitMode = FALSE;
2982 else
2983 Send8BitMode = TRUE;
2984 }
2985 break;
2986
2987 case 'q': // DECSCA
2988 switch (Param[1]) {
2989 case 0:
2990 case 2:
2991 CharAttr.Attr2 &= ~Attr2Protect;
2992 BuffSetCurCharAttr(CharAttr);
2993 break;
2994 case 1:
2995 CharAttr.Attr2 |= Attr2Protect;
2996 BuffSetCurCharAttr(CharAttr);
2997 break;
2998 default:
2999 /* nothing to do */
3000 break;
3001 }
3002 break;
3003 }
3004 }
3005
3006 void CSDolRequestMode()
3007 {
3008 char buff[256];
3009 char *pp;
3010 int len, resp = 0;
3011
3012 if (NParam == 0)
3013 Param[1] = 0;
3014
3015 switch (Prv) {
3016 case 0: /* ANSI Mode */
3017 resp = 4;
3018 pp = "";
3019 switch (Param[1]) {
3020 case 2: // KAM
3021 if (KeybEnabled)
3022 resp = 2;
3023 else
3024 resp = 1;
3025 break;
3026 case 4: // IRM
3027 if (InsertMode)
3028 resp = 1;
3029 else
3030 resp = 2;
3031 break;
3032 case 12: // SRM
3033 if (ts.LocalEcho)
3034 resp = 2;
3035 else
3036 resp = 1;
3037 break;
3038 case 20: // LNM
3039 if (LFMode)
3040 resp = 1;
3041 else
3042 resp = 2;
3043 break;
3044 case 33: // WYSTCURM
3045 if (ts.NonblinkingCursor)
3046 resp = 1;
3047 else
3048 resp = 2;
3049 if ((ts.WindowFlag & WF_CURSORCHANGE) == 0)
3050 resp += 2;
3051 break;
3052 case 34: // WYULCURM
3053 if (ts.CursorShape == IdHCur)
3054 resp = 1;
3055 else
3056 resp = 2;
3057 if ((ts.WindowFlag & WF_CURSORCHANGE) == 0)
3058 resp += 2;
3059 break;
3060 }
3061 break;
3062
3063 case '?': /* DEC Mode */
3064 pp = "?";
3065 switch (Param[1]) {
3066 case 1: // DECCKM
3067 if (AppliCursorMode)
3068 resp = 1;
3069 else
3070 resp = 2;
3071 break;
3072 case 3: // DECCOLM
3073 if (NumOfColumns == 132)
3074 resp = 1;
3075 else
3076 resp = 2;
3077 break;
3078 case 5: // DECSCNM
3079 if (ts.ColorFlag & CF_REVERSEVIDEO)
3080 resp = 1;
3081 else
3082 resp = 2;
3083 break;
3084 case 6: // DECOM
3085 if (RelativeOrgMode)
3086 resp = 1;
3087 else
3088 resp = 2;
3089 break;
3090 case 7: // DECAWM
3091 if (AutoWrapMode)
3092 resp = 1;
3093 else
3094 resp = 2;
3095 break;
3096 case 8: // DECARM
3097 if (AutoRepeatMode)
3098 resp = 1;
3099 else
3100 resp = 2;
3101 break;
3102 case 9: // XT_MSE_X10 -- X10 Mouse Tracking
3103 if (!ts.MouseEventTracking)
3104 resp = 4;
3105 else if (MouseReportMode == IdMouseTrackX10)
3106 resp = 1;
3107 else
3108 resp = 2;
3109 break;
3110 case 12: // XT_CBLINK -- att610 cursor blinking
3111 if (ts.NonblinkingCursor)
3112 resp = 2;
3113 else
3114 resp = 1;
3115 if ((ts.WindowFlag & WF_CURSORCHANGE) == 0)
3116 resp += 2;
3117 break;
3118 case 19: // DECPEX
3119 if (PrintEX)
3120 resp = 1;
3121 else
3122 resp = 2;
3123 break;
3124 case 25: // DECTCEM
3125 if (IsCaretEnabled())
3126 resp = 1;
3127 else
3128 resp = 2;
3129 break;
3130 case 38: // DECTEK
3131 resp = 4;
3132 break;
3133 case 47: // XT_ALTSCRN -- Alternate Screen / (DECGRPM)
3134 if ((ts.TermFlag & TF_ALTSCR) == 0)
3135 resp = 4;
3136 else if (AltScr)
3137 resp = 1;
3138 else
3139 resp = 2;
3140 break;
3141 case 59: // DECKKDM
3142 if (ts.Language!=IdJapanese)
3143 resp = 0;
3144 else if ((ts.KanjiCode == IdJIS) && (!ts.JIS7Katakana))
3145 resp = 4;
3146 else
3147 resp = 3;
3148 break;
3149 case 66: // DECNKM
3150 if (AppliKeyMode)
3151 resp = 1;
3152 else
3153 resp = 2;
3154 break;
3155 case 67: // DECBKM
3156 if (ts.BSKey==IdBS)
3157 resp = 1;
3158 else
3159 resp = 2;
3160 break;
3161 case 1000: // XT_MSE_X11
3162 if (!ts.MouseEventTracking)
3163 resp = 4;
3164 else if (MouseReportMode == IdMouseTrackVT200)
3165 resp = 1;
3166 else
3167 resp = 2;
3168 break;
3169 case 1001: // XT_MSE_HL
3170 #if 0
3171 if (!ts.MouseEventTracking)
3172 resp = 4;
3173 else if (MouseReportMode == IdMouseTrackVT200Hl)
3174 resp = 1;
3175 else
3176 resp = 2;
3177 #else
3178 resp = 4;
3179 #endif
3180 break;
3181 case 1002: // XT_MSE_BTN
3182 if (!ts.MouseEventTracking)
3183 resp = 4;
3184 else if (MouseReportMode == IdMouseTrackBtnEvent)
3185 resp = 1;
3186 else
3187 resp = 2;
3188 break;
3189 case 1003: // XT_MSE_ANY
3190 if (!ts.MouseEventTracking)
3191 resp = 4;
3192 else if (MouseReportMode == IdMouseTrackAllEvent)
3193 resp = 1;
3194 else
3195 resp = 2;
3196 break;
3197 case 1004: // XT_MSE_WIN
3198 if (!ts.MouseEventTracking)
3199 resp = 4;
3200 else if (FocusReportMode)
3201 resp = 1;
3202 else
3203 resp = 2;
3204 break;
3205 case 1005: // XT_MSE_UTF
3206 if (!ts.MouseEventTracking)
3207 resp = 4;
3208 else if (MouseReportExtMode == IdMouseTrackExtUTF8)
3209 resp = 1;
3210 else
3211 resp = 2;
3212 break;
3213 case 1006: // XT_MSE_SGR
3214 if (!ts.MouseEventTracking)
3215 resp = 4;
3216 else if (MouseReportExtMode == IdMouseTrackExtSGR)
3217 resp = 1;
3218 else
3219 resp = 2;
3220 break;
3221 case 1015: // urxvt-style extended mouse tracking
3222 if (!ts.MouseEventTracking)
3223 resp = 4;
3224 else if (MouseReportExtMode == IdMouseTrackExtURXVT)
3225 resp = 1;
3226 else
3227 resp = 2;
3228 break;
3229 case 1047: // XT_ALTS_47
3230 if ((ts.TermFlag & TF_ALTSCR) == 0)
3231 resp = 4;
3232 else if (AltScr)
3233 resp = 1;
3234 else
3235 resp = 2;
3236 break;
3237 case 1048:
3238 if ((ts.TermFlag & TF_ALTSCR) == 0)
3239 resp = 4;
3240 else
3241 resp = 1;
3242 break;
3243 case 1049: // XT_EXTSCRN
3244 if ((ts.TermFlag & TF_ALTSCR) == 0)
3245 resp = 4;
3246 else if (AltScr)
3247 resp = 1;
3248 else
3249 resp = 2;
3250 break;
3251 case 2004: // RL_BRACKET
3252 if (BracketedPaste)
3253 resp = 1;
3254 else
3255 resp = 2;
3256 break;
3257 case 7727: // MinTTY Application Escape Mode
3258 if (AppliEscapeMode == 1)
3259 resp = 1;
3260 else
3261 resp = 2;
3262 break;
3263 case 7786: // MinTTY Mousewheel reporting
3264 if (!ts.TranslateWheelToCursor)
3265 resp = 4;
3266 else if (AcceptWheelToCursor)
3267 resp = 1;
3268 else
3269 resp = 2;
3270 break;
3271 case 8200: // ClearThenHome
3272 if (ClearThenHome)
3273 resp = 1;
3274 else
3275 resp = 2;
3276 break;
3277 case 14001: // NetTerm Mouse Reporting (TT)
3278 if (!ts.MouseEventTracking)
3279 resp = 4;
3280 else if (MouseReportMode == IdMouseTrackNetTerm)
3281 resp = 1;
3282 else
3283 resp = 2;
3284 break;
3285 case 14002: // test Application Escape Mode 2
3286 case 14003: // test Application Escape Mode 3
3287 case 14004: // test Application Escape Mode 4
3288 if (AppliEscapeMode == Param[1] - 14000)
3289 resp = 1;
3290 else
3291 resp = 2;
3292 break;
3293 }
3294 break;
3295 }
3296
3297 len = _snprintf_s(buff, sizeof(buff), _TRUNCATE, "%s%d;%d$y", pp, Param[1], resp);
3298 SendCSIstr(buff, len);
3299 }
3300
3301 void CSDol(BYTE b)
3302 {
3303 TCharAttr attr, mask;
3304 attr = DefCharAttr;
3305 mask = DefCharAttr;
3306
3307 switch (b) {
3308 case 'p': // DECRQM
3309 CSDolRequestMode();
3310 break;
3311 case 'r': // DECCARA
3312 case 't': // DECRARA
3313 if (Param[1] < 1 || NParam < 1) Param[1] = 1;
3314 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
3315 if (Param[3] < 1 || NParam < 3) Param[3] = NumOfLines-StatusLine;
3316 if (Param[4] < 1 || NParam < 4) Param[4] = NumOfColumns;
3317 if (Param[1] <= Param[3] && Param[2] <= Param[4]) {
3318 if (RelativeOrgMode) {
3319 Param[1] += CursorTop;
3320 if (Param[1] > CursorBottom) {
3321 Param[1] = CursorBottom + 1;
3322 }
3323 Param[3] += CursorTop;
3324 if (Param[3] > CursorBottom) {
3325 Param[3] = CursorBottom + 1;
3326 }
3327 }
3328 }
3329 ParseSGRParams(&attr, &mask, 5);
3330 if (b == 'r') { // DECCARA
3331 attr.Attr &= AttrSgrMask;
3332 mask.Attr &= AttrSgrMask;
3333 attr.Attr2 &= Attr2ColorMask;
3334 mask.Attr2 &= Attr2ColorMask;
3335 BuffChangeAttrBox(Param[2]-1, Param[1]-1, Param[4]-1, Param[3]-1, &attr, &mask);
3336 }
3337 else { // DECRARA
3338 attr.Attr &= AttrSgrMask;
3339 BuffChangeAttrBox(Param[2]-1, Param[1]-1, Param[4]-1, Param[3]-1, &attr, NULL);
3340 }
3341 break;
3342 case 'v': // DECCRA
3343 if (Param[1] < 1 || NParam < 1) Param[1] = 1;
3344 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
3345 if (Param[3] < 1 || NParam < 3) Param[3] = NumOfLines-StatusLine;
3346 if (Param[4] < 1 || NParam < 4) Param[4] = NumOfColumns;
3347 if (Param[5] < 1 || NParam < 5) Param[5] = 1;
3348 if (Param[6] < 1 || NParam < 6) Param[6] = 1;
3349 if (Param[7] < 1 || NParam < 7) Param[7] = 1;
3350 if (Param[8] < 1 || NParam < 8) Param[8] = 1;
3351 if (Param[1] <= Param[3] && Param[2] <= Param[4]) {
3352 if (RelativeOrgMode) {
3353 Param[1] += CursorTop;
3354 if (Param[1] > CursorBottom) {
3355 Param[1] = CursorBottom + 1;
3356 }
3357 Param[3] += CursorTop;
3358 if (Param[3] > CursorBottom) {
3359 Param[3] = CursorBottom + 1;
3360 }
3361 Param[6] += CursorTop;
3362 if (Param[6] > CursorBottom) {
3363 Param[6] = CursorBottom + 1;
3364 }
3365 if (Param[6] + Param[3] - Param[1] > CursorBottom) {
3366 Param[3] = Param[1] + CursorBottom - Param[6] + 1;
3367 }
3368 }