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 6804 - (show annotations) (download) (as text)
Tue Jun 13 10:56:30 2017 UTC (6 years, 9 months ago) by doda
File MIME type: text/x-csrc
File size: 133150 byte(s)
SI/SO の無効化対応 Ticket: 37266

SI/SO を無効化したいという要望はわかるけれど、SI/SO だけでいいのか?
SS2, SS3, LS2, LS3, LS1R, LS2R, LS3R, その他 ISO 2022 の文字指示とかはいいのか?

英語モードで自分が困るのが SI/SO だという事なんだろうけれど……

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