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 4243 - (hide annotations) (download) (as text)
Tue Dec 21 04:11:15 2010 UTC (13 years, 3 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 99572 byte(s)
DECFI/DECBI 制御シーケンスに対応。

1 maya 3227 /* 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 doda 4225 #include <ctype.h>
14 maya 3227
15     #include "buffer.h"
16     #include "ttwinman.h"
17     #include "ttcommon.h"
18     #include "commlib.h"
19     #include "vtdisp.h"
20     #include "keyboard.h"
21     #include "ttlib.h"
22     #include "ttftypes.h"
23     #include "filesys.h"
24     #include "teraprn.h"
25     #include "telnet.h"
26    
27     #include "vtterm.h"
28    
29 doda 3443 #define MAPSIZE(x) (sizeof(x)/sizeof((x)[0]))
30 doda 3491 #define Accept8BitCtrl ((ts.TerminalID>=IdVT220J) && (ts.TermFlag & TF_ACCEPT8BITCTRL))
31 doda 3443
32 maya 3227 /* Parsing modes */
33     #define ModeFirst 0
34     #define ModeESC 1
35     #define ModeDCS 2
36     #define ModeDCUserKey 3
37     #define ModeSOS 4
38     #define ModeCSI 5
39     #define ModeXS 6
40     #define ModeDLE 7
41     #define ModeCAN 8
42    
43     #define NParamMax 16
44     #define IntCharMax 5
45    
46 doda 3997 /* DEC Locator Flag */
47     #define DecLocatorOneShot 1
48     #define DecLocatorPixel 2
49     #define DecLocatorButtonDown 4
50     #define DecLocatorButtonUp 8
51     #define DecLocatorFiltered 16
52    
53 maya 3227 void VisualBell();
54 doda 3999 BOOL DecLocatorReport(int Event, int Button);
55 maya 3227
56     /* character attribute */
57     static TCharAttr CharAttr;
58    
59     /* various modes of VT emulation */
60     static BOOL RelativeOrgMode;
61     static BOOL InsertMode;
62     static BOOL LFMode;
63     static BOOL AutoWrapMode;
64     static BOOL FocusReportMode;
65 doda 3743 static BOOL AltScr;
66 doda 3872 BOOL BracketedPaste;
67 maya 3227
68     // save/restore cursor
69     typedef struct {
70     int CursorX, CursorY;
71     TCharAttr Attr;
72     int Glr[2], Gn[4]; // G0-G3, GL & GR
73     BOOL AutoWrapMode;
74     BOOL RelativeOrgMode;
75     } TStatusBuff;
76     typedef TStatusBuff *PStatusBuff;
77    
78     // status buffer for main screen & status line
79 doda 3797 static TStatusBuff SBuff1, SBuff2, SBuff3;
80 maya 3227
81     static BOOL ESCFlag, JustAfterESC;
82     static BOOL KanjiIn;
83     static BOOL EUCkanaIn, EUCsupIn;
84     static int EUCcount;
85     static BOOL Special;
86    
87     static int Param[NParamMax+1];
88     static int NParam;
89     static BOOL FirstPrm;
90     static BYTE IntChar[IntCharMax+1];
91     static int ICount;
92     static BYTE Prv;
93     static int ParseMode, SavedMode;
94     static int ChangeEmu;
95    
96     /* user defined keys */
97     static BOOL WaitKeyId, WaitHi;
98    
99     /* GL, GR code group */
100     static int Glr[2];
101     /* G0, G1, G2, G3 code group */
102     static int Gn[4];
103     /* GL for single shift 2/3 */
104     static int GLtmp;
105     /* single shift 2/3 flag */
106     static BOOL SSflag;
107     /* JIS -> SJIS conversion flag */
108     static BOOL ConvJIS;
109     static WORD Kanji;
110    
111     // variables for status line mode
112     static int StatusX=0;
113     static BOOL StatusWrap=FALSE;
114     static BOOL StatusCursor=TRUE;
115     static int MainX, MainY; //cursor registers
116     static int MainTop, MainBottom; // scroll region registers
117     static BOOL MainWrap;
118     static BOOL MainCursor=TRUE;
119    
120     /* status for printer escape sequences */
121     static BOOL PrintEX = TRUE; // printing extent
122     // (TRUE: screen, FALSE: scroll region)
123     static BOOL AutoPrintMode = FALSE;
124     static BOOL PrinterMode = FALSE;
125     static BOOL DirectPrn = FALSE;
126    
127     /* User key */
128     static BYTE NewKeyStr[FuncKeyStrMax];
129     static int NewKeyId, NewKeyLen;
130    
131 doda 3997 /* Mouse Report */
132     int MouseReportMode;
133     unsigned int DecLocatorFlag;
134     int LastX, LastY;
135     int ButtonStat;
136 doda 3999 int FilterTop, FilterBottom, FilterLeft, FilterRight;
137 doda 3997
138 doda 3450 static _locale_t CLocale = NULL;
139 maya 3227
140 doda 3916 void ResetSBuffer(PStatusBuff sbuff)
141 maya 3227 {
142 doda 3916 sbuff->CursorX = 0;
143     sbuff->CursorY = 0;
144     sbuff->Attr = DefCharAttr;
145 maya 3227 if (ts.Language==IdJapanese)
146     {
147 doda 3916 sbuff->Gn[0] = IdASCII;
148     sbuff->Gn[1] = IdKatakana;
149     sbuff->Gn[2] = IdKatakana;
150     sbuff->Gn[3] = IdKanji;
151     sbuff->Glr[0] = 0;
152 maya 3227 if ((ts.KanjiCode==IdJIS) &&
153     (ts.JIS7Katakana==0))
154 doda 3916 sbuff->Glr[1] = 2; // 8-bit katakana
155 maya 3227 else
156 doda 3916 sbuff->Glr[1] = 3;
157 maya 3227 }
158     else {
159 doda 3916 sbuff->Gn[0] = IdASCII;
160     sbuff->Gn[1] = IdSpecial;
161     sbuff->Gn[2] = IdASCII;
162     sbuff->Gn[3] = IdASCII;
163     sbuff->Glr[0] = 0;
164     sbuff->Glr[1] = 0;
165 maya 3227 }
166 doda 3916 sbuff->AutoWrapMode = TRUE;
167     sbuff->RelativeOrgMode = FALSE;
168     }
169    
170     void ResetAllSBuffers()
171     {
172     ResetSBuffer(&SBuff1);
173 maya 3227 // copy SBuff1 to SBuff2
174     SBuff2 = SBuff1;
175 doda 3797 SBuff3 = SBuff1;
176 maya 3227 }
177    
178 doda 3916 void ResetCurSBuffer()
179     {
180     PStatusBuff Buff;
181    
182     if (AltScr) {
183     Buff = &SBuff3; // Alternate screen buffer
184     }
185     else {
186     Buff = &SBuff1; // Normal screen buffer
187     }
188     ResetSBuffer(Buff);
189     SBuff2 = *Buff;
190     }
191    
192 maya 3227 void ResetTerminal() /*reset variables but don't update screen */
193     {
194     DispReset();
195     BuffReset();
196    
197     /* Attribute */
198     CharAttr = DefCharAttr;
199     Special = FALSE;
200     BuffSetCurCharAttr(CharAttr);
201    
202     /* Various modes */
203     InsertMode = FALSE;
204     LFMode = (ts.CRSend == IdCRLF);
205     AutoWrapMode = TRUE;
206     AppliKeyMode = FALSE;
207     AppliCursorMode = FALSE;
208     RelativeOrgMode = FALSE;
209     ts.ColorFlag &= ~CF_REVERSEVIDEO;
210     AutoRepeatMode = TRUE;
211     Send8BitMode = ts.Send8BitCtrl;
212     FocusReportMode = FALSE;
213     MouseReportMode = IdMouseTrackNone;
214 doda 3997 DecLocatorFlag = 0;
215 maya 3227
216 doda 3997 LastX = 0;
217     LastY = 0;
218     ButtonStat = 0;
219    
220 doda 3450 if (CLocale == NULL) {
221     CLocale = _create_locale(LC_ALL, "C");
222     }
223 maya 3227
224     /* Character sets */
225     ResetCharSet();
226    
227     /* ESC flag for device control sequence */
228     ESCFlag = FALSE;
229     /* for TEK sequence */
230     JustAfterESC = FALSE;
231    
232     /* Parse mode */
233     ParseMode = ModeFirst;
234    
235     /* Clear printer mode */
236     PrinterMode = FALSE;
237    
238     // status buffers
239 doda 3916 ResetAllSBuffers();
240 doda 3745
241     // Alternate Screen Buffer
242     AltScr = FALSE;
243 doda 3872
244     // Bracketed Paste Mode
245     BracketedPaste = FALSE;
246 maya 3227 }
247    
248     void ResetCharSet()
249     {
250     if (ts.Language==IdJapanese)
251     {
252     Gn[0] = IdASCII;
253     Gn[1] = IdKatakana;
254     Gn[2] = IdKatakana;
255     Gn[3] = IdKanji;
256     Glr[0] = 0;
257     if ((ts.KanjiCode==IdJIS) &&
258     (ts.JIS7Katakana==0))
259     Glr[1] = 2; // 8-bit katakana
260     else
261     Glr[1] = 3;
262     }
263     else {
264     Gn[0] = IdASCII;
265     Gn[1] = IdSpecial;
266     Gn[2] = IdASCII;
267     Gn[3] = IdASCII;
268     Glr[0] = 0;
269     Glr[1] = 0;
270     cv.SendCode = IdASCII;
271     cv.SendKanjiFlag = FALSE;
272     cv.EchoCode = IdASCII;
273     cv.EchoKanjiFlag = FALSE;
274     }
275     /* Kanji flag */
276     KanjiIn = FALSE;
277     EUCkanaIn = FALSE;
278     EUCsupIn = FALSE;
279     SSflag = FALSE;
280    
281     cv.Language = ts.Language;
282     cv.CRSend = ts.CRSend;
283     cv.KanjiCodeEcho = ts.KanjiCode;
284     cv.JIS7KatakanaEcho = ts.JIS7Katakana;
285     cv.KanjiCodeSend = ts.KanjiCodeSend;
286     cv.JIS7KatakanaSend = ts.JIS7KatakanaSend;
287     cv.KanjiIn = ts.KanjiIn;
288     cv.KanjiOut = ts.KanjiOut;
289     }
290    
291     void ResetKeypadMode(BOOL DisabledModeOnly)
292     {
293     if (!DisabledModeOnly || ts.DisableAppKeypad) AppliKeyMode = FALSE;
294     if (!DisabledModeOnly || ts.DisableAppCursor) AppliCursorMode = FALSE;
295     }
296    
297     void MoveToMainScreen()
298     {
299     StatusX = CursorX;
300     StatusWrap = Wrap;
301     StatusCursor = IsCaretEnabled();
302    
303     CursorTop = MainTop;
304     CursorBottom = MainBottom;
305     Wrap = MainWrap;
306     DispEnableCaret(MainCursor);
307     MoveCursor(MainX,MainY); // move to main screen
308     }
309    
310     void MoveToStatusLine()
311     {
312     MainX = CursorX;
313     MainY = CursorY;
314     MainTop = CursorTop;
315     MainBottom = CursorBottom;
316     MainWrap = Wrap;
317     MainCursor = IsCaretEnabled();
318    
319     DispEnableCaret(StatusCursor);
320     MoveCursor(StatusX,NumOfLines-1); // move to status line
321     CursorTop = NumOfLines-1;
322     CursorBottom = CursorTop;
323     Wrap = StatusWrap;
324     }
325    
326     void HideStatusLine()
327     {
328     if ((StatusLine>0) &&
329     (CursorY==NumOfLines-1))
330     MoveToMainScreen();
331     StatusX = 0;
332     StatusWrap = FALSE;
333     StatusCursor = TRUE;
334     ShowStatusLine(0); //hide
335     }
336    
337     void ChangeTerminalSize(int Nx, int Ny)
338     {
339     BuffChangeTerminalSize(Nx,Ny);
340     StatusX = 0;
341     MainX = 0;
342     MainY = 0;
343     MainTop = 0;
344     MainBottom = NumOfColumns-1;
345     }
346    
347 doda 3471 void SendCSIstr(char *str, int len) {
348 doda 4024 int l;
349    
350     if (str == NULL || len < 0)
351 doda 3471 return;
352    
353 doda 4024 if (len == 0) {
354     l = strlen(str);
355     }
356     else {
357     l = len;
358     }
359    
360 doda 3471 if (Send8BitMode)
361     CommBinaryOut(&cv,"\233", 1);
362     else
363     CommBinaryOut(&cv,"\033[", 2);
364    
365 doda 4024 CommBinaryOut(&cv, str, l);
366 doda 3471 }
367    
368     void SendOSCstr(char *str, int len) {
369 doda 4024 int l;
370    
371 doda 4104 if (str == NULL || len < 0)
372 doda 3471 return;
373    
374 doda 4024 if (len == 0) {
375     l = strlen(str);
376     }
377     else {
378     l = len;
379     }
380    
381 doda 3486 if (Send8BitMode) {
382 doda 3471 CommBinaryOut(&cv,"\235", 1);
383 doda 4024 CommBinaryOut(&cv, str, l);
384 doda 3486 CommBinaryOut(&cv,"\234", 1);
385     }
386     else {
387 doda 3471 CommBinaryOut(&cv,"\033]", 2);
388 doda 4024 CommBinaryOut(&cv, str, l);
389 doda 3486 CommBinaryOut(&cv,"\033\\", 2);
390     }
391 doda 3471
392     }
393    
394 doda 4162 void SendDCSstr(char *str, int len) {
395     int l;
396    
397     if (str == NULL || len < 0)
398     return;
399    
400     if (len == 0) {
401     l = strlen(str);
402     }
403     else {
404     l = len;
405     }
406    
407     if (Send8BitMode) {
408     CommBinaryOut(&cv,"\220", 1);
409     CommBinaryOut(&cv, str, l);
410     CommBinaryOut(&cv,"\234", 1);
411     }
412     else {
413     CommBinaryOut(&cv,"\033P", 2);
414     CommBinaryOut(&cv, str, l);
415     CommBinaryOut(&cv,"\033\\", 2);
416     }
417    
418     }
419    
420 maya 3227 void BackSpace()
421     {
422     if (CursorX == 0)
423     {
424     if ((CursorY>0) &&
425     ((ts.TermFlag & TF_BACKWRAP)!=0))
426     {
427     MoveCursor(NumOfColumns-1,CursorY-1);
428     // if (cv.HLogBuf!=0) Log1Byte(BS);
429     // (2005.2.20 yutaka)
430     if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
431     }
432     }
433     else if (CursorX > 0)
434     {
435     MoveCursor(CursorX-1,CursorY);
436     // if (cv.HLogBuf!=0) Log1Byte(BS);
437     // (2005.2.20 yutaka)
438     if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
439     }
440     }
441    
442     void CarriageReturn(BOOL logFlag)
443     {
444     #ifndef NO_COPYLINE_FIX
445     if (!ts.EnableContinuedLineCopy || logFlag)
446     #endif /* NO_COPYLINE_FIX */
447     if (cv.HLogBuf!=0) Log1Byte(CR);
448    
449     if (CursorX>0)
450     MoveCursor(0,CursorY);
451     }
452    
453     void LineFeed(BYTE b, BOOL logFlag)
454     {
455     /* for auto print mode */
456     if ((AutoPrintMode) &&
457     (b>=LF) && (b<=FF))
458     BuffDumpCurrentLine(b);
459    
460     #ifndef NO_COPYLINE_FIX
461     if (!ts.EnableContinuedLineCopy || logFlag)
462     #endif /* NO_COPYLINE_FIX */
463     if (cv.HLogBuf!=0) Log1Byte(LF);
464    
465     if (CursorY < CursorBottom)
466     MoveCursor(CursorX,CursorY+1);
467     else if (CursorY == CursorBottom) BuffScrollNLines(1);
468     else if (CursorY < NumOfLines-StatusLine-1)
469     MoveCursor(CursorX,CursorY+1);
470    
471 doda 3312 #ifndef NO_COPYLINE_FIX
472     ClearLineContinued();
473     #endif /* NO_COPYLINE_FIX */
474    
475 maya 3227 if (LFMode) CarriageReturn(logFlag);
476     }
477    
478     void Tab()
479     {
480     if (Wrap && !ts.VTCompatTab) {
481     CarriageReturn(FALSE);
482     LineFeed(LF,FALSE);
483     #ifndef NO_COPYLINE_FIX
484     if (ts.EnableContinuedLineCopy) {
485     SetLineContinued();
486     }
487     #endif /* NO_COPYLINE_FIX */
488     Wrap = FALSE;
489     }
490     CursorForwardTab(1, AutoWrapMode);
491     if (cv.HLogBuf!=0) Log1Byte(HT);
492     }
493    
494     void PutChar(BYTE b)
495     {
496     BOOL SpecialNew;
497     TCharAttr CharAttrTmp;
498    
499     CharAttrTmp = CharAttr;
500    
501     if (PrinterMode) { // printer mode
502     WriteToPrnFile(b,TRUE);
503     return;
504     }
505    
506     if (Wrap)
507     {
508     CarriageReturn(FALSE);
509     LineFeed(LF,FALSE);
510     #ifndef NO_COPYLINE_FIX
511     CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0;
512     #endif /* NO_COPYLINE_FIX */
513     }
514    
515     // if (cv.HLogBuf!=0) Log1Byte(b);
516     // (2005.2.20 yutaka)
517     if (ts.LogTypePlainText) {
518     if (__isascii(b) && !isprint(b)) {
519     // ASCII�������A���\�������������O�����������B
520     } else {
521     if (cv.HLogBuf!=0) Log1Byte(b);
522     }
523     } else {
524     if (cv.HLogBuf!=0) Log1Byte(b);
525     }
526    
527     Wrap = FALSE;
528    
529     SpecialNew = FALSE;
530     if ((b>0x5F) && (b<0x80))
531     {
532     if (SSflag)
533     SpecialNew = (Gn[GLtmp]==IdSpecial);
534     else
535     SpecialNew = (Gn[Glr[0]]==IdSpecial);
536     }
537     else if (b>0xDF)
538     {
539     if (SSflag)
540     SpecialNew = (Gn[GLtmp]==IdSpecial);
541     else
542     SpecialNew = (Gn[Glr[1]]==IdSpecial);
543     }
544    
545     if (SpecialNew != Special)
546     {
547     UpdateStr();
548     Special = SpecialNew;
549     }
550    
551     if (Special)
552     {
553     b = b & 0x7F;
554     CharAttrTmp.Attr |= AttrSpecial;
555     }
556     else
557     CharAttrTmp.Attr |= CharAttr.Attr;
558    
559     BuffPutChar(b, CharAttrTmp, InsertMode);
560    
561     if (CursorX < NumOfColumns-1)
562     MoveRight();
563     else {
564     UpdateStr();
565     Wrap = AutoWrapMode;
566     }
567     }
568    
569     void PutDecSp(BYTE b)
570     {
571     TCharAttr CharAttrTmp;
572    
573     CharAttrTmp = CharAttr;
574    
575     if (PrinterMode) { // printer mode
576     WriteToPrnFile(b, TRUE);
577     return;
578     }
579    
580     if (Wrap) {
581     CarriageReturn(FALSE);
582     LineFeed(LF, FALSE);
583     #ifndef NO_COPYLINE_FIX
584     CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0;
585     #endif /* NO_COPYLINE_FIX */
586     }
587    
588     if (cv.HLogBuf!=0) Log1Byte(b);
589     /*
590     if (ts.LogTypePlainText && __isascii(b) && !isprint(b)) {
591     // ASCII�������A���\�������������O�����������B
592     } else {
593     if (cv.HLogBuf!=0) Log1Byte(b);
594     }
595     */
596    
597     Wrap = FALSE;
598    
599     if (!Special) {
600     UpdateStr();
601     Special = TRUE;
602     }
603    
604     CharAttrTmp.Attr |= AttrSpecial;
605     BuffPutChar(b, CharAttrTmp, InsertMode);
606    
607     if (CursorX < NumOfColumns-1)
608     MoveRight();
609     else {
610     UpdateStr();
611     Wrap = AutoWrapMode;
612     }
613     }
614    
615     void PutKanji(BYTE b)
616     {
617     #ifndef NO_COPYLINE_FIX
618     TCharAttr CharAttrTmp;
619    
620     CharAttrTmp = CharAttr;
621     #endif /* NO_COPYLINE_FIX */
622     Kanji = Kanji + b;
623    
624     if (PrinterMode && DirectPrn)
625     {
626     WriteToPrnFile(HIBYTE(Kanji),FALSE);
627     WriteToPrnFile(LOBYTE(Kanji),TRUE);
628     return;
629     }
630    
631     if (ConvJIS)
632     Kanji = JIS2SJIS((WORD)(Kanji & 0x7f7f));
633    
634     if (PrinterMode) { // printer mode
635     WriteToPrnFile(HIBYTE(Kanji),FALSE);
636     WriteToPrnFile(LOBYTE(Kanji),TRUE);
637     return;
638     }
639    
640     if (Wrap)
641     {
642     CarriageReturn(FALSE);
643     LineFeed(LF,FALSE);
644     #ifndef NO_COPYLINE_FIX
645     if (ts.EnableContinuedLineCopy)
646     CharAttrTmp.Attr |= AttrLineContinued;
647     #endif /* NO_COPYLINE_FIX */
648     }
649     else if (CursorX > NumOfColumns-2)
650     if (AutoWrapMode)
651     {
652     #ifndef NO_COPYLINE_FIX
653     if (ts.EnableContinuedLineCopy)
654     {
655     CharAttrTmp.Attr |= AttrLineContinued;
656     if (CursorX == NumOfColumns-1)
657     BuffPutChar(0x20, CharAttr, FALSE);
658     }
659     #endif /* NO_COPYLINE_FIX */
660     CarriageReturn(FALSE);
661     LineFeed(LF,FALSE);
662     }
663     else return;
664    
665     Wrap = FALSE;
666    
667     if (cv.HLogBuf!=0)
668     {
669     Log1Byte(HIBYTE(Kanji));
670     Log1Byte(LOBYTE(Kanji));
671     }
672    
673     if (Special)
674     {
675     UpdateStr();
676     Special = FALSE;
677     }
678    
679     #ifndef NO_COPYLINE_FIX
680     BuffPutKanji(Kanji, CharAttrTmp, InsertMode);
681     #else
682     BuffPutKanji(Kanji, CharAttr, InsertMode);
683     #endif /* NO_COPYLINE_FIX */
684    
685     if (CursorX < NumOfColumns-2)
686     {
687     MoveRight();
688     MoveRight();
689     }
690     else {
691     UpdateStr();
692     Wrap = AutoWrapMode;
693     }
694     }
695    
696     void PutDebugChar(BYTE b)
697     {
698 yutakapon 3637 static BYTE buff[3];
699     int i = 0;
700    
701     if (DebugFlag!=DEBUG_FLAG_NONE) {
702 maya 3227 InsertMode = FALSE;
703     AutoWrapMode = TRUE;
704    
705 yutakapon 3637 if (DebugFlag==DEBUG_FLAG_HEXD) {
706     _snprintf(buff,3,"%02X",(unsigned int) b);
707    
708     for (;i<2;i++)
709     PutChar(buff[i]);
710     PutChar(' ');
711     }
712     else if (DebugFlag==DEBUG_FLAG_NORM) {
713    
714 maya 3227 if ((b & 0x80) == 0x80)
715     {
716     UpdateStr();
717     CharAttr.Attr = AttrReverse;
718     b = b & 0x7f;
719     }
720    
721     if (b<=US)
722     {
723     PutChar('^');
724     PutChar((char)(b+0x40));
725     }
726     else if (b==DEL)
727     {
728     PutChar('<');
729     PutChar('D');
730     PutChar('E');
731     PutChar('L');
732     PutChar('>');
733     }
734     else
735     PutChar(b);
736 yutakapon 3637 }
737 maya 3227
738     if (CharAttr.Attr != AttrDefault)
739     {
740     UpdateStr();
741     CharAttr.Attr = AttrDefault;
742     }
743 yutakapon 3637 }
744 maya 3227 }
745    
746     void PrnParseControl(BYTE b) // printer mode
747     {
748     switch (b) {
749     case NUL: return;
750     case SO:
751     if (! DirectPrn)
752     {
753     if ((ts.Language==IdJapanese) &&
754     (ts.KanjiCode==IdJIS) &&
755     (ts.JIS7Katakana==1) &&
756     ((ts.TermFlag & TF_FIXEDJIS)!=0))
757     Gn[1] = IdKatakana;
758     Glr[0] = 1; /* LS1 */
759     return;
760     }
761     break;
762     case SI:
763     if (! DirectPrn)
764     {
765     Glr[0] = 0; /* LS0 */
766     return;
767     }
768     break;
769     case DC1:
770     case DC3: return;
771     case ESC:
772     ICount = 0;
773     JustAfterESC = TRUE;
774     ParseMode = ModeESC;
775     WriteToPrnFile(0,TRUE); // flush prn buff
776     return;
777     case CSI:
778 doda 3491 if (! Accept8BitCtrl) {
779 maya 3227 PutChar(b); /* Disp C1 char in VT100 mode */
780     return;
781     }
782     ICount = 0;
783     FirstPrm = TRUE;
784     NParam = 1;
785     Param[1] = -1;
786     Prv = 0;
787     ParseMode = ModeCSI;
788     WriteToPrnFile(0,TRUE); // flush prn buff
789     WriteToPrnFile(b,FALSE);
790     return;
791     }
792     /* send the uninterpreted character to printer */
793     WriteToPrnFile(b,TRUE);
794     }
795    
796     void ParseControl(BYTE b)
797     {
798     if (PrinterMode) { // printer mode
799     PrnParseControl(b);
800     return;
801     }
802    
803     if (b>=0x80) /* C1 char */
804     {
805     /* English mode */
806     if (ts.Language==IdEnglish)
807     {
808 doda 3491 if (!Accept8BitCtrl) {
809 maya 3227 PutChar(b); /* Disp C1 char in VT100 mode */
810     return;
811     }
812     }
813     else { /* Japanese mode */
814     if ((ts.TermFlag & TF_ACCEPT8BITCTRL)==0)
815     return; /* ignore C1 char */
816     /* C1 chars are interpreted as C0 chars in VT100 mode */
817     if (ts.TerminalID<IdVT220J)
818     b = b & 0x7F;
819     }
820     }
821     switch (b) {
822     /* C0 group */
823     case ENQ:
824     CommBinaryOut(&cv,&(ts.Answerback[0]),ts.AnswerbackLen);
825     break;
826     case BEL:
827     switch (ts.Beep) {
828     case IdBeepOff:
829     /* nothing to do */
830     break;
831     case IdBeepOn:
832     MessageBeep(0);
833     break;
834     case IdBeepVisual:
835     VisualBell();
836     break;
837     }
838     break;
839     case BS: BackSpace(); break;
840     case HT: Tab(); break;
841    
842     case LF:
843     // ���M�������s�R�[�h�� LF ���������A�T�[�o���� LF ���������������������������A
844     // CR+LF���������������������B
845     // cf. http://www.neocom.ca/forum/viewtopic.php?t=216
846     // (2007.1.21 yutaka)
847     if (ts.CRReceive == IdLF) {
848     CarriageReturn(TRUE);
849     LineFeed(b, TRUE);
850     break;
851     }
852    
853     case VT: LineFeed(b,TRUE); break;
854    
855     case FF:
856     if ((ts.AutoWinSwitch>0) && JustAfterESC)
857     {
858     CommInsert1Byte(&cv,b);
859     CommInsert1Byte(&cv,ESC);
860     ChangeEmu = IdTEK; /* Enter TEK Mode */
861     }
862     else
863     LineFeed(b,TRUE);
864     break;
865     case CR:
866     CarriageReturn(TRUE);
867     if (ts.CRReceive==IdCRLF)
868     CommInsert1Byte(&cv,LF);
869     break;
870     case SO:
871     if ((ts.Language==IdJapanese) &&
872     (ts.KanjiCode==IdJIS) &&
873     (ts.JIS7Katakana==1) &&
874     ((ts.TermFlag & TF_FIXEDJIS)!=0))
875     Gn[1] = IdKatakana;
876    
877     Glr[0] = 1; /* LS1 */
878     break;
879     case SI: Glr[0] = 0; break; /* LS0 */
880     case DLE:
881     if ((ts.FTFlag & FT_BPAUTO)!=0)
882     ParseMode = ModeDLE; /* Auto B-Plus activation */
883     break;
884     case CAN:
885     if ((ts.FTFlag & FT_ZAUTO)!=0)
886     ParseMode = ModeCAN; /* Auto ZMODEM activation */
887     // else if (ts.AutoWinSwitch>0)
888     // ChangeEmu = IdTEK; /* Enter TEK Mode */
889     else
890     ParseMode = ModeFirst;
891     break;
892     case SUB: ParseMode = ModeFirst; break;
893     case ESC:
894     ICount = 0;
895     JustAfterESC = TRUE;
896     ParseMode = ModeESC;
897     break;
898     case FS:
899     case GS:
900     case RS:
901     case US:
902     if (ts.AutoWinSwitch>0)
903     {
904     CommInsert1Byte(&cv,b);
905     ChangeEmu = IdTEK; /* Enter TEK Mode */
906     }
907     break;
908    
909     /* C1 char */
910     case IND: LineFeed(0,TRUE); break;
911     case NEL:
912     LineFeed(0,TRUE);
913     CarriageReturn(TRUE);
914     break;
915     case HTS: SetTabStop(); break;
916     case RI: CursorUpWithScroll(); break;
917     case SS2:
918     GLtmp = 2;
919     SSflag = TRUE;
920     break;
921     case SS3:
922     GLtmp = 3;
923     SSflag = TRUE;
924     break;
925     case DCS:
926     SavedMode = ParseMode;
927     ESCFlag = FALSE;
928 doda 4225 ICount = 0;
929 maya 3227 NParam = 1;
930     Param[1] = -1;
931 doda 4225 Prv = 0;
932 maya 3227 ParseMode = ModeDCS;
933     break;
934     case SOS:
935     SavedMode = ParseMode;
936     ESCFlag = FALSE;
937     ParseMode = ModeSOS;
938     break;
939     case CSI:
940     ICount = 0;
941     FirstPrm = TRUE;
942     NParam = 1;
943     Param[1] = -1;
944     Prv = 0;
945     ParseMode = ModeCSI;
946     break;
947     case OSC:
948     Param[1] = 0;
949     ParseMode = ModeXS;
950     break;
951     case PM:
952     case APC:
953     SavedMode = ParseMode;
954     ESCFlag = FALSE;
955     ParseMode = ModeSOS;
956     break;
957     }
958     }
959    
960     void SaveCursor()
961     {
962     int i;
963     PStatusBuff Buff;
964    
965     if ((StatusLine>0) &&
966     (CursorY==NumOfLines-1))
967     Buff = &SBuff2; // for status line
968 doda 3797 else if (AltScr)
969     Buff = &SBuff3; // for alternate screen
970 maya 3227 else
971     Buff = &SBuff1; // for main screen
972    
973     Buff->CursorX = CursorX;
974     Buff->CursorY = CursorY;
975     Buff->Attr = CharAttr;
976     Buff->Glr[0] = Glr[0];
977     Buff->Glr[1] = Glr[1];
978     for (i=0 ; i<=3; i++)
979     Buff->Gn[i] = Gn[i];
980     Buff->AutoWrapMode = AutoWrapMode;
981     Buff->RelativeOrgMode = RelativeOrgMode;
982     }
983    
984     void RestoreCursor()
985     {
986     int i;
987     PStatusBuff Buff;
988     UpdateStr();
989    
990     if ((StatusLine>0) &&
991     (CursorY==NumOfLines-1))
992     Buff = &SBuff2; // for status line
993 doda 3797 else if (AltScr)
994     Buff = &SBuff3; // for alternate screen
995 maya 3227 else
996     Buff = &SBuff1; // for main screen
997    
998     if (Buff->CursorX > NumOfColumns-1)
999     Buff->CursorX = NumOfColumns-1;
1000     if (Buff->CursorY > NumOfLines-1-StatusLine)
1001     Buff->CursorY = NumOfLines-1-StatusLine;
1002     MoveCursor(Buff->CursorX,Buff->CursorY);
1003     CharAttr = Buff->Attr;
1004     Glr[0] = Buff->Glr[0];
1005     Glr[1] = Buff->Glr[1];
1006     for (i=0 ; i<=3; i++)
1007     Gn[i] = Buff->Gn[i];
1008     AutoWrapMode = Buff->AutoWrapMode;
1009     RelativeOrgMode = Buff->RelativeOrgMode;
1010     }
1011    
1012     void AnswerTerminalType()
1013     {
1014     char Tmp[31];
1015    
1016     if (ts.TerminalID<IdVT320)
1017     strncpy_s(Tmp, sizeof(Tmp),"\033[?", _TRUNCATE);
1018     else
1019     strncpy_s(Tmp, sizeof(Tmp),"\233?", _TRUNCATE);
1020    
1021     switch (ts.TerminalID) {
1022     case IdVT100:
1023     strncat_s(Tmp,sizeof(Tmp),"1;2",_TRUNCATE);
1024     break;
1025     case IdVT100J:
1026     strncat_s(Tmp,sizeof(Tmp),"5;2",_TRUNCATE);
1027     break;
1028     case IdVT101:
1029     strncat_s(Tmp,sizeof(Tmp),"1;0",_TRUNCATE);
1030     break;
1031     case IdVT102:
1032     strncat_s(Tmp,sizeof(Tmp),"6",_TRUNCATE);
1033     break;
1034     case IdVT102J:
1035     strncat_s(Tmp,sizeof(Tmp),"15",_TRUNCATE);
1036     break;
1037     case IdVT220J:
1038     strncat_s(Tmp,sizeof(Tmp),"62;1;2;5;6;7;8",_TRUNCATE);
1039     break;
1040     case IdVT282:
1041     strncat_s(Tmp,sizeof(Tmp),"62;1;2;4;5;6;7;8;10;11",_TRUNCATE);
1042     break;
1043     case IdVT320:
1044     strncat_s(Tmp,sizeof(Tmp),"63;1;2;6;7;8",_TRUNCATE);
1045     break;
1046     case IdVT382:
1047     strncat_s(Tmp,sizeof(Tmp),"63;1;2;4;5;6;7;8;10;15",_TRUNCATE);
1048     break;
1049 doda 4084 case IdVT420:
1050     strncat_s(Tmp,sizeof(Tmp),"64;1;2;7;8;9;15;18;21",_TRUNCATE);
1051     break;
1052     case IdVT520:
1053     strncat_s(Tmp,sizeof(Tmp),"65;1;2;7;8;9;12;18;19;21;23;24;42;44;45;46",_TRUNCATE);
1054     break;
1055     case IdVT525:
1056     strncat_s(Tmp,sizeof(Tmp),"65;1;2;7;9;12;18;19;21;22;23;24;42;44;45;46",_TRUNCATE);
1057     break;
1058 maya 3227 }
1059     strncat_s(Tmp,sizeof(Tmp),"c",_TRUNCATE);
1060    
1061     CommBinaryOut(&cv,Tmp,strlen(Tmp)); /* Report terminal ID */
1062     }
1063    
1064     void ESCSpace(BYTE b)
1065     {
1066     switch (b) {
1067     case 'F': Send8BitMode = FALSE; break; // S7C1T
1068     case 'G': Send8BitMode = TRUE; break; // S8C1T
1069     }
1070     }
1071    
1072     void ESCSharp(BYTE b)
1073     {
1074     switch (b) {
1075 doda 4097 case '8': /* Fill screen with "E" (DECALN) */
1076 maya 3227 BuffUpdateScroll();
1077     BuffFillWithE();
1078 doda 4097 CursorTop = 0;
1079     CursorBottom = NumOfLines-1-StatusLine;
1080 maya 3227 MoveCursor(0,0);
1081     ParseMode = ModeFirst;
1082     break;
1083     }
1084     }
1085    
1086     /* select double byte code set */
1087     void ESCDBCSSelect(BYTE b)
1088     {
1089     int Dist;
1090    
1091     if (ts.Language!=IdJapanese) return;
1092    
1093     switch (ICount) {
1094     case 1:
1095     if ((b=='@') || (b=='B'))
1096     {
1097     Gn[0] = IdKanji; /* Kanji -> G0 */
1098     if ((ts.TermFlag & TF_AUTOINVOKE)!=0)
1099     Glr[0] = 0; /* G0->GL */
1100     }
1101     break;
1102     case 2:
1103     /* Second intermediate char must be
1104     '(' or ')' or '*' or '+'. */
1105     Dist = (IntChar[2]-'(') & 3; /* G0 - G3 */
1106     if ((b=='1') || (b=='3') ||
1107     (b=='@') || (b=='B'))
1108     {
1109     Gn[Dist] = IdKanji; /* Kanji -> G0-3 */
1110     if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
1111     (Dist==0))
1112     Glr[0] = 0; /* G0->GL */
1113     }
1114     break;
1115     }
1116     }
1117    
1118     void ESCSelectCode(BYTE b)
1119     {
1120     switch (b) {
1121     case '0':
1122     if (ts.AutoWinSwitch>0)
1123     ChangeEmu = IdTEK; /* enter TEK mode */
1124     break;
1125     }
1126     }
1127    
1128     /* select single byte code set */
1129     void ESCSBCSSelect(BYTE b)
1130     {
1131     int Dist;
1132    
1133     /* Intermediate char must be
1134     '(' or ')' or '*' or '+'. */
1135     Dist = (IntChar[1]-'(') & 3; /* G0 - G3 */
1136    
1137     switch (b) {
1138     case '0': Gn[Dist] = IdSpecial; break;
1139     case '<': Gn[Dist] = IdASCII; break;
1140     case '>': Gn[Dist] = IdASCII; break;
1141     case 'A': Gn[Dist] = IdASCII; break;
1142     case 'B': Gn[Dist] = IdASCII; break;
1143     case 'H': Gn[Dist] = IdASCII; break;
1144     case 'I':
1145     if (ts.Language==IdJapanese)
1146     Gn[Dist] = IdKatakana;
1147     break;
1148     case 'J': Gn[Dist] = IdASCII; break;
1149     }
1150    
1151     if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
1152     (Dist==0))
1153     Glr[0] = 0; /* G0->GL */
1154     }
1155    
1156     void PrnParseEscape(BYTE b) // printer mode
1157     {
1158     int i;
1159    
1160     ParseMode = ModeFirst;
1161     switch (ICount) {
1162     /* no intermediate char */
1163     case 0:
1164     switch (b) {
1165     case '[': /* CSI */
1166     ICount = 0;
1167     FirstPrm = TRUE;
1168     NParam = 1;
1169     Param[1] = -1;
1170     Prv = 0;
1171     WriteToPrnFile(ESC,FALSE);
1172     WriteToPrnFile('[',FALSE);
1173     ParseMode = ModeCSI;
1174     return;
1175     } /* end of case Icount=0 */
1176     break;
1177     /* one intermediate char */
1178     case 1:
1179     switch (IntChar[1]) {
1180     case '$':
1181     if (! DirectPrn)
1182     {
1183     ESCDBCSSelect(b);
1184     return;
1185     }
1186     break;
1187     case '(':
1188     case ')':
1189     case '*':
1190     case '+':
1191     if (! DirectPrn)
1192     {
1193     ESCSBCSSelect(b);
1194     return;
1195     }
1196     break;
1197     }
1198     break;
1199     /* two intermediate char */
1200     case 2:
1201     if ((! DirectPrn) &&
1202     (IntChar[1]=='$') &&
1203     ('('<=IntChar[2]) &&
1204     (IntChar[2]<='+'))
1205     {
1206     ESCDBCSSelect(b);
1207     return;
1208     }
1209     break;
1210     }
1211     // send the uninterpreted sequence to printer
1212     WriteToPrnFile(ESC,FALSE);
1213     for (i=1; i<=ICount; i++)
1214     WriteToPrnFile(IntChar[i],FALSE);
1215     WriteToPrnFile(b,TRUE);
1216     }
1217    
1218     void ParseEscape(BYTE b) /* b is the final char */
1219     {
1220     if (PrinterMode) { // printer mode
1221     PrnParseEscape(b);
1222     return;
1223     }
1224    
1225     switch (ICount) {
1226     /* no intermediate char */
1227     case 0:
1228     switch (b) {
1229 doda 4243 case '6': // DECBI
1230     if (CursorX == 0) {
1231     BuffScrollRight(1);
1232     }
1233     else {
1234     CursorX--;
1235     }
1236 maya 3227 case '7': SaveCursor(); break;
1237     case '8': RestoreCursor(); break;
1238 doda 4243 case '9': // DECFI
1239     if (CursorX == NumOfColumns-1) {
1240     BuffScrollLeft(1);
1241     }
1242     else {
1243     CursorX++;
1244     }
1245 maya 3227 case '=': AppliKeyMode = TRUE; break;
1246     case '>': AppliKeyMode = FALSE; break;
1247     case 'D': /* IND */
1248     LineFeed(0,TRUE);
1249     break;
1250     case 'E': /* NEL */
1251     MoveCursor(0,CursorY);
1252     LineFeed(0,TRUE);
1253     break;
1254     case 'H': /* HTS */
1255     SetTabStop();
1256     break;
1257     case 'M': /* RI */
1258     CursorUpWithScroll();
1259     break;
1260     case 'N': /* SS2 */
1261     GLtmp = 2;
1262     SSflag = TRUE;
1263     break;
1264     case 'O': /* SS3 */
1265     GLtmp = 3;
1266     SSflag = TRUE;
1267     break;
1268     case 'P': /* DCS */
1269     SavedMode = ParseMode;
1270     ESCFlag = FALSE;
1271     NParam = 1;
1272     Param[1] = -1;
1273     ParseMode = ModeDCS;
1274     return;
1275     case 'X': /* SOS */
1276     SavedMode = ParseMode;
1277     ESCFlag = FALSE;
1278     ParseMode = ModeSOS;
1279     return;
1280     case 'Z': AnswerTerminalType(); break;
1281     case '[': /* CSI */
1282     ICount = 0;
1283     FirstPrm = TRUE;
1284     NParam = 1;
1285     Param[1] = -1;
1286     Prv = 0;
1287     ParseMode = ModeCSI;
1288     return;
1289     case '\\': break; /* ST */
1290     case ']': /* XTERM sequence (OSC) */
1291     NParam = 1;
1292     Param[1] = 0;
1293     ParseMode = ModeXS;
1294     return;
1295     case '^':
1296     case '_': /* PM, APC */
1297     SavedMode = ParseMode;
1298     ESCFlag = FALSE;
1299     ParseMode = ModeSOS;
1300     return;
1301     case 'c': /* Hardware reset */
1302     HideStatusLine();
1303     ResetTerminal();
1304     ClearUserKey();
1305     ClearBuffer();
1306     if (ts.PortType==IdSerial) // reset serial port
1307     CommResetSerial(&ts, &cv, TRUE);
1308     break;
1309     case 'g': /* Visual Bell (screen original?) */
1310     VisualBell();
1311     break;
1312     case 'n': Glr[0] = 2; break; /* LS2 */
1313     case 'o': Glr[0] = 3; break; /* LS3 */
1314     case '|': Glr[1] = 3; break; /* LS3R */
1315     case '}': Glr[1] = 2; break; /* LS2R */
1316     case '~': Glr[1] = 1; break; /* LS1R */
1317     } /* end of case Icount=0 */
1318     break;
1319     /* one intermediate char */
1320     case 1:
1321     switch (IntChar[1]) {
1322     case ' ': ESCSpace(b); break;
1323     case '#': ESCSharp(b); break;
1324     case '$': ESCDBCSSelect(b); break;
1325     case '%': break;
1326     case '(':
1327     case ')':
1328     case '*':
1329     case '+':
1330     ESCSBCSSelect(b);
1331     break;
1332     }
1333     break;
1334     /* two intermediate char */
1335     case 2:
1336     if ((IntChar[1]=='$') &&
1337     ('('<=IntChar[2]) &&
1338     (IntChar[2]<='+'))
1339     ESCDBCSSelect(b);
1340     else if ((IntChar[1]=='%') &&
1341     (IntChar[2]=='!'))
1342     ESCSelectCode(b);
1343     break;
1344     }
1345     ParseMode = ModeFirst;
1346     }
1347    
1348     void EscapeSequence(BYTE b)
1349     {
1350     if (b<=US)
1351     ParseControl(b);
1352     else if ((b>=0x20) && (b<=0x2F))
1353     {
1354     if (ICount<IntCharMax) ICount++;
1355     IntChar[ICount] = b;
1356     }
1357     else if ((b>=0x30) && (b<=0x7E))
1358     ParseEscape(b);
1359     else if ((b>=0x80) && (b<=0x9F))
1360     ParseControl(b);
1361    
1362     JustAfterESC = FALSE;
1363     }
1364    
1365     void CSInsertCharacter()
1366     {
1367     // Insert space characters at cursor
1368     int Count;
1369    
1370     BuffUpdateScroll();
1371     if (Param[1]<1) Param[1] = 1;
1372     Count = Param[1];
1373     BuffInsertSpace(Count);
1374     }
1375    
1376     void CSCursorUp()
1377     {
1378     if (Param[1]<1) Param[1] = 1;
1379    
1380     if (CursorY >= CursorTop)
1381     {
1382     if (CursorY-Param[1] > CursorTop)
1383     MoveCursor(CursorX,CursorY-Param[1]);
1384     else
1385     MoveCursor(CursorX,CursorTop);
1386     }
1387     else {
1388     if (CursorY > 0)
1389     MoveCursor(CursorX,CursorY-Param[1]);
1390     else
1391     MoveCursor(CursorX,0);
1392     }
1393     }
1394    
1395     void CSCursorUp1()
1396     {
1397     MoveCursor(0,CursorY);
1398     CSCursorUp();
1399     }
1400    
1401     void CSCursorDown()
1402     {
1403     if (Param[1]<1) Param[1] = 1;
1404    
1405     if (CursorY <= CursorBottom)
1406     {
1407     if (CursorY+Param[1] < CursorBottom)
1408     MoveCursor(CursorX,CursorY+Param[1]);
1409     else
1410     MoveCursor(CursorX,CursorBottom);
1411     }
1412     else {
1413     if (CursorY < NumOfLines-StatusLine-1)
1414     MoveCursor(CursorX,CursorY+Param[1]);
1415     else
1416     MoveCursor(CursorX,NumOfLines-StatusLine);
1417     }
1418     }
1419    
1420     void CSCursorDown1()
1421     {
1422     MoveCursor(0,CursorY);
1423     CSCursorDown();
1424     }
1425    
1426     void CSScreenErase()
1427     {
1428     if (Param[1] == -1) Param[1] = 0;
1429     BuffUpdateScroll();
1430     switch (Param[1]) {
1431     case 0:
1432     // <ESC>[H(Cursor in left upper corner)�������J�[�\�������������w�������������A
1433     // <ESC>[J��<ESC>[2J�����������������A�����������A���s�o�b�t�@���X�N���[���A�E�g
1434     // �����������������B(2005.5.29 yutaka)
1435     // �R���t�B�O���[�V�������������������������������B(2008.5.3 yutaka)
1436     if (ts.ScrollWindowClearScreen &&
1437     (CursorX == 0 && CursorY == 0)) {
1438     // Erase screen (scroll out)
1439     BuffClearScreen();
1440     UpdateWindow(HVTWin);
1441    
1442     } else {
1443     // Erase characters from cursor to the end of screen
1444     BuffEraseCurToEnd();
1445     }
1446     break;
1447    
1448     case 1:
1449     // Erase characters from home to cursor
1450     BuffEraseHomeToCur();
1451     break;
1452    
1453     case 2:
1454     // Erase screen (scroll out)
1455     BuffClearScreen();
1456     UpdateWindow(HVTWin);
1457     break;
1458     }
1459     }
1460    
1461 doda 4070 void CSQSelScreenErase()
1462     {
1463     if (Param[1] == -1) Param[1] = 0;
1464     BuffUpdateScroll();
1465     switch (Param[1]) {
1466     case 0:
1467     // Erase characters from cursor to end
1468     BuffSelectedEraseCurToEnd();
1469     break;
1470    
1471     case 1:
1472     // Erase characters from home to cursor
1473     BuffSelectedEraseHomeToCur();
1474     break;
1475    
1476     case 2:
1477     // Erase entire screen
1478     BuffSelectedEraseScreen();
1479     break;
1480     }
1481     }
1482    
1483 maya 3227 void CSInsertLine()
1484     {
1485     // Insert lines at current position
1486     int Count, YEnd;
1487    
1488     if (CursorY < CursorTop) return;
1489     if (CursorY > CursorBottom) return;
1490     if (Param[1]<1) Param[1] = 1;
1491     Count = Param[1];
1492    
1493     YEnd = CursorBottom;
1494     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1495     if (Count > YEnd+1 - CursorY) Count = YEnd+1 - CursorY;
1496    
1497     BuffInsertLines(Count,YEnd);
1498     }
1499    
1500     void CSLineErase()
1501     {
1502     if (Param[1] == -1) Param[1] = 0;
1503     BuffUpdateScroll();
1504     switch (Param[1]) {
1505     /* erase char from cursor to end of line */
1506     case 0:
1507     BuffEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1508     break;
1509     /* erase char from start of line to cursor */
1510     case 1:
1511     BuffEraseCharsInLine(0,CursorX+1);
1512     break;
1513     /* erase entire line */
1514     case 2:
1515     BuffEraseCharsInLine(0,NumOfColumns);
1516     break;
1517     }
1518     }
1519    
1520 doda 4070 void CSQSelLineErase()
1521     {
1522     if (Param[1] == -1) Param[1] = 0;
1523     BuffUpdateScroll();
1524     switch (Param[1]) {
1525     /* erase char from cursor to end of line */
1526     case 0:
1527     BuffSelectedEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1528     break;
1529     /* erase char from start of line to cursor */
1530     case 1:
1531     BuffSelectedEraseCharsInLine(0,CursorX+1);
1532     break;
1533     /* erase entire line */
1534     case 2:
1535     BuffSelectedEraseCharsInLine(0,NumOfColumns);
1536     break;
1537     }
1538     }
1539    
1540 maya 3227 void CSDeleteNLines()
1541     // Delete lines from current line
1542     {
1543     int Count, YEnd;
1544    
1545     if (CursorY < CursorTop) return;
1546     if (CursorY > CursorBottom) return;
1547     Count = Param[1];
1548     if (Count<1) Count = 1;
1549    
1550     YEnd = CursorBottom;
1551     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1552     if (Count > YEnd+1-CursorY) Count = YEnd+1-CursorY;
1553     BuffDeleteLines(Count,YEnd);
1554     }
1555    
1556     void CSDeleteCharacter()
1557     {
1558     // Delete characters in current line from cursor
1559    
1560     if (Param[1]<1) Param[1] = 1;
1561     BuffUpdateScroll();
1562     BuffDeleteChars(Param[1]);
1563     }
1564    
1565     void CSEraseCharacter()
1566     {
1567     if (Param[1]<1) Param[1] = 1;
1568     BuffUpdateScroll();
1569     BuffEraseChars(Param[1]);
1570     }
1571    
1572     void CSScrollUP()
1573     {
1574     if (Param[1]<1) Param[1] = 1;
1575     BuffUpdateScroll();
1576     BuffRegionScrollUpNLines(Param[1]);
1577     }
1578    
1579     void CSScrollDown()
1580     {
1581     if (Param[1]<1) Param[1] = 1;
1582     BuffUpdateScroll();
1583     BuffRegionScrollDownNLines(Param[1]);
1584     }
1585    
1586     void CSForwardTab()
1587     {
1588     if (Param[1]<1) Param[1] = 1;
1589     CursorForwardTab(Param[1], AutoWrapMode);
1590     }
1591    
1592     void CSBackwardTab()
1593     {
1594     if (Param[1]<1) Param[1] = 1;
1595     CursorBackwardTab(Param[1]);
1596     }
1597    
1598     void CSMoveToColumnN()
1599     {
1600     if (Param[1]<1) Param[1] = 1;
1601     Param[1]--;
1602     if (Param[1] < 0) Param[1] = 0;
1603     if (Param[1] > NumOfColumns-1) Param[1] = NumOfColumns-1;
1604     MoveCursor(Param[1],CursorY);
1605     }
1606    
1607     void CSCursorRight()
1608     {
1609     if (Param[1]<1) Param[1] = 1;
1610     if (CursorX + Param[1] > NumOfColumns-1)
1611     MoveCursor(NumOfColumns-1,CursorY);
1612     else
1613     MoveCursor(CursorX+Param[1],CursorY);
1614     }
1615    
1616     void CSCursorLeft()
1617     {
1618     if (Param[1]<1) Param[1] = 1;
1619     if (CursorX-Param[1] < 0)
1620     MoveCursor(0,CursorY);
1621     else
1622     MoveCursor(CursorX-Param[1],CursorY);
1623     }
1624    
1625     void CSMoveToLineN()
1626     {
1627     if (Param[1]<1) Param[1] = 1;
1628     if (RelativeOrgMode)
1629     {
1630     if (CursorTop+Param[1]-1 > CursorBottom)
1631     MoveCursor(CursorX,CursorBottom);
1632     else
1633     MoveCursor(CursorX,CursorTop+Param[1]-1);
1634     }
1635     else {
1636     if (Param[1] > NumOfLines-StatusLine)
1637     MoveCursor(CursorX,NumOfLines-1-StatusLine);
1638     else
1639     MoveCursor(CursorX,Param[1]-1);
1640     }
1641     }
1642    
1643     void CSMoveToXY()
1644     {
1645     int NewX, NewY;
1646    
1647     if (Param[1]<1) Param[1] = 1;
1648     if ((NParam < 2) || (Param[2]<1)) Param[2] = 1;
1649     NewX = Param[2] - 1;
1650     if (NewX > NumOfColumns-1) NewX = NumOfColumns-1;
1651    
1652     if ((StatusLine>0) && (CursorY==NumOfLines-1))
1653     NewY = CursorY;
1654     else if (RelativeOrgMode)
1655     {
1656     NewY = CursorTop + Param[1] - 1;
1657     if (NewY > CursorBottom) NewY = CursorBottom;
1658     }
1659     else {
1660     NewY = Param[1] - 1;
1661     if (NewY > NumOfLines-1-StatusLine)
1662     NewY = NumOfLines-1-StatusLine;
1663     }
1664     MoveCursor(NewX,NewY);
1665     }
1666    
1667     void CSDeleteTabStop()
1668     {
1669     if (Param[1]==-1) Param[1] = 0;
1670     ClearTabStop(Param[1]);
1671     }
1672    
1673 doda 3742 void CS_h_Mode() // SM
1674 maya 3227 {
1675     switch (Param[1]) {
1676 doda 3311 case 2: // KAM
1677     KeybEnabled = FALSE; break;
1678     case 4: // IRM
1679     InsertMode = TRUE; break;
1680     case 12: // SRM
1681 doda 3485 ts.LocalEcho = 0;
1682     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1683     TelChangeEcho();
1684     break;
1685 doda 3311 case 20: // LF/NL
1686 doda 3485 LFMode = TRUE;
1687     ts.CRSend = IdCRLF;
1688     cv.CRSend = IdCRLF;
1689     break;
1690 doda 3311 case 33: // WYSTCURM
1691 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1692     ts.NonblinkingCursor = TRUE;
1693     ChangeCaret();
1694     }
1695     break;
1696 doda 3311 case 34: // WYULCURM
1697 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1698     ts.CursorShape = IdHCur;
1699     ChangeCaret();
1700     }
1701     break;
1702 maya 3227 }
1703     }
1704    
1705 doda 3742 void CS_i_Mode() // MC
1706 maya 3227 {
1707     if (Param[1]==-1) Param[1] = 0;
1708     switch (Param[1]) {
1709     /* print screen */
1710     // PrintEX -- TRUE: print screen
1711     // FALSE: scroll region
1712     case 0: BuffPrint(! PrintEX); break;
1713     /* printer controller mode off */
1714     case 4: break; /* See PrnParseCS() */
1715     /* printer controller mode on */
1716     case 5:
1717     if (! AutoPrintMode)
1718     OpenPrnFile();
1719     DirectPrn = (ts.PrnDev[0]!=0);
1720     PrinterMode = TRUE;
1721     break;
1722     }
1723     }
1724    
1725 doda 3742 void CS_l_Mode() // RM
1726 maya 3227 {
1727     switch (Param[1]) {
1728 doda 3311 case 2: // KAM
1729     KeybEnabled = TRUE; break;
1730     case 4: // IRM
1731     InsertMode = FALSE; break;
1732     case 12: // SRM
1733 doda 3485 ts.LocalEcho = 1;
1734     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1735     TelChangeEcho();
1736     break;
1737 doda 3311 case 20: // LF/NL
1738 doda 3485 LFMode = FALSE;
1739     ts.CRSend = IdCR;
1740     cv.CRSend = IdCR;
1741     break;
1742 doda 3311 case 33: // WYSTCURM
1743 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1744     ts.NonblinkingCursor = FALSE;
1745     ChangeCaret();
1746     }
1747     break;
1748 doda 3311 case 34: // WYULCURM
1749 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1750     ts.CursorShape = IdBlkCur;
1751     ChangeCaret();
1752     }
1753     break;
1754 maya 3227 }
1755     }
1756    
1757 doda 3742 void CS_n_Mode() // DSR
1758 maya 3227 {
1759     char Report[16];
1760 doda 3471 int Y, len;
1761 maya 3227
1762     switch (Param[1]) {
1763     case 5:
1764 doda 3311 /* Device Status Report -> Ready */
1765 doda 4024 SendCSIstr("0n", 0);
1766 maya 3227 break;
1767     case 6:
1768     /* Cursor Position Report */
1769     Y = CursorY+1;
1770     if ((StatusLine>0) &&
1771     (Y==NumOfLines))
1772     Y = 1;
1773 doda 3471 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%u;%uR", CLocale, Y, CursorX+1);
1774     SendCSIstr(Report, len);
1775 maya 3227 break;
1776     }
1777     }
1778    
1779 doda 3742 void CSSetAttr() // SGR
1780 maya 3227 {
1781     int i, P;
1782    
1783     UpdateStr();
1784     for (i=1 ; i<=NParam ; i++)
1785     {
1786     P = Param[i];
1787     if (P<0) P = 0;
1788     switch (P) {
1789     case 0: /* Clear all */
1790 doda 4070 if (CharAttr.Attr2 & Attr2Protect) {
1791     CharAttr = DefCharAttr;
1792     CharAttr.Attr2 |= Attr2Protect;
1793     }
1794     else {
1795     CharAttr = DefCharAttr;
1796     }
1797 maya 3227 BuffSetCurCharAttr(CharAttr);
1798     break;
1799    
1800     case 1: /* Bold */
1801     CharAttr.Attr |= AttrBold;
1802     BuffSetCurCharAttr(CharAttr);
1803     break;
1804    
1805     case 4: /* Under line */
1806     CharAttr.Attr |= AttrUnder;
1807     BuffSetCurCharAttr(CharAttr);
1808     break;
1809    
1810     case 5: /* Blink */
1811     CharAttr.Attr |= AttrBlink;
1812     BuffSetCurCharAttr(CharAttr);
1813     break;
1814    
1815     case 7: /* Reverse */
1816     CharAttr.Attr |= AttrReverse;
1817     BuffSetCurCharAttr(CharAttr);
1818     break;
1819    
1820     case 22: /* Bold off */
1821     CharAttr.Attr &= ~ AttrBold;
1822     BuffSetCurCharAttr(CharAttr);
1823     break;
1824    
1825     case 24: /* Under line off */
1826     CharAttr.Attr &= ~ AttrUnder;
1827     BuffSetCurCharAttr(CharAttr);
1828     break;
1829    
1830     case 25: /* Blink off */
1831     CharAttr.Attr &= ~ AttrBlink;
1832     BuffSetCurCharAttr(CharAttr);
1833     break;
1834    
1835     case 27: /* Reverse off */
1836     CharAttr.Attr &= ~ AttrReverse;
1837     BuffSetCurCharAttr(CharAttr);
1838     break;
1839    
1840     case 30:
1841     case 31:
1842     case 32:
1843     case 33:
1844     case 34:
1845     case 35:
1846     case 36:
1847     case 37: /* text color */
1848     CharAttr.Attr2 |= Attr2Fore;
1849     CharAttr.Fore = P - 30;
1850     BuffSetCurCharAttr(CharAttr);
1851     break;
1852    
1853     case 38: /* text color (256color mode) */
1854     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1855     i++;
1856     if (i < NParam) {
1857     P = Param[++i];
1858     if (P<0) {
1859     P = 0;
1860     }
1861     CharAttr.Attr2 |= Attr2Fore;
1862     CharAttr.Fore = P;
1863     BuffSetCurCharAttr(CharAttr);
1864     }
1865     }
1866     break;
1867    
1868     case 39: /* Reset text color */
1869     CharAttr.Attr2 &= ~ Attr2Fore;
1870     CharAttr.Fore = AttrDefaultFG;
1871     BuffSetCurCharAttr(CharAttr);
1872     break;
1873    
1874     case 40:
1875     case 41:
1876     case 42:
1877     case 43:
1878     case 44:
1879     case 45:
1880     case 46:
1881     case 47: /* Back color */
1882     CharAttr.Attr2 |= Attr2Back;
1883     CharAttr.Back = P - 40;
1884     BuffSetCurCharAttr(CharAttr);
1885     break;
1886    
1887     case 48: /* Back color (256color mode) */
1888     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1889     i++;
1890     if (i < NParam) {
1891     P = Param[++i];
1892     if (P<0) {
1893     P = 0;
1894     }
1895     CharAttr.Attr2 |= Attr2Back;
1896     CharAttr.Back = P;
1897     BuffSetCurCharAttr(CharAttr);
1898     }
1899     }
1900     break;
1901    
1902     case 49: /* Reset back color */
1903     CharAttr.Attr2 &= ~ Attr2Back;
1904     CharAttr.Back = AttrDefaultBG;
1905     BuffSetCurCharAttr(CharAttr);
1906     break;
1907    
1908     case 90:
1909     case 91:
1910     case 92:
1911     case 93:
1912     case 94:
1913     case 95:
1914     case 96:
1915     case 97: /* aixterm style text color */
1916     if (ts.ColorFlag & CF_AIXTERM16) {
1917     CharAttr.Attr2 |= Attr2Fore;
1918     CharAttr.Fore = P - 90 + 8;
1919     BuffSetCurCharAttr(CharAttr);
1920     }
1921     break;
1922    
1923     case 100:
1924     if (! (ts.ColorFlag & CF_AIXTERM16)) {
1925     /* Reset text and back color */
1926     CharAttr.Attr2 &= ~ (Attr2Fore | Attr2Back);
1927     CharAttr.Fore = AttrDefaultFG;
1928     CharAttr.Back = AttrDefaultBG;
1929     BuffSetCurCharAttr(CharAttr);
1930     break;
1931     }
1932     /* fall through to aixterm style back color */
1933    
1934     case 101:
1935     case 102:
1936     case 103:
1937     case 104:
1938     case 105:
1939     case 106:
1940     case 107: /* aixterm style back color */
1941     if (ts.ColorFlag & CF_AIXTERM16) {
1942     CharAttr.Attr2 |= Attr2Back;
1943     CharAttr.Back = P - 100 + 8;
1944     BuffSetCurCharAttr(CharAttr);
1945     }
1946     break;
1947     }
1948     }
1949     }
1950    
1951     void CSSetScrollRegion()
1952     {
1953     if ((StatusLine>0) &&
1954     (CursorY==NumOfLines-1))
1955     {
1956     MoveCursor(0,CursorY);
1957     return;
1958     }
1959     if (Param[1]<1) Param[1] =1;
1960     if ((NParam < 2) | (Param[2]<1))
1961     Param[2] = NumOfLines-StatusLine;
1962     Param[1]--;
1963     Param[2]--;
1964     if (Param[1] > NumOfLines-1-StatusLine)
1965     Param[1] = NumOfLines-1-StatusLine;
1966     if (Param[2] > NumOfLines-1-StatusLine)
1967     Param[2] = NumOfLines-1-StatusLine;
1968     if (Param[1] >= Param[2]) return;
1969     CursorTop = Param[1];
1970     CursorBottom = Param[2];
1971     if (RelativeOrgMode) MoveCursor(0,CursorTop);
1972     else MoveCursor(0,0);
1973     }
1974    
1975     void CSSunSequence() /* Sun terminal private sequences */
1976     {
1977 doda 3471 int x, y, len;
1978 doda 3487 char Report[TitleBuffSize*2+10];
1979 maya 3227
1980     switch (Param[1]) {
1981 doda 3302 case 1: // De-iconify window
1982 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1983     DispShowWindow(WINDOW_RESTORE);
1984 doda 3302 break;
1985     case 2: // Iconify window
1986 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1987     DispShowWindow(WINDOW_MINIMIZE);
1988 doda 3302 break;
1989     case 3: // set window position
1990 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
1991     if (NParam < 2) Param[2] = 0;
1992     if (NParam < 3) Param[3] = 0;
1993     DispMoveWindow(Param[2], Param[3]);
1994     }
1995 doda 3297 break;
1996 doda 3466 case 4: // set window size
1997 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
1998     if (NParam < 2) Param[2] = 0;
1999     if (NParam < 3) Param[3] = 0;
2000     DispResizeWin(Param[3], Param[2]);
2001     }
2002 doda 3464 break;
2003 doda 3311 case 5: // Raise window
2004 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
2005     DispShowWindow(WINDOW_RAISE);
2006 doda 3309 break;
2007 doda 3311 case 6: // Lower window
2008 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
2009     DispShowWindow(WINDOW_LOWER);
2010 doda 3309 break;
2011 doda 3311 case 7: // Refresh window
2012 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
2013     DispShowWindow(WINDOW_REFRESH);
2014 doda 3310 break;
2015 maya 3227 case 8: /* set terminal size */
2016 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2017     if ((Param[2]<=1) || (NParam<2)) Param[2] = 24;
2018     if ((Param[3]<=1) || (NParam<3)) Param[3] = 80;
2019     ChangeTerminalSize(Param[3],Param[2]);
2020     }
2021 maya 3227 break;
2022 doda 3302 case 9: // Maximize/Restore window
2023 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2024     if (NParam < 2 || Param[2] == 0) {
2025     DispShowWindow(WINDOW_RESTORE);
2026     }
2027 doda 3489 else if (Param[2] == 1) {
2028 doda 3485 DispShowWindow(WINDOW_MAXIMIZE);
2029     }
2030 doda 3302 }
2031     break;
2032 doda 3466 case 11: // Report window state
2033 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2034     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%dt", CLocale, DispWindowIconified()?2:1);
2035     SendCSIstr(Report, len);
2036     }
2037 doda 3466 break;
2038 doda 3469 case 13: // Report window position
2039 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2040     DispGetWindowPos(&x, &y);
2041     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "3;%d;%dt", CLocale, x, y);
2042     SendCSIstr(Report, len);
2043     }
2044 doda 3469 break;
2045 maya 3227 case 14: /* get window size??? */
2046 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2047     /* this is not actual window size */
2048 doda 4024 SendCSIstr("4;640;480t", 0);
2049 doda 3485 }
2050 maya 3227 break;
2051     case 18: /* get terminal size */
2052 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2053     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "8;%u;%u;t", CLocale,
2054     NumOfLines-StatusLine, NumOfColumns);
2055     SendCSIstr(Report, len);
2056     }
2057 maya 3227 break;
2058 doda 3475 case 19: // Report display size (character)
2059 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2060     DispGetRootWinSize(&x, &y);
2061     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "9;%d;%dt", CLocale, y, x);
2062     SendCSIstr(Report, len);
2063     }
2064 doda 3475 break;
2065 doda 3487 case 20: // Report icon label
2066 doda 3747 switch (ts.WindowFlag & WF_TITLEREPORT) {
2067 doda 3774 case IdTitleReportIgnore:
2068 doda 3747 // nothing to do
2069     break;
2070 doda 3774 case IdTitleReportAccept:
2071 doda 3747 switch (ts.AcceptTitleChangeRequest) {
2072     case IdTitleChangeRequestOff:
2073 doda 3487 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2074 doda 3747 break;
2075     case IdTitleChangeRequestAhead:
2076     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, cv.TitleRemote, ts.Title);
2077     break;
2078     case IdTitleChangeRequestLast:
2079     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, ts.Title, cv.TitleRemote);
2080     break;
2081     default:
2082     if (cv.TitleRemote[0] == 0) {
2083     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2084     }
2085     else {
2086     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, cv.TitleRemote);
2087     }
2088     }
2089     SendOSCstr(Report, len);
2090     break;
2091     default: // IdTitleReportEmpty:
2092 doda 4024 SendOSCstr("L", 0);
2093 doda 3747 break;
2094 doda 3487 }
2095     break;
2096     case 21: // Report window title
2097 doda 3747 switch (ts.WindowFlag & WF_TITLEREPORT) {
2098 doda 3774 case IdTitleReportIgnore:
2099 doda 3747 // nothing to do
2100     break;
2101 doda 3774 case IdTitleReportAccept:
2102 doda 3747 switch (ts.AcceptTitleChangeRequest) {
2103     case IdTitleChangeRequestOff:
2104 doda 3487 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2105 doda 3747 break;
2106     case IdTitleChangeRequestAhead:
2107     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, cv.TitleRemote, ts.Title);
2108     break;
2109     case IdTitleChangeRequestLast:
2110     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, ts.Title, cv.TitleRemote);
2111     break;
2112     default:
2113     if (cv.TitleRemote[0] == 0) {
2114     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2115     }
2116     else {
2117     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, cv.TitleRemote);
2118     }
2119     }
2120     SendOSCstr(Report, len);
2121     break;
2122     default: // IdTitleReportEmpty:
2123 doda 4024 SendOSCstr("l", 0);
2124 doda 3747 break;
2125 doda 3487 }
2126     break;
2127 maya 3227 }
2128     }
2129    
2130 doda 4162 void CSEQ(BYTE b)
2131     {
2132 doda 4217 char Report[16];
2133     int len;
2134    
2135 doda 4162 switch (b) {
2136     case 'c': /* Tertiary terminal report (Tertiary DA) */
2137     if (Param[1] < 1) {
2138 doda 4217 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "!|%8s", CLocale, ts.TerminalUID);
2139     SendDCSstr(Report, len);
2140 doda 4162 }
2141     break;
2142     }
2143     }
2144    
2145 maya 3227 void CSGT(BYTE b)
2146     {
2147     switch (b) {
2148 doda 3311 case 'c': /* second terminal report (Secondary DA) */
2149 doda 3472 if (Param[1] < 1) {
2150 doda 4024 SendCSIstr(">32;100;2c", 0); /* VT382 */
2151 doda 3472 }
2152 maya 3227 break;
2153 doda 4101 case 'J': // IO-8256 terminal
2154     if (Param[1]==3) {
2155     if (Param[2] < 1 || NParam < 2) Param[2] = 1;
2156     if (Param[3] < 1 || NParam < 3) Param[3] = 1;
2157 doda 4199 if (Param[4] < 1 || NParam < 4) Param[4] = NumOfLines-StatusLine;
2158     if (Param[5] < 1 || NParam < 5) Param[5] = NumOfColumns;
2159 doda 4101 BuffEraseBox(Param[3]-1, Param[2]-1, Param[5]-1, Param[4]-1);
2160 maya 3227 }
2161     break;
2162 doda 4101 case 'K': // IO-8256 terminal
2163     switch (Param[1]) {
2164     case 3:
2165     if (Param[2] < 1 || NParam < 2) Param[2] = 1;
2166     if (Param[3] < 1 || NParam < 3) Param[3] = 1;
2167     BuffEraseCharsInLine(Param[2]-1, Param[3]-Param[2]+1);
2168     break;
2169     case 5:
2170     if (NParam < 2) Param[2] = 0;
2171     if (NParam < 3) Param[3] = 0;
2172     switch (Param[2]) {
2173     case 3:
2174     case 4:
2175     case 5:
2176     case 6: // Draw Line
2177     BuffDrawLine(CharAttr, Param[2], Param[3]);
2178     break;
2179    
2180     case 12: // Text color
2181     if ((Param[3]>=0) && (Param[3]<=7)) {
2182     switch (Param[3]) {
2183     case 3: CharAttr.Fore = IdBlue; break;
2184     case 4: CharAttr.Fore = IdCyan; break;
2185     case 5: CharAttr.Fore = IdYellow; break;
2186     case 6: CharAttr.Fore = IdMagenta; break;
2187     default: CharAttr.Fore = Param[3]; break;
2188     }
2189     CharAttr.Attr2 |= Attr2Fore;
2190     BuffSetCurCharAttr(CharAttr);
2191 maya 3227 }
2192 doda 4101 break;
2193     }
2194     break;
2195 maya 3227 }
2196     break;
2197     }
2198     }
2199    
2200 doda 3742 void CSQExchangeColor() // DECSCNM / Visual Bell
2201 maya 3227 {
2202     COLORREF ColorRef;
2203    
2204     BuffUpdateScroll();
2205    
2206     if (ts.ColorFlag & CF_REVERSECOLOR) {
2207     ColorRef = ts.VTColor[0];
2208     ts.VTColor[0] = ts.VTReverseColor[0];
2209     ts.VTReverseColor[0] = ColorRef;
2210     ColorRef = ts.VTColor[1];
2211     ts.VTColor[1] = ts.VTReverseColor[1];
2212     ts.VTReverseColor[1] = ColorRef;
2213     }
2214     else {
2215     ColorRef = ts.VTColor[0];
2216     ts.VTColor[0] = ts.VTColor[1];
2217     ts.VTColor[1] = ColorRef;
2218     }
2219    
2220     ColorRef = ts.VTBoldColor[0];
2221     ts.VTBoldColor[0] = ts.VTBoldColor[1];
2222     ts.VTBoldColor[1] = ColorRef;
2223    
2224     ColorRef = ts.VTBlinkColor[0];
2225     ts.VTBlinkColor[0] = ts.VTBlinkColor[1];
2226     ts.VTBlinkColor[1] = ColorRef;
2227    
2228     ColorRef = ts.URLColor[0];
2229     ts.URLColor[0] = ts.URLColor[1];
2230     ts.URLColor[1] = ColorRef;
2231    
2232     ts.ColorFlag ^= CF_REVERSEVIDEO;
2233    
2234     #ifdef ALPHABLEND_TYPE2
2235 doda 3715 // BGInitialize();
2236     BGExchangeColor();
2237 maya 3227 #endif
2238     DispChangeBackground();
2239     UpdateWindow(HVTWin);
2240     }
2241    
2242 doda 3802 void CSQChangeColumnMode(int width) // DECCOLM
2243     {
2244     ChangeTerminalSize(width, NumOfLines-StatusLine);
2245 doda 3804 if ((ts.TermFlag & TF_CLEARONRESIZE) == 0) {
2246     MoveCursor(0, 0);
2247     BuffClearScreen();
2248     UpdateWindow(HVTWin);
2249     }
2250 doda 3802 }
2251    
2252 doda 3742 void CSQ_h_Mode() // DECSET
2253 maya 3227 {
2254     int i;
2255    
2256     for (i = 1 ; i<=NParam ; i++)
2257     switch (Param[i]) {
2258 doda 3742 case 1: AppliCursorMode = TRUE; break; // DECCKM
2259 doda 3802 case 3: CSQChangeColumnMode(132); break; // DECCOLM
2260 doda 3742 case 5: /* Reverse Video (DECSCNM) */
2261 maya 3227 if (!(ts.ColorFlag & CF_REVERSEVIDEO))
2262     CSQExchangeColor(); /* Exchange text/back color */
2263     break;
2264 doda 3742 case 6: // DECOM
2265 doda 3485 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2266 maya 3227 MoveCursor(0,CursorY);
2267     else {
2268     RelativeOrgMode = TRUE;
2269     MoveCursor(0,CursorTop);
2270     }
2271     break;
2272 doda 3742 case 7: AutoWrapMode = TRUE; break; // DECAWM
2273     case 8: AutoRepeatMode = TRUE; break; // DECARM
2274     case 9: /* X10 Mouse Tracking */
2275 maya 3227 if (ts.MouseEventTracking)
2276     MouseReportMode = IdMouseTrackX10;
2277     break;
2278 doda 3742 case 12: /* att610 cursor blinking */
2279 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
2280     ts.NonblinkingCursor = FALSE;
2281     ChangeCaret();
2282     }
2283     break;
2284 doda 3742 case 19: PrintEX = TRUE; break; // DECPEX
2285     case 25: DispEnableCaret(TRUE); break; // cursor on (DECTCEM)
2286     case 38: // DECTEK
2287 maya 3227 if (ts.AutoWinSwitch>0)
2288     ChangeEmu = IdTEK; /* Enter TEK Mode */
2289     break;
2290 doda 3743 case 47: // Alternate Screen Buffer
2291     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2292     BuffSaveScreen();
2293     AltScr = TRUE;
2294     }
2295     break;
2296 maya 3227 case 59:
2297     if (ts.Language==IdJapanese)
2298     { /* kanji terminal */
2299     Gn[0] = IdASCII;
2300     Gn[1] = IdKatakana;
2301     Gn[2] = IdKatakana;
2302     Gn[3] = IdKanji;
2303     Glr[0] = 0;
2304     if ((ts.KanjiCode==IdJIS) &&
2305     (ts.JIS7Katakana==0))
2306     Glr[1] = 2; // 8-bit katakana
2307     else
2308     Glr[1] = 3;
2309     }
2310     break;
2311 doda 3742 case 66: AppliKeyMode = TRUE; break; // DECNKM
2312     case 67: ts.BSKey = IdBS; break; // DECBKM
2313     case 1000: // Mouse Tracking
2314 maya 3227 if (ts.MouseEventTracking)
2315     MouseReportMode = IdMouseTrackVT200;
2316     break;
2317 doda 3742 case 1001: // Hilite Mouse Tracking
2318 maya 3227 if (ts.MouseEventTracking)
2319     MouseReportMode = IdMouseTrackVT200Hl;
2320     break;
2321 doda 3742 case 1002: // Button-Event Mouse Tracking
2322 maya 3227 if (ts.MouseEventTracking)
2323     MouseReportMode = IdMouseTrackBtnEvent;
2324     break;
2325 doda 3742 case 1003: // Any-Event Mouse Tracking
2326 maya 3227 if (ts.MouseEventTracking)
2327     MouseReportMode = IdMouseTrackAllEvent;
2328     break;
2329 doda 3742 case 1004: // Focus Report
2330 maya 3227 if (ts.MouseEventTracking)
2331     FocusReportMode = TRUE;
2332     break;
2333 doda 3744 case 1047: // Alternate Screen Buffer
2334     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2335     BuffSaveScreen();
2336     AltScr = TRUE;
2337     }
2338     break;
2339     case 1048: // Save Cursor Position (Alternate Screen Buffer)
2340     if (ts.TermFlag & TF_ALTSCR) {
2341     SaveCursor();
2342     }
2343 doda 3800 break;
2344 doda 3744 case 1049: // Alternate Screen Buffer
2345     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2346     SaveCursor();
2347     BuffSaveScreen();
2348     BuffClearScreen();
2349     AltScr = TRUE;
2350     }
2351 doda 3872 break;
2352     case 2004: // Bracketed Paste Mode
2353     BracketedPaste = TRUE;
2354     break;
2355 doda 3744 }
2356 maya 3227 }
2357    
2358 doda 4041 void CSQ_i_Mode() // DECMC
2359 maya 3227 {
2360     if (Param[1]==-1) Param[1] = 0;
2361     switch (Param[1]) {
2362     case 1:
2363     OpenPrnFile();
2364     BuffDumpCurrentLine(LF);
2365     if (! AutoPrintMode)
2366     ClosePrnFile();
2367     break;
2368     /* auto print mode off */
2369     case 4:
2370     if (AutoPrintMode)
2371     {
2372     ClosePrnFile();
2373     AutoPrintMode = FALSE;
2374     }
2375     break;
2376     /* auto print mode on */
2377     case 5:
2378     if (! AutoPrintMode)
2379     {
2380     OpenPrnFile();
2381     AutoPrintMode = TRUE;
2382     }
2383     break;
2384     }
2385     }
2386    
2387 doda 3742 void CSQ_l_Mode() // DECRST
2388 maya 3227 {
2389     int i;
2390    
2391     for (i = 1 ; i <= NParam ; i++)
2392     switch (Param[i]) {
2393 doda 3742 case 1: AppliCursorMode = FALSE; break; // DECCKM
2394 doda 3802 case 3: CSQChangeColumnMode(80); break; // DECCOLM
2395 doda 3742 case 5: /* Normal Video (DECSCNM) */
2396 maya 3227 if (ts.ColorFlag & CF_REVERSEVIDEO)
2397     CSQExchangeColor(); /* Exchange text/back color */
2398     break;
2399 doda 3742 case 6: // DECOM
2400 doda 3485 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2401 maya 3227 MoveCursor(0,CursorY);
2402     else {
2403     RelativeOrgMode = FALSE;
2404     MoveCursor(0,0);
2405     }
2406     break;
2407 doda 3742 case 7: AutoWrapMode = FALSE; break; // DECAWM
2408     case 8: AutoRepeatMode = FALSE; break; // DECARM
2409     case 9: MouseReportMode = IdMouseTrackNone; break; /* X10 Mouse Tracking */
2410     case 12: /* att610 cursor blinking */
2411 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
2412     ts.NonblinkingCursor = TRUE;
2413     ChangeCaret();
2414     }
2415     break;
2416 doda 3742 case 19: PrintEX = FALSE; break; // DECPEX
2417     case 25: DispEnableCaret(FALSE); break; // cursor off (DECTCEM)
2418 doda 3743 case 47: // Alternate Screen Buffer
2419     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2420     BuffRestoreScreen();
2421     AltScr = FALSE;
2422     }
2423     break;
2424 maya 3227 case 59:
2425     if (ts.Language==IdJapanese)
2426     { /* katakana terminal */
2427     Gn[0] = IdASCII;
2428     Gn[1] = IdKatakana;
2429     Gn[2] = IdKatakana;
2430     Gn[3] = IdKanji;
2431     Glr[0] = 0;
2432     if ((ts.KanjiCode==IdJIS) &&
2433     (ts.JIS7Katakana==0))
2434     Glr[1] = 2; // 8-bit katakana
2435     else
2436     Glr[1] = 3;
2437     }
2438     break;
2439 doda 3742 case 66: AppliKeyMode = FALSE; break; // DECNKM
2440     case 67: ts.BSKey = IdDEL; break; // DECBKM
2441     case 1000: // Mouse Tracking
2442     case 1001: // Hilite Mouse Tracking
2443     case 1002: // Button-Event Mouse Tracking
2444 doda 3997 case 1003: // Any-Event Mouse Tracking
2445     MouseReportMode = IdMouseTrackNone;
2446     break;
2447 doda 3742 case 1004: FocusReportMode = FALSE; break; // Focus Report
2448 doda 3744 case 1047: // Alternate Screen Buffer
2449     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2450     BuffClearScreen();
2451     BuffRestoreScreen();
2452     AltScr = FALSE;
2453     }
2454     break;
2455     case 1048: // Save Cursor Position (Alternate Screen Buffer)
2456     if (ts.TermFlag & TF_ALTSCR) {
2457     RestoreCursor();
2458     }
2459     break;
2460     case 1049: // Alternate Screen Buffer
2461     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2462     BuffClearScreen();
2463     BuffRestoreScreen();
2464 doda 3812 AltScr = FALSE;
2465 doda 3744 RestoreCursor();
2466     }
2467     break;
2468 doda 3872 case 2004: // Bracketed Paste Mode
2469     BracketedPaste = FALSE;
2470     break;
2471 maya 3227 }
2472     }
2473    
2474 doda 4041 void CSQ_n_Mode() // DECDSR
2475 maya 3227 {
2476 doda 4023 switch (Param[1]) {
2477     case 53:
2478 doda 4041 case 55:
2479 doda 4023 /* Locator Device Status Report -> Ready */
2480 doda 4024 SendCSIstr("?50n", 0);
2481 doda 4023 break;
2482     }
2483 maya 3227 }
2484    
2485     void CSQuest(BYTE b)
2486     {
2487     switch (b) {
2488 doda 4070 case 'J': CSQSelScreenErase(); break; // DECSED
2489     case 'K': CSQSelLineErase(); break; // DECSEL
2490 doda 3742 case 'h': CSQ_h_Mode(); break; // DECSET
2491 doda 4041 case 'i': CSQ_i_Mode(); break; // DECMC
2492 doda 3742 case 'l': CSQ_l_Mode(); break; // DECRST
2493 doda 4041 case 'n': CSQ_n_Mode(); break; // DECDSR
2494 maya 3227 }
2495     }
2496    
2497     void SoftReset()
2498     // called by software-reset escape sequence handler
2499     {
2500     UpdateStr();
2501     AutoRepeatMode = TRUE;
2502     DispEnableCaret(TRUE); // cursor on
2503     InsertMode = FALSE;
2504     RelativeOrgMode = FALSE;
2505     AppliKeyMode = FALSE;
2506     AppliCursorMode = FALSE;
2507     if ((StatusLine>0) &&
2508     (CursorY == NumOfLines-1))
2509     MoveToMainScreen();
2510     CursorTop = 0;
2511     CursorBottom = NumOfLines-1-StatusLine;
2512     ResetCharSet();
2513    
2514     Send8BitMode = ts.Send8BitCtrl;
2515    
2516     /* Attribute */
2517     CharAttr = DefCharAttr;
2518     Special = FALSE;
2519     BuffSetCurCharAttr(CharAttr);
2520    
2521     // status buffers
2522 doda 3916 ResetCurSBuffer();
2523 maya 3227 }
2524    
2525     void CSExc(BYTE b)
2526     {
2527     switch (b) {
2528     case 'p':
2529     /* Software reset */
2530     SoftReset();
2531     break;
2532     }
2533     }
2534    
2535     void CSDouble(BYTE b)
2536     {
2537     switch (b) {
2538 doda 4094 case 'p': // DECSCL
2539 maya 3227 /* Select terminal mode (software reset) */
2540     SoftReset();
2541     if (NParam > 0) {
2542     switch (Param[1]) {
2543 doda 4094 case 61: // VT-Level 1 (VT100)
2544 maya 3227 Send8BitMode = FALSE; break;
2545 doda 4094 case 62: // VT-Level 2 (VT200)