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 4250 - (hide annotations) (download) (as text)
Wed Dec 22 06:27:26 2010 UTC (13 years, 3 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 99559 byte(s)
ウィンドウサイズ変更制御シーケンスに対して、実際のウィンドウサイズを返すようにした。

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