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 6806 - (show annotations) (download) (as text)
Thu Jun 15 00:37:01 2017 UTC (6 years, 9 months ago) by doda
File MIME type: text/x-csrc
File size: 134616 byte(s)
TeraTerm Project としてのライセンス表記を追加

とりあえず Tera Term 本体分。
TeraTerm Project としての copyright 表記の年部分はコミットログを確認して書いたつもりだけど、ミスってたらすみません。

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