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 8904 - (show annotations) (download) (as text)
Tue Aug 18 15:31:14 2020 UTC (3 years, 7 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 152634 byte(s)
ログファイルへの文字コードの変換を filesys_log で行うようにした

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