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 2527 - (show annotations) (download) (as text)
Fri May 23 09:48:19 2008 UTC (15 years, 10 months ago) by doda
Original Path: teraterm/trunk/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 68492 byte(s)
受信漢字コードがUTF-8の時、C1制御文字による制御シーケンスが正しく扱えないのを修正した。

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

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