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 2601 - (show annotations) (download) (as text)
Thu Oct 30 04:28:29 2008 UTC (15 years, 5 months ago) by doda
Original Path: teraterm/trunk/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 69904 byte(s)
UK文字セット(BS 4730)の指示をUS-ASCIIの指示として扱うようにした。
  http://logmett.com/forum/viewtopic.php?f=2&t=923

BS 4730は厳密にはUS-ASCIIとは違うのだが(#がポンド記号)、現状ではJIS X 0201 ローマ字もUS-ASCIIとして取り扱っているし、違いは通常はフォントで吸収しているので問題ないはず。

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

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