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 9311 - (show annotations) (download) (as text)
Fri Jun 18 16:05:10 2021 UTC (2 years, 9 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 153898 byte(s)
ANSI送信関数を削除

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