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