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 2640 - (show annotations) (download) (as text)
Sun Jan 25 14:44:37 2009 UTC (15 years, 2 months ago) by doda
Original Path: teraterm/trunk/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 70128 byte(s)
反転属性の色を指定出来るようにした。

1 /* Tera Term
2 Copyright(C) 1994-1998 T. Teranishi
3 All rights reserved. */
4
5 /* TERATERM.EXE, VT terminal emulation */
6 #include "teraterm.h"
7 #include "tttypes.h"
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <mbstring.h>
12 #include <locale.h>
13
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 'A': Gn[Dist] = IdASCII; break;
985 case 'B': Gn[Dist] = IdASCII; break;
986 case 'H': Gn[Dist] = IdASCII; break;
987 case 'I':
988 if (ts.Language==IdJapanese)
989 Gn[Dist] = IdKatakana;
990 break;
991 case 'J': Gn[Dist] = IdASCII; break;
992 }
993
994 if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
995 (Dist==0))
996 Glr[0] = 0; /* G0->GL */
997 }
998
999 void PrnParseEscape(BYTE b) // printer mode
1000 {
1001 int i;
1002
1003 ParseMode = ModeFirst;
1004 switch (ICount) {
1005 /* no intermediate char */
1006 case 0:
1007 switch (b) {
1008 case '[': /* CSI */
1009 ICount = 0;
1010 FirstPrm = TRUE;
1011 NParam = 1;
1012 Param[1] = -1;
1013 Prv = 0;
1014 WriteToPrnFile(ESC,FALSE);
1015 WriteToPrnFile('[',FALSE);
1016 ParseMode = ModeCSI;
1017 return;
1018 } /* end of case Icount=0 */
1019 break;
1020 /* one intermediate char */
1021 case 1:
1022 switch (IntChar[1]) {
1023 case '$':
1024 if (! DirectPrn)
1025 {
1026 ESCDBCSSelect(b);
1027 return;
1028 }
1029 break;
1030 case '(':
1031 case ')':
1032 case '*':
1033 case '+':
1034 if (! DirectPrn)
1035 {
1036 ESCSBCSSelect(b);
1037 return;
1038 }
1039 break;
1040 }
1041 break;
1042 /* two intermediate char */
1043 case 2:
1044 if ((! DirectPrn) &&
1045 (IntChar[1]=='$') &&
1046 ('('<=IntChar[2]) &&
1047 (IntChar[2]<='+'))
1048 {
1049 ESCDBCSSelect(b);
1050 return;
1051 }
1052 break;
1053 }
1054 // send the uninterpreted sequence to printer
1055 WriteToPrnFile(ESC,FALSE);
1056 for (i=1; i<=ICount; i++)
1057 WriteToPrnFile(IntChar[i],FALSE);
1058 WriteToPrnFile(b,TRUE);
1059 }
1060
1061 void ParseEscape(BYTE b) /* b is the final char */
1062 {
1063 if (PrinterMode) { // printer mode
1064 PrnParseEscape(b);
1065 return;
1066 }
1067
1068 switch (ICount) {
1069 /* no intermediate char */
1070 case 0:
1071 switch (b) {
1072 case '7': SaveCursor(); break;
1073 case '8': RestoreCursor(); break;
1074 case '=': AppliKeyMode = TRUE; break;
1075 case '>': AppliKeyMode = FALSE; break;
1076 case 'D': /* IND */
1077 LineFeed(0,TRUE);
1078 break;
1079 case 'E': /* NEL */
1080 MoveCursor(0,CursorY);
1081 LineFeed(0,TRUE);
1082 break;
1083 case 'H': /* HTS */
1084 SetTabStop();
1085 break;
1086 case 'M': /* RI */
1087 CursorUpWithScroll();
1088 break;
1089 case 'N': /* SS2 */
1090 GLtmp = 2;
1091 SSflag = TRUE;
1092 break;
1093 case 'O': /* SS3 */
1094 GLtmp = 3;
1095 SSflag = TRUE;
1096 break;
1097 case 'P': /* DCS */
1098 SavedMode = ParseMode;
1099 ESCFlag = FALSE;
1100 NParam = 1;
1101 Param[1] = -1;
1102 ParseMode = ModeDCS;
1103 return;
1104 case 'X': /* SOS */
1105 SavedMode = ParseMode;
1106 ESCFlag = FALSE;
1107 ParseMode = ModeSOS;
1108 return;
1109 case 'Z': AnswerTerminalType(); break;
1110 case '[': /* CSI */
1111 ICount = 0;
1112 FirstPrm = TRUE;
1113 NParam = 1;
1114 Param[1] = -1;
1115 Prv = 0;
1116 ParseMode = ModeCSI;
1117 return;
1118 case '\\': break; /* ST */
1119 case ']': /* XTERM sequence (OSC) */
1120 NParam = 1;
1121 Param[1] = 0;
1122 ParseMode = ModeXS;
1123 return;
1124 case '^':
1125 case '_': /* PM, APC */
1126 SavedMode = ParseMode;
1127 ESCFlag = FALSE;
1128 ParseMode = ModeSOS;
1129 return;
1130 case 'c': /* Hardware reset */
1131 HideStatusLine();
1132 ResetTerminal();
1133 ClearUserKey();
1134 ClearBuffer();
1135 if (ts.PortType==IdSerial) // reset serial port
1136 CommResetSerial(&ts, &cv, TRUE);
1137 break;
1138 case 'g': /* Visual Bell (screen original?) */
1139 VisualBell();
1140 break;
1141 case 'n': Glr[0] = 2; break; /* LS2 */
1142 case 'o': Glr[0] = 3; break; /* LS3 */
1143 case '|': Glr[1] = 3; break; /* LS3R */
1144 case '}': Glr[1] = 2; break; /* LS2R */
1145 case '~': Glr[1] = 1; break; /* LS1R */
1146 } /* end of case Icount=0 */
1147 break;
1148 /* one intermediate char */
1149 case 1:
1150 switch (IntChar[1]) {
1151 case ' ': ESCSpace(b); break;
1152 case '#': ESCSharp(b); break;
1153 case '$': ESCDBCSSelect(b); break;
1154 case '%': break;
1155 case '(':
1156 case ')':
1157 case '*':
1158 case '+':
1159 ESCSBCSSelect(b);
1160 break;
1161 }
1162 break;
1163 /* two intermediate char */
1164 case 2:
1165 if ((IntChar[1]=='$') &&
1166 ('('<=IntChar[2]) &&
1167 (IntChar[2]<='+'))
1168 ESCDBCSSelect(b);
1169 else if ((IntChar[1]=='%') &&
1170 (IntChar[2]=='!'))
1171 ESCSelectCode(b);
1172 break;
1173 }
1174 ParseMode = ModeFirst;
1175 }
1176
1177 void EscapeSequence(BYTE b)
1178 {
1179 if (b<=US)
1180 ParseControl(b);
1181 else if ((b>=0x20) && (b<=0x2F))
1182 {
1183 if (ICount<IntCharMax) ICount++;
1184 IntChar[ICount] = b;
1185 }
1186 else if ((b>=0x30) && (b<=0x7E))
1187 ParseEscape(b);
1188 else if ((b>=0x80) && (b<=0x9F))
1189 ParseControl(b);
1190
1191 JustAfterESC = FALSE;
1192 }
1193
1194 void CSInsertCharacter()
1195 {
1196 // Insert space characters at cursor
1197 int Count;
1198
1199 BuffUpdateScroll();
1200 if (Param[1]<1) Param[1] = 1;
1201 Count = Param[1];
1202 BuffInsertSpace(Count);
1203 }
1204
1205 void CSCursorUp()
1206 {
1207 if (Param[1]<1) Param[1] = 1;
1208
1209 if (CursorY >= CursorTop)
1210 {
1211 if (CursorY-Param[1] > CursorTop)
1212 MoveCursor(CursorX,CursorY-Param[1]);
1213 else
1214 MoveCursor(CursorX,CursorTop);
1215 }
1216 else {
1217 if (CursorY > 0)
1218 MoveCursor(CursorX,CursorY-Param[1]);
1219 else
1220 MoveCursor(CursorX,0);
1221 }
1222 }
1223
1224 void CSCursorUp1()
1225 {
1226 MoveCursor(0,CursorY);
1227 CSCursorUp();
1228 }
1229
1230 void CSCursorDown()
1231 {
1232 if (Param[1]<1) Param[1] = 1;
1233
1234 if (CursorY <= CursorBottom)
1235 {
1236 if (CursorY+Param[1] < CursorBottom)
1237 MoveCursor(CursorX,CursorY+Param[1]);
1238 else
1239 MoveCursor(CursorX,CursorBottom);
1240 }
1241 else {
1242 if (CursorY < NumOfLines-StatusLine-1)
1243 MoveCursor(CursorX,CursorY+Param[1]);
1244 else
1245 MoveCursor(CursorX,NumOfLines-StatusLine);
1246 }
1247 }
1248
1249 void CSCursorDown1()
1250 {
1251 MoveCursor(0,CursorY);
1252 CSCursorDown();
1253 }
1254
1255 void CSScreenErase()
1256 {
1257 if (Param[1] == -1) Param[1] = 0;
1258 BuffUpdateScroll();
1259 switch (Param[1]) {
1260 case 0:
1261 // <ESC>[H(Cursor in left upper corner)�������J�[�\�������������w�������������A
1262 // <ESC>[J��<ESC>[2J�����������������A�����������A���s�o�b�t�@���X�N���[���A�E�g
1263 // �����������������B(2005.5.29 yutaka)
1264 // �R���t�B�O���[�V�������������������������������B(2008.5.3 yutaka)
1265 if (ts.ScrollWindowClearScreen &&
1266 (CursorX == 0 && CursorY == 0)) {
1267 // Erase screen (scroll out)
1268 BuffClearScreen();
1269 UpdateWindow(HVTWin);
1270
1271 } else {
1272 // Erase characters from cursor to the end of screen
1273 BuffEraseCurToEnd();
1274 }
1275 break;
1276
1277 case 1:
1278 // Erase characters from home to cursor
1279 BuffEraseHomeToCur();
1280 break;
1281
1282 case 2:
1283 // Erase screen (scroll out)
1284 BuffClearScreen();
1285 UpdateWindow(HVTWin);
1286 break;
1287 }
1288 }
1289
1290 void CSInsertLine()
1291 {
1292 // Insert lines at current position
1293 int Count, YEnd;
1294
1295 if (CursorY < CursorTop) return;
1296 if (CursorY > CursorBottom) return;
1297 if (Param[1]<1) Param[1] = 1;
1298 Count = Param[1];
1299
1300 YEnd = CursorBottom;
1301 if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1302 if (Count > YEnd+1 - CursorY) Count = YEnd+1 - CursorY;
1303
1304 BuffInsertLines(Count,YEnd);
1305 }
1306
1307 void CSLineErase()
1308 {
1309 if (Param[1] == -1) Param[1] = 0;
1310 BuffUpdateScroll();
1311 switch (Param[1]) {
1312 /* erase char from cursor to end of line */
1313 case 0:
1314 BuffEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1315 break;
1316 /* erase char from start of line to cursor */
1317 case 1:
1318 BuffEraseCharsInLine(0,CursorX+1);
1319 break;
1320 /* erase entire line */
1321 case 2:
1322 BuffEraseCharsInLine(0,NumOfColumns);
1323 break;
1324 }
1325 }
1326
1327 void CSDeleteNLines()
1328 // Delete lines from current line
1329 {
1330 int Count, YEnd;
1331
1332 if (CursorY < CursorTop) return;
1333 if (CursorY > CursorBottom) return;
1334 Count = Param[1];
1335 if (Count<1) Count = 1;
1336
1337 YEnd = CursorBottom;
1338 if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1339 if (Count > YEnd+1-CursorY) Count = YEnd+1-CursorY;
1340 BuffDeleteLines(Count,YEnd);
1341 }
1342
1343 void CSDeleteCharacter()
1344 {
1345 // Delete characters in current line from cursor
1346
1347 if (Param[1]<1) Param[1] = 1;
1348 BuffUpdateScroll();
1349 BuffDeleteChars(Param[1]);
1350 }
1351
1352 void CSEraseCharacter()
1353 {
1354 if (Param[1]<1) Param[1] = 1;
1355 BuffUpdateScroll();
1356 BuffEraseChars(Param[1]);
1357 }
1358
1359 void CSScrollUP()
1360 {
1361 if (Param[1]<1) Param[1] = 1;
1362 BuffUpdateScroll();
1363 BuffRegionScrollUpNLines(Param[1]);
1364 }
1365
1366 void CSScrollDown()
1367 {
1368 if (Param[1]<1) Param[1] = 1;
1369 BuffUpdateScroll();
1370 BuffRegionScrollDownNLines(Param[1]);
1371 }
1372
1373 void CSForwardTab()
1374 {
1375 if (Param[1]<1) Param[1] = 1;
1376 CursorForwardTab(Param[1], AutoWrapMode);
1377 }
1378
1379 void CSBackwardTab()
1380 {
1381 if (Param[1]<1) Param[1] = 1;
1382 CursorBackwardTab(Param[1]);
1383 }
1384
1385 void CSMoveToColumnN()
1386 {
1387 if (Param[1]<1) Param[1] = 1;
1388 Param[1]--;
1389 if (Param[1] < 0) Param[1] = 0;
1390 if (Param[1] > NumOfColumns-1) Param[1] = NumOfColumns-1;
1391 MoveCursor(Param[1],CursorY);
1392 }
1393
1394 void CSCursorRight()
1395 {
1396 if (Param[1]<1) Param[1] = 1;
1397 if (CursorX + Param[1] > NumOfColumns-1)
1398 MoveCursor(NumOfColumns-1,CursorY);
1399 else
1400 MoveCursor(CursorX+Param[1],CursorY);
1401 }
1402
1403 void CSCursorLeft()
1404 {
1405 if (Param[1]<1) Param[1] = 1;
1406 if (CursorX-Param[1] < 0)
1407 MoveCursor(0,CursorY);
1408 else
1409 MoveCursor(CursorX-Param[1],CursorY);
1410 }
1411
1412 void CSMoveToLineN()
1413 {
1414 if (Param[1]<1) Param[1] = 1;
1415 if (RelativeOrgMode)
1416 {
1417 if (CursorTop+Param[1]-1 > CursorBottom)
1418 MoveCursor(CursorX,CursorBottom);
1419 else
1420 MoveCursor(CursorX,CursorTop+Param[1]-1);
1421 }
1422 else {
1423 if (Param[1] > NumOfLines-StatusLine)
1424 MoveCursor(CursorX,NumOfLines-1-StatusLine);
1425 else
1426 MoveCursor(CursorX,Param[1]-1);
1427 }
1428 }
1429
1430 void CSMoveToXY()
1431 {
1432 int NewX, NewY;
1433
1434 if (Param[1]<1) Param[1] = 1;
1435 if ((NParam < 2) || (Param[2]<1)) Param[2] = 1;
1436 NewX = Param[2] - 1;
1437 if (NewX > NumOfColumns-1) NewX = NumOfColumns-1;
1438
1439 if ((StatusLine>0) && (CursorY==NumOfLines-1))
1440 NewY = CursorY;
1441 else if (RelativeOrgMode)
1442 {
1443 NewY = CursorTop + Param[1] - 1;
1444 if (NewY > CursorBottom) NewY = CursorBottom;
1445 }
1446 else {
1447 NewY = Param[1] - 1;
1448 if (NewY > NumOfLines-1-StatusLine)
1449 NewY = NumOfLines-1-StatusLine;
1450 }
1451 MoveCursor(NewX,NewY);
1452 }
1453
1454 void CSDeleteTabStop()
1455 {
1456 if (Param[1]==-1) Param[1] = 0;
1457 ClearTabStop(Param[1]);
1458 }
1459
1460 void CS_h_Mode()
1461 {
1462 switch (Param[1]) {
1463 case 2: KeybEnabled = FALSE; break;
1464 case 4: InsertMode = TRUE; break;
1465 case 12:
1466 ts.LocalEcho = 0;
1467 if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1468 TelChangeEcho();
1469 break;
1470 case 20:
1471 LFMode = TRUE;
1472 ts.CRSend = IdCRLF;
1473 cv.CRSend = IdCRLF;
1474 break;
1475 }
1476 }
1477
1478 void CS_i_Mode()
1479 {
1480 if (Param[1]==-1) Param[1] = 0;
1481 switch (Param[1]) {
1482 /* print screen */
1483 // PrintEX -- TRUE: print screen
1484 // FALSE: scroll region
1485 case 0: BuffPrint(! PrintEX); break;
1486 /* printer controller mode off */
1487 case 4: break; /* See PrnParseCS() */
1488 /* printer controller mode on */
1489 case 5:
1490 if (! AutoPrintMode)
1491 OpenPrnFile();
1492 DirectPrn = (ts.PrnDev[0]!=0);
1493 PrinterMode = TRUE;
1494 break;
1495 }
1496 }
1497
1498 void CS_l_Mode()
1499 {
1500 switch (Param[1]) {
1501 case 2: KeybEnabled = TRUE; break;
1502 case 4: InsertMode = FALSE; break;
1503 case 12:
1504 ts.LocalEcho = 1;
1505 if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1506 TelChangeEcho();
1507 break;
1508 case 20:
1509 LFMode = FALSE;
1510 ts.CRSend = IdCR;
1511 cv.CRSend = IdCR;
1512 break;
1513 }
1514 }
1515
1516 void CS_n_Mode()
1517 {
1518 char Report[16];
1519 int Y;
1520
1521 switch (Param[1]) {
1522 case 5:
1523 if (Send8BitMode)
1524 CommBinaryOut(&cv,"\2330n",3); /* Device Status Report -> Ready */
1525 else
1526 CommBinaryOut(&cv,"\033[0n",4); /* Device Status Report -> Ready */
1527 break;
1528 case 6:
1529 /* Cursor Position Report */
1530 Y = CursorY+1;
1531 if ((StatusLine>0) &&
1532 (Y==NumOfLines))
1533 Y = 1;
1534 if (Send8BitMode)
1535 _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\233%u;%uR", CLocale, Y, CursorX+1);
1536 else
1537 _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\033[%u;%uR", CLocale, Y, CursorX+1);
1538 CommBinaryOut(&cv,Report,strlen(Report));
1539 break;
1540 }
1541 }
1542
1543 void CSSetAttr()
1544 {
1545 int i, P;
1546
1547 UpdateStr();
1548 for (i=1 ; i<=NParam ; i++)
1549 {
1550 P = Param[i];
1551 if (P<0) P = 0;
1552 switch (P) {
1553 case 0: /* Clear all */
1554 CharAttr = DefCharAttr;
1555 BuffSetCurCharAttr(CharAttr);
1556 break;
1557
1558 case 1: /* Bold */
1559 CharAttr.Attr |= AttrBold;
1560 BuffSetCurCharAttr(CharAttr);
1561 break;
1562
1563 case 4: /* Under line */
1564 CharAttr.Attr |= AttrUnder;
1565 BuffSetCurCharAttr(CharAttr);
1566 break;
1567
1568 case 5: /* Blink */
1569 CharAttr.Attr |= AttrBlink;
1570 BuffSetCurCharAttr(CharAttr);
1571 break;
1572
1573 case 7: /* Reverse */
1574 CharAttr.Attr |= AttrReverse;
1575 BuffSetCurCharAttr(CharAttr);
1576 break;
1577
1578 case 22: /* Bold off */
1579 CharAttr.Attr &= ~ AttrBold;
1580 BuffSetCurCharAttr(CharAttr);
1581 break;
1582
1583 case 24: /* Under line off */
1584 CharAttr.Attr &= ~ AttrUnder;
1585 BuffSetCurCharAttr(CharAttr);
1586 break;
1587
1588 case 25: /* Blink off */
1589 CharAttr.Attr &= ~ AttrBlink;
1590 BuffSetCurCharAttr(CharAttr);
1591 break;
1592
1593 case 27: /* Reverse off */
1594 CharAttr.Attr &= ~ AttrReverse;
1595 BuffSetCurCharAttr(CharAttr);
1596 break;
1597
1598 case 30:
1599 case 31:
1600 case 32:
1601 case 33:
1602 case 34:
1603 case 35:
1604 case 36:
1605 case 37: /* text color */
1606 CharAttr.Attr2 |= Attr2Fore;
1607 CharAttr.Fore = P - 30;
1608 BuffSetCurCharAttr(CharAttr);
1609 break;
1610
1611 case 38: /* text color (256color mode) */
1612 if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1613 i++;
1614 if (i < NParam) {
1615 P = Param[++i];
1616 if (P<0) {
1617 P = 0;
1618 }
1619 CharAttr.Attr2 |= Attr2Fore;
1620 CharAttr.Fore = P;
1621 BuffSetCurCharAttr(CharAttr);
1622 }
1623 }
1624 break;
1625
1626 case 39: /* Reset text color */
1627 CharAttr.Attr2 &= ~ Attr2Fore;
1628 CharAttr.Fore = AttrDefaultFG;
1629 BuffSetCurCharAttr(CharAttr);
1630 break;
1631
1632 case 40:
1633 case 41:
1634 case 42:
1635 case 43:
1636 case 44:
1637 case 45:
1638 case 46:
1639 case 47: /* Back color */
1640 CharAttr.Attr2 |= Attr2Back;
1641 CharAttr.Back = P - 40;
1642 BuffSetCurCharAttr(CharAttr);
1643 break;
1644
1645 case 48: /* Back color (256color mode) */
1646 if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1647 i++;
1648 if (i < NParam) {
1649 P = Param[++i];
1650 if (P<0) {
1651 P = 0;
1652 }
1653 CharAttr.Attr2 |= Attr2Back;
1654 CharAttr.Back = P;
1655 BuffSetCurCharAttr(CharAttr);
1656 }
1657 }
1658 break;
1659
1660 case 49: /* Reset back color */
1661 CharAttr.Attr2 &= ~ Attr2Back;
1662 CharAttr.Back = AttrDefaultBG;
1663 BuffSetCurCharAttr(CharAttr);
1664 break;
1665
1666 case 90:
1667 case 91:
1668 case 92:
1669 case 93:
1670 case 94:
1671 case 95:
1672 case 96:
1673 case 97: /* aixterm style text color */
1674 if (ts.ColorFlag & CF_AIXTERM16) {
1675 CharAttr.Attr2 |= Attr2Fore;
1676 CharAttr.Fore = P - 90 + 8;
1677 BuffSetCurCharAttr(CharAttr);
1678 }
1679 break;
1680
1681 case 100:
1682 if (! (ts.ColorFlag & CF_AIXTERM16)) {
1683 /* Reset text and back color */
1684 CharAttr.Attr2 &= ~ (Attr2Fore | Attr2Back);
1685 CharAttr.Fore = AttrDefaultFG;
1686 CharAttr.Back = AttrDefaultBG;
1687 BuffSetCurCharAttr(CharAttr);
1688 break;
1689 }
1690 /* fall through to aixterm style back color */
1691
1692 case 101:
1693 case 102:
1694 case 103:
1695 case 104:
1696 case 105:
1697 case 106:
1698 case 107: /* aixterm style back color */
1699 if (ts.ColorFlag & CF_AIXTERM16) {
1700 CharAttr.Attr2 |= Attr2Back;
1701 CharAttr.Back = P - 100 + 8;
1702 BuffSetCurCharAttr(CharAttr);
1703 }
1704 break;
1705 }
1706 }
1707 }
1708
1709 void CSSetScrollRegion()
1710 {
1711 if ((StatusLine>0) &&
1712 (CursorY==NumOfLines-1))
1713 {
1714 MoveCursor(0,CursorY);
1715 return;
1716 }
1717 if (Param[1]<1) Param[1] =1;
1718 if ((NParam < 2) | (Param[2]<1))
1719 Param[2] = NumOfLines-StatusLine;
1720 Param[1]--;
1721 Param[2]--;
1722 if (Param[1] > NumOfLines-1-StatusLine)
1723 Param[1] = NumOfLines-1-StatusLine;
1724 if (Param[2] > NumOfLines-1-StatusLine)
1725 Param[2] = NumOfLines-1-StatusLine;
1726 if (Param[1] >= Param[2]) return;
1727 CursorTop = Param[1];
1728 CursorBottom = Param[2];
1729 if (RelativeOrgMode) MoveCursor(0,CursorTop);
1730 else MoveCursor(0,0);
1731 }
1732
1733 void CSSunSequence() /* Sun terminal private sequences */
1734 {
1735 char Report[16];
1736
1737 switch (Param[1]) {
1738 case 8: /* set terminal size */
1739 if ((Param[2]<=1) || (NParam<2)) Param[2] = 24;
1740 if ((Param[3]<=1) || (NParam<3)) Param[3] = 80;
1741 ChangeTerminalSize(Param[3],Param[2]);
1742 break;
1743 case 14: /* get window size??? */
1744 /* this is not actual window size */
1745 if (Send8BitMode)
1746 CommBinaryOut(&cv,"\2334;640;480t",11);
1747 else
1748 CommBinaryOut(&cv,"\033[4;640;480t",12);
1749 break;
1750 case 18: /* get terminal size */
1751 if (Send8BitMode)
1752 _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\2338;%u;%u;t", CLocale, NumOfLines-StatusLine, NumOfColumns);
1753 else
1754 _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\033[8;%u;%u;t", CLocale, NumOfLines-StatusLine, NumOfColumns);
1755 CommBinaryOut(&cv,Report,strlen(Report));
1756 break;
1757 }
1758 }
1759
1760 void CSGT(BYTE b)
1761 {
1762 switch (b) {
1763 case 'c': /* second terminal report */
1764 if (Send8BitMode)
1765 CommBinaryOut(&cv,"\233>32;10;2c",11); /* VT382 */
1766 else
1767 CommBinaryOut(&cv,"\033[>32;10;2c",11); /* VT382 */
1768 break;
1769 case 'J':
1770 if (Param[1]==3) // IO-8256 terminal
1771 {
1772 if (Param[2]<1) Param[2]=1;
1773 if (Param[3]<1) Param[3]=1;
1774 if (Param[4]<1) Param[4]=1;
1775 if (Param[5]<1) Param[5]=1;
1776 BuffEraseBox(Param[3]-1,Param[2]-1,
1777 Param[5]-1,Param[4]-1);
1778 }
1779 break;
1780 case 'K':
1781 if ((NParam>=2) && (Param[1]==5))
1782 { // IO-8256 terminal
1783 switch (Param[2]) {
1784 case 3:
1785 case 4:
1786 case 5:
1787 case 6:
1788 BuffDrawLine(CharAttr, Param[2], Param[3]);
1789 break;
1790 case 12:
1791 /* Text color */
1792 if ((Param[3]>=0) && (Param[3]<=7))
1793 {
1794 switch (Param[3]) {
1795 case 3: CharAttr.Fore = IdBlue; break;
1796 case 4: CharAttr.Fore = IdCyan; break;
1797 case 5: CharAttr.Fore = IdYellow; break;
1798 case 6: CharAttr.Fore = IdMagenta; break;
1799 default: CharAttr.Fore = Param[3]; break;
1800 }
1801 CharAttr.Attr2 |= Attr2Fore;
1802 BuffSetCurCharAttr(CharAttr);
1803 }
1804 break;
1805 }
1806 }
1807 else if (Param[1]==3)
1808 {// IO-8256 terminal
1809 if (Param[2]<1) Param[2] = 1;
1810 if (Param[3]<1) Param[2] = 1;
1811 BuffEraseCharsInLine(Param[2]-1,Param[3]-Param[2]+1);
1812 }
1813 break;
1814 }
1815 }
1816
1817 void CSQExchangeColor()
1818 {
1819 COLORREF ColorRef;
1820
1821 BuffUpdateScroll();
1822
1823 ColorRef = ts.VTColor[0];
1824 ts.VTColor[0] = ts.VTReverseColor[0];
1825 ts.VTReverseColor[0] = ColorRef;
1826 ColorRef = ts.VTColor[1];
1827 ts.VTColor[1] = ts.VTReverseColor[1];
1828 ts.VTReverseColor[1] = ColorRef;
1829
1830 ColorRef = ts.VTBoldColor[0];
1831 ts.VTBoldColor[0] = ts.VTBoldColor[1];
1832 ts.VTBoldColor[1] = ColorRef;
1833
1834 ColorRef = ts.VTBlinkColor[0];
1835 ts.VTBlinkColor[0] = ts.VTBlinkColor[1];
1836 ts.VTBlinkColor[1] = ColorRef;
1837
1838 ColorRef = ts.URLColor[0];
1839 ts.URLColor[0] = ts.URLColor[1];
1840 ts.URLColor[1] = ColorRef;
1841
1842 ReverseColor = !ReverseColor;
1843
1844 #ifdef ALPHABLEND_TYPE2
1845 BGInitialize();
1846 #endif
1847 DispChangeBackground();
1848 UpdateWindow(HVTWin);
1849 }
1850
1851 void CSQ_h_Mode()
1852 {
1853 int i;
1854
1855 for (i = 1 ; i<=NParam ; i++)
1856 switch (Param[i]) {
1857 case 1: AppliCursorMode = TRUE; break;
1858 case 3:
1859 ChangeTerminalSize(132,NumOfLines-StatusLine);
1860 break;
1861 case 5: /* Reverse Video */
1862 if (!ReverseColor)
1863 CSQExchangeColor(); /* Exchange text/back color */
1864 break;
1865 case 6:
1866 if ((StatusLine>0) &&
1867 (CursorY==NumOfLines-1))
1868 MoveCursor(0,CursorY);
1869 else {
1870 RelativeOrgMode = TRUE;
1871 MoveCursor(0,CursorTop);
1872 }
1873 break;
1874 case 7: AutoWrapMode = TRUE; break;
1875 case 8: AutoRepeatMode = TRUE; break;
1876 case 9:
1877 if (ts.MouseEventTracking)
1878 MouseReportMode = IdMouseTrackX10;
1879 break;
1880 case 19: PrintEX = TRUE; break;
1881 case 25: DispEnableCaret(TRUE); break; // cursor on
1882 case 38:
1883 if (ts.AutoWinSwitch>0)
1884 ChangeEmu = IdTEK; /* Enter TEK Mode */
1885 break;
1886 case 59:
1887 if (ts.Language==IdJapanese)
1888 { /* kanji terminal */
1889 Gn[0] = IdASCII;
1890 Gn[1] = IdKatakana;
1891 Gn[2] = IdKatakana;
1892 Gn[3] = IdKanji;
1893 Glr[0] = 0;
1894 if ((ts.KanjiCode==IdJIS) &&
1895 (ts.JIS7Katakana==0))
1896 Glr[1] = 2; // 8-bit katakana
1897 else
1898 Glr[1] = 3;
1899 }
1900 break;
1901 case 66: AppliKeyMode = TRUE; break;
1902 case 67: ts.BSKey = IdBS; break;
1903 case 1000:
1904 if (ts.MouseEventTracking)
1905 MouseReportMode = IdMouseTrackVT200;
1906 break;
1907 case 1001:
1908 if (ts.MouseEventTracking)
1909 MouseReportMode = IdMouseTrackVT200Hl;
1910 break;
1911 case 1002:
1912 if (ts.MouseEventTracking)
1913 MouseReportMode = IdMouseTrackBtnEvent;
1914 break;
1915 case 1003:
1916 if (ts.MouseEventTracking)
1917 MouseReportMode = IdMouseTrackAllEvent;
1918 break;
1919 case 1004:
1920 if (ts.MouseEventTracking)
1921 FocusReportMode = TRUE;
1922 break;
1923 }
1924 }
1925
1926 void CSQ_i_Mode()
1927 {
1928 if (Param[1]==-1) Param[1] = 0;
1929 switch (Param[1]) {
1930 case 1:
1931 OpenPrnFile();
1932 BuffDumpCurrentLine(LF);
1933 if (! AutoPrintMode)
1934 ClosePrnFile();
1935 break;
1936 /* auto print mode off */
1937 case 4:
1938 if (AutoPrintMode)
1939 {
1940 ClosePrnFile();
1941 AutoPrintMode = FALSE;
1942 }
1943 break;
1944 /* auto print mode on */
1945 case 5:
1946 if (! AutoPrintMode)
1947 {
1948 OpenPrnFile();
1949 AutoPrintMode = TRUE;
1950 }
1951 break;
1952 }
1953 }
1954
1955 void CSQ_l_Mode()
1956 {
1957 int i;
1958
1959 for (i = 1 ; i <= NParam ; i++)
1960 switch (Param[i]) {
1961 case 1: AppliCursorMode = FALSE; break;
1962 case 3:
1963 ChangeTerminalSize(80,NumOfLines-StatusLine);
1964 break;
1965 case 5: /* Normal Video */
1966 if (ReverseColor)
1967 CSQExchangeColor(); /* Exchange text/back color */
1968 break;
1969 case 6:
1970 if ((StatusLine>0) &&
1971 (CursorY==NumOfLines-1))
1972 MoveCursor(0,CursorY);
1973 else {
1974 RelativeOrgMode = FALSE;
1975 MoveCursor(0,0);
1976 }
1977 break;
1978 case 7: AutoWrapMode = FALSE; break;
1979 case 8: AutoRepeatMode = FALSE; break;
1980 case 9: MouseReportMode = IdMouseTrackNone; break;
1981 case 19: PrintEX = FALSE; break;
1982 case 25: DispEnableCaret(FALSE); break; // cursor off
1983 case 59:
1984 if (ts.Language==IdJapanese)
1985 { /* katakana terminal */
1986 Gn[0] = IdASCII;
1987 Gn[1] = IdKatakana;
1988 Gn[2] = IdKatakana;
1989 Gn[3] = IdKanji;
1990 Glr[0] = 0;
1991 if ((ts.KanjiCode==IdJIS) &&
1992 (ts.JIS7Katakana==0))
1993 Glr[1] = 2; // 8-bit katakana
1994 else
1995 Glr[1] = 3;
1996 }
1997 break;
1998 case 66: AppliKeyMode = FALSE; break;
1999 case 67: ts.BSKey = IdDEL; break;
2000 case 1000:
2001 case 1001:
2002 case 1002:
2003 case 1003: MouseReportMode = IdMouseTrackNone; break;
2004 case 1004: FocusReportMode = FALSE; break;
2005 }
2006 }
2007
2008 void CSQ_n_Mode()
2009 {
2010 }
2011
2012 void CSQuest(BYTE b)
2013 {
2014 switch (b) {
2015 case 'K': CSLineErase(); break;
2016 case 'h': CSQ_h_Mode(); break;
2017 case 'i': CSQ_i_Mode(); break;
2018 case 'l': CSQ_l_Mode(); break;
2019 case 'n': CSQ_n_Mode(); break;
2020 }
2021 }
2022
2023 void SoftReset()
2024 // called by software-reset escape sequence handler
2025 {
2026 UpdateStr();
2027 AutoRepeatMode = TRUE;
2028 DispEnableCaret(TRUE); // cursor on
2029 InsertMode = FALSE;
2030 RelativeOrgMode = FALSE;
2031 AppliKeyMode = FALSE;
2032 AppliCursorMode = FALSE;
2033 if ((StatusLine>0) &&
2034 (CursorY == NumOfLines-1))
2035 MoveToMainScreen();
2036 CursorTop = 0;
2037 CursorBottom = NumOfLines-1-StatusLine;
2038 ResetCharSet();
2039
2040 Send8BitMode = ts.Send8BitCtrl;
2041
2042 /* Attribute */
2043 CharAttr = DefCharAttr;
2044 Special = FALSE;
2045 BuffSetCurCharAttr(CharAttr);
2046
2047 // status buffers
2048 ResetSBuffers();
2049 }
2050
2051 void CSExc(BYTE b)
2052 {
2053 switch (b) {
2054 case 'p':
2055 /* Software reset */
2056 SoftReset();
2057 break;
2058 }
2059 }
2060
2061 void CSDouble(BYTE b)
2062 {
2063 switch (b) {
2064 case 'p':
2065 /* Select terminal mode (software reset) */
2066 SoftReset();
2067 if (NParam > 0) {
2068 switch (Param[1]) {
2069 case 61: // VT100 Mode
2070 Send8BitMode = FALSE; break;
2071 case 62: // VT200 Mode
2072 case 63: // VT300 Mode
2073 case 64: // VT400 Mode
2074 if (NParam > 1 && Param[2] == 1)
2075 Send8BitMode = FALSE;
2076 else
2077 Send8BitMode = TRUE;
2078 break;
2079 }
2080 }
2081 break;
2082 }
2083 }
2084
2085 void CSDol(BYTE b)
2086 {
2087 switch (b) {
2088 case '}':
2089 if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2090 if (StatusLine==0) return;
2091 if ((Param[1]<1) && (CursorY==NumOfLines-1))
2092 MoveToMainScreen();
2093 else if ((Param[1]==1) && (CursorY<NumOfLines-1))
2094 MoveToStatusLine();
2095 break;
2096 case '~':
2097 if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2098 if (Param[1]<=1)
2099 HideStatusLine();
2100 else if ((StatusLine==0) && (Param[1]==2))
2101 ShowStatusLine(1); // show
2102 break;
2103 }
2104 }
2105
2106 void PrnParseCS(BYTE b) // printer mode
2107 {
2108 ParseMode = ModeFirst;
2109 switch (ICount) {
2110 /* no intermediate char */
2111 case 0:
2112 switch (Prv) {
2113 /* no private parameter */
2114 case 0:
2115 switch (b) {
2116 case 'i':
2117 if (Param[1]==4)
2118 {
2119 PrinterMode = FALSE;
2120 // clear prn buff
2121 WriteToPrnFile(0,FALSE);
2122 if (! AutoPrintMode)
2123 ClosePrnFile();
2124 return;
2125 }
2126 break;
2127 } /* of case Prv=0 */
2128 break;
2129 }
2130 break;
2131 /* one intermediate char */
2132 case 1: break;
2133 } /* of case Icount */
2134
2135 WriteToPrnFile(b,TRUE);
2136 }
2137
2138 void ParseCS(BYTE b) /* b is the final char */
2139 {
2140 if (PrinterMode) { // printer mode
2141 PrnParseCS(b);
2142 return;
2143 }
2144
2145 switch (ICount) {
2146 /* no intermediate char */
2147 case 0:
2148 switch (Prv) {
2149 /* no private parameter */
2150 case 0:
2151 switch (b) {
2152 case '@': CSInsertCharacter(); break;
2153 case 'A': CSCursorUp(); break;
2154 case 'B': CSCursorDown(); break;
2155 case 'C': CSCursorRight(); break;
2156 case 'D': CSCursorLeft(); break;
2157 case 'E': CSCursorDown1(); break;
2158 case 'F': CSCursorUp1(); break;
2159 case 'G': CSMoveToColumnN(); break;
2160 case 'H': CSMoveToXY(); break;
2161 case 'I': CSForwardTab(); break; // CHT
2162 case 'J': CSScreenErase(); break;
2163 case 'K': CSLineErase(); break;
2164 case 'L': CSInsertLine(); break;
2165 case 'M': CSDeleteNLines(); break;
2166 case 'P': CSDeleteCharacter(); break;
2167 case 'S': CSScrollUP(); break; // SU
2168 case 'T': CSScrollDown(); break; // SD
2169 case 'X': CSEraseCharacter(); break;
2170 case 'Z': CSBackwardTab(); break; // CBT
2171 case '`': CSMoveToColumnN(); break;
2172 case 'a': CSCursorRight(); break;
2173 case 'c': AnswerTerminalType(); break;
2174 case 'd': CSMoveToLineN(); break;
2175 case 'e': CSCursorUp(); break;
2176 case 'f': CSMoveToXY(); break;
2177 case 'g': CSDeleteTabStop(); break;
2178 case 'h': CS_h_Mode(); break;
2179 case 'i': CS_i_Mode(); break;
2180 case 'l': CS_l_Mode(); break;
2181 case 'm': CSSetAttr(); break;
2182 case 'n': CS_n_Mode(); break;
2183 case 'r': CSSetScrollRegion(); break;
2184 case 's': SaveCursor(); break;
2185 case 't': CSSunSequence(); break;
2186 case 'u': RestoreCursor(); break;
2187 } /* of case Prv=0 */
2188 break;
2189 /* private parameter = '>' */
2190 case '>': CSGT(b); break;
2191 /* private parameter = '?' */
2192 case '?': CSQuest(b); break;
2193 }
2194 break;
2195 /* one intermediate char */
2196 case 1:
2197 switch (IntChar[1]) {
2198 /* intermediate char = '!' */
2199 case '!': CSExc(b); break;
2200 /* intermediate char = '"' */
2201 case '"': CSDouble(b); break;
2202 /* intermediate char = '$' */
2203 case '$': CSDol(b); break;
2204 }
2205 break;
2206 } /* of case Icount */
2207
2208 ParseMode = ModeFirst;
2209 }
2210
2211 void ControlSequence(BYTE b)
2212 {
2213 if ((b<=US) || (b>=0x80) && (b<=0x9F))
2214 ParseControl(b); /* ctrl char */
2215 else if ((b>=0x40) && (b<=0x7E))
2216 ParseCS(b); /* terminate char */
2217 else {
2218 if (PrinterMode)
2219 WriteToPrnFile(b,FALSE);
2220
2221 if ((b>=0x20) && (b<=0x2F))
2222 { /* intermediate char */
2223 if (ICount<IntCharMax) ICount++;
2224 IntChar[ICount] = b;
2225 }
2226 else if ((b>=0x30) && (b<=0x39))
2227 {
2228 if (Param[NParam] < 0)
2229 Param[NParam] = 0;
2230 if (Param[NParam]<1000)
2231 Param[NParam] = Param[NParam]*10 + b - 0x30;
2232 }
2233 else if (b==0x3B)
2234 {
2235 if (NParam < NParamMax)
2236 {
2237 NParam++;
2238 Param[NParam] = -1;
2239 }
2240 }
2241 else if ((b>=0x3C) && (b<=0x3F))
2242 { /* private char */
2243 if (FirstPrm) Prv = b;
2244 }
2245 }
2246 FirstPrm = FALSE;
2247 }
2248
2249 void DeviceControl(BYTE b)
2250 {
2251 if (ESCFlag && (b=='\\') || (b==ST && ts.KanjiCode!=IdSJIS))
2252 {
2253 ESCFlag = FALSE;
2254 ParseMode = SavedMode;
2255 return;
2256 }
2257
2258 if (b==ESC)
2259 {
2260 ESCFlag = TRUE;
2261 return;
2262 }
2263 else ESCFlag = FALSE;
2264
2265 if (b<=US)
2266 ParseControl(b);
2267 else if ((b>=0x30) && (b<=0x39))
2268 {
2269 if (Param[NParam] < 0) Param[NParam] = 0;
2270 if (Param[NParam]<1000)
2271 Param[NParam] = Param[NParam]*10 + b - 0x30;
2272 }
2273 else if (b==0x3B)
2274 {
2275 if (NParam < NParamMax)
2276 {
2277 NParam++;
2278 Param[NParam] = -1;
2279 }
2280 }
2281 else if ((b>=0x40) && (b<=0x7E))
2282 {
2283 if (b=='|')
2284 {
2285 ParseMode = ModeDCUserKey;
2286 if (Param[1] < 1) ClearUserKey();
2287 WaitKeyId = TRUE;
2288 NewKeyId = 0;
2289 }
2290 else ParseMode = ModeSOS;
2291 }
2292 }
2293
2294 void DCUserKey(BYTE b)
2295 {
2296 if (ESCFlag && (b=='\\') || (b==ST && ts.KanjiCode!=IdSJIS))
2297 {
2298 if (! WaitKeyId) DefineUserKey(NewKeyId,NewKeyStr,NewKeyLen);
2299 ESCFlag = FALSE;
2300 ParseMode = SavedMode;
2301 return;
2302 }
2303
2304 if (b==ESC)
2305 {
2306 ESCFlag = TRUE;
2307 return;
2308 }
2309 else ESCFlag = FALSE;
2310
2311 if (WaitKeyId)
2312 {
2313 if ((b>=0x30) && (b<=0x39))
2314 {
2315 if (NewKeyId<1000)
2316 NewKeyId = NewKeyId*10 + b - 0x30;
2317 }
2318 else if (b==0x2F)
2319 {
2320 WaitKeyId = FALSE;
2321 WaitHi = TRUE;
2322 NewKeyLen = 0;
2323 }
2324 }
2325 else {
2326 if (b==0x3B)
2327 {
2328 DefineUserKey(NewKeyId,NewKeyStr,NewKeyLen);
2329 WaitKeyId = TRUE;
2330 NewKeyId = 0;
2331 }
2332 else {
2333 if (NewKeyLen < FuncKeyStrMax)
2334 {
2335 if (WaitHi)
2336 {
2337 NewKeyStr[NewKeyLen] = ConvHexChar(b) << 4;
2338 WaitHi = FALSE;
2339 }
2340 else {
2341 NewKeyStr[NewKeyLen] = NewKeyStr[NewKeyLen] +
2342 ConvHexChar(b);
2343 WaitHi = TRUE;
2344 NewKeyLen++;
2345 }
2346 }
2347 }
2348 }
2349 }
2350
2351 void IgnoreString(BYTE b)
2352 {
2353 if ((ESCFlag && (b=='\\')) ||
2354 (b<=US && b!=ESC && b!=HT) ||
2355 (b==ST && ts.KanjiCode!=IdSJIS))
2356 ParseMode = SavedMode;
2357
2358 if (b==ESC) ESCFlag = TRUE;
2359 else ESCFlag = FALSE;
2360 }
2361
2362 BOOL XsParseColor(char *colspec, COLORREF *color)
2363 {
2364 unsigned int r, g, b;
2365 // double dr, dg, db;
2366
2367 r = g = b = 255;
2368
2369 if (colspec == NULL || color == NULL) {
2370 return FALSE;
2371 }
2372
2373 if (_strnicmp(colspec, "rgb:", 4) == 0) {
2374 switch (strlen(colspec)) {
2375 case 9: // rgb:R/G/B
2376 if (sscanf(colspec, "rgb:%1x/%1x/%1x", &r, &g, &b) != 3) {
2377 return FALSE;
2378 }
2379 r *= 17; g *= 17; b *= 17;
2380 break;
2381 case 12: // rgb:RR/GG/BB
2382 if (sscanf(colspec, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3) {
2383 return FALSE;
2384 }
2385 break;
2386 case 15: // rgb:RRR/GGG/BBB
2387 if (sscanf(colspec, "rgb:%3x/%3x/%3x", &r, &g, &b) != 3) {
2388 return FALSE;
2389 }
2390 r >>= 4; g >>= 4; b >>= 4;
2391 break;
2392 case 18: // rgb:RRRR/GGGG/BBBB
2393 if (sscanf(colspec, "rgb:%4x/%4x/%4x", &r, &g, &b) != 3) {
2394 return FALSE;
2395 }
2396 r >>= 8; g >>= 8; b >>= 8;
2397 break;
2398 default:
2399 return FALSE;
2400 }
2401 }
2402 // else if (_strnicmp(colspec, "rgbi:", 5) == 0) {
2403 // ; /* nothing to do */
2404 // }
2405 else if (colspec[0] == '#') {
2406 switch (strlen(colspec)) {
2407 case 4: // #RGB
2408 if (sscanf(colspec, "#%1x%1x%1x", &r, &g, &b) != 3) {
2409 return FALSE;
2410 }
2411 r <<= 4; g <<= 4; b <<= 4;
2412 break;
2413 case 7: // #RRGGBB
2414 if (sscanf(colspec, "#%2x%2x%2x", &r, &g, &b) != 3) {
2415 return FALSE;
2416 }
2417 break;
2418 case 10: // #RRRGGGBBB
2419 if (sscanf(colspec, "#%3x%3x%3x", &r, &g, &b) != 3) {
2420 return FALSE;
2421 }
2422 r >>= 4; g >>= 4; b >>= 4;
2423 break;
2424 case 13: // #RRRRGGGGBBBB
2425 if (sscanf(colspec, "#%4x%4x%4x", &r, &g, &b) != 3) {
2426 return FALSE;
2427 }
2428 r >>= 8; g >>= 8; b >>= 8;
2429 break;
2430 default:
2431 return FALSE;
2432 }
2433 }
2434 else {
2435 return FALSE;
2436 }
2437
2438 if (r > 255 || g > 255 || b > 255) {
2439 return FALSE;
2440 }
2441
2442 *color = RGB(r, g, b);
2443 return TRUE;
2444 }
2445
2446 #define ModeXsFirst 1
2447 #define ModeXsString 2
2448 #define ModeXsColorNum 3
2449 #define ModeXsColorSpec 4
2450 #define ModeXsEsc 5
2451 void XSequence(BYTE b)
2452 {
2453 static BYTE XsParseMode = ModeXsFirst, PrevMode;
2454 static char StrBuff[sizeof(ts.Title)];
2455 static unsigned int ColorNumber, StrLen;
2456 COLORREF color;
2457
2458 switch (XsParseMode) {
2459 case ModeXsFirst:
2460 if (isdigit(b)) {
2461 if (Param[1] < 1000) {
2462 Param[1] = Param[1]*10 + b - '0';
2463 }
2464 }
2465 else if (b == ';') {
2466 StrBuff[0] = '\0';
2467 StrLen = 0;
2468 if (Param[1] == 4) {
2469 ColorNumber = 0;
2470 XsParseMode = ModeXsColorNum;
2471 }
2472 else {
2473 XsParseMode = ModeXsString;
2474 }
2475 }
2476 else {
2477 ParseMode = ModeFirst;
2478 }
2479 break;
2480 case ModeXsString:
2481 if ((b==ST && ts.KanjiCode!=IdSJIS) || b==BEL) { /* String Terminator */
2482 StrBuff[StrLen] = '\0';
2483 switch (Param[1]) {
2484 case 0: /* Change window title and icon name */
2485 case 1: /* Change icon name */
2486 case 2: /* Change window title */
2487 if (ts.AcceptTitleChangeRequest) {
2488 strncpy_s(cv.TitleRemote, sizeof(cv.TitleRemote), StrBuff, _TRUNCATE);
2489 // (2006.6.15 maya) �^�C�g�����n����������SJIS������
2490 ConvertToCP932(cv.TitleRemote, sizeof(cv.TitleRemote));
2491 ChangeTitle();
2492 }
2493 break;
2494 default:
2495 /* nothing to do */;
2496 }
2497 ParseMode = ModeFirst;
2498 XsParseMode = ModeXsFirst;
2499 }
2500 else if (b == ESC) { /* Escape */
2501 PrevMode = ModeXsString;
2502 XsParseMode = ModeXsEsc;
2503 }
2504 else if (b <= US) { /* Other control character -- invalid sequence */
2505 ParseMode = ModeFirst;
2506 XsParseMode = ModeXsFirst;
2507 }
2508 else if (StrLen < sizeof(StrBuff) - 1) {
2509 StrBuff[StrLen++] = b;
2510 }
2511 break;
2512 case ModeXsColorNum:
2513 if (isdigit(b)) {
2514 ColorNumber = ColorNumber*10 + b - '0';
2515 }
2516 else if (b == ';') {
2517 XsParseMode = ModeXsColorSpec;
2518 StrBuff[0] = '\0';
2519 StrLen = 0;
2520 }
2521 else {
2522 ParseMode = ModeFirst;
2523 XsParseMode = ModeXsFirst;
2524 }
2525 break;
2526 case ModeXsColorSpec:
2527 if ((b==ST && ts.KanjiCode!=IdSJIS) || b==BEL) { /* String Terminator */
2528 StrBuff[StrLen] = '\0';
2529 if ((ts.ColorFlag & CF_XTERM256) && ColorNumber <= 255) {
2530 if (strcmp(StrBuff, "?") == 0) {
2531 color = DispGetANSIColor(ColorNumber);
2532 if (Send8BitMode) {
2533 _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2534 "\2354;%d;rgb:%02x/%02x/%02x\234", CLocale, ColorNumber,
2535 GetRValue(color), GetGValue(color), GetBValue(color));
2536 }
2537 else {
2538 _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2539 "\033]4;%d;rgb:%02x/%02x/%02x\033\\", CLocale, ColorNumber,
2540 GetRValue(color), GetGValue(color), GetBValue(color));
2541 }
2542 ParseMode = ModeFirst;
2543 XsParseMode = ModeXsFirst;
2544 CommBinaryOut(&cv, StrBuff, strlen(StrBuff));
2545 break;
2546 }
2547 else if (XsParseColor(StrBuff, &color)) {
2548 DispSetANSIColor(ColorNumber, color);
2549 }
2550 }
2551 ParseMode = ModeFirst;
2552 XsParseMode = ModeXsFirst;
2553 }
2554 else if (b == ESC) {
2555 PrevMode = ModeXsColorSpec;
2556 XsParseMode = ModeXsEsc;
2557 }
2558 else if (b <= US) { /* Other control character -- invalid sequence */
2559 ParseMode = ModeFirst;
2560 XsParseMode = ModeXsFirst;
2561 }
2562 else if (b == ';') {
2563 if ((ts.ColorFlag & CF_XTERM256) && ColorNumber <= 255) {
2564 if (strcmp(StrBuff, "?") == 0) {
2565 color = DispGetANSIColor(ColorNumber);
2566 if (Send8BitMode) {
2567 _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2568 "\2354;%d;rgb:%02x/%02x/%02x\234", CLocale, ColorNumber,
2569 GetRValue(color), GetGValue(color), GetBValue(color));
2570 }
2571 else {
2572 _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2573 "\033]4;%d;rgb:%02x/%02x/%02x\033\\", CLocale, ColorNumber,
2574 GetRValue(color), GetGValue(color), GetBValue(color));
2575 }
2576 XsParseMode = ModeXsColorNum;
2577 CommBinaryOut(&cv, StrBuff, strlen(StrBuff));
2578 }
2579 else if (XsParseColor(StrBuff, &color)) {
2580 DispSetANSIColor(ColorNumber, color);
2581 }
2582 }
2583 ColorNumber = 0;
2584 StrBuff[0] = '\0';
2585 StrLen = 0;
2586 XsParseMode = ModeXsColorNum;
2587 }
2588 else if (StrLen < sizeof(StrBuff) - 1) {
2589 StrBuff[StrLen++] = b;
2590 }
2591 break;
2592 case ModeXsEsc:
2593 if (b == '\\') { /* String Terminator */
2594 XsParseMode = PrevMode;
2595 // XSequence(ST);
2596 XSequence(BEL);
2597 }
2598 else { /* Other character -- invalid sequence */
2599 ParseMode = ModeFirst;
2600 XsParseMode = ModeXsFirst;
2601 }
2602 break;
2603 // default:
2604 // ParseMode = ModeFirst;
2605 // XsParseMode = ModeXsFirst;
2606 }
2607 }
2608
2609 void DLESeen(BYTE b)
2610 {
2611 ParseMode = ModeFirst;
2612 if (((ts.FTFlag & FT_BPAUTO)!=0) && (b=='B'))
2613 BPStart(IdBPAuto); /* Auto B-Plus activation */
2614 ChangeEmu = -1;
2615 }
2616
2617 void CANSeen(BYTE b)
2618 {
2619 ParseMode = ModeFirst;
2620 if (((ts.FTFlag & FT_ZAUTO)!=0) && (b=='B'))
2621 ZMODEMStart(IdZAuto); /* Auto ZMODEM activation */
2622 ChangeEmu = -1;
2623 }
2624
2625 BOOL CheckKanji(BYTE b)
2626 {
2627 BOOL Check;
2628
2629 if (ts.Language!=IdJapanese) return FALSE;
2630
2631 ConvJIS = FALSE;
2632
2633 if (ts.KanjiCode==IdSJIS)
2634 {
2635 if ((0x80<b) && (b<0xa0) || (0xdf<b) && (b<0xfd))
2636 return TRUE; // SJIS kanji
2637 if ((0xa1<=b) && (b<=0xdf))
2638 return FALSE; // SJIS katakana
2639 }
2640
2641 if ((b>=0x21) && (b<=0x7e))
2642 {
2643 Check = (Gn[Glr[0]]==IdKanji);
2644 ConvJIS = Check;
2645 }
2646 else if ((b>=0xA1) && (b<=0xFE))
2647 {
2648 Check = (Gn[Glr[1]]==IdKanji);
2649 if (ts.KanjiCode==IdEUC)
2650 Check = TRUE;
2651 else if (ts.KanjiCode==IdJIS)
2652 {
2653 if (((ts.TermFlag & TF_FIXEDJIS)!=0) &&
2654 (ts.JIS7Katakana==0))
2655 Check = FALSE; // 8-bit katakana
2656 }
2657 ConvJIS = Check;
2658 }
2659 else
2660 Check = FALSE;
2661
2662 return Check;
2663 }
2664
2665 BOOL ParseFirstJP(BYTE b)
2666 // returns TRUE if b is processed
2667 // (actually allways returns TRUE)
2668 {
2669 if (KanjiIn)
2670 {
2671 if ((! ConvJIS) && (0x3F<b) && (b<0xFD) ||
2672 ConvJIS && ( (0x20<b) && (b<0x7f) ||
2673 (0xa0<b) && (b<0xff) ))
2674 {
2675 PutKanji(b);
2676 KanjiIn = FALSE;
2677 return TRUE;
2678 }
2679 else if ((ts.TermFlag & TF_CTRLINKANJI)==0)
2680 KanjiIn = FALSE;
2681 else if ((b==CR) && Wrap) {
2682 CarriageReturn(FALSE);
2683 LineFeed(LF,FALSE);
2684 Wrap = FALSE;
2685 }
2686 }
2687
2688 if (SSflag)
2689 {
2690 if (Gn[GLtmp] == IdKanji)
2691 {
2692 Kanji = b << 8;
2693 KanjiIn = TRUE;
2694 SSflag = FALSE;
2695 return TRUE;
2696 }
2697 else if (Gn[GLtmp] == IdKatakana) b = b | 0x80;
2698
2699 PutChar(b);
2700 SSflag = FALSE;
2701 return TRUE;
2702 }
2703
2704 if ((! EUCsupIn) && (! EUCkanaIn) &&
2705 (! KanjiIn) && CheckKanji(b))
2706 {
2707 Kanji = b << 8;
2708 KanjiIn = TRUE;
2709 return TRUE;
2710 }
2711
2712 if (b<=US)
2713 ParseControl(b);
2714 else if (b==0x20)
2715 PutChar(b);
2716 else if ((b>=0x21) && (b<=0x7E))
2717 {
2718 if (EUCsupIn)
2719 {
2720 EUCcount--;
2721 EUCsupIn = (EUCcount==0);
2722 return TRUE;
2723 }
2724
2725 if ((Gn[Glr[0]] == IdKatakana) || EUCkanaIn)
2726 {
2727 b = b | 0x80;
2728 EUCkanaIn = FALSE;
2729 }
2730 PutChar(b);
2731 }
2732 else if (b==0x7f)
2733 return TRUE;
2734 else if ((b>=0x80) && (b<=0x8D))
2735 ParseControl(b);
2736 else if (b==0x8E)
2737 {
2738 if (ts.KanjiCode==IdEUC)
2739 EUCkanaIn = TRUE;
2740 else
2741 ParseControl(b);
2742 }
2743 else if (b==0x8F)
2744 {
2745 if (ts.KanjiCode==IdEUC)
2746 {
2747 EUCcount = 2;
2748 EUCsupIn = TRUE;
2749 } else
2750 ParseControl(b);
2751 }
2752 else if ((b>=0x90) && (b<=0x9F))
2753 ParseControl(b);
2754 else if (b==0xA0)
2755 PutChar(0x20);
2756 else if ((b>=0xA1) && (b<=0xFE))
2757 {
2758 if (EUCsupIn)
2759 {
2760 EUCcount--;
2761 EUCsupIn = (EUCcount==0);
2762 return TRUE;
2763 }
2764
2765 if ((Gn[Glr[1]] != IdASCII) ||
2766 (ts.KanjiCode==IdEUC) && EUCkanaIn ||
2767 (ts.KanjiCode==IdSJIS) ||
2768 (ts.KanjiCode==IdJIS) &&
2769 (ts.JIS7Katakana==0) &&
2770 ((ts.TermFlag & TF_FIXEDJIS)!=0))
2771 PutChar(b); // katakana
2772 else {
2773 if (Gn[Glr[1]] == IdASCII)
2774 b = b & 0x7f;
2775 PutChar(b);
2776 }
2777 EUCkanaIn = FALSE;
2778 }
2779 else
2780 PutChar(b);
2781
2782 return TRUE;
2783 }
2784
2785
2786 static void ParseASCII(BYTE b)
2787 {
2788 if (b<=US) {
2789 ParseControl(b);
2790 } else if ((b>=0x20) && (b<=0x7E)) {
2791 //Kanji = 0;
2792 //PutKanji(b);
2793 PutChar(b);
2794 } else if ((b>=0x80) && (b<=0x9F)) {
2795 ParseControl(b);
2796 } else if (b>=0xA0) {
2797 //Kanji = 0;
2798 //PutKanji(b);
2799 PutChar(b);
2800 }
2801 }
2802
2803 //
2804 // UTF-8
2805 //
2806 #include "uni2sjis.map"
2807 #include "unisym2decsp.map"
2808 extern unsigned short ConvertUnicode(unsigned short code, codemap_t *table, int tmax);
2809
2810
2811 //
2812 // UTF-8 for Mac OS X(HFS plus)
2813 //
2814 #include "hfs_plus.map"
2815
2816 unsigned short GetIllegalUnicode(int start_index, unsigned short first_code, unsigned short code,
2817 hfsplus_codemap_t *table, int tmax)
2818 {
2819 unsigned short result = 0;
2820 int i;
2821
2822 for (i = start_index ; i < tmax ; i++) {
2823 if (table[i].first_code != first_code) { // 1�������������������A���~���������������������B
2824 break;
2825 }
2826
2827 if (table[i].second_code == code) {
2828 result = table[i].illegal_code;
2829 break;
2830 }
2831 }
2832
2833 return (result);
2834 }
2835
2836 int GetIndexOfHFSPlusFirstCode(unsigned short code, hfsplus_codemap_t *table, int tmax)
2837 {
2838 int low, mid, high;
2839 int index = -1;
2840
2841 low = 0;
2842 high = tmax - 1;
2843
2844 // binary search
2845 while (low < high) {
2846 mid = (low + high) / 2;
2847 if (table[mid].first_code < code) {
2848 low = mid + 1;
2849 } else {
2850 high = mid;
2851 }
2852 }
2853
2854 if (table[low].first_code == code) {
2855 while (low >= 0 && table[low].first_code == code) {
2856 index = low;
2857 low--;
2858 }
2859 }
2860
2861 return (index);
2862 }
2863
2864
2865 static void UnicodeToCP932(unsigned int code, int byte)
2866 {
2867 int ret;
2868 char mbchar[32];
2869 unsigned char wchar[32];
2870 unsigned short cset = 0;
2871
2872 #if 0
2873 Kanji = code & 0xff00;
2874 PutKanji(code & 0x00ff);
2875 return;
2876 #else
2877
2878 wchar[0] = code & 0xff;
2879 wchar[1] = (code >> 8) & 0xff;
2880
2881 if (ts.UnicodeDecSpMapping) {
2882 cset = ConvertUnicode(code, mapUnicodeSymbolToDecSp, sizeof(mapUnicodeSymbolToDecSp)/sizeof(mapUnicodeSymbolToDecSp[0]));
2883 }
2884 if (((cset >> 8) & ts.UnicodeDecSpMapping) != 0) {
2885 PutDecSp(cset & 0xff);
2886 }
2887 else {
2888 // Unicode -> CP932
2889 ret = wctomb(mbchar, ((wchar_t *)wchar)[0]);
2890 switch (ret) {
2891 case -1:
2892 if (_stricmp(ts.Locale, DEFAULT_LOCALE) == 0) {
2893 // U+301C�������������������BUnicode -> Shift_JIS���������������B
2894 cset = ConvertUnicode(code, mapUnicodeToSJIS, sizeof(mapUnicodeToSJIS)/sizeof(mapUnicodeToSJIS[0]));
2895 if (cset != 0) {
2896 Kanji = cset & 0xff00;
2897 PutKanji(cset & 0x00ff);
2898 }
2899 }
2900
2901 if (cset == 0) {
2902 ParseASCII('?');
2903 if (ts.UnknownUnicodeCharaAsWide) {
2904 ParseASCII('?');
2905 }
2906 }
2907 break;
2908 case 1:
2909 ParseASCII(mbchar[0]);
2910 break;
2911 default:
2912 Kanji = mbchar[0] << 8;
2913 PutKanji(mbchar[1]);
2914 break;
2915 }
2916 }
2917 #endif
2918 }
2919
2920 // UTF-8�����M�f�[�^����������
2921 BOOL ParseFirstUTF8(BYTE b, int hfsplus_mode)
2922 // returns TRUE if b is processed
2923 // (actually allways returns TRUE)
2924 {
2925 static BYTE buf[3];
2926 static int count = 0;
2927 static int maybe_hfsplus = 0;
2928 static unsigned int first_code;
2929 static int first_code_index;
2930
2931 unsigned int code;
2932 char mbchar[32];
2933 unsigned short cset;
2934 char *locptr;
2935
2936 locptr = setlocale(LC_ALL, ts.Locale);
2937
2938 if ((b & 0x80) != 0x80 || ((b & 0xe0) == 0x80 && count == 0)) {
2939 // 1�o�C�g��������2�o�C�g����ASCII���������A������ASCII�o���������B
2940 // 1�o�C�g����C1��������(0x80-0x9f)�����������l�B
2941 if (count == 0 || count == 1) {
2942 if (hfsplus_mode == 1 && maybe_hfsplus == 1) {
2943 UnicodeToCP932(first_code, 3);
2944 maybe_hfsplus = 0;
2945 }
2946
2947 if (count == 1) {
2948 ParseASCII(buf[0]);
2949 //code = buf[0];
2950 //UnicodeToCP932(code, 2);
2951 }
2952 ParseASCII(b);
2953 //code = b;
2954 //UnicodeToCP932(code, 2);
2955
2956 count = 0; // reset counter
2957 return TRUE;
2958 }
2959 }
2960
2961 if (count < 2) {
2962 buf[count++] = b;
2963 return TRUE;
2964 }
2965
2966 memset(mbchar, 0, sizeof(mbchar));
2967
2968 // 2�o�C�g�R�[�h������
2969 if ((buf[0] & 0xe0) == 0xc0 &&
2970 (buf[1] & 0xc0) == 0x80) {
2971
2972 if (hfsplus_mode == 1 && maybe_hfsplus == 1) {
2973 UnicodeToCP932(first_code, 3);
2974 maybe_hfsplus = 0;
2975 }
2976
2977 code = ((buf[0] & 0x1f) << 6);
2978 code |= ((buf[1] & 0x3f));
2979
2980 UnicodeToCP932(code, 2);
2981
2982 // �����o�C�g��ASCII�������������\�� (2006.6.30 yutaka)
2983 if ((b & 0x80) != 0x80) { // ASCII(0x00-0x7f)
2984 ParseASCII(b);
2985 count = 0; // reset counter
2986
2987 } else {
2988 // ASCII�������������A�}���`�o�C�g�������n�������������B
2989 buf[0] = b;
2990 count = 1;
2991 }
2992
2993 return TRUE;
2994 }
2995
2996 buf[count++] = b;
2997
2998 if ((buf[0] & 0xe0) == 0xe0 &&
2999 (buf[1] & 0xc0) == 0x80 &&
3000 (buf[2] & 0xc0) == 0x80) { // 3�o�C�g�R�[�h������
3001
3002 // UTF-8 BOM(Byte Order Mark)
3003 if (buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf) {
3004 goto skip;
3005 }
3006
3007 code = ((buf[0] & 0xf) << 12);
3008 code |= ((buf[1] & 0x3f) << 6);
3009 code |= ((buf[2] & 0x3f));
3010
3011 if (hfsplus_mode == 1) {
3012 if (maybe_hfsplus == 0) {
3013 if ((first_code_index = GetIndexOfHFSPlusFirstCode(
3014 code, mapHFSPlusUnicode, sizeof(mapHFSPlusUnicode)/sizeof(mapHFSPlusUnicode[0])
3015 )) != -1) {
3016 maybe_hfsplus = 1;
3017 first_code = code;
3018 count = 0;
3019 return (TRUE);
3020 }
3021 } else {
3022 maybe_hfsplus = 0;
3023 cset = GetIllegalUnicode(first_code_index, first_code, code, mapHFSPlusUnicode, sizeof(mapHFSPlusUnicode)/sizeof(mapHFSPlusUnicode[0]));
3024 if (cset != 0) { // success
3025 code = cset;
3026
3027 } else { // error
3028 // 2�����������������_��1�����������������������A���x�������������B(2005.10.15 yutaka)
3029 if ((first_code_index = GetIndexOfHFSPlusFirstCode(
3030 code, mapHFSPlusUnicode, sizeof(mapHFSPlusUnicode)/sizeof(mapHFSPlusUnicode[0])
3031 )) != -1) {
3032
3033 // 1���������������������o������
3034 UnicodeToCP932(first_code, 3);
3035
3036 maybe_hfsplus = 1;
3037 first_code = code;
3038 count = 0;
3039 return (TRUE);
3040 }
3041
3042 UnicodeToCP932(first_code, 3);
3043 UnicodeToCP932(code, 3);
3044 count = 0;
3045 return (TRUE);
3046 }
3047 }
3048 }
3049
3050 UnicodeToCP932(code, 3);
3051
3052 skip:
3053 count = 0;
3054
3055 } else {
3056 ParseASCII(buf[0]);
3057 ParseASCII(buf[1]);
3058 ParseASCII(buf[2]);
3059 count = 0;
3060
3061 }
3062
3063 return TRUE;
3064 }
3065
3066
3067 BOOL ParseFirstRus(BYTE b)
3068 // returns if b is processed
3069 {
3070 if (b>=128)
3071 {
3072 b = RussConv(ts.RussHost,ts.RussClient,b);
3073 PutChar(b);
3074 return TRUE;
3075 }
3076 return FALSE;
3077 }
3078
3079 void ParseFirst(BYTE b)
3080 {
3081 // UTF-8����������������������
3082 if ((ts.Language==IdKorean && ts.KanjiCode == IdUTF8) &&
3083 ParseFirstUTF8(b, 0)) {
3084 return;
3085 } else if ((ts.Language==IdJapanese && ts.KanjiCode == IdUTF8) &&
3086 ParseFirstUTF8(b, 0)) {
3087 return;
3088 } else if ((ts.Language==IdJapanese && ts.KanjiCode == IdUTF8m) &&
3089 ParseFirstUTF8(b, 1)) {
3090 return;
3091 } else if ((ts.Language==IdJapanese) &&
3092 ParseFirstJP(b)) return;
3093 else if ((ts.Language==IdRussian) &&
3094 ParseFirstRus(b)) return;
3095
3096 if (SSflag)
3097 {
3098 PutChar(b);
3099 SSflag = FALSE;
3100 return;
3101 }
3102
3103 if (b<=US)
3104 ParseControl(b);
3105 else if ((b>=0x20) && (b<=0x7E))
3106 PutChar(b);
3107 else if ((b>=0x80) && (b<=0x9F))
3108 ParseControl(b);
3109 else if (b>=0xA0)
3110 PutChar(b);
3111 }
3112
3113 int VTParse()
3114 {
3115 BYTE b;
3116 int c;
3117
3118 c = CommRead1Byte(&cv,&b);
3119
3120 if (c==0) return 0;
3121
3122 CaretOff();
3123 UpdateCaretKillFocus(FALSE); // ���A�N�e�B�u�������������`������
3124
3125 ChangeEmu = 0;
3126
3127 /* Get Device Context */
3128 DispInitDC();
3129
3130 LockBuffer();
3131
3132 while ((c>0) && (ChangeEmu==0))
3133 {
3134 if (DebugFlag)
3135 PutDebugChar(b);
3136 else {
3137 switch (ParseMode) {
3138 case ModeFirst: ParseFirst(b); break;
3139 case ModeESC: EscapeSequence(b); break;
3140 case ModeDCS: DeviceControl(b); break;
3141 case ModeDCUserKey: DCUserKey(b); break;
3142 case ModeSOS: IgnoreString(b); break;
3143 case ModeCSI: ControlSequence(b); break;
3144 case ModeXS: XSequence(b); break;
3145 case ModeDLE: DLESeen(b); break;
3146 case ModeCAN: CANSeen(b); break;
3147 default:
3148 ParseMode = ModeFirst;
3149 ParseFirst(b);
3150 }
3151 }
3152
3153 if (ChangeEmu==0)
3154 c = CommRead1Byte(&cv,&b);
3155 }
3156
3157 BuffUpdateScroll();
3158
3159 BuffSetCaretWidth();
3160 UnlockBuffer();
3161
3162 /* release device context */
3163 DispReleaseDC();
3164
3165 CaretOn();
3166
3167 if (ChangeEmu > 0) ParseMode = ModeFirst;
3168 return ChangeEmu;
3169 }
3170
3171 int MakeMouseReportStr(char *buff, size_t buffsize, int mb, int x, int y) {
3172 if (Send8BitMode)
3173 return _snprintf_s_l(buff, buffsize, _TRUNCATE, "\233M%c%c%c", CLocale, mb+32, x+32, y+32);
3174 else
3175 return _snprintf_s_l(buff, buffsize, _TRUNCATE, "\033[M%c%c%c", CLocale, mb+32, x+32, y+32);
3176 }
3177
3178 BOOL MouseReport(int Event, int Button, int Xpos, int Ypos) {
3179 char Report[10];
3180 int x, y, len, modifier;
3181
3182 len = 0;
3183
3184 if (MouseReportMode == IdMouseTrackNone)
3185 return FALSE;
3186
3187 if (ts.DisableMouseTrackingByCtrl && ControlKey())
3188 return FALSE;
3189
3190 DispConvWinToScreen(Xpos, Ypos, &x, &y, NULL);
3191 x++; y++;
3192
3193 if (x < 1) x = 1;
3194 if (y < 1) y = 1;
3195
3196 if (MouseReportMode != IdMouseTrackDECELR) {
3197 if (x > 0xff - 32) x = 0xff - 32;
3198 if (x > 0xff - 32) y = 0xff - 32;
3199 }
3200
3201 if (ShiftKey())
3202 modifier = 4;
3203 else
3204 modifier = 0;
3205
3206 if (ControlKey())
3207 modifier |= 8;
3208
3209 if (AltKey())
3210 modifier |= 16;
3211
3212 modifier = (ShiftKey()?4:0) | (ControlKey()?8:0) | (AltKey()?16:0);
3213
3214 switch (Event) {
3215 case IdMouseEventBtnDown:
3216 switch (MouseReportMode) {
3217 case IdMouseTrackX10:
3218 len = MakeMouseReportStr(Report, sizeof Report, Button, x, y);
3219 break;
3220
3221 case IdMouseTrackVT200:
3222 case IdMouseTrackBtnEvent:
3223 case IdMouseTrackAllEvent:
3224 len = MakeMouseReportStr(Report, sizeof Report, Button | modifier, x, y);
3225 break;
3226
3227 case IdMouseTrackDECELR: /* not supported yet */
3228 case IdMouseTrackVT200Hl: /* not supported yet */
3229 default:
3230 return FALSE;
3231 }
3232 break;
3233
3234 case IdMouseEventBtnUp:
3235 switch (MouseReportMode) {
3236 case IdMouseTrackVT200:
3237 case IdMouseTrackBtnEvent:
3238 case IdMouseTrackAllEvent:
3239 len = MakeMouseReportStr(Report, sizeof Report, 3 | modifier, x, y);
3240 break;
3241
3242 case IdMouseTrackX10: /* nothing to do */
3243 case IdMouseTrackDECELR: /* not supported yet */
3244 case IdMouseTrackVT200Hl: /* not supported yet */
3245 default:
3246 return FALSE;
3247 }
3248 break;
3249
3250 case IdMouseEventMove:
3251 switch (MouseReportMode) {
3252 case IdMouseTrackBtnEvent: /* not supported yet */
3253 case IdMouseTrackAllEvent: /* not supported yet */
3254 case IdMouseTrackDECELR: /* not supported yet */
3255 case IdMouseTrackVT200Hl: /* not supported yet */
3256 case IdMouseTrackX10: /* nothing to do */
3257 case IdMouseTrackVT200: /* nothing to do */
3258 default:
3259 return FALSE;
3260 }
3261 break;
3262
3263 case IdMouseEventWheel:
3264 switch (MouseReportMode) {
3265 case IdMouseTrackVT200:
3266 case IdMouseTrackBtnEvent:
3267 case IdMouseTrackAllEvent:
3268 len = MakeMouseReportStr(Report, sizeof Report, Button | modifier | 64, x, y);
3269 break;
3270
3271 case IdMouseTrackX10: /* nothing to do */
3272 case IdMouseTrackDECELR: /* not supported yet */
3273 case IdMouseTrackVT200Hl: /* not supported yet */
3274 return FALSE;
3275 }
3276 break;
3277 }
3278
3279 if (len == 0)
3280 return FALSE;
3281
3282 CommBinaryOut(&cv, Report, len);
3283 return TRUE;
3284 }
3285
3286 void FocusReport(BOOL focus) {
3287 if (!FocusReportMode)
3288 return;
3289
3290 if (focus) {
3291 // Focus In
3292 if (Send8BitMode) {
3293 CommBinaryOut(&cv,"\233I",2);
3294 } else {
3295 CommBinaryOut(&cv,"\033[I",3);
3296 }
3297 } else {
3298 // Focus Out
3299 if (Send8BitMode) {
3300 CommBinaryOut(&cv,"\233O",2);
3301 } else {
3302 CommBinaryOut(&cv,"\033[O",3);
3303 }
3304 }
3305 }
3306
3307 void VisualBell() {
3308 CSQExchangeColor();
3309 Sleep(10);
3310 CSQExchangeColor();
3311 }

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