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 6841 - (show annotations) (download) (as text)
Tue Jul 4 15:02:28 2017 UTC (6 years, 9 months ago) by doda
File MIME type: text/x-csrc
File size: 134612 byte(s)
TeraTerm Project としてのライセンス表記を追加

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