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 2666 - (show annotations) (download) (as text)
Mon Mar 2 01:43:13 2009 UTC (15 years, 1 month ago) by doda
Original Path: teraterm/trunk/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 70366 byte(s)
属性色およびANSIカラー表示を無効にできるようにした。

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

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