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 2708 - (show annotations) (download) (as text)
Wed Mar 18 18:42:00 2009 UTC (15 years ago) by doda
Original Path: teraterm/trunk/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 70347 byte(s)
Reverse Video Mode(DECSCNM)が壊れていたのを修正。[Ttssh2-devel 1392]

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 }
1475 }
1476
1477 void CS_i_Mode()
1478 {
1479 if (Param[1]==-1) Param[1] = 0;
1480 switch (Param[1]) {
1481 /* print screen */
1482 // PrintEX -- TRUE: print screen
1483 // FALSE: scroll region
1484 case 0: BuffPrint(! PrintEX); break;
1485 /* printer controller mode off */
1486 case 4: break; /* See PrnParseCS() */
1487 /* printer controller mode on */
1488 case 5:
1489 if (! AutoPrintMode)
1490 OpenPrnFile();
1491 DirectPrn = (ts.PrnDev[0]!=0);
1492 PrinterMode = TRUE;
1493 break;
1494 }
1495 }
1496
1497 void CS_l_Mode()
1498 {
1499 switch (Param[1]) {
1500 case 2: KeybEnabled = TRUE; break;
1501 case 4: InsertMode = FALSE; break;
1502 case 12:
1503 ts.LocalEcho = 1;
1504 if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1505 TelChangeEcho();
1506 break;
1507 case 20:
1508 LFMode = FALSE;
1509 ts.CRSend = IdCR;
1510 cv.CRSend = IdCR;
1511 break;
1512 }
1513 }
1514
1515 void CS_n_Mode()
1516 {
1517 char Report[16];
1518 int Y;
1519
1520 switch (Param[1]) {
1521 case 5:
1522 if (Send8BitMode)
1523 CommBinaryOut(&cv,"\2330n",3); /* Device Status Report -> Ready */
1524 else
1525 CommBinaryOut(&cv,"\033[0n",4); /* Device Status Report -> Ready */
1526 break;
1527 case 6:
1528 /* Cursor Position Report */
1529 Y = CursorY+1;
1530 if ((StatusLine>0) &&
1531 (Y==NumOfLines))
1532 Y = 1;
1533 if (Send8BitMode)
1534 _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\233%u;%uR", CLocale, Y, CursorX+1);
1535 else
1536 _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\033[%u;%uR", CLocale, Y, CursorX+1);
1537 CommBinaryOut(&cv,Report,strlen(Report));
1538 break;
1539 }
1540 }
1541
1542 void CSSetAttr()
1543 {
1544 int i, P;
1545
1546 UpdateStr();
1547 for (i=1 ; i<=NParam ; i++)
1548 {
1549 P = Param[i];
1550 if (P<0) P = 0;
1551 switch (P) {
1552 case 0: /* Clear all */
1553 CharAttr = DefCharAttr;
1554 BuffSetCurCharAttr(CharAttr);
1555 break;
1556
1557 case 1: /* Bold */
1558 CharAttr.Attr |= AttrBold;
1559 BuffSetCurCharAttr(CharAttr);
1560 break;
1561
1562 case 4: /* Under line */
1563 CharAttr.Attr |= AttrUnder;
1564 BuffSetCurCharAttr(CharAttr);
1565 break;
1566
1567 case 5: /* Blink */
1568 CharAttr.Attr |= AttrBlink;
1569 BuffSetCurCharAttr(CharAttr);
1570 break;
1571
1572 case 7: /* Reverse */
1573 CharAttr.Attr |= AttrReverse;
1574 BuffSetCurCharAttr(CharAttr);
1575 break;
1576
1577 case 22: /* Bold off */
1578 CharAttr.Attr &= ~ AttrBold;
1579 BuffSetCurCharAttr(CharAttr);
1580 break;
1581
1582 case 24: /* Under line off */
1583 CharAttr.Attr &= ~ AttrUnder;
1584 BuffSetCurCharAttr(CharAttr);
1585 break;
1586
1587 case 25: /* Blink off */
1588 CharAttr.Attr &= ~ AttrBlink;
1589 BuffSetCurCharAttr(CharAttr);
1590 break;
1591
1592 case 27: /* Reverse off */
1593 CharAttr.Attr &= ~ AttrReverse;
1594 BuffSetCurCharAttr(CharAttr);
1595 break;
1596
1597 case 30:
1598 case 31:
1599 case 32:
1600 case 33:
1601 case 34:
1602 case 35:
1603 case 36:
1604 case 37: /* text color */
1605 CharAttr.Attr2 |= Attr2Fore;
1606 CharAttr.Fore = P - 30;
1607 BuffSetCurCharAttr(CharAttr);
1608 break;
1609
1610 case 38: /* text color (256color mode) */
1611 if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1612 i++;
1613 if (i < NParam) {
1614 P = Param[++i];
1615 if (P<0) {
1616 P = 0;
1617 }
1618 CharAttr.Attr2 |= Attr2Fore;
1619 CharAttr.Fore = P;
1620 BuffSetCurCharAttr(CharAttr);
1621 }
1622 }
1623 break;
1624
1625 case 39: /* Reset text color */
1626 CharAttr.Attr2 &= ~ Attr2Fore;
1627 CharAttr.Fore = AttrDefaultFG;
1628 BuffSetCurCharAttr(CharAttr);
1629 break;
1630
1631 case 40:
1632 case 41:
1633 case 42:
1634 case 43:
1635 case 44:
1636 case 45:
1637 case 46:
1638 case 47: /* Back color */
1639 CharAttr.Attr2 |= Attr2Back;
1640 CharAttr.Back = P - 40;
1641 BuffSetCurCharAttr(CharAttr);
1642 break;
1643
1644 case 48: /* Back color (256color mode) */
1645 if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1646 i++;
1647 if (i < NParam) {
1648 P = Param[++i];
1649 if (P<0) {
1650 P = 0;
1651 }
1652 CharAttr.Attr2 |= Attr2Back;
1653 CharAttr.Back = P;
1654 BuffSetCurCharAttr(CharAttr);
1655 }
1656 }
1657 break;
1658
1659 case 49: /* Reset back color */
1660 CharAttr.Attr2 &= ~ Attr2Back;
1661 CharAttr.Back = AttrDefaultBG;
1662 BuffSetCurCharAttr(CharAttr);
1663 break;
1664
1665 case 90:
1666 case 91:
1667 case 92:
1668 case 93:
1669 case 94:
1670 case 95:
1671 case 96:
1672 case 97: /* aixterm style text color */
1673 if (ts.ColorFlag & CF_AIXTERM16) {
1674 CharAttr.Attr2 |= Attr2Fore;
1675 CharAttr.Fore = P - 90 + 8;
1676 BuffSetCurCharAttr(CharAttr);
1677 }
1678 break;
1679
1680 case 100:
1681 if (! (ts.ColorFlag & CF_AIXTERM16)) {
1682 /* Reset text and back color */
1683 CharAttr.Attr2 &= ~ (Attr2Fore | Attr2Back);
1684 CharAttr.Fore = AttrDefaultFG;
1685 CharAttr.Back = AttrDefaultBG;
1686 BuffSetCurCharAttr(CharAttr);
1687 break;
1688 }
1689 /* fall through to aixterm style back color */
1690
1691 case 101:
1692 case 102:
1693 case 103:
1694 case 104:
1695 case 105:
1696 case 106:
1697 case 107: /* aixterm style back color */
1698 if (ts.ColorFlag & CF_AIXTERM16) {
1699 CharAttr.Attr2 |= Attr2Back;
1700 CharAttr.Back = P - 100 + 8;
1701 BuffSetCurCharAttr(CharAttr);
1702 }
1703 break;
1704 }
1705 }
1706 }
1707
1708 void CSSetScrollRegion()
1709 {
1710 if ((StatusLine>0) &&
1711 (CursorY==NumOfLines-1))
1712 {
1713 MoveCursor(0,CursorY);
1714 return;
1715 }
1716 if (Param[1]<1) Param[1] =1;
1717 if ((NParam < 2) | (Param[2]<1))
1718 Param[2] = NumOfLines-StatusLine;
1719 Param[1]--;
1720 Param[2]--;
1721 if (Param[1] > NumOfLines-1-StatusLine)
1722 Param[1] = NumOfLines-1-StatusLine;
1723 if (Param[2] > NumOfLines-1-StatusLine)
1724 Param[2] = NumOfLines-1-StatusLine;
1725 if (Param[1] >= Param[2]) return;
1726 CursorTop = Param[1];
1727 CursorBottom = Param[2];
1728 if (RelativeOrgMode) MoveCursor(0,CursorTop);
1729 else MoveCursor(0,0);
1730 }
1731
1732 void CSSunSequence() /* Sun terminal private sequences */
1733 {
1734 char Report[16];
1735
1736 switch (Param[1]) {
1737 case 8: /* set terminal size */
1738 if ((Param[2]<=1) || (NParam<2)) Param[2] = 24;
1739 if ((Param[3]<=1) || (NParam<3)) Param[3] = 80;
1740 ChangeTerminalSize(Param[3],Param[2]);
1741 break;
1742 case 14: /* get window size??? */
1743 /* this is not actual window size */
1744 if (Send8BitMode)
1745 CommBinaryOut(&cv,"\2334;640;480t",11);
1746 else
1747 CommBinaryOut(&cv,"\033[4;640;480t",12);
1748 break;
1749 case 18: /* get terminal size */
1750 if (Send8BitMode)
1751 _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\2338;%u;%u;t", CLocale, NumOfLines-StatusLine, NumOfColumns);
1752 else
1753 _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\033[8;%u;%u;t", CLocale, NumOfLines-StatusLine, NumOfColumns);
1754 CommBinaryOut(&cv,Report,strlen(Report));
1755 break;
1756 }
1757 }
1758
1759 void CSGT(BYTE b)
1760 {
1761 switch (b) {
1762 case 'c': /* second terminal report */
1763 if (Send8BitMode)
1764 CommBinaryOut(&cv,"\233>32;10;2c",11); /* VT382 */
1765 else
1766 CommBinaryOut(&cv,"\033[>32;10;2c",11); /* VT382 */
1767 break;
1768 case 'J':
1769 if (Param[1]==3) // IO-8256 terminal
1770 {
1771 if (Param[2]<1) Param[2]=1;
1772 if (Param[3]<1) Param[3]=1;
1773 if (Param[4]<1) Param[4]=1;
1774 if (Param[5]<1) Param[5]=1;
1775 BuffEraseBox(Param[3]-1,Param[2]-1,
1776 Param[5]-1,Param[4]-1);
1777 }
1778 break;
1779 case 'K':
1780 if ((NParam>=2) && (Param[1]==5))
1781 { // IO-8256 terminal
1782 switch (Param[2]) {
1783 case 3:
1784 case 4:
1785 case 5:
1786 case 6:
1787 BuffDrawLine(CharAttr, Param[2], Param[3]);
1788 break;
1789 case 12:
1790 /* Text color */
1791 if ((Param[3]>=0) && (Param[3]<=7))
1792 {
1793 switch (Param[3]) {
1794 case 3: CharAttr.Fore = IdBlue; break;
1795 case 4: CharAttr.Fore = IdCyan; break;
1796 case 5: CharAttr.Fore = IdYellow; break;
1797 case 6: CharAttr.Fore = IdMagenta; break;
1798 default: CharAttr.Fore = Param[3]; break;
1799 }
1800 CharAttr.Attr2 |= Attr2Fore;
1801 BuffSetCurCharAttr(CharAttr);
1802 }
1803 break;
1804 }
1805 }
1806 else if (Param[1]==3)
1807 {// IO-8256 terminal
1808 if (Param[2]<1) Param[2] = 1;
1809 if (Param[3]<1) Param[2] = 1;
1810 BuffEraseCharsInLine(Param[2]-1,Param[3]-Param[2]+1);
1811 }
1812 break;
1813 }
1814 }
1815
1816 void CSQExchangeColor()
1817 {
1818 COLORREF ColorRef;
1819
1820 BuffUpdateScroll();
1821
1822 if (ts.ColorFlag & CF_REVERSECOLOR) {
1823 ColorRef = ts.VTColor[0];
1824 ts.VTColor[0] = ts.VTReverseColor[0];
1825 ts.VTReverseColor[0] = ColorRef;
1826 ColorRef = ts.VTColor[1];
1827 ts.VTColor[1] = ts.VTReverseColor[1];
1828 ts.VTReverseColor[1] = ColorRef;
1829 }
1830 else {
1831 ColorRef = ts.VTColor[0];
1832 ts.VTColor[0] = ts.VTColor[1];
1833 ts.VTColor[1] = ColorRef;
1834 }
1835
1836 ColorRef = ts.VTBoldColor[0];
1837 ts.VTBoldColor[0] = ts.VTBoldColor[1];
1838 ts.VTBoldColor[1] = ColorRef;
1839
1840 ColorRef = ts.VTBlinkColor[0];
1841 ts.VTBlinkColor[0] = ts.VTBlinkColor[1];
1842 ts.VTBlinkColor[1] = ColorRef;
1843
1844 ColorRef = ts.URLColor[0];
1845 ts.URLColor[0] = ts.URLColor[1];
1846 ts.URLColor[1] = ColorRef;
1847
1848 ts.ColorFlag ^= CF_REVERSEVIDEO;
1849
1850 #ifdef ALPHABLEND_TYPE2
1851 BGInitialize();
1852 #endif
1853 DispChangeBackground();
1854 UpdateWindow(HVTWin);
1855 }
1856
1857 void CSQ_h_Mode()
1858 {
1859 int i;
1860
1861 for (i = 1 ; i<=NParam ; i++)
1862 switch (Param[i]) {
1863 case 1: AppliCursorMode = TRUE; break;
1864 case 3:
1865 ChangeTerminalSize(132,NumOfLines-StatusLine);
1866 break;
1867 case 5: /* Reverse Video */
1868 if (!(ts.ColorFlag & CF_REVERSEVIDEO))
1869 CSQExchangeColor(); /* Exchange text/back color */
1870 break;
1871 case 6:
1872 if ((StatusLine>0) &&
1873 (CursorY==NumOfLines-1))
1874 MoveCursor(0,CursorY);
1875 else {
1876 RelativeOrgMode = TRUE;
1877 MoveCursor(0,CursorTop);
1878 }
1879 break;
1880 case 7: AutoWrapMode = TRUE; break;
1881 case 8: AutoRepeatMode = TRUE; break;
1882 case 9:
1883 if (ts.MouseEventTracking)
1884 MouseReportMode = IdMouseTrackX10;
1885 break;
1886 case 19: PrintEX = TRUE; break;
1887 case 25: DispEnableCaret(TRUE); break; // cursor on
1888 case 38:
1889 if (ts.AutoWinSwitch>0)
1890 ChangeEmu = IdTEK; /* Enter TEK Mode */
1891 break;
1892 case 59:
1893 if (ts.Language==IdJapanese)
1894 { /* kanji terminal */
1895 Gn[0] = IdASCII;
1896 Gn[1] = IdKatakana;
1897 Gn[2] = IdKatakana;
1898 Gn[3] = IdKanji;
1899 Glr[0] = 0;
1900 if ((ts.KanjiCode==IdJIS) &&
1901 (ts.JIS7Katakana==0))
1902 Glr[1] = 2; // 8-bit katakana
1903 else
1904 Glr[1] = 3;
1905 }
1906 break;
1907 case 66: AppliKeyMode = TRUE; break;
1908 case 67: ts.BSKey = IdBS; break;
1909 case 1000:
1910 if (ts.MouseEventTracking)
1911 MouseReportMode = IdMouseTrackVT200;
1912 break;
1913 case 1001:
1914 if (ts.MouseEventTracking)
1915 MouseReportMode = IdMouseTrackVT200Hl;
1916 break;
1917 case 1002:
1918 if (ts.MouseEventTracking)
1919 MouseReportMode = IdMouseTrackBtnEvent;
1920 break;
1921 case 1003:
1922 if (ts.MouseEventTracking)
1923 MouseReportMode = IdMouseTrackAllEvent;
1924 break;
1925 case 1004:
1926 if (ts.MouseEventTracking)
1927 FocusReportMode = TRUE;
1928 break;
1929 }
1930 }
1931
1932 void CSQ_i_Mode()
1933 {
1934 if (Param[1]==-1) Param[1] = 0;
1935 switch (Param[1]) {
1936 case 1:
1937 OpenPrnFile();
1938 BuffDumpCurrentLine(LF);
1939 if (! AutoPrintMode)
1940 ClosePrnFile();
1941 break;
1942 /* auto print mode off */
1943 case 4:
1944 if (AutoPrintMode)
1945 {
1946 ClosePrnFile();
1947 AutoPrintMode = FALSE;
1948 }
1949 break;
1950 /* auto print mode on */
1951 case 5:
1952 if (! AutoPrintMode)
1953 {
1954 OpenPrnFile();
1955 AutoPrintMode = TRUE;
1956 }
1957 break;
1958 }
1959 }
1960
1961 void CSQ_l_Mode()
1962 {
1963 int i;
1964
1965 for (i = 1 ; i <= NParam ; i++)
1966 switch (Param[i]) {
1967 case 1: AppliCursorMode = FALSE; break;
1968 case 3:
1969 ChangeTerminalSize(80,NumOfLines-StatusLine);
1970 break;
1971 case 5: /* Normal Video */
1972 if (ts.ColorFlag & CF_REVERSEVIDEO)
1973 CSQExchangeColor(); /* Exchange text/back color */
1974 break;
1975 case 6:
1976 if ((StatusLine>0) &&
1977 (CursorY==NumOfLines-1))
1978 MoveCursor(0,CursorY);
1979 else {
1980 RelativeOrgMode = FALSE;
1981 MoveCursor(0,0);
1982 }
1983 break;
1984 case 7: AutoWrapMode = FALSE; break;
1985 case 8: AutoRepeatMode = FALSE; break;
1986 case 9: MouseReportMode = IdMouseTrackNone; break;
1987 case 19: PrintEX = FALSE; break;
1988 case 25: DispEnableCaret(FALSE); break; // cursor off
1989 case 59:
1990 if (ts.Language==IdJapanese)
1991 { /* katakana terminal */
1992 Gn[0] = IdASCII;
1993 Gn[1] = IdKatakana;
1994 Gn[2] = IdKatakana;
1995 Gn[3] = IdKanji;
1996 Glr[0] = 0;
1997 if ((ts.KanjiCode==IdJIS) &&
1998 (ts.JIS7Katakana==0))
1999 Glr[1] = 2; // 8-bit katakana
2000 else
2001 Glr[1] = 3;
2002 }
2003 break;
2004 case 66: AppliKeyMode = FALSE; break;
2005 case 67: ts.BSKey = IdDEL; break;
2006 case 1000:
2007 case 1001:
2008 case 1002:
2009 case 1003: MouseReportMode = IdMouseTrackNone; break;
2010 case 1004: FocusReportMode = FALSE; break;
2011 }
2012 }
2013
2014 void CSQ_n_Mode()
2015 {
2016 }
2017
2018 void CSQuest(BYTE b)
2019 {
2020 switch (b) {
2021 case 'K': CSLineErase(); break;
2022 case 'h': CSQ_h_Mode(); break;
2023 case 'i': CSQ_i_Mode(); break;
2024 case 'l': CSQ_l_Mode(); break;
2025 case 'n': CSQ_n_Mode(); break;
2026 }
2027 }
2028
2029 void SoftReset()
2030 // called by software-reset escape sequence handler
2031 {
2032 UpdateStr();
2033 AutoRepeatMode = TRUE;
2034 DispEnableCaret(TRUE); // cursor on
2035 InsertMode = FALSE;
2036 RelativeOrgMode = FALSE;
2037 AppliKeyMode = FALSE;
2038 AppliCursorMode = FALSE;
2039 if ((StatusLine>0) &&
2040 (CursorY == NumOfLines-1))
2041 MoveToMainScreen();
2042 CursorTop = 0;
2043 CursorBottom = NumOfLines-1-StatusLine;
2044 ResetCharSet();
2045
2046 Send8BitMode = ts.Send8BitCtrl;
2047
2048 /* Attribute */
2049 CharAttr = DefCharAttr;
2050 Special = FALSE;
2051 BuffSetCurCharAttr(CharAttr);
2052
2053 // status buffers
2054 ResetSBuffers();
2055 }
2056
2057 void CSExc(BYTE b)
2058 {
2059 switch (b) {
2060 case 'p':
2061 /* Software reset */
2062 SoftReset();
2063 break;
2064 }
2065 }
2066
2067 void CSDouble(BYTE b)
2068 {
2069 switch (b) {
2070 case 'p':
2071 /* Select terminal mode (software reset) */
2072 SoftReset();
2073 if (NParam > 0) {
2074 switch (Param[1]) {
2075 case 61: // VT100 Mode
2076 Send8BitMode = FALSE; break;
2077 case 62: // VT200 Mode
2078 case 63: // VT300 Mode
2079 case 64: // VT400 Mode
2080 if (NParam > 1 && Param[2] == 1)
2081 Send8BitMode = FALSE;
2082 else
2083 Send8BitMode = TRUE;
2084 break;
2085 }
2086 }
2087 break;
2088 }
2089 }
2090
2091 void CSDol(BYTE b)
2092 {
2093 switch (b) {
2094 case '}':
2095 if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2096 if (StatusLine==0) return;
2097 if ((Param[1]<1) && (CursorY==NumOfLines-1))
2098 MoveToMainScreen();
2099 else if ((Param[1]==1) && (CursorY<NumOfLines-1))
2100 MoveToStatusLine();
2101 break;
2102 case '~':
2103 if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2104 if (Param[1]<=1)
2105 HideStatusLine();
2106 else if ((StatusLine==0) && (Param[1]==2))
2107 ShowStatusLine(1); // show
2108 break;
2109 }
2110 }
2111
2112 void PrnParseCS(BYTE b) // printer mode
2113 {
2114 ParseMode = ModeFirst;
2115 switch (ICount) {
2116 /* no intermediate char */
2117 case 0:
2118 switch (Prv) {
2119 /* no private parameter */
2120 case 0:
2121 switch (b) {
2122 case 'i':
2123 if (Param[1]==4)
2124 {
2125 PrinterMode = FALSE;
2126 // clear prn buff
2127 WriteToPrnFile(0,FALSE);
2128 if (! AutoPrintMode)
2129 ClosePrnFile();
2130 return;
2131 }
2132 break;
2133 } /* of case Prv=0 */
2134 break;
2135 }
2136 break;
2137 /* one intermediate char */
2138 case 1: break;
2139 } /* of case Icount */
2140
2141 WriteToPrnFile(b,TRUE);
2142 }
2143
2144 void ParseCS(BYTE b) /* b is the final char */
2145 {
2146 if (PrinterMode) { // printer mode
2147 PrnParseCS(b);
2148 return;
2149 }
2150
2151 switch (ICount) {
2152 /* no intermediate char */
2153 case 0:
2154 switch (Prv) {
2155 /* no private parameter */
2156 case 0:
2157 switch (b) {
2158 case '@': CSInsertCharacter(); break;
2159 case 'A': CSCursorUp(); break;
2160 case 'B': CSCursorDown(); break;
2161 case 'C': CSCursorRight(); break;
2162 case 'D': CSCursorLeft(); break;
2163 case 'E': CSCursorDown1(); break;
2164 case 'F': CSCursorUp1(); break;
2165 case 'G': CSMoveToColumnN(); break;
2166 case 'H': CSMoveToXY(); break;
2167 case 'I': CSForwardTab(); break; // CHT
2168 case 'J': CSScreenErase(); break;
2169 case 'K': CSLineErase(); break;
2170 case 'L': CSInsertLine(); break;
2171 case 'M': CSDeleteNLines(); break;
2172 case 'P': CSDeleteCharacter(); break;
2173 case 'S': CSScrollUP(); break; // SU
2174 case 'T': CSScrollDown(); break; // SD
2175 case 'X': CSEraseCharacter(); break;
2176 case 'Z': CSBackwardTab(); break; // CBT
2177 case '`': CSMoveToColumnN(); break;
2178 case 'a': CSCursorRight(); break;
2179 case 'c': AnswerTerminalType(); break;
2180 case 'd': CSMoveToLineN(); break;
2181 case 'e': CSCursorUp(); break;
2182 case 'f': CSMoveToXY(); break;
2183 case 'g': CSDeleteTabStop(); break;
2184 case 'h': CS_h_Mode(); break;
2185 case 'i': CS_i_Mode(); break;
2186 case 'l': CS_l_Mode(); break;
2187 case 'm': CSSetAttr(); break;
2188 case 'n': CS_n_Mode(); break;
2189 case 'r': CSSetScrollRegion(); break;
2190 case 's': SaveCursor(); break;
2191 case 't': CSSunSequence(); break;
2192 case 'u': RestoreCursor(); break;
2193 } /* of case Prv=0 */
2194 break;
2195 /* private parameter = '>' */
2196 case '>': CSGT(b); break;
2197 /* private parameter = '?' */
2198 case '?': CSQuest(b); break;
2199 }
2200 break;
2201 /* one intermediate char */
2202 case 1:
2203 switch (IntChar[1]) {
2204 /* intermediate char = '!' */
2205 case '!': CSExc(b); break;
2206 /* intermediate char = '"' */
2207 case '"': CSDouble(b); break;
2208 /* intermediate char = '$' */
2209 case '$': CSDol(b); break;
2210 }
2211 break;
2212 } /* of case Icount */
2213
2214 ParseMode = ModeFirst;
2215 }
2216
2217 void ControlSequence(BYTE b)
2218 {
2219 if ((b<=US) || (b>=0x80) && (b<=0x9F))
2220 ParseControl(b); /* ctrl char */
2221 else if ((b>=0x40) && (b<=0x7E))
2222 ParseCS(b); /* terminate char */
2223 else {
2224 if (PrinterMode)
2225 WriteToPrnFile(b,FALSE);
2226
2227 if ((b>=0x20) && (b<=0x2F))
2228 { /* intermediate char */
2229 if (ICount<IntCharMax) ICount++;
2230 IntChar[ICount] = b;
2231 }
2232 else if ((b>=0x30) && (b<=0x39))
2233 {
2234 if (Param[NParam] < 0)
2235 Param[NParam] = 0;
2236 if (Param[NParam]<1000)
2237 Param[NParam] = Param[NParam]*10 + b - 0x30;
2238 }
2239 else if (b==0x3B)
2240 {
2241 if (NParam < NParamMax)
2242 {
2243 NParam++;
2244 Param[NParam] = -1;
2245 }
2246 }
2247 else if ((b>=0x3C) && (b<=0x3F))
2248 { /* private char */
2249 if (FirstPrm) Prv = b;
2250 }
2251 }
2252 FirstPrm = FALSE;
2253 }
2254
2255 void DeviceControl(BYTE b)
2256 {
2257 if (ESCFlag && (b=='\\') || (b==ST && ts.KanjiCode!=IdSJIS))
2258 {
2259 ESCFlag = FALSE;
2260 ParseMode = SavedMode;
2261 return;
2262 }
2263
2264 if (b==ESC)
2265 {
2266 ESCFlag = TRUE;
2267 return;
2268 }
2269 else ESCFlag = FALSE;
2270
2271 if (b<=US)
2272 ParseControl(b);
2273 else if ((b>=0x30) && (b<=0x39))
2274 {
2275 if (Param[NParam] < 0) Param[NParam] = 0;
2276 if (Param[NParam]<1000)
2277 Param[NParam] = Param[NParam]*10 + b - 0x30;
2278 }
2279 else if (b==0x3B)
2280 {
2281 if (NParam < NParamMax)
2282 {
2283 NParam++;
2284 Param[NParam] = -1;
2285 }
2286 }
2287 else if ((b>=0x40) && (b<=0x7E))
2288 {
2289 if (b=='|')
2290 {
2291 ParseMode = ModeDCUserKey;
2292 if (Param[1] < 1) ClearUserKey();
2293 WaitKeyId = TRUE;
2294 NewKeyId = 0;
2295 }
2296 else ParseMode = ModeSOS;
2297 }
2298 }
2299
2300 void DCUserKey(BYTE b)
2301 {
2302 if (ESCFlag && (b=='\\') || (b==ST && ts.KanjiCode!=IdSJIS))
2303 {
2304 if (! WaitKeyId) DefineUserKey(NewKeyId,NewKeyStr,NewKeyLen);
2305 ESCFlag = FALSE;
2306 ParseMode = SavedMode;
2307 return;
2308 }
2309
2310 if (b==ESC)
2311 {
2312 ESCFlag = TRUE;
2313 return;
2314 }
2315 else ESCFlag = FALSE;
2316
2317 if (WaitKeyId)
2318 {
2319 if ((b>=0x30) && (b<=0x39))
2320 {
2321 if (NewKeyId<1000)
2322 NewKeyId = NewKeyId*10 + b - 0x30;
2323 }
2324 else if (b==0x2F)
2325 {
2326 WaitKeyId = FALSE;
2327 WaitHi = TRUE;
2328 NewKeyLen = 0;
2329 }
2330 }
2331 else {
2332 if (b==0x3B)
2333 {
2334 DefineUserKey(NewKeyId,NewKeyStr,NewKeyLen);
2335 WaitKeyId = TRUE;
2336 NewKeyId = 0;
2337 }
2338 else {
2339 if (NewKeyLen < FuncKeyStrMax)
2340 {
2341 if (WaitHi)
2342 {
2343 NewKeyStr[NewKeyLen] = ConvHexChar(b) << 4;
2344 WaitHi = FALSE;
2345 }
2346 else {
2347 NewKeyStr[NewKeyLen] = NewKeyStr[NewKeyLen] +
2348 ConvHexChar(b);
2349 WaitHi = TRUE;
2350 NewKeyLen++;
2351 }
2352 }
2353 }
2354 }
2355 }
2356
2357 void IgnoreString(BYTE b)
2358 {
2359 if ((ESCFlag && (b=='\\')) ||
2360 (b<=US && b!=ESC && b!=HT) ||
2361 (b==ST && ts.KanjiCode!=IdSJIS))
2362 ParseMode = SavedMode;
2363
2364 if (b==ESC) ESCFlag = TRUE;
2365 else ESCFlag = FALSE;
2366 }
2367
2368 BOOL XsParseColor(char *colspec, COLORREF *color)
2369 {
2370 unsigned int r, g, b;
2371 // double dr, dg, db;
2372
2373 r = g = b = 255;
2374
2375 if (colspec == NULL || color == NULL) {
2376 return FALSE;
2377 }
2378
2379 if (_strnicmp(colspec, "rgb:", 4) == 0) {
2380 switch (strlen(colspec)) {
2381 case 9: // rgb:R/G/B
2382 if (sscanf(colspec, "rgb:%1x/%1x/%1x", &r, &g, &b) != 3) {
2383 return FALSE;
2384 }
2385 r *= 17; g *= 17; b *= 17;
2386 break;
2387 case 12: // rgb:RR/GG/BB
2388 if (sscanf(colspec, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3) {
2389 return FALSE;
2390 }
2391 break;
2392 case 15: // rgb:RRR/GGG/BBB
2393 if (sscanf(colspec, "rgb:%3x/%3x/%3x", &r, &g, &b) != 3) {
2394 return FALSE;
2395 }
2396 r >>= 4; g >>= 4; b >>= 4;
2397 break;
2398 case 18: // rgb:RRRR/GGGG/BBBB
2399 if (sscanf(colspec, "rgb:%4x/%4x/%4x", &r, &g, &b) != 3) {
2400 return FALSE;
2401 }
2402 r >>= 8; g >>= 8; b >>= 8;
2403 break;
2404 default:
2405 return FALSE;
2406 }
2407 }
2408 // else if (_strnicmp(colspec, "rgbi:", 5) == 0) {
2409 // ; /* nothing to do */
2410 // }
2411 else if (colspec[0] == '#') {
2412 switch (strlen(colspec)) {
2413 case 4: // #RGB
2414 if (sscanf(colspec, "#%1x%1x%1x", &r, &g, &b) != 3) {
2415 return FALSE;
2416 }
2417 r <<= 4; g <<= 4; b <<= 4;
2418 break;
2419 case 7: // #RRGGBB
2420 if (sscanf(colspec, "#%2x%2x%2x", &r, &g, &b) != 3) {
2421 return FALSE;
2422 }
2423 break;
2424 case 10: // #RRRGGGBBB
2425 if (sscanf(colspec, "#%3x%3x%3x", &r, &g, &b) != 3) {
2426 return FALSE;
2427 }
2428 r >>= 4; g >>= 4; b >>= 4;
2429 break;
2430 case 13: // #RRRRGGGGBBBB
2431 if (sscanf(colspec, "#%4x%4x%4x", &r, &g, &b) != 3) {
2432 return FALSE;
2433 }
2434 r >>= 8; g >>= 8; b >>= 8;
2435 break;
2436 default:
2437 return FALSE;
2438 }
2439 }
2440 else {
2441 return FALSE;
2442 }
2443
2444 if (r > 255 || g > 255 || b > 255) {
2445 return FALSE;
2446 }
2447
2448 *color = RGB(r, g, b);
2449 return TRUE;
2450 }
2451
2452 #define ModeXsFirst 1
2453 #define ModeXsString 2
2454 #define ModeXsColorNum 3
2455 #define ModeXsColorSpec 4
2456 #define ModeXsEsc 5
2457 void XSequence(BYTE b)
2458 {
2459 static BYTE XsParseMode = ModeXsFirst, PrevMode;
2460 static char StrBuff[sizeof(ts.Title)];
2461 static unsigned int ColorNumber, StrLen;
2462 COLORREF color;
2463
2464 switch (XsParseMode) {
2465 case ModeXsFirst:
2466 if (isdigit(b)) {
2467 if (Param[1] < 1000) {
2468 Param[1] = Param[1]*10 + b - '0';
2469 }
2470 }
2471 else if (b == ';') {
2472 StrBuff[0] = '\0';
2473 StrLen = 0;
2474 if (Param[1] == 4) {
2475 ColorNumber = 0;
2476 XsParseMode = ModeXsColorNum;
2477 }
2478 else {
2479 XsParseMode = ModeXsString;
2480 }
2481 }
2482 else {
2483 ParseMode = ModeFirst;
2484 }
2485 break;
2486 case ModeXsString:
2487 if ((b==ST && ts.KanjiCode!=IdSJIS) || b==BEL) { /* String Terminator */
2488 StrBuff[StrLen] = '\0';
2489 switch (Param[1]) {
2490 case 0: /* Change window title and icon name */
2491 case 1: /* Change icon name */
2492 case 2: /* Change window title */
2493 if (ts.AcceptTitleChangeRequest) {
2494 strncpy_s(cv.TitleRemote, sizeof(cv.TitleRemote), StrBuff, _TRUNCATE);
2495 // (2006.6.15 maya) �^�C�g�����n����������SJIS������
2496 ConvertToCP932(cv.TitleRemote, sizeof(cv.TitleRemote));
2497 ChangeTitle();
2498 }
2499 break;
2500 default:
2501 /* nothing to do */;
2502 }
2503 ParseMode = ModeFirst;
2504 XsParseMode = ModeXsFirst;
2505 }
2506 else if (b == ESC) { /* Escape */
2507 PrevMode = ModeXsString;
2508 XsParseMode = ModeXsEsc;
2509 }
2510 else if (b <= US) { /* Other control character -- invalid sequence */
2511 ParseMode = ModeFirst;
2512 XsParseMode = ModeXsFirst;
2513 }
2514 else if (StrLen < sizeof(StrBuff) - 1) {
2515 StrBuff[StrLen++] = b;
2516 }
2517 break;
2518 case ModeXsColorNum:
2519 if (isdigit(b)) {
2520 ColorNumber = ColorNumber*10 + b - '0';
2521 }
2522 else if (b == ';') {
2523 XsParseMode = ModeXsColorSpec;
2524 StrBuff[0] = '\0';
2525 StrLen = 0;
2526 }
2527 else {
2528 ParseMode = ModeFirst;
2529 XsParseMode = ModeXsFirst;
2530 }
2531 break;
2532 case ModeXsColorSpec:
2533 if ((b==ST && ts.KanjiCode!=IdSJIS) || b==BEL) { /* String Terminator */
2534 StrBuff[StrLen] = '\0';
2535 if ((ts.ColorFlag & CF_XTERM256) && ColorNumber <= 255) {
2536 if (strcmp(StrBuff, "?") == 0) {
2537 color = DispGetANSIColor(ColorNumber);
2538 if (Send8BitMode) {
2539 _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2540 "\2354;%d;rgb:%02x/%02x/%02x\234", CLocale, ColorNumber,
2541 GetRValue(color), GetGValue(color), GetBValue(color));
2542 }
2543 else {
2544 _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2545 "\033]4;%d;rgb:%02x/%02x/%02x\033\\", CLocale, ColorNumber,
2546 GetRValue(color), GetGValue(color), GetBValue(color));
2547 }
2548 ParseMode = ModeFirst;
2549 XsParseMode = ModeXsFirst;
2550 CommBinaryOut(&cv, StrBuff, strlen(StrBuff));
2551 break;
2552 }
2553 else if (XsParseColor(StrBuff, &color)) {
2554 DispSetANSIColor(ColorNumber, color);
2555 }
2556 }
2557 ParseMode = ModeFirst;
2558 XsParseMode = ModeXsFirst;
2559 }
2560 else if (b == ESC) {
2561 PrevMode = ModeXsColorSpec;
2562 XsParseMode = ModeXsEsc;
2563 }
2564 else if (b <= US) { /* Other control character -- invalid sequence */
2565 ParseMode = ModeFirst;
2566 XsParseMode = ModeXsFirst;
2567 }
2568 else if (b == ';') {
2569 if ((ts.ColorFlag & CF_XTERM256) && ColorNumber <= 255) {
2570 if (strcmp(StrBuff, "?") == 0) {
2571 color = DispGetANSIColor(ColorNumber);
2572 if (Send8BitMode) {
2573 _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2574 "\2354;%d;rgb:%02x/%02x/%02x\234", CLocale, ColorNumber,
2575 GetRValue(color), GetGValue(color), GetBValue(color));
2576 }
2577 else {
2578 _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2579 "\033]4;%d;rgb:%02x/%02x/%02x\033\\", CLocale, ColorNumber,
2580 GetRValue(color), GetGValue(color), GetBValue(color));
2581 }
2582 XsParseMode = ModeXsColorNum;
2583 CommBinaryOut(&cv, StrBuff, strlen(StrBuff));
2584 }
2585 else if (XsParseColor(StrBuff, &color)) {
2586 DispSetANSIColor(ColorNumber, color);
2587 }
2588 }
2589 ColorNumber = 0;
2590 StrBuff[0] = '\0';
2591 StrLen = 0;
2592 XsParseMode = ModeXsColorNum;
2593 }
2594 else if (StrLen < sizeof(StrBuff) - 1) {
2595 StrBuff[StrLen++] = b;
2596 }
2597 break;
2598 case ModeXsEsc:
2599 if (b == '\\') { /* String Terminator */
2600 XsParseMode = PrevMode;
2601 // XSequence(ST);
2602 XSequence(BEL);
2603 }
2604 else { /* Other character -- invalid sequence */
2605 ParseMode = ModeFirst;
2606 XsParseMode = ModeXsFirst;
2607 }
2608 break;
2609 // default:
2610 // ParseMode = ModeFirst;
2611 // XsParseMode = ModeXsFirst;
2612 }
2613 }
2614
2615 void DLESeen(BYTE b)
2616 {
2617 ParseMode = ModeFirst;
2618 if (((ts.FTFlag & FT_BPAUTO)!=0) && (b=='B'))
2619 BPStart(IdBPAuto); /* Auto B-Plus activation */
2620 ChangeEmu = -1;
2621 }
2622
2623 void CANSeen(BYTE b)
2624 {
2625 ParseMode = ModeFirst;
2626 if (((ts.FTFlag & FT_ZAUTO)!=0) && (b=='B'))
2627 ZMODEMStart(IdZAuto); /* Auto ZMODEM activation */
2628 ChangeEmu = -1;
2629 }
2630
2631 BOOL CheckKanji(BYTE b)
2632 {
2633 BOOL Check;
2634
2635 if (ts.Language!=IdJapanese) return FALSE;
2636
2637 ConvJIS = FALSE;
2638
2639 if (ts.KanjiCode==IdSJIS)
2640 {
2641 if ((0x80<b) && (b<0xa0) || (0xdf<b) && (b<0xfd))
2642 return TRUE; // SJIS kanji
2643 if ((0xa1<=b) && (b<=0xdf))
2644 return FALSE; // SJIS katakana
2645 }
2646
2647 if ((b>=0x21) && (b<=0x7e))
2648 {
2649 Check = (Gn[Glr[0]]==IdKanji);
2650 ConvJIS = Check;
2651 }
2652 else if ((b>=0xA1) && (b<=0xFE))
2653 {
2654 Check = (Gn[Glr[1]]==IdKanji);
2655 if (ts.KanjiCode==IdEUC)
2656 Check = TRUE;
2657 else if (ts.KanjiCode==IdJIS)
2658 {
2659 if (((ts.TermFlag & TF_FIXEDJIS)!=0) &&
2660 (ts.JIS7Katakana==0))
2661 Check = FALSE; // 8-bit katakana
2662 }
2663 ConvJIS = Check;
2664 }
2665 else
2666 Check = FALSE;
2667
2668 return Check;
2669 }
2670
2671 BOOL ParseFirstJP(BYTE b)
2672 // returns TRUE if b is processed
2673 // (actually allways returns TRUE)
2674 {
2675 if (KanjiIn)
2676 {
2677 if ((! ConvJIS) && (0x3F<b) && (b<0xFD) ||
2678 ConvJIS && ( (0x20<b) && (b<0x7f) ||
2679 (0xa0<b) && (b<0xff) ))
2680 {
2681 PutKanji(b);
2682 KanjiIn = FALSE;
2683 return TRUE;
2684 }
2685 else if ((ts.TermFlag & TF_CTRLINKANJI)==0)
2686 KanjiIn = FALSE;
2687 else if ((b==CR) && Wrap) {
2688 CarriageReturn(FALSE);
2689 LineFeed(LF,FALSE);
2690 Wrap = FALSE;
2691 }
2692 }
2693
2694 if (SSflag)
2695 {
2696 if (Gn[GLtmp] == IdKanji)
2697 {
2698 Kanji = b << 8;
2699 KanjiIn = TRUE;
2700 SSflag = FALSE;
2701 return TRUE;
2702 }
2703 else if (Gn[GLtmp] == IdKatakana) b = b | 0x80;
2704
2705 PutChar(b);
2706 SSflag = FALSE;
2707 return TRUE;
2708 }
2709
2710 if ((! EUCsupIn) && (! EUCkanaIn) &&
2711 (! KanjiIn) && CheckKanji(b))
2712 {
2713 Kanji = b << 8;
2714 KanjiIn = TRUE;
2715 return TRUE;
2716 }
2717
2718 if (b<=US)
2719 ParseControl(b);
2720 else if (b==0x20)
2721 PutChar(b);
2722 else if ((b>=0x21) && (b<=0x7E))
2723 {
2724 if (EUCsupIn)
2725 {
2726 EUCcount--;
2727 EUCsupIn = (EUCcount==0);
2728 return TRUE;
2729 }
2730
2731 if ((Gn[Glr[0]] == IdKatakana) || EUCkanaIn)
2732 {
2733 b = b | 0x80;
2734 EUCkanaIn = FALSE;
2735 }
2736 PutChar(b);
2737 }
2738 else if (b==0x7f)
2739 return TRUE;
2740 else if ((b>=0x80) && (b<=0x8D))
2741 ParseControl(b);
2742 else if (b==0x8E)
2743 {
2744 if (ts.KanjiCode==IdEUC)
2745 EUCkanaIn = TRUE;
2746 else
2747 ParseControl(b);
2748 }
2749 else if (b==0x8F)
2750 {
2751 if (ts.KanjiCode==IdEUC)
2752 {
2753 EUCcount = 2;
2754 EUCsupIn = TRUE;
2755 } else
2756 ParseControl(b);
2757 }
2758 else if ((b>=0x90) && (b<=0x9F))
2759 ParseControl(b);
2760 else if (b==0xA0)
2761 PutChar(0x20);
2762 else if ((b>=0xA1) && (b<=0xFE))
2763 {
2764 if (EUCsupIn)
2765 {
2766 EUCcount--;
2767 EUCsupIn = (EUCcount==0);
2768 return TRUE;
2769 }
2770
2771 if ((Gn[Glr[1]] != IdASCII) ||
2772 (ts.KanjiCode==IdEUC) && EUCkanaIn ||
2773 (ts.KanjiCode==IdSJIS) ||
2774 (ts.KanjiCode==IdJIS) &&
2775 (ts.JIS7Katakana==0) &&
2776 ((ts.TermFlag & TF_FIXEDJIS)!=0))
2777 PutChar(b); // katakana
2778 else {
2779 if (Gn[Glr[1]] == IdASCII)
2780 b = b & 0x7f;
2781 PutChar(b);
2782 }
2783 EUCkanaIn = FALSE;
2784 }
2785 else
2786 PutChar(b);
2787
2788 return TRUE;
2789 }
2790
2791
2792 static void ParseASCII(BYTE b)
2793 {
2794 if (b<=US) {
2795 ParseControl(b);
2796 } else if ((b>=0x20) && (b<=0x7E)) {
2797 //Kanji = 0;
2798 //PutKanji(b);
2799 PutChar(b);
2800 } else if ((b>=0x80) && (b<=0x9F)) {
2801 ParseControl(b);
2802 } else if (b>=0xA0) {
2803 //Kanji = 0;
2804 //PutKanji(b);
2805 PutChar(b);
2806 }
2807 }
2808
2809 //
2810 // UTF-8
2811 //
2812 #include "uni2sjis.map"
2813 #include "unisym2decsp.map"
2814 extern unsigned short ConvertUnicode(unsigned short code, codemap_t *table, int tmax);
2815
2816
2817 //
2818 // UTF-8 for Mac OS X(HFS plus)
2819 //
2820 #include "hfs_plus.map"
2821
2822 unsigned short GetIllegalUnicode(int start_index, unsigned short first_code, unsigned short code,
2823 hfsplus_codemap_t *table, int tmax)
2824 {
2825 unsigned short result = 0;
2826 int i;
2827
2828 for (i = start_index ; i < tmax ; i++) {
2829 if (table[i].first_code != first_code) { // 1�������������������A���~���������������������B
2830 break;
2831 }
2832
2833 if (table[i].second_code == code) {
2834 result = table[i].illegal_code;
2835 break;
2836 }
2837 }
2838
2839 return (result);
2840 }
2841
2842 int GetIndexOfHFSPlusFirstCode(unsigned short code, hfsplus_codemap_t *table, int tmax)
2843 {
2844 int low, mid, high;
2845 int index = -1;
2846
2847 low = 0;
2848 high = tmax - 1;
2849
2850 // binary search
2851 while (low < high) {
2852 mid = (low + high) / 2;
2853 if (table[mid].first_code < code) {
2854 low = mid + 1;
2855 } else {
2856 high = mid;
2857 }
2858 }
2859
2860 if (table[low].first_code == code) {
2861 while (low >= 0 && table[low].first_code == code) {
2862 index = low;
2863 low--;
2864 }
2865 }
2866
2867 return (index);
2868 }
2869
2870
2871 static void UnicodeToCP932(unsigned int code, int byte)
2872 {
2873 int ret;
2874 char mbchar[32];
2875 unsigned char wchar[32];
2876 unsigned short cset = 0;
2877
2878 #if 0
2879 Kanji = code & 0xff00;
2880 PutKanji(code & 0x00ff);
2881 return;
2882 #else
2883
2884 wchar[0] = code & 0xff;
2885 wchar[1] = (code >> 8) & 0xff;
2886
2887 if (ts.UnicodeDecSpMapping) {
2888 cset = ConvertUnicode(code, mapUnicodeSymbolToDecSp, sizeof(mapUnicodeSymbolToDecSp)/sizeof(mapUnicodeSymbolToDecSp[0]));
2889 }
2890 if (((cset >> 8) & ts.UnicodeDecSpMapping) != 0) {
2891 PutDecSp(cset & 0xff);
2892 }
2893 else {
2894 // Unicode -> CP932
2895 ret = wctomb(mbchar, ((wchar_t *)wchar)[0]);
2896 switch (ret) {
2897 case -1:
2898 if (_stricmp(ts.Locale, DEFAULT_LOCALE) == 0) {
2899 // U+301C�������������������BUnicode -> Shift_JIS���������������B
2900 cset = ConvertUnicode(code, mapUnicodeToSJIS, sizeof(mapUnicodeToSJIS)/sizeof(mapUnicodeToSJIS[0]));
2901 if (cset != 0) {
2902 Kanji = cset & 0xff00;
2903 PutKanji(cset & 0x00ff);
2904 }
2905 }
2906
2907 if (cset == 0) {
2908 ParseASCII('?');
2909 if (ts.UnknownUnicodeCharaAsWide) {
2910 ParseASCII('?');
2911 }
2912 }
2913 break;
2914 case 1:
2915 ParseASCII(mbchar[0]);
2916 break;
2917 default:
2918 Kanji = mbchar[0] << 8;
2919 PutKanji(mbchar[1]);
2920 break;
2921 }
2922 }
2923 #endif
2924 }
2925
2926 // UTF-8�����M�f�[�^����������
2927 BOOL ParseFirstUTF8(BYTE b, int hfsplus_mode)
2928 // returns TRUE if b is processed
2929 // (actually allways returns TRUE)
2930 {
2931 static BYTE buf[3];
2932 static int count = 0;
2933 static int maybe_hfsplus = 0;
2934 static unsigned int first_code;
2935 static int first_code_index;
2936
2937 unsigned int code;
2938 char mbchar[32];
2939 unsigned short cset;
2940 char *locptr;
2941
2942 locptr = setlocale(LC_ALL, ts.Locale);
2943
2944 if ((b & 0x80) != 0x80 || ((b & 0xe0) == 0x80 && count == 0)) {
2945 // 1�o�C�g��������2�o�C�g����ASCII���������A������ASCII�o���������B
2946 // 1�o�C�g����C1��������(0x80-0x9f)�����������l�B
2947 if (count == 0 || count == 1) {
2948 if (hfsplus_mode == 1 && maybe_hfsplus == 1) {
2949 UnicodeToCP932(first_code, 3);
2950 maybe_hfsplus = 0;
2951 }
2952
2953 if (count == 1) {
2954 ParseASCII(buf[0]);
2955 //code = buf[0];
2956 //UnicodeToCP932(code, 2);
2957 }
2958 ParseASCII(b);
2959 //code = b;
2960 //UnicodeToCP932(code, 2);
2961
2962 count = 0; // reset counter
2963 return TRUE;
2964 }
2965 }
2966
2967 if (count < 2) {
2968 buf[count++] = b;
2969 return TRUE;
2970 }
2971
2972 memset(mbchar, 0, sizeof(mbchar));
2973
2974 // 2�o�C�g�R�[�h������
2975 if ((buf[0] & 0xe0) == 0xc0 &&
2976 (buf[1] & 0xc0) == 0x80) {
2977
2978 if (hfsplus_mode == 1 && maybe_hfsplus == 1) {
2979 UnicodeToCP932(first_code, 3);
2980 maybe_hfsplus = 0;
2981 }
2982
2983 code = ((buf[0] & 0x1f) << 6);
2984 code |= ((buf[1] & 0x3f));
2985
2986 UnicodeToCP932(code, 2);
2987
2988 // �����o�C�g��ASCII�������������\�� (2006.6.30 yutaka)
2989 if ((b & 0x80) != 0x80) { // ASCII(0x00-0x7f)
2990 ParseASCII(b);
2991 count = 0; // reset counter
2992
2993 } else {
2994 // ASCII�������������A�}���`�o�C�g�������n�������������B
2995 buf[0] = b;
2996 count = 1;
2997 }
2998
2999 return TRUE;
3000 }
3001
3002 buf[count++] = b;
3003
3004 if ((buf[0] & 0xe0) == 0xe0 &&
3005 (buf[1] & 0xc0) == 0x80 &&
3006 (buf[2] & 0xc0) == 0x80) { // 3�o�C�g�R�[�h������
3007
3008 // UTF-8 BOM(Byte Order Mark)
3009 if (buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf) {
3010 goto skip;
3011 }
3012
3013 code = ((buf[0] & 0xf) << 12);
3014 code |= ((buf[1] & 0x3f) << 6);
3015 code |= ((buf[2] & 0x3f));
3016
3017 if (hfsplus_mode == 1) {
3018 if (maybe_hfsplus == 0) {
3019 if ((first_code_index = GetIndexOfHFSPlusFirstCode(
3020 code, mapHFSPlusUnicode, sizeof(mapHFSPlusUnicode)/sizeof(mapHFSPlusUnicode[0])
3021 )) != -1) {
3022 maybe_hfsplus = 1;
3023 first_code = code;
3024 count = 0;
3025 return (TRUE);
3026 }
3027 } else {
3028 maybe_hfsplus = 0;
3029 cset = GetIllegalUnicode(first_code_index, first_code, code, mapHFSPlusUnicode, sizeof(mapHFSPlusUnicode)/sizeof(mapHFSPlusUnicode[0]));
3030 if (cset != 0) { // success
3031 code = cset;
3032
3033 } else { // error
3034 // 2�����������������_��1�����������������������A���x�������������B(2005.10.15 yutaka)
3035 if ((first_code_index = GetIndexOfHFSPlusFirstCode(
3036 code, mapHFSPlusUnicode, sizeof(mapHFSPlusUnicode)/sizeof(mapHFSPlusUnicode[0])
3037 )) != -1) {
3038
3039 // 1���������������������o������
3040 UnicodeToCP932(first_code, 3);
3041
3042 maybe_hfsplus = 1;
3043 first_code = code;
3044 count = 0;
3045 return (TRUE);
3046 }
3047
3048 UnicodeToCP932(first_code, 3);
3049 UnicodeToCP932(code, 3);
3050 count = 0;
3051 return (TRUE);
3052 }
3053 }
3054 }
3055
3056 UnicodeToCP932(code, 3);
3057
3058 skip:
3059 count = 0;
3060
3061 } else {
3062 ParseASCII(buf[0]);
3063 ParseASCII(buf[1]);
3064 ParseASCII(buf[2]);
3065 count = 0;
3066
3067 }
3068
3069 return TRUE;
3070 }
3071
3072
3073 BOOL ParseFirstRus(BYTE b)
3074 // returns if b is processed
3075 {
3076 if (b>=128)
3077 {
3078 b = RussConv(ts.RussHost,ts.RussClient,b);
3079 PutChar(b);
3080 return TRUE;
3081 }
3082 return FALSE;
3083 }
3084
3085 void ParseFirst(BYTE b)
3086 {
3087 // UTF-8����������������������
3088 if ((ts.Language==IdKorean && ts.KanjiCode == IdUTF8) &&
3089 ParseFirstUTF8(b, 0)) {
3090 return;
3091 } else if ((ts.Language==IdJapanese && ts.KanjiCode == IdUTF8) &&
3092 ParseFirstUTF8(b, 0)) {
3093 return;
3094 } else if ((ts.Language==IdJapanese && ts.KanjiCode == IdUTF8m) &&
3095 ParseFirstUTF8(b, 1)) {
3096 return;
3097 } else if ((ts.Language==IdJapanese) &&
3098 ParseFirstJP(b)) return;
3099 else if ((ts.Language==IdRussian) &&
3100 ParseFirstRus(b)) return;
3101
3102 if (SSflag)
3103 {
3104 PutChar(b);
3105 SSflag = FALSE;
3106 return;
3107 }
3108
3109 if (b<=US)
3110 ParseControl(b);
3111 else if ((b>=0x20) && (b<=0x7E))
3112 PutChar(b);
3113 else if ((b>=0x80) && (b<=0x9F))
3114 ParseControl(b);
3115 else if (b>=0xA0)
3116 PutChar(b);
3117 }
3118
3119 int VTParse()
3120 {
3121 BYTE b;
3122 int c;
3123
3124 c = CommRead1Byte(&cv,&b);
3125
3126 if (c==0) return 0;
3127
3128 CaretOff();
3129 UpdateCaretKillFocus(FALSE); // ���A�N�e�B�u�������������`������
3130
3131 ChangeEmu = 0;
3132
3133 /* Get Device Context */
3134 DispInitDC();
3135
3136 LockBuffer();
3137
3138 while ((c>0) && (ChangeEmu==0))
3139 {
3140 if (DebugFlag)
3141 PutDebugChar(b);
3142 else {
3143 switch (ParseMode) {
3144 case ModeFirst: ParseFirst(b); break;
3145 case ModeESC: EscapeSequence(b); break;
3146 case ModeDCS: DeviceControl(b); break;
3147 case ModeDCUserKey: DCUserKey(b); break;
3148 case ModeSOS: IgnoreString(b); break;
3149 case ModeCSI: ControlSequence(b); break;
3150 case ModeXS: XSequence(b); break;
3151 case ModeDLE: DLESeen(b); break;
3152 case ModeCAN: CANSeen(b); break;
3153 default:
3154 ParseMode = ModeFirst;
3155 ParseFirst(b);
3156 }
3157 }
3158
3159 if (ChangeEmu==0)
3160 c = CommRead1Byte(&cv,&b);
3161 }
3162
3163 BuffUpdateScroll();
3164
3165 BuffSetCaretWidth();
3166 UnlockBuffer();
3167
3168 /* release device context */
3169 DispReleaseDC();
3170
3171 CaretOn();
3172
3173 if (ChangeEmu > 0) ParseMode = ModeFirst;
3174 return ChangeEmu;
3175 }
3176
3177 int MakeMouseReportStr(char *buff, size_t buffsize, int mb, int x, int y) {
3178 if (Send8BitMode)
3179 return _snprintf_s_l(buff, buffsize, _TRUNCATE, "\233M%c%c%c", CLocale, mb+32, x+32, y+32);
3180 else
3181 return _snprintf_s_l(buff, buffsize, _TRUNCATE, "\033[M%c%c%c", CLocale, mb+32, x+32, y+32);
3182 }
3183
3184 BOOL MouseReport(int Event, int Button, int Xpos, int Ypos) {
3185 char Report[10];
3186 int x, y, len, modifier;
3187
3188 len = 0;
3189
3190 if (MouseReportMode == IdMouseTrackNone)
3191 return FALSE;
3192
3193 if (ts.DisableMouseTrackingByCtrl && ControlKey())
3194 return FALSE;
3195
3196 DispConvWinToScreen(Xpos, Ypos, &x, &y, NULL);
3197 x++; y++;
3198
3199 if (x < 1) x = 1;
3200 if (y < 1) y = 1;
3201
3202 if (MouseReportMode != IdMouseTrackDECELR) {
3203 if (x > 0xff - 32) x = 0xff - 32;
3204 if (x > 0xff - 32) y = 0xff - 32;
3205 }
3206
3207 if (ShiftKey())
3208 modifier = 4;
3209 else
3210 modifier = 0;
3211
3212 if (ControlKey())
3213 modifier |= 8;
3214
3215 if (AltKey())
3216 modifier |= 16;
3217
3218 modifier = (ShiftKey()?4:0) | (ControlKey()?8:0) | (AltKey()?16:0);
3219
3220 switch (Event) {
3221 case IdMouseEventBtnDown:
3222 switch (MouseReportMode) {
3223 case IdMouseTrackX10:
3224 len = MakeMouseReportStr(Report, sizeof Report, Button, x, y);
3225 break;
3226
3227 case IdMouseTrackVT200:
3228 case IdMouseTrackBtnEvent:
3229 case IdMouseTrackAllEvent:
3230 len = MakeMouseReportStr(Report, sizeof Report, Button | modifier, x, y);
3231 break;
3232
3233 case IdMouseTrackDECELR: /* not supported yet */
3234 case IdMouseTrackVT200Hl: /* not supported yet */
3235 default:
3236 return FALSE;
3237 }
3238 break;
3239
3240 case IdMouseEventBtnUp:
3241 switch (MouseReportMode) {
3242 case IdMouseTrackVT200:
3243 case IdMouseTrackBtnEvent:
3244 case IdMouseTrackAllEvent:
3245 len = MakeMouseReportStr(Report, sizeof Report, 3 | modifier, x, y);
3246 break;
3247
3248 case IdMouseTrackX10: /* nothing to do */
3249 case IdMouseTrackDECELR: /* not supported yet */
3250 case IdMouseTrackVT200Hl: /* not supported yet */
3251 default:
3252 return FALSE;
3253 }
3254 break;
3255
3256 case IdMouseEventMove:
3257 switch (MouseReportMode) {
3258 case IdMouseTrackBtnEvent: /* not supported yet */
3259 case IdMouseTrackAllEvent: /* not supported yet */
3260 case IdMouseTrackDECELR: /* not supported yet */
3261 case IdMouseTrackVT200Hl: /* not supported yet */
3262 case IdMouseTrackX10: /* nothing to do */
3263 case IdMouseTrackVT200: /* nothing to do */
3264 default:
3265 return FALSE;
3266 }
3267 break;
3268
3269 case IdMouseEventWheel:
3270 switch (MouseReportMode) {
3271 case IdMouseTrackVT200:
3272 case IdMouseTrackBtnEvent:
3273 case IdMouseTrackAllEvent:
3274 len = MakeMouseReportStr(Report, sizeof Report, Button | modifier | 64, x, y);
3275 break;
3276
3277 case IdMouseTrackX10: /* nothing to do */
3278 case IdMouseTrackDECELR: /* not supported yet */
3279 case IdMouseTrackVT200Hl: /* not supported yet */
3280 return FALSE;
3281 }
3282 break;
3283 }
3284
3285 if (len == 0)
3286 return FALSE;
3287
3288 CommBinaryOut(&cv, Report, len);
3289 return TRUE;
3290 }
3291
3292 void FocusReport(BOOL focus) {
3293 if (!FocusReportMode)
3294 return;
3295
3296 if (focus) {
3297 // Focus In
3298 if (Send8BitMode) {
3299 CommBinaryOut(&cv,"\233I",2);
3300 } else {
3301 CommBinaryOut(&cv,"\033[I",3);
3302 }
3303 } else {
3304 // Focus Out
3305 if (Send8BitMode) {
3306 CommBinaryOut(&cv,"\233O",2);
3307 } else {
3308 CommBinaryOut(&cv,"\033[O",3);
3309 }
3310 }
3311 }
3312
3313 void VisualBell() {
3314 CSQExchangeColor();
3315 Sleep(10);
3316 CSQExchangeColor();
3317 }

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