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 3916 - (show annotations) (download) (as text)
Wed May 26 07:13:46 2010 UTC (13 years, 10 months ago) by doda
File MIME type: text/x-csrc
File size: 86614 byte(s)
Alternate Screen Buffer 使用時、カーソル位置の復元が正しく動かない場合が有ったのを修正。

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