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 3999 - (show annotations) (download) (as text)
Sun Aug 15 14:29:38 2010 UTC (13 years, 7 months ago) by doda
File MIME type: text/x-csrc
File size: 91207 byte(s)
DEC Locator Mode の Filter Rectangle に対応(したつもり)

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