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