Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/vtterm.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4256 - (hide annotations) (download) (as text)
Thu Dec 23 14:55:44 2010 UTC (13 years, 3 months ago) by doda
File MIME type: text/x-csrc
File size: 99742 byte(s)
Escape / CSI シーケンス中に 0xA0 以降の文字が来た場合、シーケンスの解釈を中断するようにした。
http://sourceforge.jp/ticket/browse.php?group_id=1412&tid=23931
# いまいち自信なし

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