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 3310 - (show annotations) (download) (as text)
Wed Apr 15 03:40:16 2009 UTC (14 years, 11 months ago) by doda
File MIME type: text/x-csrc
File size: 76096 byte(s)
ウィンドウリフレッシュ制御シーケンス(dtterm由来?)に対応
  <CSI> 7 t

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