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 5325 - (show annotations) (download) (as text)
Mon Jun 17 17:47:08 2013 UTC (10 years, 9 months ago) by doda
File MIME type: text/x-csrc
File size: 129057 byte(s)
DCH の 左右マージン対応

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