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 2551 - (show annotations) (download) (as text)
Thu Jul 3 20:14:09 2008 UTC (15 years, 9 months ago) by doda
Original Path: teraterm/trunk/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 68817 byte(s)
CBT制御シーケンスに対応。

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

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