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