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 4246 - (show annotations) (download) (as text)
Tue Dec 21 11:59:56 2010 UTC (13 years, 3 months ago) by doda
File MIME type: text/x-csrc
File size: 99486 byte(s)
VT-Level の概念を導入。
・VT-Lvelev 1 では 8bit 送信モードが無効になるようにした。
・端末 ID でのレベルより VT-Level が上にならないようにした。

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