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 2558 - (show annotations) (download) (as text)
Wed Jul 9 06:06:56 2008 UTC (15 years, 9 months ago) by doda
Original Path: teraterm/trunk/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 69323 byte(s)
リモートからのウィンドウタイトル変更要求を受け入れるかを設定できるようにした。
http://sourceforge.jp/tracker/index.php?func=detail&aid=12951&group_id=1412&atid=5333

設定パラメータ名は暫定であり、要検討。

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

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