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 7043 - (show annotations) (download) (as text)
Wed Feb 21 03:01:46 2018 UTC (6 years, 1 month ago) by doda
File MIME type: text/x-csrc
File size: 135439 byte(s)
NumOfColumns -> NumOfLines

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