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 9104 - (show annotations) (download) (as text)
Sun Dec 20 12:16:27 2020 UTC (3 years, 3 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 152940 byte(s)
ttftypes.h への依存を減らした

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