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 9538 - (show annotations) (download) (as text)
Sat Nov 20 15:13:32 2021 UTC (2 years, 4 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 151312 byte(s)
OSC 52 によるクリップボード操作制御の文字コードをANSIからUTF-8に変更した

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