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 8861 - (show annotations) (download) (as text)
Sat Jul 25 16:00:36 2020 UTC (3 years, 8 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 154447 byte(s)
ログ/マクロ送信を別の文字コードで行えるようにした

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