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 3800 - (show annotations) (download) (as text)
Thu Feb 25 10:19:51 2010 UTC (14 years, 1 month ago) by doda
File MIME type: text/x-csrc
File size: 85796 byte(s)
Alternate screen buffer 対応のカーソル保存 (<CSI>?1048h) が正しく働かないのを修正。

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