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 4769 - (hide annotations) (download) (as text)
Tue Dec 6 10:01:20 2011 UTC (12 years, 4 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 106463 byte(s)
OSC 52 のクリップボード読み込みに対応

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