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 7274 - (show annotations) (download) (as text)
Wed Nov 21 08:45:37 2018 UTC (5 years, 4 months ago) by doda
File MIME type: text/x-csrc
File size: 138273 byte(s)
dttermのウィンドウ操作シーケンス(10:フルスクリーンモード)に暫定対応

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