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