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 2562 - (show annotations) (download) (as text)
Mon Jul 14 08:19:02 2008 UTC (15 years, 9 months ago) by doda
Original Path: teraterm/trunk/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 69858 byte(s)
Reverse Video時、Bold/Blink/URL属性の前景色と背景色も入れ換えるようにした。

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

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26