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 10192 - (show annotations) (download) (as text)
Fri Aug 26 14:29:24 2022 UTC (19 months, 2 weeks ago) by zmatsuo
File MIME type: text/x-csrc
File size: 151617 byte(s)
文字色設定の整理

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