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 6601 - (show annotations) (download) (as text)
Tue Feb 21 18:05:04 2017 UTC (7 years, 1 month ago) by doda
File MIME type: text/x-csrc
File size: 133061 byte(s)
UTF-8 設定時に正しく無いコードは CP932 として扱うよう変更

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