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 4250 - (show annotations) (download) (as text)
Wed Dec 22 06:27:26 2010 UTC (13 years, 3 months ago) by doda
File MIME type: text/x-csrc
File size: 99559 byte(s)
ウィンドウサイズ変更制御シーケンスに対して、実際のウィンドウサイズを返すようにした。

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 DispGetWindowSize(&x, &y);
2057 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "4;%d;%dt", CLocale, y, x);
2058 SendCSIstr(Report, len);
2059 }
2060 break;
2061 case 18: /* get terminal size */
2062 if (ts.WindowFlag & WF_WINDOWREPORT) {
2063 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "8;%u;%u;t", CLocale,
2064 NumOfLines-StatusLine, NumOfColumns);
2065 SendCSIstr(Report, len);
2066 }
2067 break;
2068 case 19: // Report display size (character)
2069 if (ts.WindowFlag & WF_WINDOWREPORT) {
2070 DispGetRootWinSize(&x, &y);
2071 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "9;%d;%dt", CLocale, y, x);
2072 SendCSIstr(Report, len);
2073 }
2074 break;
2075 case 20: // Report icon label
2076 switch (ts.WindowFlag & WF_TITLEREPORT) {
2077 case IdTitleReportIgnore:
2078 // nothing to do
2079 break;
2080 case IdTitleReportAccept:
2081 switch (ts.AcceptTitleChangeRequest) {
2082 case IdTitleChangeRequestOff:
2083 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2084 break;
2085 case IdTitleChangeRequestAhead:
2086 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, cv.TitleRemote, ts.Title);
2087 break;
2088 case IdTitleChangeRequestLast:
2089 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, ts.Title, cv.TitleRemote);
2090 break;
2091 default:
2092 if (cv.TitleRemote[0] == 0) {
2093 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2094 }
2095 else {
2096 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, cv.TitleRemote);
2097 }
2098 }
2099 SendOSCstr(Report, len);
2100 break;
2101 default: // IdTitleReportEmpty:
2102 SendOSCstr("L", 0);
2103 break;
2104 }
2105 break;
2106 case 21: // Report window title
2107 switch (ts.WindowFlag & WF_TITLEREPORT) {
2108 case IdTitleReportIgnore:
2109 // nothing to do
2110 break;
2111 case IdTitleReportAccept:
2112 switch (ts.AcceptTitleChangeRequest) {
2113 case IdTitleChangeRequestOff:
2114 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2115 break;
2116 case IdTitleChangeRequestAhead:
2117 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, cv.TitleRemote, ts.Title);
2118 break;
2119 case IdTitleChangeRequestLast:
2120 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, ts.Title, cv.TitleRemote);
2121 break;
2122 default:
2123 if (cv.TitleRemote[0] == 0) {
2124 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2125 }
2126 else {
2127 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, cv.TitleRemote);
2128 }
2129 }
2130 SendOSCstr(Report, len);
2131 break;
2132 default: // IdTitleReportEmpty:
2133 SendOSCstr("l", 0);
2134 break;
2135 }
2136 break;
2137 }
2138 }
2139
2140 void CSEQ(BYTE b)
2141 {
2142 char Report[16];
2143 int len;
2144
2145 switch (b) {
2146 case 'c': /* Tertiary terminal report (Tertiary DA) */
2147 if (Param[1] < 1) {
2148 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "!|%8s", CLocale, ts.TerminalUID);
2149 SendDCSstr(Report, len);
2150 }
2151 break;
2152 }
2153 }
2154
2155 void CSGT(BYTE b)
2156 {
2157 switch (b) {
2158 case 'c': /* second terminal report (Secondary DA) */
2159 if (Param[1] < 1) {
2160 SendCSIstr(">32;100;2c", 0); /* VT382 */
2161 }
2162 break;
2163 case 'J': // IO-8256 terminal
2164 if (Param[1]==3) {
2165 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
2166 if (Param[3] < 1 || NParam < 3) Param[3] = 1;
2167 if (Param[4] < 1 || NParam < 4) Param[4] = NumOfLines-StatusLine;
2168 if (Param[5] < 1 || NParam < 5) Param[5] = NumOfColumns;
2169 BuffEraseBox(Param[3]-1, Param[2]-1, Param[5]-1, Param[4]-1);
2170 }
2171 break;
2172 case 'K': // IO-8256 terminal
2173 switch (Param[1]) {
2174 case 3:
2175 if (Param[2] < 1 || NParam < 2) Param[2] = 1;
2176 if (Param[3] < 1 || NParam < 3) Param[3] = 1;
2177 BuffEraseCharsInLine(Param[2]-1, Param[3]-Param[2]+1);
2178 break;
2179 case 5:
2180 if (NParam < 2) Param[2] = 0;
2181 if (NParam < 3) Param[3] = 0;
2182 switch (Param[2]) {
2183 case 3:
2184 case 4:
2185 case 5:
2186 case 6: // Draw Line
2187 BuffDrawLine(CharAttr, Param[2], Param[3]);
2188 break;
2189
2190 case 12: // Text color
2191 if ((Param[3]>=0) && (Param[3]<=7)) {
2192 switch (Param[3]) {
2193 case 3: CharAttr.Fore = IdBlue; break;
2194 case 4: CharAttr.Fore = IdCyan; break;
2195 case 5: CharAttr.Fore = IdYellow; break;
2196 case 6: CharAttr.Fore = IdMagenta; break;
2197 default: CharAttr.Fore = Param[3]; break;
2198 }
2199 CharAttr.Attr2 |= Attr2Fore;
2200 BuffSetCurCharAttr(CharAttr);
2201 }
2202 break;
2203 }
2204 break;
2205 }
2206 break;
2207 }
2208 }
2209
2210 void CSQExchangeColor() // DECSCNM / Visual Bell
2211 {
2212 COLORREF ColorRef;
2213
2214 BuffUpdateScroll();
2215
2216 if (ts.ColorFlag & CF_REVERSECOLOR) {
2217 ColorRef = ts.VTColor[0];
2218 ts.VTColor[0] = ts.VTReverseColor[0];
2219 ts.VTReverseColor[0] = ColorRef;
2220 ColorRef = ts.VTColor[1];
2221 ts.VTColor[1] = ts.VTReverseColor[1];
2222 ts.VTReverseColor[1] = ColorRef;
2223 }
2224 else {
2225 ColorRef = ts.VTColor[0];
2226 ts.VTColor[0] = ts.VTColor[1];
2227 ts.VTColor[1] = ColorRef;
2228 }
2229
2230 ColorRef = ts.VTBoldColor[0];
2231 ts.VTBoldColor[0] = ts.VTBoldColor[1];
2232 ts.VTBoldColor[1] = ColorRef;
2233
2234 ColorRef = ts.VTBlinkColor[0];
2235 ts.VTBlinkColor[0] = ts.VTBlinkColor[1];
2236 ts.VTBlinkColor[1] = ColorRef;
2237
2238 ColorRef = ts.URLColor[0];
2239 ts.URLColor[0] = ts.URLColor[1];
2240 ts.URLColor[1] = ColorRef;
2241
2242 ts.ColorFlag ^= CF_REVERSEVIDEO;
2243
2244 #ifdef ALPHABLEND_TYPE2
2245 // BGInitialize();
2246 BGExchangeColor();
2247 #endif
2248 DispChangeBackground();
2249 UpdateWindow(HVTWin);
2250 }
2251
2252 void CSQChangeColumnMode(int width) // DECCOLM
2253 {
2254 ChangeTerminalSize(width, NumOfLines-StatusLine);
2255 if ((ts.TermFlag & TF_CLEARONRESIZE) == 0) {
2256 MoveCursor(0, 0);
2257 BuffClearScreen();
2258 UpdateWindow(HVTWin);
2259 }
2260 }
2261
2262 void CSQ_h_Mode() // DECSET
2263 {
2264 int i;
2265
2266 for (i = 1 ; i<=NParam ; i++)
2267 switch (Param[i]) {
2268 case 1: AppliCursorMode = TRUE; break; // DECCKM
2269 case 3: CSQChangeColumnMode(132); break; // DECCOLM
2270 case 5: /* Reverse Video (DECSCNM) */
2271 if (!(ts.ColorFlag & CF_REVERSEVIDEO))
2272 CSQExchangeColor(); /* Exchange text/back color */
2273 break;
2274 case 6: // DECOM
2275 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2276 MoveCursor(0,CursorY);
2277 else {
2278 RelativeOrgMode = TRUE;
2279 MoveCursor(0,CursorTop);
2280 }
2281 break;
2282 case 7: AutoWrapMode = TRUE; break; // DECAWM
2283 case 8: AutoRepeatMode = TRUE; break; // DECARM
2284 case 9: /* X10 Mouse Tracking */
2285 if (ts.MouseEventTracking)
2286 MouseReportMode = IdMouseTrackX10;
2287 break;
2288 case 12: /* att610 cursor blinking */
2289 if (ts.WindowFlag & WF_CURSORCHANGE) {
2290 ts.NonblinkingCursor = FALSE;
2291 ChangeCaret();
2292 }
2293 break;
2294 case 19: PrintEX = TRUE; break; // DECPEX
2295 case 25: DispEnableCaret(TRUE); break; // cursor on (DECTCEM)
2296 case 38: // DECTEK
2297 if (ts.AutoWinSwitch>0)
2298 ChangeEmu = IdTEK; /* Enter TEK Mode */
2299 break;
2300 case 47: // Alternate Screen Buffer
2301 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2302 BuffSaveScreen();
2303 AltScr = TRUE;
2304 }
2305 break;
2306 case 59:
2307 if (ts.Language==IdJapanese)
2308 { /* kanji terminal */
2309 Gn[0] = IdASCII;
2310 Gn[1] = IdKatakana;
2311 Gn[2] = IdKatakana;
2312 Gn[3] = IdKanji;
2313 Glr[0] = 0;
2314 if ((ts.KanjiCode==IdJIS) &&
2315 (ts.JIS7Katakana==0))
2316 Glr[1] = 2; // 8-bit katakana
2317 else
2318 Glr[1] = 3;
2319 }
2320 break;
2321 case 66: AppliKeyMode = TRUE; break; // DECNKM
2322 case 67: ts.BSKey = IdBS; break; // DECBKM
2323 case 1000: // Mouse Tracking
2324 if (ts.MouseEventTracking)
2325 MouseReportMode = IdMouseTrackVT200;
2326 break;
2327 case 1001: // Hilite Mouse Tracking
2328 if (ts.MouseEventTracking)
2329 MouseReportMode = IdMouseTrackVT200Hl;
2330 break;
2331 case 1002: // Button-Event Mouse Tracking
2332 if (ts.MouseEventTracking)
2333 MouseReportMode = IdMouseTrackBtnEvent;
2334 break;
2335 case 1003: // Any-Event Mouse Tracking
2336 if (ts.MouseEventTracking)
2337 MouseReportMode = IdMouseTrackAllEvent;
2338 break;
2339 case 1004: // Focus Report
2340 if (ts.MouseEventTracking)
2341 FocusReportMode = TRUE;
2342 break;
2343 case 1047: // Alternate Screen Buffer
2344 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2345 BuffSaveScreen();
2346 AltScr = TRUE;
2347 }
2348 break;
2349 case 1048: // Save Cursor Position (Alternate Screen Buffer)
2350 if (ts.TermFlag & TF_ALTSCR) {
2351 SaveCursor();
2352 }
2353 break;
2354 case 1049: // Alternate Screen Buffer
2355 if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2356 SaveCursor();
2357 BuffSaveScreen();
2358 BuffClearScreen();
2359 AltScr = TRUE;
2360 }
2361 break;
2362 case 2004: // Bracketed Paste Mode
2363 BracketedPaste = TRUE;
2364 break;
2365 }
2366 }
2367
2368 void CSQ_i_Mode() // DECMC
2369 {
2370 if (Param[1]==-1) Param[1] = 0;
2371 switch (Param[1]) {
2372 case 1:
2373 OpenPrnFile();
2374 BuffDumpCurrentLine(LF);
2375 if (! AutoPrintMode)
2376 ClosePrnFile();
2377 break;
2378 /* auto print mode off */
2379 case 4:
2380 if (AutoPrintMode)
2381 {
2382 ClosePrnFile();
2383 AutoPrintMode = FALSE;
2384 }
2385 break;
2386 /* auto print mode on */
2387 case 5:
2388 if (! AutoPrintMode)
2389 {
2390 OpenPrnFile();
2391 AutoPrintMode = TRUE;
2392 }
2393 break;
2394 }
2395 }
2396
2397 void CSQ_l_Mode() // DECRST
2398 {
2399 int i;
2400
2401 for (i = 1 ; i <= NParam ; i++)
2402 switch (Param[i]) {
2403 case 1: AppliCursorMode = FALSE; break; // DECCKM
2404 case 3: CSQChangeColumnMode(80); break; // DECCOLM
2405 case 5: /* Normal Video (DECSCNM) */
2406 if (ts.ColorFlag & CF_REVERSEVIDEO)
2407 CSQExchangeColor(); /* Exchange text/back color */
2408 break;
2409 case 6: // DECOM
2410 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2411 MoveCursor(0,CursorY);
2412 else {
2413 RelativeOrgMode = FALSE;
2414 MoveCursor(0,0);
2415 }
2416 break;
2417 case 7: AutoWrapMode = FALSE; break; // DECAWM
2418 case 8: AutoRepeatMode = FALSE; break; // DECARM
2419 case 9: MouseReportMode = IdMouseTrackNone; break; /* X10 Mouse Tracking */
2420 case 12: /* att610 cursor blinking */
2421 if (ts.WindowFlag & WF_CURSORCHANGE) {
2422 ts.NonblinkingCursor = TRUE;
2423 ChangeCaret();
2424 }
2425 break;
2426 case 19: PrintEX = FALSE; break; // DECPEX
2427 case 25: DispEnableCaret(FALSE); break; // cursor off (DECTCEM)
2428 case 47: // Alternate Screen Buffer
2429 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2430 BuffRestoreScreen();
2431 AltScr = FALSE;
2432 }
2433 break;
2434 case 59:
2435 if (ts.Language==IdJapanese)
2436 { /* katakana terminal */
2437 Gn[0] = IdASCII;
2438 Gn[1] = IdKatakana;
2439 Gn[2] = IdKatakana;
2440 Gn[3] = IdKanji;
2441 Glr[0] = 0;
2442 if ((ts.KanjiCode==IdJIS) &&
2443 (ts.JIS7Katakana==0))
2444 Glr[1] = 2; // 8-bit katakana
2445 else
2446 Glr[1] = 3;
2447 }
2448 break;
2449 case 66: AppliKeyMode = FALSE; break; // DECNKM
2450 case 67: ts.BSKey = IdDEL; break; // DECBKM
2451 case 1000: // Mouse Tracking
2452 case 1001: // Hilite Mouse Tracking
2453 case 1002: // Button-Event Mouse Tracking
2454 case 1003: // Any-Event Mouse Tracking
2455 MouseReportMode = IdMouseTrackNone;
2456 break;
2457 case 1004: FocusReportMode = FALSE; break; // Focus Report
2458 case 1047: // Alternate Screen Buffer
2459 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2460 BuffClearScreen();
2461 BuffRestoreScreen();
2462 AltScr = FALSE;
2463 }
2464 break;
2465 case 1048: // Save Cursor Position (Alternate Screen Buffer)
2466 if (ts.TermFlag & TF_ALTSCR) {
2467 RestoreCursor();
2468 }
2469 break;
2470 case 1049: // Alternate Screen Buffer
2471 if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2472 BuffClearScreen();
2473 BuffRestoreScreen();
2474 AltScr = FALSE;
2475 RestoreCursor();
2476 }
2477 break;
2478 case 2004: // Bracketed Paste Mode
2479 BracketedPaste = FALSE;
2480 break;
2481 }
2482 }
2483
2484 void CSQ_n_Mode() // DECDSR
2485 {
2486 switch (Param[1]) {
2487 case 53:
2488 case 55:
2489 /* Locator Device Status Report -> Ready */
2490 SendCSIstr("?50n", 0);
2491 break;
2492 }
2493 }
2494
2495 void CSQuest(BYTE b)
2496 {
2497 switch (b) {
2498 case 'J': CSQSelScreenErase(); break; // DECSED
2499 case 'K': CSQSelLineErase(); break; // DECSEL
2500 case 'h': CSQ_h_Mode(); break; // DECSET
2501 case 'i': CSQ_i_Mode(); break; // DECMC
2502 case 'l': CSQ_l_Mode(); break; // DECRST
2503 case 'n': CSQ_n_Mode(); break; // DECDSR
2504 }
2505 }
2506
2507 void SoftReset()
2508 // called by software-reset escape sequence handler
2509 {
2510 UpdateStr();
2511 AutoRepeatMode = TRUE;
2512 DispEnableCaret(TRUE); // cursor on
2513 InsertMode = FALSE;
2514 RelativeOrgMode = FALSE;
2515 AppliKeyMode = FALSE;
2516 AppliCursorMode = FALSE;
2517 if ((StatusLine>0) &&
2518 (CursorY == NumOfLines-1))
2519 MoveToMainScreen();
2520 CursorTop = 0;
2521 CursorBottom = NumOfLines-1-StatusLine;
2522 ResetCharSet();
2523
2524 /* Attribute */
2525 CharAttr = DefCharAttr;
2526 Special = FALSE;
2527 BuffSetCurCharAttr(CharAttr);
2528
2529 // status buffers
2530 ResetCurSBuffer();
2531 }
2532
2533 void CSExc(BYTE b)
2534 {
2535 switch (b) {
2536 case 'p':
2537 /* Software reset */
2538 SoftReset();
2539 break;
2540 }
2541 }
2542
2543 void CSDouble(BYTE b)
2544 {
2545 switch (b) {
2546 case 'p': // DECSCL
2547 /* Select terminal mode (software reset) */
2548 SoftReset();
2549 if (NParam > 0) {
2550 ChangeTerminalID();
2551 if (Param[1] >= 61 && Param[1] <= 65) {
2552 if (VTlevel > Param[1] - 60) {
2553 VTlevel = Param[1] - 60;
2554 }
2555 }
2556 else {
2557 VTlevel = 1;
2558 }
2559
2560 if (VTlevel < 2 || (NParam > 1 && Param[2] == 1))
2561 Send8BitMode = FALSE;
2562 else
2563 Send8BitMode = TRUE;
2564 }
2565 break;
2566
2567 case 'q': // DECSCA
2568 if (Param[1] < 0)
2569 Param[1] = 0;
2570 switch (Param[1]) {
2571 case 0:
2572 case 2:
2573 CharAttr.Attr2 &= ~Attr2Protect;
2574 BuffSetCurCharAttr(CharAttr);
2575 break;
2576 case 1:
2577 CharAttr.Attr2 |= Attr2Protect;
2578 BuffSetCurCharAttr(CharAttr);
2579 break;
2580 default:
2581 /* nothing to do */
2582 break;
2583 }
2584 break;
2585 }
2586 }
2587
2588 void CSDol(BYTE b)
2589 {
2590 switch (b) {
2591 case 'z': // DECERA
2592 case '{': // DECSERA
2593 if (Param[1] < 1 || NParam < 1) Param[1]=1;
2594 if (Param[2] < 1 || NParam < 2) Param[2]=1;
2595 if (Param[3] < 1 || NParam < 3) Param[3]=NumOfLines-StatusLine;
2596 if (Param[4] < 1 || NParam < 4) Param[4]=NumOfColumns;
2597 if (RelativeOrgMode) {
2598 Param[1] += CursorTop;
2599 if (Param[1] > CursorBottom) {
2600 Param[1] = CursorBottom + 1;
2601 }
2602 Param[3] += CursorTop;
2603 if (Param[3] > CursorBottom) {
2604 Param[3] = CursorBottom + 1;
2605 }
2606 }
2607 if (b == 'z') {
2608 BuffEraseBox(Param[2]-1, Param[1]-1, Param[4]-1, Param[3]-1);
2609 }
2610 else {
2611 BuffSelectEraseBox(Param[2]-1, Param[1]-1, Param[4]-1, Param[3]-1);
2612 }
2613 break;
2614
2615 case '}': // DECSASD
2616 if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2617 if (StatusLine==0) return;
2618 if ((Param[1]<1) && (CursorY==NumOfLines-1))
2619 MoveToMainScreen();
2620 else if ((Param[1]==1) && (CursorY<NumOfLines-1))
2621 MoveToStatusLine();
2622 break;
2623 case '~': // DECSSDT
2624 if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2625 if (Param[1]<=1)
2626 HideStatusLine();
2627 else if ((StatusLine==0) && (Param[1]==2))
2628 ShowStatusLine(1); // show
2629 break;
2630 }
2631 }
2632
2633 void CSQuote(BYTE b)
2634 {
2635 int i, x, y;
2636 switch (b) {
2637 case 'w': // Enable Filter Rectangle (DECEFR)
2638 if (MouseReportMode == IdMouseTrackDECELR) {
2639 if (DecLocatorFlag & DecLocatorPixel) {
2640 x = LastX + 1;
2641 y = LastY + 1;
2642 }
2643 else {
2644 DispConvWinToScreen(LastX, LastY, &x, &y, NULL);
2645 x++;
2646 y++;
2647 }
2648 FilterTop = (NParam<1 || Param[1]<1)? y : Param[1];
2649 FilterLeft = (NParam<2 || Param[2]<1)? x : Param[2];
2650 FilterBottom = (NParam<3 || Param[3]<1)? y : Param[3];
2651 FilterRight = (NParam<4 || Param[4]<1)? x : Param[4];
2652 if (FilterTop > FilterBottom) {
2653 i = FilterTop; FilterTop = FilterBottom; FilterBottom = i;
2654 }
2655 if (FilterLeft > FilterRight) {
2656 i = FilterLeft; FilterLeft = FilterRight; FilterRight = i;
2657 }
2658 DecLocatorFlag |= DecLocatorFiltered;
2659 DecLocatorReport(IdMouseEventMove, 0);
2660 }
2661 break;
2662
2663 case 'z': // Enable DEC Locator reporting (DECELR)
2664 if (Param[1] < 0) {
2665 Param[1] = 0;
2666 }
2667 switch (Param[1]) {
2668 case 0:
2669 if (MouseReportMode == IdMouseTrackDECELR) {
2670 MouseReportMode = IdMouseTrackNone;
2671 }
2672 break;
2673 case 1:
2674 if (ts.MouseEventTracking) {
2675 MouseReportMode = IdMouseTrackDECELR;
2676 DecLocatorFlag &= ~DecLocatorOneShot;
2677 }
2678 break;
2679 case 2:
2680 if (ts.MouseEventTracking) {
2681 MouseReportMode = IdMouseTrackDECELR;
2682 DecLocatorFlag |= DecLocatorOneShot;
2683 }
2684 break;
2685 }
2686 if (NParam > 1 && Param[2] == 1) {
2687 DecLocatorFlag |= DecLocatorPixel;
2688 }
2689 else {
2690 DecLocatorFlag &= ~DecLocatorPixel;
2691 }
2692 break;
2693
2694 case '{': // Select Locator Events (DECSLE)
2695 for (i=1; i<=NParam; i++) {
2696 if (Param[i] < 0) {
2697 Param[i] = 0;
2698 }
2699 switch (Param[i]) {
2700 case 0:
2701 DecLocatorFlag &= ~(DecLocatorButtonUp | DecLocatorButtonDown | DecLocatorFiltered);
2702 break;
2703 case 1:
2704 DecLocatorFlag |= DecLocatorButtonDown;
2705 break;
2706 case 2:
2707 DecLocatorFlag &= ~DecLocatorButtonDown;
2708 break;
2709 case 3:
2710 DecLocatorFlag |= DecLocatorButtonUp;
2711 break;
2712 case 4:
2713 DecLocatorFlag &= ~DecLocatorButtonUp;
2714 break;
2715 }
2716 }
2717 break;
2718
2719 case '|': // Request Locator Position (DECRQLP)
2720 DecLocatorReport(IdMouseEventCurStat, 0);
2721 break;
2722 }
2723 }
2724
2725 void CSSpace(BYTE b) {
2726 switch (b) {
2727 case 'q':
2728 if (ts.WindowFlag & WF_CURSORCHANGE) {
2729 if (NParam > 0) {
2730 if (Param[1] < 0) Param[1] = 0;
2731 switch (Param[1]) {
2732 case 0:
2733 case 1:
2734 ts.CursorShape = IdBlkCur;
2735 ts.NonblinkingCursor = FALSE;
2736 break;
2737 case 2:
2738 ts.CursorShape = IdBlkCur;
2739 ts.NonblinkingCursor = TRUE;
2740 break;
2741 case 3:
2742 ts.CursorShape = IdHCur;
2743 ts.NonblinkingCursor = FALSE;
2744 break;
2745 case 4:
2746 ts.CursorShape = IdHCur;
2747 ts.NonblinkingCursor = TRUE;
2748 break;
2749 case 5:
2750 ts.CursorShape = IdVCur;
2751 ts.NonblinkingCursor = FALSE;
2752 break;
2753 case 6:
2754 ts.CursorShape = IdVCur;
2755 ts.NonblinkingCursor = TRUE;
2756 break;
2757 default:
2758 return;
2759 }
2760 ChangeCaret();
2761 }
2762 }
2763 break;
2764 }
2765 }
2766
2767 void PrnParseCS(BYTE b) // printer mode
2768 {
2769 ParseMode = ModeFirst;
2770 switch (ICount) {
2771 /* no intermediate char */
2772 case 0:
2773 switch (Prv) {
2774 /* no private parameter */
2775 case 0:
2776 switch (b) {
2777 case 'i':
2778 if (Param[1]==4)
2779 {
2780 PrinterMode = FALSE;
2781 // clear prn buff
2782 WriteToPrnFile(0,FALSE);
2783 if (! AutoPrintMode)
2784 ClosePrnFile();
2785 return;
2786 }
2787 break;
2788 } /* of case Prv=0 */
2789 break;
2790 }
2791 break;
2792 /* one intermediate char */
2793 case 1: break;
2794 } /* of case Icount */
2795
2796 WriteToPrnFile(b,TRUE);
2797 }
2798
2799 void ParseCS(BYTE b) /* b is the final char */
2800 {
2801 if (PrinterMode) { // printer mode
2802 PrnParseCS(b);
2803 return;
2804 }
2805
2806 switch (ICount) {
2807 /* no intermediate char */
2808 case 0:
2809 switch (Prv) {
2810 /* no private parameter */
2811 case 0:
2812 switch (b) {
2813 // ISO/IEC 6429 / ECMA-48 Sequence
2814 case '@': CSInsertCharacter(); break; // ICH
2815 case 'A': CSCursorUp(); break; // CUU
2816 case 'B': CSCursorDown(); break; // CUD
2817 case 'C': CSCursorRight(); break; // CUF
2818 case 'D': CSCursorLeft(); break; // CUB
2819 case 'E': CSCursorDown1(); break; // CNL
2820 case 'F': CSCursorUp1(); break; // CPL
2821 case 'G': CSMoveToColumnN(); break; // CHA
2822 case 'H': CSMoveToXY(); break; // CUP
2823 case 'I': CSForwardTab(); break; // CHT
2824 case 'J': CSScreenErase(); break; // ED
2825 case 'K': CSLineErase(); break; // EL
2826 case 'L': CSInsertLine(); break; // IL
2827 case 'M': CSDeleteNLines(); break; // DL
2828 // case 'N': break; // EF -- Not support
2829 // case 'O': break; // EA -- Not support
2830 case 'P': CSDeleteCharacter(); break; // DCH
2831 // case 'Q': break; // SEE -- Not support
2832 // case 'R': break; // CPR -- Not support
2833 case 'S': CSScrollUP(); break; // SU
2834 case 'T': CSScrollDown(); break; // SD
2835 // case 'U': break; // NP -- Not support
2836 // case 'V': break; // PP -- Not support
2837 // case 'W': break; // CTC -- Not support
2838 case 'X': CSEraseCharacter(); break; // ECH
2839 // case 'Y': break; // CVT -- Not support
2840 case 'Z': CSBackwardTab(); break; // CBT
2841 // case '[': break; // SRS -- Not support
2842 // case '\\': break; // PTX -- Not support
2843 // case ']': break; // SDS -- Not support
2844 // case '^': break; // SIMD -- Not support
2845 case '`': CSMoveToColumnN(); break; // HPA
2846 case 'a': CSCursorRight(); break; // HPR
2847 // case 'b': break; // REP -- Not support
2848 case 'c': AnswerTerminalType(); break; // DA
2849 case 'd': CSMoveToLineN(); break; // VPA
2850 case 'e': CSCursorDown(); break; // VPR
2851 case 'f': CSMoveToXY(); break; // HVP
2852 case 'g': CSDeleteTabStop(); break; // TBC
2853 case 'h': CS_h_Mode(); break; // SM
2854 case 'i': CS_i_Mode(); break; // MC
2855 case 'j': CSCursorLeft(); break; // HPB
2856 case 'k': CSCursorUp(); // VPB
2857 case 'l': CS_l_Mode(); break; // RM
2858 case 'm': CSSetAttr(); break; // SGR
2859 case 'n': CS_n_Mode(); break; // DSR
2860 // case 'o': break; // DAQ -- Not support
2861
2862 // Private Sequence
2863 case 'r': CSSetScrollRegion(); break; // DECSTBM
2864 case 's': SaveCursor(); break; // SCP (Save cursor (ANSI.SYS/SCO?))
2865 case 't': CSSunSequence(); break; // DECSLPP / Window manipulation(dtterm?)
2866 case 'u': RestoreCursor(); break; // RCP (Restore cursor (ANSI.SYS/SCO))
2867 } /* of case Prv=0 */
2868 break;
2869 /* private parameter = '=' */
2870 case '=': CSEQ(b); break;
2871 /* private parameter = '>' */
2872 case '>': CSGT(b); break;
2873 /* private parameter = '?' */
2874 case '?': CSQuest(b); break;
2875 } /* end of siwtch (Prv) */
2876 break;
2877 /* one intermediate char */
2878 case 1:
2879 switch (IntChar[1]) {
2880 /* intermediate char = ' ' */
2881 case ' ': CSSpace(b); break;
2882 /* intermediate char = '!' */
2883 case '!': CSExc(b); break;
2884 /* intermediate char = '"' */
2885 case '"': CSDouble(b); break;
2886 /* intermediate char = '$' */
2887 case '$': CSDol(b); break;
2888 /* intermediate char = '\'' */
2889 case '\'': CSQuote(b); break;
2890 }
2891 break;
2892 } /* of case Icount */
2893
2894 ParseMode = ModeFirst;
2895 }
2896
2897 void ControlSequence(BYTE b)
2898 {
2899 if ((b<=US) || (b>=0x80) && (b<=0x9F))
2900 ParseControl(b); /* ctrl char */
2901 else if ((b>=0x40) && (b<=0x7E))
2902 ParseCS(b); /* terminate char */
2903 else {
2904 if (PrinterMode)
2905 WriteToPrnFile(b,FALSE);
2906
2907 if ((b>=0x20) && (b<=0x2F))
2908 { /* intermediate char */
2909 if (ICount<IntCharMax) ICount++;
2910 IntChar[ICount] = b;
2911 }
2912 else if ((b>=0x30) && (b<=0x39))
2913 {
2914 if (Param[NParam] < 0)
2915 Param[NParam] = 0;
2916 if (Param[NParam]<1000)
2917 Param[NParam] = Param[NParam]*10 + b - 0x30;
2918 }
2919 else if (b==0x3B)
2920 {
2921 if (NParam < NParamMax)
2922 {
2923 NParam++;
2924 Param[NParam] = -1;
2925 }
2926 }
2927 else if ((b>=0x3C) && (b<=0x3F))
2928 { /* private char */
2929 if (FirstPrm) Prv = b;
2930 }
2931 }
2932 FirstPrm = FALSE;
2933 }
2934
2935 void RequestStatusString(unsigned char *StrBuff, int StrLen) {
2936 unsigned char RepStr[256];
2937 int len = 0;
2938
2939 switch (StrBuff[0]) {
2940 case '"':
2941 switch (StrBuff[1]) {
2942 case 'p': // DECSCL
2943 if (VTlevel > 1 && Send8BitMode) {
2944 len = _snprintf_s_l(RepStr, sizeof(RepStr), _TRUNCATE, "0$r6%d;0\"p", CLocale, VTlevel);
2945 }
2946 else {
2947 len = _snprintf_s_l(RepStr, sizeof(RepStr), _TRUNCATE, "0$r6%d;1\"p", CLocale, VTlevel);
2948 }
2949 break;
2950
2951 case 'q': // DECSCA
2952 if (CharAttr.Attr2 & Attr2Protect) {
2953 len = _snprintf_s_l(RepStr, sizeof(RepStr), _TRUNCATE, "0$r1\"q", CLocale);
2954 }
2955 else {
2956 len = _snprintf_s_l(RepStr, sizeof(RepStr), _TRUNCATE, "0$r0\"q", CLocale);
2957 }
2958 break;
2959 }
2960 break;
2961 case 'm': // SGR
2962 if (StrBuff[1] == 0) {
2963 RepStr[0] = '0';
2964 RepStr[1] = '$';
2965 RepStr[2] = 'r';
2966 len = 3;
2967 if (CharAttr.Attr & AttrBold) {
2968 RepStr[len++] = '1';
2969 RepStr[len++] = ';';
2970 }
2971 if (CharAttr.Attr & AttrUnder) {
2972 RepStr[len++] = '4';
2973 RepStr[len++] = ';';
2974 }
2975 if (CharAttr.Attr & AttrBlink) {
2976 RepStr[len++] = '5';
2977 RepStr[len++] = ';';
2978 }
2979 if (CharAttr.Attr & AttrReverse) {
2980 RepStr[len++] = '7';
2981 RepStr[len++] = ';';
2982 }
2983 if (len == 3) {
2984 RepStr[len++] = '0';
2985 }
2986 else {
2987 len--;
2988 }
2989 RepStr[len++] = 'm';
2990 RepStr[len] = 0;
2991 }
2992 break;
2993 case 'r': // DECSTBM
2994 if (StrBuff[1] == 0) {
2995 len = _snprintf_s_l(RepStr, sizeof(RepStr), _TRUNCATE, "0$r%d;%dr", CLocale, CursorTop+1, CursorBottom+1);
2996 }
2997 break;
2998 }
2999 if (len > 0) {
3000 SendDCSstr(RepStr, len);
3001 }
3002 else {
3003 SendDCSstr("1$r", 0);
3004 }
3005 }
3006
3007 void ParseDCS(BYTE Cmd, unsigned char *StrBuff, int len) {
3008 switch (ICount) {
3009 case 0:
3010 break;
3011 case 1:
3012 switch (IntChar[1]) {
3013 case '!':
3014 if (Cmd == '{') { // DECSTUI
3015 if (! (ts.TermFlag & TF_LOCKTUID)) {
3016 int i;
3017 for (i=0; i<8 && isxdigit(StrBuff[i]); i++) {
3018 if (islower(StrBuff[i])) {
3019 StrBuff[i] = toupper(StrBuff[i]);
3020 }
3021 }
3022 if (len == 8 && i == 8) {
3023 strncpy_s(ts.TerminalUID, sizeof(ts.TerminalUID), StrBuff, _TRUNCATE);
3024 }
3025 }
3026 }
3027 break;
3028 case '$':
3029 if (Cmd == 'q') { // DECRQSS
3030 RequestStatusString(StrBuff, len);
3031 }
3032 break;
3033 default:
3034 break;
3035 }
3036 break;
3037 default:
3038 break;
3039 }
3040 }
3041
3042 #define ModeDcsFirst 1
3043 #define ModeDcsString 2
3044 void DeviceControl(BYTE b)
3045 {
3046 static unsigned char StrBuff[256];
3047 static int DcsParseMode = ModeDcsFirst;
3048 static int StrLen;
3049 static BYTE Cmd;
3050
3051 if ((ESCFlag && (b=='\\')) || (b==ST && ts.KanjiCode!=IdSJIS)) {
3052 if (DcsParseMode == ModeDcsString) {
3053 StrBuff[StrLen] = 0;
3054 ParseDCS(Cmd, StrBuff, StrLen);
3055 }
3056 ESCFlag = FALSE;
3057 ParseMode = SavedMode;
3058 DcsParseMode = ModeDcsFirst;
3059 StrLen = 0;
3060 return;
3061 }
3062
3063 if (b==ESC) {
3064 ESCFlag = TRUE;
3065 return;
3066 }
3067 else {
3068 ESCFlag = FALSE;
3069 }
3070
3071 switch (DcsParseMode) {
3072 case ModeDcsFirst:
3073 if (b<=US) {
3074 ParseControl(b);
3075 }
3076 else if ((b>=0x20) && (b<=0x2F)) {
3077 if (ICount<IntCharMax) ICount++;
3078 IntChar[ICount] = b;
3079 }
3080 else if ((b>=0x30) && (b<=0x39)) {
3081 if (Param[NParam] < 0) Param[NParam] = 0;
3082 if (Param[NParam]<1000)
3083 Param[NParam] = Param[NParam]*10 + b - 0x30;
3084 }
3085 else if (b==0x3B) {
3086 if (NParam < NParamMax) {
3087 NParam++;
3088 Param[NParam] = -1;
3089 }
3090 }
3091 else if ((b>=0x40) && (b<=0x7E)) {
3092 if (ICount == 0 && b=='|') {
3093 ParseMode = ModeDCUserKey;
3094 if (Param[1] < 1) ClearUserKey();
3095 WaitKeyId = TRUE;
3096 NewKeyId = 0;
3097 }
3098 else {
3099 Cmd = b;
3100 DcsParseMode = ModeDcsString;
3101 }
3102 }
3103 else {
3104 ParseMode = ModeSOS;
3105 }
3106 break;
3107
3108 case ModeDcsString:
3109 if (b <= US && b != HT && b != CR) {
3110 ESCFlag = FALSE;
3111 ParseMode = SavedMode;
3112 DcsParseMode = ModeDcsFirst;
3113 StrLen = 0;
3114 }
3115 else if (StrLen < sizeof(StrBuff)-1) {
3116 StrBuff[StrLen++] = b;
3117 }
3118 break;
3119 }
3120 }
3121
3122 void DCUserKey(BYTE b)
3123 {
3124 if (ESCFlag && (b=='\\') || (b==ST && ts.KanjiCode!=IdSJIS))
3125 {
3126 if (! WaitKeyId) DefineUserKey(NewKeyId,NewKeyStr,NewKeyLen);
3127 ESCFlag = FALSE;
3128 ParseMode = SavedMode;
3129 return;
3130 }
3131
3132 if (b==ESC)
3133 {
3134 ESCFlag = TRUE;
3135 return;
3136 }
3137 else ESCFlag = FALSE;
3138
3139 if (WaitKeyId)
3140 {
3141 if ((b>=0x30) && (b<=0x39))
3142 {
3143 if (NewKeyId<1000)
3144 NewKeyId = NewKeyId*10 + b - 0x30;
3145 }
3146 else if (b==0x2F)
3147 {
3148 WaitKeyId = FALSE;
3149 WaitHi = TRUE;
3150 NewKeyLen = 0;
3151 }
3152 }
3153 else {
3154 if (b==0x3B)
3155 {
3156 DefineUserKey(NewKeyId,NewKeyStr,NewKeyLen);
3157 WaitKeyId = TRUE;
3158 NewKeyId = 0;
3159 }
3160 else {
3161 if (NewKeyLen < FuncKeyStrMax)
3162 {
3163 if (WaitHi)
3164 {
3165 NewKeyStr[NewKeyLen] = ConvHexChar(b) << 4;
3166 WaitHi = FALSE;
3167 }
3168 else {
3169 NewKeyStr[NewKeyLen] = NewKeyStr[NewKeyLen] +
3170 ConvHexChar(b);
3171 WaitHi = TRUE;
3172 NewKeyLen++;
3173 }
3174 }
3175 }
3176 }
3177 }
3178
3179 void IgnoreString(BYTE b)
3180 {
3181 if ((ESCFlag && (b=='\\')) ||
3182 (b<=US && b!=ESC && b!=HT) ||
3183 (b==ST && ts.KanjiCode!=IdSJIS))
3184 ParseMode = SavedMode;
3185
3186 if (b==ESC) ESCFlag = TRUE;
3187 else ESCFlag = FALSE;
3188 }
3189
3190 BOOL XsParseColor(char *colspec, COLORREF *color)
3191 {
3192 unsigned int r, g, b;
3193 // double dr, dg, db;
3194
3195 r = g = b = 255;
3196
3197 if (colspec == NULL || color == NULL) {
3198 return FALSE;
3199 }
3200
3201 if (_strnicmp(colspec, "rgb:", 4) == 0) {
3202 switch (strlen(colspec)) {
3203 case 9: // rgb:R/G/B
3204 if (sscanf(colspec, "rgb:%1x/%1x/%1x", &r, &g, &b) != 3) {
3205 return FALSE;
3206 }
3207 r *= 17; g *= 17; b *= 17;
3208 break;
3209 case 12: // rgb:RR/GG/BB
3210 if (sscanf(colspec, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3) {
3211 return FALSE;
3212 }
3213 break;
3214 case 15: // rgb:RRR/GGG/BBB
3215 if (sscanf(colspec, "rgb:%3x/%3x/%3x", &r, &g, &b) != 3) {
3216 return FALSE;
3217 }
3218 r >>= 4; g >>= 4; b >>= 4;
3219 break;
3220 case 18: // rgb:RRRR/GGGG/BBBB
3221 if (sscanf(colspec, "rgb:%4x/%4x/%4x", &r, &g, &b) != 3) {
3222 return FALSE;
3223 }
3224 r >>= 8; g >>= 8; b >>= 8;
3225 break;
3226 default:
3227 return FALSE;
3228 }
3229 }
3230 // else if (_strnicmp(colspec, "rgbi:", 5) == 0) {
3231 // ; /* nothing to do */
3232 // }
3233 else if (colspec[0] == '#') {
3234 switch (strlen(colspec)) {
3235 case 4: // #RGB
3236 if (sscanf(colspec, "#%1x%1x%1x", &r, &g, &b) != 3) {
3237 return FALSE;
3238 }
3239 r <<= 4; g <<= 4; b <<= 4;
3240 break;
3241 case 7: // #RRGGBB
3242 if (sscanf(colspec, "#%2x%2x%2x", &r, &g, &b) != 3) {
3243 return FALSE;
3244 }
3245 break;
3246 case 10: // #RRRGGGBBB
3247 if (sscanf(colspec, "#%3x%3x%3x", &r, &g, &b) != 3) {
3248 return FALSE;
3249 }
3250 r >>= 4; g >>= 4; b >>= 4;
3251 break;
3252 case 13: // #RRRRGGGGBBBB
3253 if (sscanf(colspec, "#%4x%4x%4x", &r, &g, &b) != 3) {
3254 return FALSE;
3255 }
3256 r >>= 8; g >>= 8; b >>= 8;
3257 break;
3258 default:
3259 return FALSE;
3260 }
3261 }
3262 else {
3263 return FALSE;
3264 }
3265
3266 if (r > 255 || g > 255 || b > 255) {
3267 return FALSE;
3268 }
3269
3270 *color = RGB(r, g, b);
3271 return TRUE;
3272 }
3273
3274 #define ModeXsFirst 1
3275 #define ModeXsString 2
3276 #define ModeXsColorNum 3
3277 #define ModeXsColorSpec 4
3278 #define ModeXsEsc 5
3279 void XSequence(BYTE b)
3280 {
3281 static BYTE XsParseMode = ModeXsFirst, PrevMode;
3282 static char StrBuff[sizeof(ts.Title)];
3283 static unsigned int ColorNumber, StrLen;
3284 int len;
3285 COLORREF color;
3286
3287 switch (XsParseMode) {
3288 case ModeXsFirst:
3289 if (isdigit(b)) {
3290 if (Param[1] < 1000) {
3291 Param[1] = Param[1]*10 + b - '0';
3292 }
3293 }
3294 else if (b == ';') {
3295 StrBuff[0] = '\0';
3296 StrLen = 0;
3297 if (Param[1] == 4) {
3298 ColorNumber = 0;
3299 XsParseMode = ModeXsColorNum;
3300 }
3301 else {
3302 XsParseMode = ModeXsString;
3303 }
3304 }
3305 else {
3306 ParseMode = ModeFirst;
3307 }
3308 break;
3309 case ModeXsString:
3310 if ((b==ST && Accept8BitCtrl && !(ts.Language==IdJapanese && ts.KanjiCode==IdSJIS)) || b==BEL) { /* String Terminator */
3311 StrBuff[StrLen] = '\0';
3312 switch (Param[1]) {
3313 case 0: /* Change window title and icon name */
3314 case 1: /* Change icon name */
3315 case 2: /* Change window title */
3316 if (ts.AcceptTitleChangeRequest) {
3317 strncpy_s(cv.TitleRemote, sizeof(cv.TitleRemote), StrBuff, _TRUNCATE);
3318 // (2006.6.15 maya) �^�C�g�����n����������SJIS������
3319 ConvertToCP932(cv.TitleRemote, sizeof(cv.TitleRemote));
3320 ChangeTitle();
3321 }
3322 break;
3323 default:
3324 /* nothing to do */;
3325 }
3326 ParseMode = ModeFirst;
3327 XsParseMode = ModeXsFirst;