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