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 9118 - (show annotations) (download) (as text)
Mon Dec 28 15:38:09 2020 UTC (3 years, 3 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 153851 byte(s)
mbstring.h を削除

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