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 7086 - (show annotations) (download) (as text)
Thu Mar 29 14:58:31 2018 UTC (6 years ago) by doda
File MIME type: text/x-csrc
File size: 136076 byte(s)
DECSACE に対応 #33906

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