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 7270 - (show annotations) (download) (as text)
Wed Nov 21 08:45:21 2018 UTC (5 years, 4 months ago) by doda
File MIME type: text/x-csrc
File size: 137090 byte(s)
dttermのウィンドウ操作シーケンス(14:ウィンドウサイズ報告)の動作を更新

- CSI 14 t で送るのをウィンドウのサイズからクライアント領域のサイズに変更
- 二番目のパラメータ(Ps2)の値を見るように変更
  - Ps2 が 0 または 1 の時は Ps2 が無い時の動作に合わせた
  - Ps2 が 2 の時はウィンドウサイズを送るようにした
  - Ps2 がそれ以外の値の時は応答しないようにした

最後の以外は xterm の動作への追従。
xterm では Ps2 が 0 - 2 以外の時はクライアント領域のサイズを送っているが、
Tera Term ではあえて無視する。
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 11: // Report window state
2413 if (ts.WindowFlag & WF_WINDOWREPORT) {
2414 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%dt", CLocale, DispWindowIconified()?2:1);
2415 SendCSIstr(Report, len);
2416 }
2417 break;
2418
2419 case 13: // Report window position
2420 if (ts.WindowFlag & WF_WINDOWREPORT) {
2421 DispGetWindowPos(&x, &y);
2422 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "3;%u;%ut", CLocale, (unsigned int)x, (unsigned int)y);
2423 SendCSIstr(Report, len);
2424 }
2425 break;
2426
2427 case 14: /* get window size */
2428 if (ts.WindowFlag & WF_WINDOWREPORT) {
2429 RequiredParams(2);
2430 switch (Param[2]) {
2431 case 0:
2432 case 1:
2433 DispGetWindowSize(&x, &y, TRUE);
2434 break;
2435 case 2:
2436 DispGetWindowSize(&x, &y, FALSE);
2437 break;
2438 default:
2439 return;
2440 }
2441
2442 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "4;%d;%dt", CLocale, y, x);
2443 SendCSIstr(Report, len);
2444 }
2445 break;
2446
2447 case 18: /* get terminal size */
2448 if (ts.WindowFlag & WF_WINDOWREPORT) {
2449 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "8;%u;%ut", CLocale,
2450 NumOfLines-StatusLine, NumOfColumns);
2451 SendCSIstr(Report, len);
2452 }
2453 break;
2454
2455 case 19: // Report display size (character)
2456 if (ts.WindowFlag & WF_WINDOWREPORT) {
2457 DispGetRootWinSize(&x, &y);
2458 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "9;%d;%dt", CLocale, y, x);
2459 SendCSIstr(Report, len);
2460 }
2461 break;
2462
2463 case 20: // Report icon label
2464 switch (ts.WindowFlag & WF_TITLEREPORT) {
2465 case IdTitleReportIgnore:
2466 // nothing to do
2467 break;
2468
2469 case IdTitleReportAccept:
2470 switch (ts.AcceptTitleChangeRequest) {
2471 case IdTitleChangeRequestOff:
2472 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2473 break;
2474
2475 case IdTitleChangeRequestAhead:
2476 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, cv.TitleRemote, ts.Title);
2477 break;
2478
2479 case IdTitleChangeRequestLast:
2480 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, ts.Title, cv.TitleRemote);
2481 break;
2482
2483 default:
2484 if (cv.TitleRemote[0] == 0) {
2485 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2486 }
2487 else {
2488 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, cv.TitleRemote);
2489 }
2490 }
2491 SendOSCstr(Report, len, ST);
2492 break;
2493
2494 default: // IdTitleReportEmpty:
2495 SendOSCstr("L", 0, ST);
2496 break;
2497 }
2498 break;
2499
2500 case 21: // Report window title
2501 switch (ts.WindowFlag & WF_TITLEREPORT) {
2502 case IdTitleReportIgnore:
2503 // nothing to do
2504 break;
2505
2506 case IdTitleReportAccept:
2507 switch (ts.AcceptTitleChangeRequest) {
2508 case IdTitleChangeRequestOff:
2509 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2510 break;
2511
2512 case IdTitleChangeRequestAhead:
2513 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, cv.TitleRemote, ts.Title);
2514 break;
2515
2516 case IdTitleChangeRequestLast:
2517 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, ts.Title, cv.TitleRemote);
2518 break;
2519
2520 default:
2521 if (cv.TitleRemote[0] == 0) {
2522 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2523 }
2524 else {
2525 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, cv.TitleRemote);
2526 }
2527 }
2528 SendOSCstr(Report, len, ST);
2529 break;
2530
2531 default: // IdTitleReportEmpty:
2532 SendOSCstr("l", 0, ST);
2533 break;
2534 }
2535 break;
2536
2537 case 22: // Push Title
2538 RequiredParams(2);
2539 switch (Param[2]) {
2540 case 0:
2541 case 1:
2542 case 2:
2543 if (ts.AcceptTitleChangeRequest && (t=malloc(sizeof(TStack))) != NULL) {
2544 if ((t->title = _strdup(cv.TitleRemote)) != NULL) {
2545 t->next = TitleStack;
2546 TitleStack = t;
2547 }
2548 else {
2549 free(t);
2550 }
2551 }
2552 break;
2553 }
2554 break;
2555
2556 case 23: // Pop Title
2557 RequiredParams(2);
2558 switch (Param[2]) {
2559 case 0:
2560 case 1:
2561 case 2:
2562 if (ts.AcceptTitleChangeRequest && TitleStack != NULL) {
2563 t = TitleStack;
2564 TitleStack = t->next;
2565 strncpy_s(cv.TitleRemote, sizeof(cv.TitleRemote), t->title, _TRUNCATE);
2566 ChangeTitle();
2567 free(t->title);
2568 free(t);
2569 }
2570 break;
2571 }
2572 }
2573 }
2574
2575 void CSLT(BYTE b)
2576 {
2577 switch (b) {
2578 case 'r':
2579 if (CanUseIME()) {
2580 SetIMEOpenStatus(IMEstat);
2581 }
2582 break;
2583
2584 case 's':
2585 if (CanUseIME()) {
2586 IMEstat = GetIMEOpenStatus();
2587 }
2588 break;
2589
2590 case 't':
2591 if (CanUseIME()) {
2592 SetIMEOpenStatus(Param[1] == 1);
2593 }
2594 break;
2595 }
2596 }
2597
2598 void CSEQ(BYTE b)
2599 {
2600 char Report[16];
2601 int len;
2602
2603 switch (b) {
2604 case 'c': /* Tertiary terminal report (Tertiary DA) */
2605 if (Param[1] == 0) {
2606 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "!|%8s", CLocale, ts.TerminalUID);
2607 SendDCSstr(Report, len);
2608 }
2609 break;
2610 }
2611 }
2612
2613 void CSGT(BYTE b)
2614 {
2615 switch (b) {
2616 case 'c': /* second terminal report (Secondary DA) */
2617 if (Param[1] == 0) {
2618 SendCSIstr(">32;331;0c", 0); /* VT382(>32) + xterm rev 331 */
2619 }
2620 break;
2621
2622 case 'J': // IO-8256 terminal
2623 if (Param[1]==3) {
2624 RequiredParams(5);
2625 CheckParamVal(Param[2], NumOfLines-StatusLine);
2626 CheckParamVal(Param[3], NumOfColumns);
2627 CheckParamValMax(Param[4], NumOfLines-StatusLine);
2628 CheckParamValMax(Param[5], NumOfColumns);
2629
2630 if (Param[2] > Param[4] || Param[3] > Param[5]) {
2631 return;
2632 }
2633
2634 BuffEraseBox(Param[3]-1, Param[2]-1, Param[5]-1, Param[4]-1);
2635 }
2636 break;
2637
2638 case 'K': // IO-8256 terminal
2639 switch (Param[1]) {
2640 case 3:
2641 RequiredParams(3);
2642 CheckParamVal(Param[2], NumOfColumns);
2643 CheckParamVal(Param[3], NumOfColumns);
2644
2645 if (Param[2] > Param[3]) {
2646 return;
2647 }
2648
2649 BuffEraseCharsInLine(Param[2]-1, Param[3]-Param[2]+1);
2650 break;
2651
2652 case 5:
2653 RequiredParams(3);
2654 switch (Param[2]) {
2655 case 3:
2656 case 4:
2657 case 5:
2658 case 6: // Draw Line
2659 BuffDrawLine(CharAttr, Param[2], Param[3]);
2660 break;
2661
2662 case 12: // Text color
2663 if ((Param[3]>=0) && (Param[3]<=7)) {
2664 switch (Param[3]) {
2665 case 3: CharAttr.Fore = IdBlue; break;
2666 case 4: CharAttr.Fore = IdCyan; break;
2667 case 5: CharAttr.Fore = IdYellow; break;
2668 case 6: CharAttr.Fore = IdMagenta; break;
2669 default: CharAttr.Fore = Param[3]; break;
2670 }
2671 CharAttr.Attr2 |= Attr2Fore;
2672 BuffSetCurCharAttr(CharAttr);
2673 }
2674 break;
2675 }
2676 break;
2677 }
2678 break;
2679 }
2680 }
2681
2682 void CSQExchangeColor() // DECSCNM / Visual Bell
2683 {
2684 COLORREF ColorRef;
2685
2686 BuffUpdateScroll();
2687
2688 if (ts.ColorFlag & CF_REVERSECOLOR) {
2689 ColorRef = ts.VTColor[0];
2690 ts.VTColor[0] = ts.VTReverseColor[0];
2691 ts.VTReverseColor[0] = ColorRef;
2692 ColorRef = ts.VTColor[1];
2693 ts.VTColor[1] = ts.VTReverseColor[1];
2694 ts.VTReverseColor[1] = ColorRef;
2695 }
2696 else {
2697 ColorRef = ts.VTColor[0];
2698 ts.VTColor[0] = ts.VTColor[1];
2699 ts.VTColor[1] = ColorRef;
2700 }
2701
2702 ColorRef = ts.VTBoldColor[0];
2703 ts.VTBoldColor[0] = ts.VTBoldColor[1];
2704 ts.VTBoldColor[1] = ColorRef;
2705
2706 ColorRef = ts.VTBlinkColor[0];
2707 ts.VTBlinkColor[0] = ts.VTBlinkColor[1];
2708 ts.VTBlinkColor[1] = ColorRef;
2709
2710 ColorRef = ts.URLColor[0];
2711 ts.URLColor[0] = ts.URLColor[1];
2712 ts.URLColor[1] = ColorRef;
2713
2714 ts.ColorFlag ^= CF_REVERSEVIDEO;
2715
2716 #ifdef ALPHABLEND_TYPE2
2717 BGExchangeColor();
2718 #endif
2719 DispChangeBackground();
2720 UpdateWindow(HVTWin);
2721 }
2722
2723 void CSQChangeColumnMode(int width) // DECCOLM
2724 {
2725 ChangeTerminalSize(width, NumOfLines-StatusLine);
2726 if ((ts.TermFlag & TF_CLEARONRESIZE) == 0) {
2727 MoveCursor(0, 0);
2728 BuffClearScreen();
2729 UpdateWindow(HVTWin);
2730 }
2731 }
2732
2733 void CSQ_h_Mode() // DECSET
2734 {
2735 int i;
2736
2737 for (i = 1 ; i<=NParam ; i++) {
2738 switch (Param[i]) {
2739 case 1: AppliCursorMode = TRUE; break; // DECCKM
2740 case 3: CSQChangeColumnMode(132); break; // DECCOLM
2741 case 5: /* Reverse Video (DECSCNM) */
2742 if (!(ts.ColorFlag & CF_REVERSEVIDEO))
2743 CSQExchangeColor(); /* Exchange text/back color */
2744 break;
2745 case 6: // DECOM
2746 if (isCursorOnStatusLine)
2747 MoveCursor(0,CursorY);
2748 else {
2749 RelativeOrgMode = TRUE;
2750 MoveCursor(0,CursorTop);
2751 }
2752 break;
2753 case 7: AutoWrapMode = TRUE; break; // DECAWM
2754 case 8: AutoRepeatMode = TRUE; break; // DECARM
2755 case 9: /* X10 Mouse Tracking */
2756 if (ts.MouseEventTracking)
2757 MouseReportMode = IdMouseTrackX10;
2758 break;
2759 case 12: /* att610 cursor blinking */
2760 if (ts.WindowFlag & WF_CURSORCHANGE) {
2761 ts.NonblinkingCursor = FALSE;
2762 ChangeCaret();
2763 }
2764 break;
2765 case 19: PrintEX = TRUE; break; // DECPEX
2766 case 25: DispEnableCaret(TRUE); break; // cursor on (DECTCEM)
2767 case 38: // DECTEK
2768 if (ts.AutoWinSwitch>0)
2769 ChangeEmu = IdTEK; /* Enter TEK Mode */
2770 break;
2771 case 47: // Alternate Screen Buffer
2772 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2773 BuffSaveScreen();
2774 AltScr = TRUE;
2775 }
2776 break;
2777 case 59:
2778 if (ts.Language==IdJapanese) {
2779 /* kanji terminal */
2780 Gn[0] = IdASCII;
2781 Gn[1] = IdKatakana;
2782 Gn[2] = IdKatakana;
2783 Gn[3] = IdKanji;
2784 Glr[0] = 0;
2785 if ((ts.KanjiCode==IdJIS) &&
2786 (ts.JIS7Katakana==0))
2787 Glr[1] = 2; // 8-bit katakana
2788 else
2789 Glr[1] = 3;
2790 }
2791 break;
2792 case 66: AppliKeyMode = TRUE; break; // DECNKM
2793 case 67: ts.BSKey = IdBS; break; // DECBKM
2794 case 69: LRMarginMode = TRUE; break; // DECLRMM (DECVSSM)
2795 case 1000: // Mouse Tracking
2796 if (ts.MouseEventTracking)
2797 MouseReportMode = IdMouseTrackVT200;
2798 break;
2799 case 1001: // Hilite Mouse Tracking
2800 if (ts.MouseEventTracking)
2801 MouseReportMode = IdMouseTrackVT200Hl;
2802 break;
2803 case 1002: // Button-Event Mouse Tracking
2804 if (ts.MouseEventTracking)
2805 MouseReportMode = IdMouseTrackBtnEvent;
2806 break;
2807 case 1003: // Any-Event Mouse Tracking
2808 if (ts.MouseEventTracking)
2809 MouseReportMode = IdMouseTrackAllEvent;
2810 break;
2811 case 1004: // Focus Report
2812 if (ts.MouseEventTracking)
2813 FocusReportMode = TRUE;
2814 break;
2815 case 1005: // Extended Mouse Tracking (UTF-8)
2816 if (ts.MouseEventTracking)
2817 MouseReportExtMode = IdMouseTrackExtUTF8;
2818 break;
2819 case 1006: // Extended Mouse Tracking (SGR)
2820 if (ts.MouseEventTracking)
2821 MouseReportExtMode = IdMouseTrackExtSGR;
2822 break;
2823 case 1015: // Extended Mouse Tracking (rxvt-unicode)
2824 if (ts.MouseEventTracking)
2825 MouseReportExtMode = IdMouseTrackExtURXVT;
2826 break;
2827 case 1047: // Alternate Screen Buffer
2828 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2829 BuffSaveScreen();
2830 AltScr = TRUE;
2831 }
2832 break;
2833 case 1048: // Save Cursor Position (Alternate Screen Buffer)
2834 if (ts.TermFlag & TF_ALTSCR) {
2835 SaveCursor();
2836 }
2837 break;
2838 case 1049: // Alternate Screen Buffer
2839 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2840 SaveCursor();
2841 BuffSaveScreen();
2842 BuffClearScreen();
2843 AltScr = TRUE;
2844 }
2845 break;
2846 case 2004: // Bracketed Paste Mode
2847 BracketedPaste = TRUE;
2848 break;
2849 case 7727: // mintty Application Escape Mode
2850 AppliEscapeMode = 1;
2851 break;
2852 case 7786: // Wheel to Cursor translation
2853 if (ts.TranslateWheelToCursor) {
2854 AcceptWheelToCursor = TRUE;
2855 }
2856 break;
2857 case 8200: // ClearThenHome
2858 ClearThenHome = TRUE;
2859 break;
2860 case 14001: // NetTerm mouse mode
2861 if (ts.MouseEventTracking)
2862 MouseReportMode = IdMouseTrackNetTerm;
2863 break;
2864 case 14002: // test Application Escape Mode 2
2865 case 14003: // test Application Escape Mode 3
2866 case 14004: // test Application Escape Mode 4
2867 AppliEscapeMode = Param[i] - 14000;
2868 break;
2869 }
2870 }
2871 }
2872
2873 void CSQ_i_Mode() // DECMC
2874 {
2875 switch (Param[1]) {
2876 case 1:
2877 if (ts.TermFlag&TF_PRINTERCTRL) {
2878 OpenPrnFile();
2879 BuffDumpCurrentLine(LF);
2880 if (! AutoPrintMode)
2881 ClosePrnFile();
2882 }
2883 break;
2884 /* auto print mode off */
2885 case 4:
2886 if (AutoPrintMode) {
2887 ClosePrnFile();
2888 AutoPrintMode = FALSE;
2889 }
2890 break;
2891 /* auto print mode on */
2892 case 5:
2893 if (ts.TermFlag&TF_PRINTERCTRL) {
2894 if (! AutoPrintMode) {
2895 OpenPrnFile();
2896 AutoPrintMode = TRUE;
2897 }
2898 }
2899 break;
2900 }
2901 }
2902
2903 void CSQ_l_Mode() // DECRST
2904 {
2905 int i;
2906
2907 for (i = 1 ; i <= NParam ; i++) {
2908 switch (Param[i]) {
2909 case 1: AppliCursorMode = FALSE; break; // DECCKM
2910 case 3: CSQChangeColumnMode(80); break; // DECCOLM
2911 case 5: /* Normal Video (DECSCNM) */
2912 if (ts.ColorFlag & CF_REVERSEVIDEO)
2913 CSQExchangeColor(); /* Exchange text/back color */
2914 break;
2915 case 6: // DECOM
2916 if (isCursorOnStatusLine)
2917 MoveCursor(0,CursorY);
2918 else {
2919 RelativeOrgMode = FALSE;
2920 MoveCursor(0,0);
2921 }
2922 break;
2923 case 7: AutoWrapMode = FALSE; break; // DECAWM
2924 case 8: AutoRepeatMode = FALSE; break; // DECARM
2925 case 9: MouseReportMode = IdMouseTrackNone; break; /* X10 Mouse Tracking */
2926 case 12: /* att610 cursor blinking */
2927 if (ts.WindowFlag & WF_CURSORCHANGE) {
2928 ts.NonblinkingCursor = TRUE;
2929 ChangeCaret();
2930 }
2931 break;
2932 case 19: PrintEX = FALSE; break; // DECPEX
2933 case 25: DispEnableCaret(FALSE); break; // cursor off (DECTCEM)
2934 case 47: // Alternate Screen Buffer
2935 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2936 BuffRestoreScreen();
2937 AltScr = FALSE;
2938 }
2939 break;
2940 case 59:
2941 if (ts.Language==IdJapanese) {
2942 /* katakana terminal */
2943 Gn[0] = IdASCII;
2944 Gn[1] = IdKatakana;
2945 Gn[2] = IdKatakana;
2946 Gn[3] = IdKanji;
2947 Glr[0] = 0;
2948 if ((ts.KanjiCode==IdJIS) &&
2949 (ts.JIS7Katakana==0))
2950 Glr[1] = 2; // 8-bit katakana
2951 else
2952 Glr[1] = 3;
2953 }
2954 break;
2955 case 66: AppliKeyMode = FALSE; break; // DECNKM
2956 case 67: ts.BSKey = IdDEL; break; // DECBKM
2957 case 69: // DECLRMM (DECVSSM)
2958 LRMarginMode = FALSE;
2959 CursorLeftM = 0;
2960 CursorRightM = NumOfColumns - 1;
2961 break;
2962 case 1000: // Mouse Tracking
2963 case 1001: // Hilite Mouse Tracking
2964 case 1002: // Button-Event Mouse Tracking
2965 case 1003: // Any-Event Mouse Tracking
2966 MouseReportMode = IdMouseTrackNone;
2967 break;
2968 case 1004: // Focus Report
2969 FocusReportMode = FALSE;
2970 break;
2971 case 1005: // Extended Mouse Tracking (UTF-8)
2972 case 1006: // Extended Mouse Tracking (SGR)
2973 case 1015: // Extended Mouse Tracking (rxvt-unicode)
2974 MouseReportExtMode = IdMouseTrackExtNone;
2975 break;
2976 case 1047: // Alternate Screen Buffer
2977 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2978 BuffClearScreen();
2979 BuffRestoreScreen();
2980 AltScr = FALSE;
2981 }
2982 break;
2983 case 1048: // Save Cursor Position (Alternate Screen Buffer)
2984 if (ts.TermFlag & TF_ALTSCR) {
2985 RestoreCursor();
2986 }
2987 break;
2988 case 1049: // Alternate Screen Buffer
2989 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2990 BuffClearScreen();
2991 BuffRestoreScreen();
2992 AltScr = FALSE;
2993 RestoreCursor();
2994 }
2995 break;
2996 case 2004: // Bracketed Paste Mode
2997 BracketedPaste = FALSE;
2998 break;
2999 case 7727: // mintty Application Escape Mode
3000 AppliEscapeMode = 0;
3001 break;
3002 case 7786: // Wheel to Cursor translation
3003 AcceptWheelToCursor = FALSE;
3004 break;
3005 case 8200: // ClearThenHome
3006 ClearThenHome = FALSE;
3007 break;
3008 case 14001: // NetTerm mouse mode
3009 MouseReportMode = IdMouseTrackNone;
3010 break;
3011 case 14002: // test Application Escape Mode 2
3012 case 14003: // test Application Escape Mode 3
3013 case 14004: // test Application Escape Mode 4
3014 AppliEscapeMode = 0;
3015 break;
3016 }
3017 }
3018 }
3019
3020 void CSQ_n_Mode() // DECDSR
3021 {
3022 switch (Param[1]) {
3023 case 53:
3024 case 55:
3025 /* Locator Device Status Report -> Ready */
3026 SendCSIstr("?50n", 0);
3027 break;
3028 }
3029 }
3030
3031 void CSQuest(BYTE b)
3032 {
3033 switch (b) {
3034 case 'J': CSQSelScreenErase(); break; // DECSED
3035 case 'K': CSQSelLineErase(); break; // DECSEL
3036 case 'h': CSQ_h_Mode(); break; // DECSET
3037 case 'i': CSQ_i_Mode(); break; // DECMC
3038 case 'l': CSQ_l_Mode(); break; // DECRST
3039 case 'n': CSQ_n_Mode(); break; // DECDSR
3040 }
3041 }
3042
3043 void SoftReset()
3044 // called by software-reset escape sequence handler
3045 {
3046 UpdateStr();
3047 AutoRepeatMode = TRUE;
3048 DispEnableCaret(TRUE); // cursor on
3049 InsertMode = FALSE;
3050 RelativeOrgMode = FALSE;
3051 AppliKeyMode = FALSE;
3052 AppliCursorMode = FALSE;
3053 AppliEscapeMode = FALSE;
3054 AcceptWheelToCursor = ts.TranslateWheelToCursor;
3055 if (isCursorOnStatusLine)
3056 MoveToMainScreen();
3057 CursorTop = 0;
3058 CursorBottom = NumOfLines-1-StatusLine;
3059 CursorLeftM = 0;
3060 CursorRightM = NumOfColumns - 1;
3061 ResetCharSet();
3062
3063 /* Attribute */
3064 CharAttr = DefCharAttr;
3065 Special = FALSE;
3066 BuffSetCurCharAttr(CharAttr);
3067
3068 // status buffers
3069 ResetCurSBuffer();
3070
3071 // Saved IME status
3072 IMEstat = FALSE;
3073 }
3074
3075 void CSExc(BYTE b)
3076 {
3077 switch (b) {
3078 case 'p':
3079 /* Software reset */
3080 SoftReset();
3081 break;
3082 }
3083 }
3084
3085 void CSDouble(BYTE b)
3086 {
3087 switch (b) {
3088 case 'p': // DECSCL
3089 /* Select terminal mode (software reset) */
3090 RequiredParams(2);
3091
3092 SoftReset();
3093 ChangeTerminalID();
3094 if (Param[1] >= 61 && Param[1] <= 65) {
3095 if (VTlevel > Param[1] - 60) {
3096 VTlevel = Param[1] - 60;
3097 }
3098 }
3099 else {
3100 VTlevel = 1;
3101 }
3102
3103 if (VTlevel < 2 || Param[2] == 1)
3104 Send8BitMode = FALSE;
3105 else
3106 Send8BitMode = TRUE;
3107 break;
3108
3109 case 'q': // DECSCA
3110 switch (Param[1]) {
3111 case 0:
3112 case 2:
3113 CharAttr.Attr2 &= ~Attr2Protect;
3114 BuffSetCurCharAttr(CharAttr);
3115 break;
3116 case 1:
3117 CharAttr.Attr2 |= Attr2Protect;
3118 BuffSetCurCharAttr(CharAttr);
3119 break;
3120 default:
3121 /* nothing to do */
3122 break;
3123 }
3124 break;
3125 }
3126 }
3127
3128 void CSDolRequestMode() // DECRQM
3129 {
3130 char buff[256];
3131 char *pp;
3132 int len, resp = 0;
3133
3134 switch (Prv) {
3135 case 0: /* ANSI Mode */
3136 resp = 4;
3137 pp = "";
3138 switch (Param[1]) {
3139 case 2: // KAM
3140 if (KeybEnabled)
3141 resp = 2;
3142 else
3143 resp = 1;
3144 break;
3145 case 4: // IRM
3146 if (InsertMode)
3147 resp = 1;
3148 else
3149 resp = 2;
3150 break;
3151 case 12: // SRM
3152 if (ts.LocalEcho)
3153 resp = 2;
3154 else
3155 resp = 1;
3156 break;
3157 case 20: // LNM
3158 if (LFMode)
3159 resp = 1;
3160 else
3161 resp = 2;
3162 break;
3163 case 33: // WYSTCURM
3164 if (ts.NonblinkingCursor)
3165 resp = 1;
3166 else
3167 resp = 2;
3168 if ((ts.WindowFlag & WF_CURSORCHANGE) == 0)
3169 resp += 2;
3170 break;
3171 case 34: // WYULCURM
3172 if (ts.CursorShape == IdHCur)
3173 resp = 1;
3174 else
3175 resp = 2;
3176 if ((ts.WindowFlag & WF_CURSORCHANGE) == 0)
3177 resp += 2;
3178 break;
3179 }
3180 break;
3181
3182 case '?': /* DEC Mode */
3183 pp = "?";
3184 switch (Param[1]) {
3185 case 1: // DECCKM
3186 if (AppliCursorMode)
3187 resp = 1;
3188 else
3189 resp = 2;
3190 break;
3191 case 3: // DECCOLM
3192 if (NumOfColumns == 132)
3193 resp = 1;
3194 else
3195 resp = 2;
3196 break;
3197 case 5: // DECSCNM
3198 if (ts.ColorFlag & CF_REVERSEVIDEO)
3199 resp = 1;
3200 else
3201 resp = 2;
3202 break;
3203 case 6: // DECOM
3204 if (RelativeOrgMode)
3205 resp = 1;
3206 else
3207 resp = 2;
3208 break;
3209 case 7: // DECAWM
3210 if (AutoWrapMode)
3211 resp = 1;
3212 else
3213 resp = 2;
3214 break;
3215 case 8: // DECARM
3216 if (AutoRepeatMode)
3217 resp = 1;
3218 else
3219 resp = 2;
3220 break;
3221 case 9: // XT_MSE_X10 -- X10 Mouse Tracking
3222 if (!ts.MouseEventTracking)
3223 resp = 4;
3224 else if (MouseReportMode == IdMouseTrackX10)
3225 resp = 1;
3226 else
3227 resp = 2;
3228 break;
3229 case 12: // XT_CBLINK -- att610 cursor blinking
3230 if (ts.NonblinkingCursor)
3231 resp = 2;
3232 else
3233 resp = 1;
3234 if ((ts.WindowFlag & WF_CURSORCHANGE) == 0)
3235 resp += 2;
3236 break;
3237 case 19: // DECPEX
3238 if (PrintEX)
3239 resp = 1;
3240 else
3241 resp = 2;
3242 break;
3243 case 25: // DECTCEM
3244 if (IsCaretEnabled())
3245 resp = 1;
3246 else
3247 resp = 2;
3248 break;
3249 case 38: // DECTEK
3250 resp = 4;
3251 break;
3252 case 47: // XT_ALTSCRN -- Alternate Screen / (DECGRPM)
3253 if ((ts.TermFlag & TF_ALTSCR) == 0)
3254 resp = 4;
3255 else if (AltScr)
3256 resp = 1;
3257 else
3258 resp = 2;
3259 break;
3260 case 59: // DECKKDM
3261 if (ts.Language!=IdJapanese)
3262 resp = 0;
3263 else if ((ts.KanjiCode == IdJIS) && (!ts.JIS7Katakana))
3264 resp = 4;
3265 else
3266 resp = 3;
3267 break;
3268 case 66: // DECNKM
3269 if (AppliKeyMode)
3270 resp = 1;
3271 else
3272 resp = 2;
3273 break;
3274 case 67: // DECBKM
3275 if (ts.BSKey==IdBS)
3276 resp = 1;
3277 else
3278 resp = 2;
3279 break;
3280 case 69: // DECRQM
3281 if (LRMarginMode)
3282 resp = 1;
3283 else
3284 resp = 2;
3285 break;
3286 case 1000: // XT_MSE_X11
3287 if (!ts.MouseEventTracking)
3288 resp = 4;
3289 else if (MouseReportMode == IdMouseTrackVT200)
3290 resp = 1;
3291 else
3292 resp = 2;
3293 break;
3294 case 1001: // XT_MSE_HL
3295 #if 0
3296 if (!ts.MouseEventTracking)
3297 resp = 4;
3298 else if (MouseReportMode == IdMouseTrackVT200Hl)
3299 resp = 1;
3300 else
3301 resp = 2;
3302 #else
3303 resp = 4;
3304 #endif
3305 break;
3306 case 1002: // XT_MSE_BTN
3307 if (!ts.MouseEventTracking)
3308 resp = 4;
3309 else if (MouseReportMode == IdMouseTrackBtnEvent)
3310 resp = 1;
3311 else
3312 resp = 2;
3313 break;
3314 case 1003: // XT_MSE_ANY
3315 if (!ts.MouseEventTracking)
3316 resp = 4;
3317 else if (MouseReportMode == IdMouseTrackAllEvent)
3318 resp = 1;
3319 else
3320 resp = 2;
3321 break;
3322 case 1004: // XT_MSE_WIN
3323 if (!ts.MouseEventTracking)
3324 resp = 4;
3325 else if (FocusReportMode)
3326 resp = 1;
3327 else
3328 resp = 2;
3329 break;
3330 case 1005: // XT_MSE_UTF
3331 if (!ts.MouseEventTracking)
3332 resp = 4;
3333 else if (MouseReportExtMode == IdMouseTrackExtUTF8)
3334 resp = 1;
3335 else
3336 resp = 2;
3337 break;
3338 case 1006: // XT_MSE_SGR
3339 if (!ts.MouseEventTracking)
3340 resp = 4;
3341 else if (MouseReportExtMode == IdMouseTrackExtSGR)
3342 resp = 1;
3343 else
3344 resp = 2;
3345 break;
3346 case 1015: // urxvt-style extended mouse tracking
3347 if (!ts.MouseEventTracking)
3348 resp = 4;
3349 else if (MouseReportExtMode == IdMouseTrackExtURXVT)
3350 resp = 1;
3351 else
3352 resp = 2;
3353 break;
3354 case 1047: // XT_ALTS_47
3355 if ((ts.TermFlag & TF_ALTSCR) == 0)
3356 resp = 4;
3357 else if (AltScr)
3358 resp = 1;
3359 else
3360 resp = 2;
3361 break;
3362 case 1048:
3363 if ((ts.TermFlag & TF_ALTSCR) == 0)
3364 resp = 4;
3365 else
3366 resp = 1;
3367 break;
3368 case 1049: // XT_EXTSCRN
3369 if ((ts.TermFlag & TF_ALTSCR) == 0)
3370 resp = 4;
3371 else if (AltScr)
3372 resp = 1;
3373 else
3374 resp = 2;
3375 break;
3376 case 2004: // RL_BRACKET
3377 if (BracketedPaste)
3378 resp = 1;
3379 else
3380 resp = 2;
3381 break;
3382 case 7727: // MinTTY Application Escape Mode
3383 if (AppliEscapeMode == 1)
3384 resp = 1;
3385 else
3386 resp = 2;
3387 break;
3388 case 7786: // MinTTY Mousewheel reporting
3389 if (!ts.TranslateWheelToCursor)
3390 resp = 4;
3391 else if (AcceptWheelToCursor)
3392 resp = 1;
3393 else
3394 resp = 2;
3395 break;
3396 case 8200: // ClearThenHome
3397 if (ClearThenHome)
3398 resp = 1;
3399 else
3400 resp = 2;
3401 break;
3402 case 14001: // NetTerm Mouse Reporting (TT)
3403 if (!ts.MouseEventTracking)
3404 resp = 4;
3405 else if (MouseReportMode == IdMouseTrackNetTerm)
3406 resp = 1;
3407 else
3408 resp = 2;
3409 break;
3410 case 14002: // test Application Escape Mode 2
3411 case 14003: // test Application Escape Mode 3
3412 case 14004: // test Application Escape Mode 4
3413