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 3998 - (show annotations) (download) (as text)
Sun Aug 15 11:59:22 2010 UTC (13 years, 7 months ago) by doda
File MIME type: text/x-csrc
File size: 90760 byte(s)
DECSLE で複数のパラメータが正しく扱えていなかったのを修正。

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