Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/vtterm.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2554 - (hide annotations) (download) (as text)
Sat Jul 5 21:36:42 2008 UTC (15 years, 9 months ago) by doda
Original Path: teraterm/trunk/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 69260 byte(s)
ビジュアルベルをサポート。BEL文字を受信した時に、Beepを鳴らす代わりに画面をフラッシュさせる事が出来るようにした。
TERATERM.INIのBeepエントリを拡張し、On/Offの他にVisualを指定できるようにした。

1 maya 2476 /* 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 doda 2554 void CSQExchangeColor();
43    
44 maya 2476 /* 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 doda 2553 CursorForwardTab(1, AutoWrapMode);
362 maya 2476 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 doda 2491 void PutDecSp(BYTE b)
441     {
442     TCharAttr CharAttrTmp;
443 maya 2476
444 doda 2491 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 maya 2476 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 doda 2484
550 maya 2476 #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 doda 2554 switch (ts.Beep) {
688     case IdBeepOff:
689     /* nothing to do */
690     break;
691     case IdBeepOn:
692     MessageBeep(0);
693     break;
694     case IdBeepVisual:
695     CSQExchangeColor();
696     CSQExchangeColor();
697     break;
698     }
699 maya 2476 break;
700     case BS: BackSpace(); break;
701     case HT: Tab(); break;
702    
703     case LF:
704     // ���M�������s�R�[�h�� LF ���������A�T�[�o���� LF ���������������������������A
705     // CR+LF���������������������B
706     // cf. http://www.neocom.ca/forum/viewtopic.php?t=216
707     // (2007.1.21 yutaka)
708     if (ts.CRReceive == IdLF) {
709     CarriageReturn(TRUE);
710     LineFeed(b, TRUE);
711     break;
712     }
713    
714     case VT: LineFeed(b,TRUE); break;
715    
716     case FF:
717     if ((ts.AutoWinSwitch>0) && JustAfterESC)
718     {
719     CommInsert1Byte(&cv,b);
720     CommInsert1Byte(&cv,ESC);
721     ChangeEmu = IdTEK; /* Enter TEK Mode */
722     }
723     else
724     LineFeed(b,TRUE);
725     break;
726     case CR:
727     CarriageReturn(TRUE);
728     if (ts.CRReceive==IdCRLF)
729     CommInsert1Byte(&cv,LF);
730     break;
731     case SO:
732     if ((ts.Language==IdJapanese) &&
733     (ts.KanjiCode==IdJIS) &&
734     (ts.JIS7Katakana==1) &&
735     ((ts.TermFlag & TF_FIXEDJIS)!=0))
736     Gn[1] = IdKatakana;
737    
738     Glr[0] = 1; /* LS1 */
739     break;
740     case SI: Glr[0] = 0; break; /* LS0 */
741     case DLE:
742     if ((ts.FTFlag & FT_BPAUTO)!=0)
743     ParseMode = ModeDLE; /* Auto B-Plus activation */
744     break;
745     case CAN:
746     if ((ts.FTFlag & FT_ZAUTO)!=0)
747     ParseMode = ModeCAN; /* Auto ZMODEM activation */
748     // else if (ts.AutoWinSwitch>0)
749     // ChangeEmu = IdTEK; /* Enter TEK Mode */
750     else
751     ParseMode = ModeFirst;
752     break;
753     case SUB: ParseMode = ModeFirst; break;
754     case ESC:
755     ICount = 0;
756     JustAfterESC = TRUE;
757     ParseMode = ModeESC;
758     break;
759     case FS:
760     case GS:
761     case RS:
762     case US:
763     if (ts.AutoWinSwitch>0)
764     {
765     CommInsert1Byte(&cv,b);
766     ChangeEmu = IdTEK; /* Enter TEK Mode */
767     }
768     break;
769    
770     /* C1 char */
771     case IND: LineFeed(0,TRUE); break;
772     case NEL:
773     LineFeed(0,TRUE);
774     CarriageReturn(TRUE);
775     break;
776     case HTS: SetTabStop(); break;
777     case RI: CursorUpWithScroll(); break;
778     case SS2:
779     GLtmp = 2;
780     SSflag = TRUE;
781     break;
782     case SS3:
783     GLtmp = 3;
784     SSflag = TRUE;
785     break;
786     case DCS:
787     SavedMode = ParseMode;
788     ESCFlag = FALSE;
789     NParam = 1;
790     Param[1] = -1;
791     ParseMode = ModeDCS;
792     break;
793     case SOS:
794     SavedMode = ParseMode;
795     ESCFlag = FALSE;
796     ParseMode = ModeSOS;
797     break;
798     case CSI:
799     ICount = 0;
800     FirstPrm = TRUE;
801     NParam = 1;
802     Param[1] = -1;
803     Prv = 0;
804     ParseMode = ModeCSI;
805     break;
806     case OSC:
807     Param[1] = 0;
808     ParseMode = ModeXS;
809     break;
810     case PM:
811     case APC:
812     SavedMode = ParseMode;
813     ESCFlag = FALSE;
814     ParseMode = ModeSOS;
815     break;
816     }
817     }
818    
819     void SaveCursor()
820     {
821     int i;
822     PStatusBuff Buff;
823    
824     if ((StatusLine>0) &&
825     (CursorY==NumOfLines-1))
826     Buff = &SBuff2; // for status line
827     else
828     Buff = &SBuff1; // for main screen
829    
830     Buff->CursorX = CursorX;
831     Buff->CursorY = CursorY;
832     Buff->Attr = CharAttr;
833     Buff->Glr[0] = Glr[0];
834     Buff->Glr[1] = Glr[1];
835     for (i=0 ; i<=3; i++)
836     Buff->Gn[i] = Gn[i];
837     Buff->AutoWrapMode = AutoWrapMode;
838     Buff->RelativeOrgMode = RelativeOrgMode;
839     }
840    
841     void RestoreCursor()
842     {
843     int i;
844     PStatusBuff Buff;
845     UpdateStr();
846    
847     if ((StatusLine>0) &&
848     (CursorY==NumOfLines-1))
849     Buff = &SBuff2; // for status line
850     else
851     Buff = &SBuff1; // for main screen
852    
853     if (Buff->CursorX > NumOfColumns-1)
854     Buff->CursorX = NumOfColumns-1;
855     if (Buff->CursorY > NumOfLines-1-StatusLine)
856     Buff->CursorY = NumOfLines-1-StatusLine;
857     MoveCursor(Buff->CursorX,Buff->CursorY);
858     CharAttr = Buff->Attr;
859     Glr[0] = Buff->Glr[0];
860     Glr[1] = Buff->Glr[1];
861     for (i=0 ; i<=3; i++)
862     Gn[i] = Buff->Gn[i];
863     AutoWrapMode = Buff->AutoWrapMode;
864     RelativeOrgMode = Buff->RelativeOrgMode;
865     }
866    
867     void AnswerTerminalType()
868     {
869     char Tmp[31];
870    
871     if (ts.TerminalID<IdVT320)
872     strncpy_s(Tmp, sizeof(Tmp),"\033[?", _TRUNCATE);
873     else
874     strncpy_s(Tmp, sizeof(Tmp),"\233?", _TRUNCATE);
875    
876     switch (ts.TerminalID) {
877     case IdVT100:
878     strncat_s(Tmp,sizeof(Tmp),"1;2",_TRUNCATE);
879     break;
880     case IdVT100J:
881     strncat_s(Tmp,sizeof(Tmp),"5;2",_TRUNCATE);
882     break;
883     case IdVT101:
884     strncat_s(Tmp,sizeof(Tmp),"1;0",_TRUNCATE);
885     break;
886     case IdVT102:
887     strncat_s(Tmp,sizeof(Tmp),"6",_TRUNCATE);
888     break;
889     case IdVT102J:
890     strncat_s(Tmp,sizeof(Tmp),"15",_TRUNCATE);
891     break;
892     case IdVT220J:
893     strncat_s(Tmp,sizeof(Tmp),"62;1;2;5;6;7;8",_TRUNCATE);
894     break;
895     case IdVT282:
896     strncat_s(Tmp,sizeof(Tmp),"62;1;2;4;5;6;7;8;10;11",_TRUNCATE);
897     break;
898     case IdVT320:
899     strncat_s(Tmp,sizeof(Tmp),"63;1;2;6;7;8",_TRUNCATE);
900     break;
901     case IdVT382:
902     strncat_s(Tmp,sizeof(Tmp),"63;1;2;4;5;6;7;8;10;15",_TRUNCATE);
903     break;
904     }
905     strncat_s(Tmp,sizeof(Tmp),"c",_TRUNCATE);
906    
907     CommBinaryOut(&cv,Tmp,strlen(Tmp)); /* Report terminal ID */
908     }
909    
910     void ESCSpace(BYTE b)
911     {
912     switch (b) {
913     case 'F': Send8BitMode = FALSE; break; // S7C1T
914     case 'G': Send8BitMode = TRUE; break; // S8C1T
915     }
916     }
917    
918     void ESCSharp(BYTE b)
919     {
920     switch (b) {
921     case '8': /* Fill screen with "E" */
922     BuffUpdateScroll();
923     BuffFillWithE();
924     MoveCursor(0,0);
925     ParseMode = ModeFirst;
926     break;
927     }
928     }
929    
930     /* select double byte code set */
931     void ESCDBCSSelect(BYTE b)
932     {
933     int Dist;
934    
935     if (ts.Language!=IdJapanese) return;
936    
937     switch (ICount) {
938     case 1:
939     if ((b=='@') || (b=='B'))
940     {
941     Gn[0] = IdKanji; /* Kanji -> G0 */
942     if ((ts.TermFlag & TF_AUTOINVOKE)!=0)
943     Glr[0] = 0; /* G0->GL */
944     }
945     break;
946     case 2:
947     /* Second intermediate char must be
948     '(' or ')' or '*' or '+'. */
949     Dist = (IntChar[2]-'(') & 3; /* G0 - G3 */
950     if ((b=='1') || (b=='3') ||
951     (b=='@') || (b=='B'))
952     {
953     Gn[Dist] = IdKanji; /* Kanji -> G0-3 */
954     if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
955     (Dist==0))
956     Glr[0] = 0; /* G0->GL */
957     }
958     break;
959     }
960 doda 2484 }
961 maya 2476
962     void ESCSelectCode(BYTE b)
963     {
964     switch (b) {
965     case '0':
966     if (ts.AutoWinSwitch>0)
967     ChangeEmu = IdTEK; /* enter TEK mode */
968     break;
969     }
970     }
971    
972     /* select single byte code set */
973     void ESCSBCSSelect(BYTE b)
974     {
975     int Dist;
976    
977     /* Intermediate char must be
978     '(' or ')' or '*' or '+'. */
979     Dist = (IntChar[1]-'(') & 3; /* G0 - G3 */
980    
981     switch (b) {
982     case '0': Gn[Dist] = IdSpecial; break;
983     case '<': Gn[Dist] = IdASCII; break;
984     case '>': 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 doda 2484 return;
1124 maya 2476 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 'n': Glr[0] = 2; break; /* LS2 */
1139     case 'o': Glr[0] = 3; break; /* LS3 */
1140     case '|': Glr[1] = 3; break; /* LS3R */
1141     case '}': Glr[1] = 2; break; /* LS2R */
1142     case '~': Glr[1] = 1; break; /* LS1R */
1143     } /* end of case Icount=0 */
1144     break;
1145     /* one intermediate char */
1146     case 1:
1147     switch (IntChar[1]) {
1148     case ' ': ESCSpace(b); break;
1149     case '#': ESCSharp(b); break;
1150     case '$': ESCDBCSSelect(b); break;
1151     case '%': break;
1152     case '(':
1153     case ')':
1154     case '*':
1155     case '+':
1156     ESCSBCSSelect(b);
1157     break;
1158     }
1159     break;
1160     /* two intermediate char */
1161     case 2:
1162     if ((IntChar[1]=='$') &&
1163     ('('<=IntChar[2]) &&
1164     (IntChar[2]<='+'))
1165     ESCDBCSSelect(b);
1166     else if ((IntChar[1]=='%') &&
1167     (IntChar[2]=='!'))
1168     ESCSelectCode(b);
1169     break;
1170     }
1171     ParseMode = ModeFirst;
1172     }
1173    
1174     void EscapeSequence(BYTE b)
1175     {
1176     if (b<=US)
1177     ParseControl(b);
1178     else if ((b>=0x20) && (b<=0x2F))
1179     {
1180     if (ICount<IntCharMax) ICount++;
1181     IntChar[ICount] = b;
1182     }
1183     else if ((b>=0x30) && (b<=0x7E))
1184     ParseEscape(b);
1185     else if ((b>=0x80) && (b<=0x9F))
1186     ParseControl(b);
1187    
1188     JustAfterESC = FALSE;
1189     }
1190    
1191     void CSInsertCharacter()
1192     {
1193     // Insert space characters at cursor
1194     int Count;
1195    
1196     BuffUpdateScroll();
1197     if (Param[1]<1) Param[1] = 1;
1198     Count = Param[1];
1199     BuffInsertSpace(Count);
1200     }
1201    
1202     void CSCursorUp()
1203     {
1204     if (Param[1]<1) Param[1] = 1;
1205    
1206     if (CursorY >= CursorTop)
1207     {
1208     if (CursorY-Param[1] > CursorTop)
1209     MoveCursor(CursorX,CursorY-Param[1]);
1210     else
1211     MoveCursor(CursorX,CursorTop);
1212     }
1213     else {
1214     if (CursorY > 0)
1215     MoveCursor(CursorX,CursorY-Param[1]);
1216     else
1217     MoveCursor(CursorX,0);
1218     }
1219     }
1220    
1221     void CSCursorUp1()
1222     {
1223     MoveCursor(0,CursorY);
1224     CSCursorUp();
1225     }
1226    
1227     void CSCursorDown()
1228     {
1229     if (Param[1]<1) Param[1] = 1;
1230    
1231     if (CursorY <= CursorBottom)
1232     {
1233     if (CursorY+Param[1] < CursorBottom)
1234     MoveCursor(CursorX,CursorY+Param[1]);
1235     else
1236     MoveCursor(CursorX,CursorBottom);
1237     }
1238     else {
1239     if (CursorY < NumOfLines-StatusLine-1)
1240     MoveCursor(CursorX,CursorY+Param[1]);
1241     else
1242     MoveCursor(CursorX,NumOfLines-StatusLine);
1243     }
1244     }
1245    
1246     void CSCursorDown1()
1247     {
1248     MoveCursor(0,CursorY);
1249     CSCursorDown();
1250     }
1251    
1252     void CSScreenErase()
1253     {
1254     if (Param[1] == -1) Param[1] = 0;
1255     BuffUpdateScroll();
1256     switch (Param[1]) {
1257     case 0:
1258     // <ESC>[H(Cursor in left upper corner)�������J�[�\�������������w�������������A
1259     // <ESC>[J��<ESC>[2J�����������������A�����������A���s�o�b�t�@���X�N���[���A�E�g
1260     // �����������������B(2005.5.29 yutaka)
1261 yutakapon 2498 // �R���t�B�O���[�V�������������������������������B(2008.5.3 yutaka)
1262     if (ts.ScrollWindowClearScreen &&
1263     (CursorX == 0 && CursorY == 0)) {
1264 maya 2476 // Erase screen (scroll out)
1265     BuffClearScreen();
1266     UpdateWindow(HVTWin);
1267    
1268     } else {
1269     // Erase characters from cursor to the end of screen
1270     BuffEraseCurToEnd();
1271     }
1272     break;
1273    
1274     case 1:
1275     // Erase characters from home to cursor
1276     BuffEraseHomeToCur();
1277     break;
1278    
1279     case 2:
1280     // Erase screen (scroll out)
1281     BuffClearScreen();
1282     UpdateWindow(HVTWin);
1283     break;
1284     }
1285     }
1286    
1287     void CSInsertLine()
1288     {
1289     // Insert lines at current position
1290     int Count, YEnd;
1291    
1292     if (CursorY < CursorTop) return;
1293     if (CursorY > CursorBottom) return;
1294     if (Param[1]<1) Param[1] = 1;
1295     Count = Param[1];
1296    
1297     YEnd = CursorBottom;
1298     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1299     if (Count > YEnd+1 - CursorY) Count = YEnd+1 - CursorY;
1300    
1301     BuffInsertLines(Count,YEnd);
1302     }
1303    
1304     void CSLineErase()
1305     {
1306     if (Param[1] == -1) Param[1] = 0;
1307     BuffUpdateScroll();
1308     switch (Param[1]) {
1309     /* erase char from cursor to end of line */
1310     case 0:
1311     BuffEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1312     break;
1313     /* erase char from start of line to cursor */
1314     case 1:
1315     BuffEraseCharsInLine(0,CursorX+1);
1316     break;
1317     /* erase entire line */
1318     case 2:
1319     BuffEraseCharsInLine(0,NumOfColumns);
1320     break;
1321     }
1322     }
1323    
1324     void CSDeleteNLines()
1325     // Delete lines from current line
1326     {
1327     int Count, YEnd;
1328    
1329     if (CursorY < CursorTop) return;
1330     if (CursorY > CursorBottom) return;
1331     Count = Param[1];
1332     if (Count<1) Count = 1;
1333    
1334     YEnd = CursorBottom;
1335     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1336     if (Count > YEnd+1-CursorY) Count = YEnd+1-CursorY;
1337     BuffDeleteLines(Count,YEnd);
1338     }
1339    
1340     void CSDeleteCharacter()
1341     {
1342     // Delete characters in current line from cursor
1343    
1344     if (Param[1]<1) Param[1] = 1;
1345     BuffUpdateScroll();
1346     BuffDeleteChars(Param[1]);
1347     }
1348    
1349     void CSEraseCharacter()
1350     {
1351     if (Param[1]<1) Param[1] = 1;
1352     BuffUpdateScroll();
1353     BuffEraseChars(Param[1]);
1354     }
1355    
1356     void CSScrollUP()
1357     {
1358     if (Param[1]<1) Param[1] = 1;
1359     BuffUpdateScroll();
1360     BuffRegionScrollUpNLines(Param[1]);
1361     }
1362    
1363     void CSScrollDown()
1364     {
1365     if (Param[1]<1) Param[1] = 1;
1366     BuffUpdateScroll();
1367     BuffRegionScrollDownNLines(Param[1]);
1368     }
1369    
1370 doda 2553 void CSForwardTab()
1371 doda 2551 {
1372     if (Param[1]<1) Param[1] = 1;
1373 doda 2553 CursorForwardTab(Param[1], AutoWrapMode);
1374 doda 2551 }
1375    
1376 doda 2553 void CSBackwardTab()
1377     {
1378     if (Param[1]<1) Param[1] = 1;
1379     CursorBackwardTab(Param[1]);
1380     }
1381    
1382 maya 2476 void CSMoveToColumnN()
1383     {
1384     if (Param[1]<1) Param[1] = 1;
1385     Param[1]--;
1386     if (Param[1] < 0) Param[1] = 0;
1387     if (Param[1] > NumOfColumns-1) Param[1] = NumOfColumns-1;
1388     MoveCursor(Param[1],CursorY);
1389     }
1390    
1391     void CSCursorRight()
1392     {
1393     if (Param[1]<1) Param[1] = 1;
1394     if (CursorX + Param[1] > NumOfColumns-1)
1395     MoveCursor(NumOfColumns-1,CursorY);
1396     else
1397     MoveCursor(CursorX+Param[1],CursorY);
1398     }
1399    
1400     void CSCursorLeft()
1401     {
1402     if (Param[1]<1) Param[1] = 1;
1403     if (CursorX-Param[1] < 0)
1404     MoveCursor(0,CursorY);
1405     else
1406     MoveCursor(CursorX-Param[1],CursorY);
1407     }
1408    
1409     void CSMoveToLineN()
1410     {
1411     if (Param[1]<1) Param[1] = 1;
1412     if (RelativeOrgMode)
1413     {
1414     if (CursorTop+Param[1]-1 > CursorBottom)
1415     MoveCursor(CursorX,CursorBottom);
1416     else
1417     MoveCursor(CursorX,CursorTop+Param[1]-1);
1418     }
1419     else {
1420     if (Param[1] > NumOfLines-StatusLine)
1421     MoveCursor(CursorX,NumOfLines-1-StatusLine);
1422     else
1423     MoveCursor(CursorX,Param[1]-1);
1424     }
1425     }
1426    
1427     void CSMoveToXY()
1428     {
1429     int NewX, NewY;
1430    
1431     if (Param[1]<1) Param[1] = 1;
1432     if ((NParam < 2) || (Param[2]<1)) Param[2] = 1;
1433     NewX = Param[2] - 1;
1434     if (NewX > NumOfColumns-1) NewX = NumOfColumns-1;
1435    
1436     if ((StatusLine>0) && (CursorY==NumOfLines-1))
1437     NewY = CursorY;
1438     else if (RelativeOrgMode)
1439     {
1440     NewY = CursorTop + Param[1] - 1;
1441     if (NewY > CursorBottom) NewY = CursorBottom;
1442     }
1443     else {
1444     NewY = Param[1] - 1;
1445     if (NewY > NumOfLines-1-StatusLine)
1446     NewY = NumOfLines-1-StatusLine;
1447     }
1448     MoveCursor(NewX,NewY);
1449     }
1450    
1451     void CSDeleteTabStop()
1452     {
1453     if (Param[1]==-1) Param[1] = 0;
1454     ClearTabStop(Param[1]);
1455     }
1456    
1457     void CS_h_Mode()
1458     {
1459     switch (Param[1]) {
1460     case 2: KeybEnabled = FALSE; break;
1461     case 4: InsertMode = TRUE; break;
1462     case 12:
1463     ts.LocalEcho = 0;
1464     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1465     TelChangeEcho();
1466     break;
1467     case 20:
1468     LFMode = TRUE;
1469     ts.CRSend = IdCRLF;
1470     cv.CRSend = IdCRLF;
1471     break;
1472     }
1473     }
1474    
1475     void CS_i_Mode()
1476     {
1477     if (Param[1]==-1) Param[1] = 0;
1478     switch (Param[1]) {
1479     /* print screen */
1480     // PrintEX -- TRUE: print screen
1481     // FALSE: scroll region
1482     case 0: BuffPrint(! PrintEX); break;
1483     /* printer controller mode off */
1484     case 4: break; /* See PrnParseCS() */
1485     /* printer controller mode on */
1486     case 5:
1487     if (! AutoPrintMode)
1488     OpenPrnFile();
1489     DirectPrn = (ts.PrnDev[0]!=0);
1490     PrinterMode = TRUE;
1491     break;
1492     }
1493     }
1494    
1495     void CS_l_Mode()
1496     {
1497     switch (Param[1]) {
1498     case 2: KeybEnabled = TRUE; break;
1499     case 4: InsertMode = FALSE; break;
1500     case 12:
1501     ts.LocalEcho = 1;
1502     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1503     TelChangeEcho();
1504     break;
1505     case 20:
1506     LFMode = FALSE;
1507     ts.CRSend = IdCR;
1508     cv.CRSend = IdCR;
1509     break;
1510     }
1511     }
1512    
1513     void CS_n_Mode()
1514     {
1515     char Report[16];
1516     int Y;
1517    
1518     switch (Param[1]) {
1519     case 5:
1520     if (Send8BitMode)
1521     CommBinaryOut(&cv,"\2330n",3); /* Device Status Report -> Ready */
1522     else
1523     CommBinaryOut(&cv,"\033[0n",4); /* Device Status Report -> Ready */
1524     break;
1525     case 6:
1526     /* Cursor Position Report */
1527     Y = CursorY+1;
1528     if ((StatusLine>0) &&
1529     (Y==NumOfLines))
1530     Y = 1;
1531     if (Send8BitMode)
1532     _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\233%u;%uR", CLocale, Y, CursorX+1);
1533     else
1534     _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\033[%u;%uR", CLocale, Y, CursorX+1);
1535     CommBinaryOut(&cv,Report,strlen(Report));
1536     break;
1537     }
1538     }
1539    
1540     void CSSetAttr()
1541     {
1542     int i, P;
1543    
1544     UpdateStr();
1545     for (i=1 ; i<=NParam ; i++)
1546     {
1547     P = Param[i];
1548     if (P<0) P = 0;
1549     switch (P) {
1550     case 0: /* Clear all */
1551     CharAttr = DefCharAttr;
1552     BuffSetCurCharAttr(CharAttr);
1553     break;
1554    
1555     case 1: /* Bold */
1556     CharAttr.Attr |= AttrBold;
1557     BuffSetCurCharAttr(CharAttr);
1558     break;
1559    
1560     case 4: /* Under line */
1561     CharAttr.Attr |= AttrUnder;
1562     BuffSetCurCharAttr(CharAttr);
1563     break;
1564    
1565     case 5: /* Blink */
1566     CharAttr.Attr |= AttrBlink;
1567     BuffSetCurCharAttr(CharAttr);
1568     break;
1569    
1570     case 7: /* Reverse */
1571     CharAttr.Attr |= AttrReverse;
1572     BuffSetCurCharAttr(CharAttr);
1573     break;
1574    
1575     case 22: /* Bold off */
1576     CharAttr.Attr &= ~ AttrBold;
1577     BuffSetCurCharAttr(CharAttr);
1578     break;
1579    
1580     case 24: /* Under line off */
1581     CharAttr.Attr &= ~ AttrUnder;
1582     BuffSetCurCharAttr(CharAttr);
1583     break;
1584    
1585     case 25: /* Blink off */
1586     CharAttr.Attr &= ~ AttrBlink;
1587     BuffSetCurCharAttr(CharAttr);
1588     break;
1589    
1590     case 27: /* Reverse off */
1591     CharAttr.Attr &= ~ AttrReverse;
1592     BuffSetCurCharAttr(CharAttr);
1593     break;
1594    
1595     case 30:
1596     case 31:
1597     case 32:
1598     case 33:
1599     case 34:
1600     case 35:
1601     case 36:
1602     case 37: /* text color */
1603     CharAttr.Attr2 |= Attr2Fore;
1604     CharAttr.Fore = P - 30;
1605     BuffSetCurCharAttr(CharAttr);
1606     break;
1607    
1608     case 38: /* text color (256color mode) */
1609     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1610     i++;
1611     if (i < NParam) {
1612     P = Param[++i];
1613     if (P<0) {
1614     P = 0;
1615     }
1616     CharAttr.Attr2 |= Attr2Fore;
1617     CharAttr.Fore = P;
1618     BuffSetCurCharAttr(CharAttr);
1619     }
1620     }
1621     break;
1622    
1623     case 39: /* Reset text color */
1624     CharAttr.Attr2 &= ~ Attr2Fore;
1625     CharAttr.Fore = AttrDefaultFG;
1626     BuffSetCurCharAttr(CharAttr);
1627     break;
1628    
1629     case 40:
1630     case 41:
1631     case 42:
1632     case 43:
1633     case 44:
1634     case 45:
1635     case 46:
1636     case 47: /* Back color */
1637     CharAttr.Attr2 |= Attr2Back;
1638     CharAttr.Back = P - 40;
1639     BuffSetCurCharAttr(CharAttr);
1640     break;
1641    
1642     case 48: /* Back color (256color mode) */
1643     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1644     i++;
1645     if (i < NParam) {
1646     P = Param[++i];
1647     if (P<0) {
1648     P = 0;
1649     }
1650     CharAttr.Attr2 |= Attr2Back;
1651     CharAttr.Back = P;
1652     BuffSetCurCharAttr(CharAttr);
1653     }
1654     }
1655     break;
1656    
1657     case 49: /* Reset back color */
1658     CharAttr.Attr2 &= ~ Attr2Back;
1659     CharAttr.Back = AttrDefaultBG;
1660     BuffSetCurCharAttr(CharAttr);
1661     break;
1662    
1663     case 90:
1664     case 91:
1665     case 92:
1666     case 93:
1667     case 94:
1668     case 95:
1669     case 96:
1670     case 97: /* aixterm style text color */
1671     if (ts.ColorFlag & CF_AIXTERM16) {
1672     CharAttr.Attr2 |= Attr2Fore;
1673     CharAttr.Fore = P - 90 + 8;
1674     BuffSetCurCharAttr(CharAttr);
1675     }
1676     break;
1677    
1678     case 100:
1679     if (! (ts.ColorFlag & CF_AIXTERM16)) {
1680     /* Reset text and back color */
1681     CharAttr.Attr2 &= ~ (Attr2Fore | Attr2Back);
1682     CharAttr.Fore = AttrDefaultFG;
1683     CharAttr.Back = AttrDefaultBG;
1684     BuffSetCurCharAttr(CharAttr);
1685     break;
1686     }
1687     /* fall through to aixterm style back color */
1688    
1689     case 101:
1690     case 102:
1691     case 103:
1692     case 104:
1693     case 105:
1694     case 106:
1695     case 107: /* aixterm style back color */
1696     if (ts.ColorFlag & CF_AIXTERM16) {
1697     CharAttr.Attr2 |= Attr2Back;
1698     CharAttr.Back = P - 100 + 8;
1699     BuffSetCurCharAttr(CharAttr);
1700     }
1701     break;
1702     }
1703     }
1704     }
1705    
1706     void CSSetScrollRegion()
1707     {
1708     if ((StatusLine>0) &&
1709     (CursorY==NumOfLines-1))
1710     {
1711     MoveCursor(0,CursorY);
1712     return;
1713     }
1714 doda 2484 if (Param[1]<1) Param[1] =1;
1715 maya 2476 if ((NParam < 2) | (Param[2]<1))
1716     Param[2] = NumOfLines-StatusLine;
1717     Param[1]--;
1718     Param[2]--;
1719     if (Param[1] > NumOfLines-1-StatusLine)
1720     Param[1] = NumOfLines-1-StatusLine;
1721     if (Param[2] > NumOfLines-1-StatusLine)
1722     Param[2] = NumOfLines-1-StatusLine;
1723     if (Param[1] >= Param[2]) return;
1724     CursorTop = Param[1];
1725     CursorBottom = Param[2];
1726     if (RelativeOrgMode) MoveCursor(0,CursorTop);
1727     else MoveCursor(0,0);
1728     }
1729    
1730     void CSSunSequence() /* Sun terminal private sequences */
1731     {
1732     char Report[16];
1733    
1734     switch (Param[1]) {
1735     case 8: /* set terminal size */
1736     if ((Param[2]<=1) || (NParam<2)) Param[2] = 24;
1737     if ((Param[3]<=1) || (NParam<3)) Param[3] = 80;
1738     ChangeTerminalSize(Param[3],Param[2]);
1739     break;
1740     case 14: /* get window size??? */
1741     /* this is not actual window size */
1742     if (Send8BitMode)
1743     CommBinaryOut(&cv,"\2334;640;480t",11);
1744     else
1745     CommBinaryOut(&cv,"\033[4;640;480t",12);
1746     break;
1747     case 18: /* get terminal size */
1748     if (Send8BitMode)
1749     _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\2338;%u;%u;t", CLocale, NumOfLines-StatusLine, NumOfColumns);
1750     else
1751     _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "\033[8;%u;%u;t", CLocale, NumOfLines-StatusLine, NumOfColumns);
1752     CommBinaryOut(&cv,Report,strlen(Report));
1753     break;
1754     }
1755     }
1756    
1757     void CSGT(BYTE b)
1758     {
1759     switch (b) {
1760     case 'c': /* second terminal report */
1761     if (Send8BitMode)
1762     CommBinaryOut(&cv,"\233>32;10;2c",11); /* VT382 */
1763     else
1764     CommBinaryOut(&cv,"\033[>32;10;2c",11); /* VT382 */
1765     break;
1766     case 'J':
1767     if (Param[1]==3) // IO-8256 terminal
1768     {
1769     if (Param[2]<1) Param[2]=1;
1770     if (Param[3]<1) Param[3]=1;
1771     if (Param[4]<1) Param[4]=1;
1772     if (Param[5]<1) Param[5]=1;
1773     BuffEraseBox(Param[3]-1,Param[2]-1,
1774     Param[5]-1,Param[4]-1);
1775     }
1776     break;
1777     case 'K':
1778     if ((NParam>=2) && (Param[1]==5))
1779     { // IO-8256 terminal
1780     switch (Param[2]) {
1781     case 3:
1782     case 4:
1783     case 5:
1784     case 6:
1785     BuffDrawLine(CharAttr, Param[2], Param[3]);
1786     break;
1787     case 12:
1788     /* Text color */
1789     if ((Param[3]>=0) && (Param[3]<=7))
1790     {
1791     switch (Param[3]) {
1792     case 3: CharAttr.Fore = IdBlue; break;
1793     case 4: CharAttr.Fore = IdCyan; break;
1794     case 5: CharAttr.Fore = IdYellow; break;
1795     case 6: CharAttr.Fore = IdMagenta; break;
1796     default: CharAttr.Fore = Param[3]; break;
1797     }
1798     CharAttr.Attr2 |= Attr2Fore;
1799     BuffSetCurCharAttr(CharAttr);
1800     }
1801     break;
1802     }
1803     }
1804     else if (Param[1]==3)
1805     {// IO-8256 terminal
1806     if (Param[2]<1) Param[2] = 1;
1807     if (Param[3]<1) Param[2] = 1;
1808     BuffEraseCharsInLine(Param[2]-1,Param[3]-Param[2]+1);
1809     }
1810     break;
1811     }
1812     }
1813    
1814     void CSQExchangeColor()
1815     {
1816     COLORREF ColorRef;
1817    
1818     BuffUpdateScroll();
1819    
1820     ColorRef = ts.VTColor[0];
1821     ts.VTColor[0] = ts.VTColor[1];
1822     ts.VTColor[1] = ColorRef;
1823     #ifdef ALPHABLEND_TYPE2
1824     BGInitialize();
1825     #endif
1826     DispChangeBackground();
1827 doda 2554 UpdateWindow(HVTWin);
1828 maya 2476 }
1829    
1830     void CSQ_h_Mode()
1831     {
1832     int i;
1833    
1834     for (i = 1 ; i<=NParam ; i++)
1835     switch (Param[i]) {
1836     case 1: AppliCursorMode = TRUE; break;
1837     case 3:
1838     ChangeTerminalSize(132,NumOfLines-StatusLine);
1839     break;
1840     case 5:
1841     if (ReverseColor) return;
1842     ReverseColor = TRUE;
1843     /* Exchange text/back color */
1844     CSQExchangeColor();
1845     break;
1846     case 6:
1847     if ((StatusLine>0) &&
1848     (CursorY==NumOfLines-1))
1849     MoveCursor(0,CursorY);
1850     else {
1851     RelativeOrgMode = TRUE;
1852     MoveCursor(0,CursorTop);
1853     }
1854     break;
1855     case 7: AutoWrapMode = TRUE; break;
1856     case 8: AutoRepeatMode = TRUE; break;
1857     case 9:
1858     if (ts.MouseEventTracking)
1859     MouseReportMode = IdMouseTrackX10;
1860     break;
1861     case 19: PrintEX = TRUE; break;
1862     case 25: DispEnableCaret(TRUE); break; // cursor on
1863     case 38:
1864     if (ts.AutoWinSwitch>0)
1865     ChangeEmu = IdTEK; /* Enter TEK Mode */
1866     break;
1867     case 59:
1868     if (ts.Language==IdJapanese)
1869     { /* kanji terminal */
1870     Gn[0] = IdASCII;
1871     Gn[1] = IdKatakana;
1872     Gn[2] = IdKatakana;
1873     Gn[3] = IdKanji;
1874     Glr[0] = 0;
1875     if ((ts.KanjiCode==IdJIS) &&
1876     (ts.JIS7Katakana==0))
1877     Glr[1] = 2; // 8-bit katakana
1878     else
1879     Glr[1] = 3;
1880     }
1881     break;
1882     case 66: AppliKeyMode = TRUE; break;
1883     case 67: ts.BSKey = IdBS; break;
1884     case 1000:
1885     if (ts.MouseEventTracking)
1886     MouseReportMode = IdMouseTrackVT200;
1887     break;
1888     case 1001:
1889     if (ts.MouseEventTracking)
1890     MouseReportMode = IdMouseTrackVT200Hl;
1891     break;
1892     case 1002:
1893     if (ts.MouseEventTracking)
1894     MouseReportMode = IdMouseTrackBtnEvent;
1895     break;
1896     case 1003:
1897     if (ts.MouseEventTracking)
1898     MouseReportMode = IdMouseTrackAllEvent;
1899     break;
1900     case 1004:
1901     if (ts.MouseEventTracking)
1902     FocusReportMode = TRUE;
1903     break;
1904     }
1905     }
1906    
1907     void CSQ_i_Mode()
1908     {
1909     if (Param[1]==-1) Param[1] = 0;
1910     switch (Param[1]) {
1911     case 1:
1912     OpenPrnFile();
1913     BuffDumpCurrentLine(LF);
1914     if (! AutoPrintMode)
1915     ClosePrnFile();
1916     break;
1917     /* auto print mode off */
1918     case 4:
1919     if (AutoPrintMode)
1920     {
1921     ClosePrnFile();
1922     AutoPrintMode = FALSE;
1923     }
1924     break;
1925     /* auto print mode on */
1926     case 5:
1927     if (! AutoPrintMode)
1928     {
1929     OpenPrnFile();
1930     AutoPrintMode = TRUE;
1931     }
1932     break;
1933     }
1934     }
1935    
1936     void CSQ_l_Mode()
1937     {
1938     int i;
1939    
1940     for (i = 1 ; i <= NParam ; i++)
1941     switch (Param[i]) {
1942     case 1: AppliCursorMode = FALSE; break;
1943     case 3:
1944     ChangeTerminalSize(80,NumOfLines-StatusLine);
1945     break;
1946     case 5:
1947     if (! ReverseColor) return;
1948     ReverseColor = FALSE;
1949     /* Exchange text/back color */
1950     CSQExchangeColor();
1951     break;
1952     case 6:
1953     if ((StatusLine>0) &&
1954     (CursorY==NumOfLines-1))
1955     MoveCursor(0,CursorY);
1956     else {
1957     RelativeOrgMode = FALSE;
1958     MoveCursor(0,0);
1959     }
1960     break;
1961     case 7: AutoWrapMode = FALSE; break;
1962     case 8: AutoRepeatMode = FALSE; break;
1963     case 9: MouseReportMode = IdMouseTrackNone; break;
1964     case 19: PrintEX = FALSE; break;
1965     case 25: DispEnableCaret(FALSE); break; // cursor off
1966     case 59:
1967     if (ts.Language==IdJapanese)
1968     { /* katakana terminal */
1969     Gn[0] = IdASCII;
1970     Gn[1] = IdKatakana;
1971     Gn[2] = IdKatakana;
1972     Gn[3] = IdKanji;
1973     Glr[0] = 0;
1974     if ((ts.KanjiCode==IdJIS) &&
1975     (ts.JIS7Katakana==0))
1976     Glr[1] = 2; // 8-bit katakana
1977     else
1978     Glr[1] = 3;
1979     }
1980     break;
1981     case 66: AppliKeyMode = FALSE; break;
1982     case 67: ts.BSKey = IdDEL; break;
1983     case 1000:
1984     case 1001:
1985     case 1002:
1986     case 1003: MouseReportMode = IdMouseTrackNone; break;
1987     case 1004: FocusReportMode = FALSE; break;
1988     }
1989     }
1990    
1991     void CSQ_n_Mode()
1992     {
1993     }
1994    
1995     void CSQuest(BYTE b)
1996     {
1997     switch (b) {
1998 doda 2484 case 'K': CSLineErase(); break;
1999 maya 2476 case 'h': CSQ_h_Mode(); break;
2000     case 'i': CSQ_i_Mode(); break;
2001     case 'l': CSQ_l_Mode(); break;
2002     case 'n': CSQ_n_Mode(); break;
2003     }
2004     }
2005    
2006     void SoftReset()
2007     // called by software-reset escape sequence handler
2008     {
2009     UpdateStr();
2010     AutoRepeatMode = TRUE;
2011     DispEnableCaret(TRUE); // cursor on
2012     InsertMode = FALSE;
2013     RelativeOrgMode = FALSE;
2014     AppliKeyMode = FALSE;
2015     AppliCursorMode = FALSE;
2016     if ((StatusLine>0) &&
2017     (CursorY == NumOfLines-1))
2018     MoveToMainScreen();
2019     CursorTop = 0;
2020     CursorBottom = NumOfLines-1-StatusLine;
2021     ResetCharSet();
2022    
2023     Send8BitMode = ts.Send8BitCtrl;
2024    
2025     /* Attribute */
2026     CharAttr = DefCharAttr;
2027     Special = FALSE;
2028     BuffSetCurCharAttr(CharAttr);
2029    
2030     // status buffers
2031     ResetSBuffers();
2032     }
2033    
2034     void CSExc(BYTE b)
2035     {
2036     switch (b) {
2037     case 'p':
2038     /* Software reset */
2039     SoftReset();
2040     break;
2041     }
2042     }
2043    
2044     void CSDouble(BYTE b)
2045     {
2046     switch (b) {
2047     case 'p':
2048     /* Select terminal mode (software reset) */
2049     SoftReset();
2050     if (NParam > 0) {
2051     switch (Param[1]) {
2052     case 61: // VT100 Mode
2053     Send8BitMode = FALSE; break;
2054     case 62: // VT200 Mode
2055     case 63: // VT300 Mode
2056     case 64: // VT400 Mode
2057     if (NParam > 1 && Param[2] == 1)
2058     Send8BitMode = FALSE;
2059     else
2060     Send8BitMode = TRUE;
2061     break;
2062     }
2063     }
2064     break;
2065     }
2066     }
2067    
2068     void CSDol(BYTE b)
2069     {
2070     switch (b) {
2071     case '}':
2072     if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2073     if (StatusLine==0) return;
2074     if ((Param[1]<1) && (CursorY==NumOfLines-1))
2075     MoveToMainScreen();
2076     else if ((Param[1]==1) && (CursorY<NumOfLines-1))
2077     MoveToStatusLine();
2078     break;
2079     case '~':
2080     if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2081     if (Param[1]<=1)
2082     HideStatusLine();
2083     else if ((StatusLine==0) && (Param[1]==2))
2084     ShowStatusLine(1); // show
2085     break;
2086     }
2087     }
2088    
2089     void PrnParseCS(BYTE b) // printer mode
2090     {
2091     ParseMode = ModeFirst;
2092     switch (ICount) {
2093     /* no intermediate char */
2094     case 0:
2095     switch (Prv) {
2096     /* no private parameter */
2097     case 0:
2098     switch (b) {
2099     case 'i':
2100     if (Param[1]==4)
2101     {
2102     PrinterMode = FALSE;
2103     // clear prn buff
2104     WriteToPrnFile(0,FALSE);
2105     if (! AutoPrintMode)
2106     ClosePrnFile();
2107     return;
2108     }
2109     break;
2110     } /* of case Prv=0 */
2111     break;
2112     }
2113     break;
2114     /* one intermediate char */
2115     case 1: break;
2116     } /* of case Icount */
2117    
2118     WriteToPrnFile(b,TRUE);
2119     }
2120    
2121     void ParseCS(BYTE b) /* b is the final char */
2122     {
2123     if (PrinterMode) { // printer mode
2124     PrnParseCS(b);
2125     return;
2126     }
2127    
2128     switch (ICount) {
2129     /* no intermediate char */
2130     case 0:
2131     switch (Prv) {
2132     /* no private parameter */
2133     case 0:
2134     switch (b) {
2135     case '@': CSInsertCharacter(); break;
2136     case 'A': CSCursorUp(); break;
2137     case 'B': CSCursorDown(); break;
2138     case 'C': CSCursorRight(); break;
2139     case 'D': CSCursorLeft(); break;
2140     case 'E': CSCursorDown1(); break;
2141     case 'F': CSCursorUp1(); break;
2142     case 'G': CSMoveToColumnN(); break;
2143     case 'H': CSMoveToXY(); break;
2144 doda 2553 case 'I': CSForwardTab(); break; // CHT
2145 maya 2476 case 'J': CSScreenErase(); break;
2146     case 'K': CSLineErase(); break;
2147     case 'L': CSInsertLine(); break;
2148     case 'M': CSDeleteNLines(); break;
2149     case 'P': CSDeleteCharacter(); break;
2150     case 'S': CSScrollUP(); break; // SU
2151     case 'T': CSScrollDown(); break; // SD
2152     case 'X': CSEraseCharacter(); break;
2153 doda 2553 case 'Z': CSBackwardTab(); break; // CBT
2154 maya 2476 case '`': CSMoveToColumnN(); break;
2155     case 'a': CSCursorRight(); break;
2156     case 'c': AnswerTerminalType(); break;
2157     case 'd': CSMoveToLineN(); break;
2158     case 'e': CSCursorUp(); break;
2159     case 'f': CSMoveToXY(); break;
2160     case 'g': CSDeleteTabStop(); break;
2161     case 'h': CS_h_Mode(); break;
2162     case 'i': CS_i_Mode(); break;
2163     case 'l': CS_l_Mode(); break;
2164     case 'm': CSSetAttr(); break;
2165     case 'n': CS_n_Mode(); break;
2166     case 'r': CSSetScrollRegion(); break;
2167     case 's': SaveCursor(); break;
2168     case 't': CSSunSequence(); break;
2169     case 'u': RestoreCursor(); break;
2170     } /* of case Prv=0 */
2171     break;
2172     /* private parameter = '>' */
2173     case '>': CSGT(b); break;
2174     /* private parameter = '?' */
2175     case '?': CSQuest(b); break;
2176     }
2177     break;
2178     /* one intermediate char */
2179     case 1:
2180     switch (IntChar[1]) {
2181     /* intermediate char = '!' */
2182     case '!': CSExc(b); break;
2183     /* intermediate char = '"' */
2184     case '"': CSDouble(b); break;
2185     /* intermediate char = '$' */
2186     case '$': CSDol(b); break;
2187     }
2188     break;
2189     } /* of case Icount */
2190    
2191     ParseMode = ModeFirst;
2192     }
2193    
2194     void ControlSequence(BYTE b)
2195     {
2196     if ((b<=US) || (b>=0x80) && (b<=0x9F))
2197     ParseControl(b); /* ctrl char */
2198     else if ((b>=0x40) && (b<=0x7E))
2199     ParseCS(b); /* terminate char */
2200     else {
2201     if (PrinterMode)
2202     WriteToPrnFile(b,FALSE);
2203    
2204     if ((b>=0x20) && (b<=0x2F))
2205     { /* intermediate char */
2206     if (ICount<IntCharMax) ICount++;
2207     IntChar[ICount] = b;
2208     }
2209     else if ((b>=0x30) && (b<=0x39))
2210     {
2211     if (Param[NParam] < 0)
2212 doda 2484 Param[NParam] = 0;
2213 maya 2476 if (Param[NParam]<1000)
2214     Param[NParam] = Param[NParam]*10 + b - 0x30;
2215     }
2216     else if (b==0x3B)
2217     {
2218     if (NParam < NParamMax)
2219     {
2220     NParam++;
2221     Param[NParam] = -1;
2222     }
2223     }
2224     else if ((b>=0x3C) && (b<=0x3F))
2225     { /* private char */
2226     if (FirstPrm) Prv = b;
2227     }
2228     }
2229     FirstPrm = FALSE;
2230     }
2231    
2232     void DeviceControl(BYTE b)
2233     {
2234 doda 2528 if (ESCFlag && (b=='\\') || (b==ST && ts.KanjiCode!=IdSJIS))
2235 maya 2476 {
2236     ESCFlag = FALSE;
2237     ParseMode = SavedMode;
2238     return;
2239     }
2240    
2241     if (b==ESC)
2242     {
2243     ESCFlag = TRUE;
2244     return;
2245     }
2246     else ESCFlag = FALSE;
2247    
2248 doda 2487 if (b<=US)
2249 maya 2476 ParseControl(b);
2250     else if ((b>=0x30) && (b<=0x39))
2251     {
2252 doda 2484 if (Param[NParam] < 0) Param[NParam] = 0;
2253 maya 2476 if (Param[NParam]<1000)
2254     Param[NParam] = Param[NParam]*10 + b - 0x30;
2255     }
2256     else if (b==0x3B)
2257     {
2258     if (NParam < NParamMax)
2259     {
2260     NParam++;
2261     Param[NParam] = -1;
2262     }
2263     }
2264     else if ((b>=0x40) && (b<=0x7E))
2265     {
2266     if (b=='|')
2267     {
2268     ParseMode = ModeDCUserKey;
2269     if (Param[1] < 1) ClearUserKey();
2270     WaitKeyId = TRUE;
2271     NewKeyId = 0;
2272     }
2273     else ParseMode = ModeSOS;
2274     }
2275     }
2276    
2277     void DCUserKey(BYTE b)
2278     {
2279 doda 2528 if (ESCFlag && (b=='\\') || (b==ST && ts.KanjiCode!=IdSJIS))
2280 maya 2476 {
2281     if (! WaitKeyId) DefineUserKey(NewKeyId,NewKeyStr,NewKeyLen);
2282     ESCFlag = FALSE;
2283     ParseMode = SavedMode;
2284     return;
2285     }
2286    
2287     if (b==ESC)
2288     {
2289     ESCFlag = TRUE;
2290     return;
2291     }
2292     else ESCFlag = FALSE;
2293    
2294     if (WaitKeyId)
2295     {
2296     if ((b>=0x30) && (b<=0x39))
2297     {
2298     if (NewKeyId<1000)
2299     NewKeyId = NewKeyId*10 + b - 0x30;
2300     }
2301     else if (b==0x2F)
2302     {
2303     WaitKeyId = FALSE;
2304     WaitHi = TRUE;
2305     NewKeyLen = 0;
2306     }
2307     }
2308     else {
2309     if (b==0x3B)
2310     {
2311     DefineUserKey(NewKeyId,NewKeyStr,NewKeyLen);
2312     WaitKeyId = TRUE;
2313     NewKeyId = 0;
2314     }
2315     else {
2316     if (NewKeyLen < FuncKeyStrMax)
2317     {
2318     if (WaitHi)
2319     {
2320     NewKeyStr[NewKeyLen] = ConvHexChar(b) << 4;
2321     WaitHi = FALSE;
2322     }
2323     else {
2324     NewKeyStr[NewKeyLen] = NewKeyStr[NewKeyLen] +
2325     ConvHexChar(b);
2326     WaitHi = TRUE;
2327     NewKeyLen++;
2328     }
2329     }
2330     }
2331     }
2332     }
2333    
2334     void IgnoreString(BYTE b)
2335     {
2336 doda 2528 if ((ESCFlag && (b=='\\')) ||
2337     (b<=US && b!=ESC && b!=HT) ||
2338     (b==ST && ts.KanjiCode!=IdSJIS))
2339 maya 2476 ParseMode = SavedMode;
2340    
2341     if (b==ESC) ESCFlag = TRUE;
2342     else ESCFlag = FALSE;
2343     }
2344    
2345     BOOL XsParseColor(char *colspec, COLORREF *color)
2346     {
2347 doda 2486 unsigned int r, g, b;
2348 doda 2484 // double dr, dg, db;
2349 maya 2476
2350 doda 2484 r = g = b = 255;
2351 maya 2476
2352 doda 2484 if (colspec == NULL || color == NULL) {
2353     return FALSE;
2354     }
2355 maya 2476
2356 doda 2484 if (_strnicmp(colspec, "rgb:", 4) == 0) {
2357     switch (strlen(colspec)) {
2358     case 9: // rgb:R/G/B
2359     if (sscanf(colspec, "rgb:%1x/%1x/%1x", &r, &g, &b) != 3) {
2360     return FALSE;
2361     }
2362     r *= 17; g *= 17; b *= 17;
2363     break;
2364     case 12: // rgb:RR/GG/BB
2365     if (sscanf(colspec, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3) {
2366     return FALSE;
2367     }
2368     break;
2369     case 15: // rgb:RRR/GGG/BBB
2370     if (sscanf(colspec, "rgb:%3x/%3x/%3x", &r, &g, &b) != 3) {
2371     return FALSE;
2372     }
2373     r >>= 4; g >>= 4; b >>= 4;
2374     break;
2375     case 18: // rgb:RRRR/GGGG/BBBB
2376     if (sscanf(colspec, "rgb:%4x/%4x/%4x", &r, &g, &b) != 3) {
2377     return FALSE;
2378     }
2379     r >>= 8; g >>= 8; b >>= 8;
2380     break;
2381     default:
2382     return FALSE;
2383     }
2384 maya 2476 }
2385 doda 2484 // else if (_strnicmp(colspec, "rgbi:", 5) == 0) {
2386     // ; /* nothing to do */
2387     // }
2388     else if (colspec[0] == '#') {
2389     switch (strlen(colspec)) {
2390     case 4: // #RGB
2391     if (sscanf(colspec, "#%1x%1x%1x", &r, &g, &b) != 3) {
2392     return FALSE;
2393     }
2394     r <<= 4; g <<= 4; b <<= 4;
2395     break;
2396     case 7: // #RRGGBB
2397     if (sscanf(colspec, "#%2x%2x%2x", &r, &g, &b) != 3) {
2398     return FALSE;
2399     }
2400     break;
2401     case 10: // #RRRGGGBBB
2402     if (sscanf(colspec, "#%3x%3x%3x", &r, &g, &b) != 3) {
2403     return FALSE;
2404     }
2405     r >>= 4; g >>= 4; b >>= 4;
2406     break;
2407     case 13: // #RRRRGGGGBBBB
2408     if (sscanf(colspec, "#%4x%4x%4x", &r, &g, &b) != 3) {
2409     return FALSE;
2410     }
2411     r >>= 8; g >>= 8; b >>= 8;
2412     break;
2413     default:
2414     return FALSE;
2415     }
2416 maya 2476 }
2417 doda 2484 else {
2418     return FALSE;
2419 maya 2476 }
2420 doda 2484
2421 doda 2486 if (r > 255 || g > 255 || b > 255) {
2422 doda 2484 return FALSE;
2423 maya 2476 }
2424    
2425 doda 2484 *color = RGB(r, g, b);
2426     return TRUE;
2427 maya 2476 }
2428    
2429     #define ModeXsFirst 1
2430     #define ModeXsString 2
2431     #define ModeXsColorNum 3
2432     #define ModeXsColorSpec 4
2433     #define ModeXsEsc 5
2434     void XSequence(BYTE b)
2435     {
2436 doda 2484 static BYTE XsParseMode = ModeXsFirst, PrevMode;
2437     static char StrBuff[sizeof(ts.Title)];
2438 doda 2486 static unsigned int ColorNumber, StrLen;
2439 doda 2484 COLORREF color;
2440 maya 2476
2441 doda 2484 switch (XsParseMode) {
2442     case ModeXsFirst:
2443     if (isdigit(b)) {
2444     if (Param[1] < 1000) {
2445     Param[1] = Param[1]*10 + b - '0';
2446     }
2447     }
2448     else if (b == ';') {
2449     StrBuff[0] = '\0';
2450     StrLen = 0;
2451     if (Param[1] == 4) {
2452     ColorNumber = 0;
2453     XsParseMode = ModeXsColorNum;
2454     }
2455     else {
2456     XsParseMode = ModeXsString;
2457     }
2458     }
2459     else {
2460     ParseMode = ModeFirst;
2461     }
2462     break;
2463     case ModeXsString:
2464 doda 2528 if ((b==ST && ts.KanjiCode!=IdSJIS) || b==BEL) { /* String Terminator */
2465 doda 2484 StrBuff[StrLen] = '\0';
2466     switch (Param[1]) {
2467     case 0: /* Change window title and icon name */
2468     case 1: /* Change icon name */
2469     case 2: /* Change window title */
2470     strncpy_s(ts.Title, sizeof(ts.Title), StrBuff, _TRUNCATE);
2471     // (2006.6.15 maya) �^�C�g�����n����������SJIS������
2472     ConvertToCP932(ts.Title, sizeof(ts.Title));
2473     ChangeTitle();
2474     break;
2475     default:
2476     /* nothing to do */;
2477     }
2478     ParseMode = ModeFirst;
2479     XsParseMode = ModeXsFirst;
2480     }
2481     else if (b == ESC) { /* Escape */
2482     PrevMode = ModeXsString;
2483     XsParseMode = ModeXsEsc;
2484     }
2485     else if (b <= US) { /* Other control character -- invalid sequence */
2486     ParseMode = ModeFirst;
2487     XsParseMode = ModeXsFirst;
2488     }
2489     else if (StrLen < sizeof(StrBuff) - 1) {
2490     StrBuff[StrLen++] = b;
2491     }
2492     break;
2493     case ModeXsColorNum:
2494     if (isdigit(b)) {
2495     ColorNumber = ColorNumber*10 + b - '0';
2496     }
2497     else if (b == ';') {
2498     XsParseMode = ModeXsColorSpec;
2499     StrBuff[0] = '\0';
2500     StrLen = 0;
2501     }
2502     else {
2503     ParseMode = ModeFirst;
2504     XsParseMode = ModeXsFirst;
2505     }
2506     break;
2507     case ModeXsColorSpec:
2508 doda 2528 if ((b==ST && ts.KanjiCode!=IdSJIS) || b==BEL) { /* String Terminator */
2509 doda 2484 StrBuff[StrLen] = '\0';
2510 doda 2486 if ((ts.ColorFlag & CF_XTERM256) && ColorNumber <= 255) {
2511 doda 2484 if (strcmp(StrBuff, "?") == 0) {
2512     color = DispGetANSIColor(ColorNumber);
2513     if (Send8BitMode) {
2514     _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2515     "\2354;%d;rgb:%02x/%02x/%02x\234", CLocale, ColorNumber,
2516     GetRValue(color), GetGValue(color), GetBValue(color));
2517     }
2518     else {
2519     _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2520     "\033]4;%d;rgb:%02x/%02x/%02x\033\\", CLocale, ColorNumber,
2521     GetRValue(color), GetGValue(color), GetBValue(color));
2522     }
2523     ParseMode = ModeFirst;
2524     XsParseMode = ModeXsFirst;
2525     CommBinaryOut(&cv, StrBuff, strlen(StrBuff));
2526     break;
2527     }
2528     else if (XsParseColor(StrBuff, &color)) {
2529     DispSetANSIColor(ColorNumber, color);
2530     }
2531     }
2532     ParseMode = ModeFirst;
2533     XsParseMode = ModeXsFirst;
2534     }
2535     else if (b == ESC) {
2536     PrevMode = ModeXsColorSpec;
2537     XsParseMode = ModeXsEsc;
2538     }
2539     else if (b <= US) { /* Other control character -- invalid sequence */
2540     ParseMode = ModeFirst;
2541     XsParseMode = ModeXsFirst;
2542     }
2543     else if (b == ';') {
2544 doda 2486 if ((ts.ColorFlag & CF_XTERM256) && ColorNumber <= 255) {
2545 doda 2484 if (strcmp(StrBuff, "?") == 0) {
2546     color = DispGetANSIColor(ColorNumber);
2547     if (Send8BitMode) {
2548     _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2549     "\2354;%d;rgb:%02x/%02x/%02x\234", CLocale, ColorNumber,
2550     GetRValue(color), GetGValue(color), GetBValue(color));
2551     }
2552     else {
2553     _snprintf_s_l(StrBuff, sizeof(StrBuff), _TRUNCATE,
2554     "\033]4;%d;rgb:%02x/%02x/%02x\033\\", CLocale, ColorNumber,
2555     GetRValue(color), GetGValue(color), GetBValue(color));
2556     }
2557     XsParseMode = ModeXsColorNum;
2558     CommBinaryOut(&cv, StrBuff, strlen(StrBuff));
2559     }
2560     else if (XsParseColor(StrBuff, &color)) {
2561     DispSetANSIColor(ColorNumber, color);
2562     }
2563     }
2564     ColorNumber = 0;
2565     StrBuff[0] = '\0';
2566     StrLen = 0;
2567     XsParseMode = ModeXsColorNum;
2568     }
2569     else if (StrLen < sizeof(StrBuff) - 1) {
2570     StrBuff[StrLen++] = b;
2571     }
2572     break;
2573     case ModeXsEsc:
2574     if (b == '\\') { /* String Terminator */
2575     XsParseMode = PrevMode;
2576 doda 2528 // XSequence(ST);
2577     XSequence(BEL);
2578 doda 2484 }
2579     else { /* Other character -- invalid sequence */
2580     ParseMode = ModeFirst;
2581     XsParseMode = ModeXsFirst;
2582     }
2583     break;
2584     // default:
2585     // ParseMode = ModeFirst;
2586     // XsParseMode = ModeXsFirst;
2587 maya 2476 }
2588     }
2589    
2590     void DLESeen(BYTE b)
2591     {
2592     ParseMode = ModeFirst;
2593     if (((ts.FTFlag & FT_BPAUTO)!=0) && (b=='B'))
2594     BPStart(IdBPAuto); /* Auto B-Plus activation */
2595     ChangeEmu = -1;
2596     }
2597    
2598     void CANSeen(BYTE b)
2599     {
2600     ParseMode = ModeFirst;
2601     if (((ts.FTFlag & FT_ZAUTO)!=0) && (b=='B'))
2602     ZMODEMStart(IdZAuto); /* Auto ZMODEM activation */
2603     ChangeEmu = -1;
2604     }
2605    
2606     BOOL CheckKanji(BYTE b)
2607     {
2608     BOOL Check;
2609    
2610     if (ts.Language!=IdJapanese) return FALSE;
2611    
2612     ConvJIS = FALSE;
2613    
2614     if (ts.KanjiCode==IdSJIS)
2615     {
2616     if ((0x80<b) && (b<0xa0) || (0xdf<b) && (b<0xfd))
2617     return TRUE; // SJIS kanji
2618     if ((0xa1<=b) && (b<=0xdf))
2619