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 8897 - (show annotations) (download) (as text)
Tue Aug 18 15:27:54 2020 UTC (3 years, 7 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 155352 byte(s)
ログに関するコードを filesys_log.c に移動した

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