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 4552 - (hide annotations) (download) (as text)
Fri Jul 29 12:34:06 2011 UTC (12 years, 8 months ago) by doda
File MIME type: text/x-csrc
File size: 103090 byte(s)
OSC 文字列中に CSI 等のシーケンスが含まれていた場合、その CSI シーケンスを解釈するようにした。
bash 3.2 のバグの work around.
http://logmett.com/forum/viewtopic.php?f=8&t=1749

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