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