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 7983 - (show annotations) (download) (as text)
Sun Aug 18 02:57:16 2019 UTC (4 years, 7 months ago) by yutakapon
File MIME type: text/x-csrc
File size: 139757 byte(s)
r7978 の再修正。setlocaleが失敗した場合は、現在にANSIコードページを設定する。

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