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 4420 - (hide annotations) (download) (as text)
Fri Apr 8 03:08:19 2011 UTC (13 years ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 103748 byte(s)
NetTerm 形式のマウスボタン通知に対応
NetTerm 形式には有効化/無効化する為の制御シーケンスが無い為、暫定で DECSET/DECRST の 14001 で有効/無効に出来るようにした。

[.vimrc]
set mouse=a
set ttymouse=netterm
let &t_ti .= "\e[?14001h"
let &t_te .= "\e[?14001l"

# 左ボタンダウンイベントしか無いためドラッグによる選択が出来ないので、あまり使い勝手は良くない

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     Param[1] = -1;
802     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     Param[1] = -1;
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     Param[1] = -1;
958     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     Param[1] = -1;
1189     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     Param[1] = -1;
1291     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     Param[1] = -1;
1303     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     if (Param[1] == -1) Param[1] = 0;
1449     BuffUpdateScroll();
1450     switch (Param[1]) {
1451     case 0:
1452     // <ESC>[H(Cursor in left upper corner)�������J�[�\�������������w�������������A
1453     // <ESC>[J��<ESC>[2J�����������������A�����������A���s�o�b�t�@���X�N���[���A�E�g
1454     // �����������������B(2005.5.29 yutaka)
1455     // �R���t�B�O���[�V�������������������������������B(2008.5.3 yutaka)
1456     if (ts.ScrollWindowClearScreen &&
1457     (CursorX == 0 && CursorY == 0)) {
1458     // Erase screen (scroll out)
1459     BuffClearScreen();
1460     UpdateWindow(HVTWin);
1461    
1462     } else {
1463     // Erase characters from cursor to the end of screen
1464     BuffEraseCurToEnd();
1465     }
1466     break;
1467    
1468     case 1:
1469     // Erase characters from home to cursor
1470     BuffEraseHomeToCur();
1471     break;
1472    
1473     case 2:
1474     // Erase screen (scroll out)
1475     BuffClearScreen();
1476     UpdateWindow(HVTWin);
1477     break;
1478     }
1479     }
1480    
1481 doda 4070 void CSQSelScreenErase()
1482     {
1483     if (Param[1] == -1) Param[1] = 0;
1484     BuffUpdateScroll();
1485     switch (Param[1]) {
1486     case 0:
1487     // Erase characters from cursor to end
1488     BuffSelectedEraseCurToEnd();
1489     break;
1490    
1491     case 1:
1492     // Erase characters from home to cursor
1493     BuffSelectedEraseHomeToCur();
1494     break;
1495    
1496     case 2:
1497     // Erase entire screen
1498     BuffSelectedEraseScreen();
1499     break;
1500     }
1501     }
1502    
1503 maya 3227 void CSInsertLine()
1504     {
1505     // Insert lines at current position
1506     int Count, YEnd;
1507    
1508     if (CursorY < CursorTop) return;
1509     if (CursorY > CursorBottom) return;
1510     if (Param[1]<1) Param[1] = 1;
1511     Count = Param[1];
1512    
1513     YEnd = CursorBottom;
1514     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1515     if (Count > YEnd+1 - CursorY) Count = YEnd+1 - CursorY;
1516    
1517     BuffInsertLines(Count,YEnd);
1518     }
1519    
1520     void CSLineErase()
1521     {
1522     if (Param[1] == -1) Param[1] = 0;
1523     BuffUpdateScroll();
1524     switch (Param[1]) {
1525     /* erase char from cursor to end of line */
1526     case 0:
1527     BuffEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1528     break;
1529     /* erase char from start of line to cursor */
1530     case 1:
1531     BuffEraseCharsInLine(0,CursorX+1);
1532     break;
1533     /* erase entire line */
1534     case 2:
1535     BuffEraseCharsInLine(0,NumOfColumns);
1536     break;
1537     }
1538     }
1539    
1540 doda 4070 void CSQSelLineErase()
1541     {
1542     if (Param[1] == -1) Param[1] = 0;
1543     BuffUpdateScroll();
1544     switch (Param[1]) {
1545     /* erase char from cursor to end of line */
1546     case 0:
1547     BuffSelectedEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1548     break;
1549     /* erase char from start of line to cursor */
1550     case 1:
1551     BuffSelectedEraseCharsInLine(0,CursorX+1);
1552     break;
1553     /* erase entire line */
1554     case 2:
1555     BuffSelectedEraseCharsInLine(0,NumOfColumns);
1556     break;
1557     }
1558     }
1559    
1560 maya 3227 void CSDeleteNLines()
1561     // Delete lines from current line
1562     {
1563     int Count, YEnd;
1564    
1565     if (CursorY < CursorTop) return;
1566     if (CursorY > CursorBottom) return;
1567     Count = Param[1];
1568     if (Count<1) Count = 1;
1569    
1570     YEnd = CursorBottom;
1571     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1572     if (Count > YEnd+1-CursorY) Count = YEnd+1-CursorY;
1573     BuffDeleteLines(Count,YEnd);
1574     }
1575    
1576     void CSDeleteCharacter()
1577     {
1578     // Delete characters in current line from cursor
1579    
1580     if (Param[1]<1) Param[1] = 1;
1581     BuffUpdateScroll();
1582     BuffDeleteChars(Param[1]);
1583     }
1584    
1585     void CSEraseCharacter()
1586     {
1587     if (Param[1]<1) Param[1] = 1;
1588     BuffUpdateScroll();
1589     BuffEraseChars(Param[1]);
1590     }
1591    
1592     void CSScrollUP()
1593     {
1594     if (Param[1]<1) Param[1] = 1;
1595     BuffUpdateScroll();
1596     BuffRegionScrollUpNLines(Param[1]);
1597     }
1598    
1599     void CSScrollDown()
1600     {
1601     if (Param[1]<1) Param[1] = 1;
1602     BuffUpdateScroll();
1603     BuffRegionScrollDownNLines(Param[1]);
1604     }
1605    
1606     void CSForwardTab()
1607     {
1608     if (Param[1]<1) Param[1] = 1;
1609     CursorForwardTab(Param[1], AutoWrapMode);
1610     }
1611    
1612     void CSBackwardTab()
1613     {
1614     if (Param[1]<1) Param[1] = 1;
1615     CursorBackwardTab(Param[1]);
1616     }
1617    
1618     void CSMoveToColumnN()
1619     {
1620     if (Param[1]<1) Param[1] = 1;
1621     Param[1]--;
1622     if (Param[1] < 0) Param[1] = 0;
1623     if (Param[1] > NumOfColumns-1) Param[1] = NumOfColumns-1;
1624     MoveCursor(Param[1],CursorY);
1625     }
1626    
1627     void CSCursorRight()
1628     {
1629     if (Param[1]<1) Param[1] = 1;
1630     if (CursorX + Param[1] > NumOfColumns-1)
1631     MoveCursor(NumOfColumns-1,CursorY);
1632     else
1633     MoveCursor(CursorX+Param[1],CursorY);
1634     }
1635    
1636     void CSCursorLeft()
1637     {
1638     if (Param[1]<1) Param[1] = 1;
1639     if (CursorX-Param[1] < 0)
1640     MoveCursor(0,CursorY);
1641     else
1642     MoveCursor(CursorX-Param[1],CursorY);
1643     }
1644    
1645     void CSMoveToLineN()
1646     {
1647     if (Param[1]<1) Param[1] = 1;
1648     if (RelativeOrgMode)
1649     {
1650     if (CursorTop+Param[1]-1 > CursorBottom)
1651     MoveCursor(CursorX,CursorBottom);
1652     else
1653     MoveCursor(CursorX,CursorTop+Param[1]-1);
1654     }
1655     else {
1656     if (Param[1] > NumOfLines-StatusLine)
1657     MoveCursor(CursorX,NumOfLines-1-StatusLine);
1658     else
1659     MoveCursor(CursorX,Param[1]-1);
1660     }
1661     }
1662    
1663     void CSMoveToXY()
1664     {
1665     int NewX, NewY;
1666    
1667     if (Param[1]<1) Param[1] = 1;
1668     if ((NParam < 2) || (Param[2]<1)) Param[2] = 1;
1669     NewX = Param[2] - 1;
1670     if (NewX > NumOfColumns-1) NewX = NumOfColumns-1;
1671    
1672     if ((StatusLine>0) && (CursorY==NumOfLines-1))
1673     NewY = CursorY;
1674     else if (RelativeOrgMode)
1675     {
1676     NewY = CursorTop + Param[1] - 1;
1677     if (NewY > CursorBottom) NewY = CursorBottom;
1678     }
1679     else {
1680     NewY = Param[1] - 1;
1681     if (NewY > NumOfLines-1-StatusLine)
1682     NewY = NumOfLines-1-StatusLine;
1683     }
1684     MoveCursor(NewX,NewY);
1685     }
1686    
1687     void CSDeleteTabStop()
1688     {
1689     if (Param[1]==-1) Param[1] = 0;
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     if (Param[1]==-1) Param[1] = 0;
1728     switch (Param[1]) {
1729     /* print screen */
1730     // PrintEX -- TRUE: print screen
1731     // FALSE: scroll region
1732 doda 4397 case 0:
1733     if (ts.TermFlag&TF_PRINTERCTRL) {
1734     BuffPrint(! PrintEX);
1735     }
1736     break;
1737 maya 3227 /* printer controller mode off */
1738     case 4: break; /* See PrnParseCS() */
1739     /* printer controller mode on */
1740     case 5:
1741 doda 4397 if (ts.TermFlag&TF_PRINTERCTRL) {
1742     if (! AutoPrintMode)
1743     OpenPrnFile();
1744     DirectPrn = (ts.PrnDev[0]!=0);
1745     PrinterMode = TRUE;
1746     }
1747 maya 3227 break;
1748     }
1749     }
1750    
1751 doda 3742 void CS_l_Mode() // RM
1752 maya 3227 {
1753     switch (Param[1]) {
1754 doda 3311 case 2: // KAM
1755     KeybEnabled = TRUE; break;
1756     case 4: // IRM
1757     InsertMode = FALSE; break;
1758     case 12: // SRM
1759 doda 3485 ts.LocalEcho = 1;
1760     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1761     TelChangeEcho();
1762     break;
1763 doda 3311 case 20: // LF/NL
1764 doda 3485 LFMode = FALSE;
1765     ts.CRSend = IdCR;
1766     cv.CRSend = IdCR;
1767     break;
1768 doda 3311 case 33: // WYSTCURM
1769 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1770     ts.NonblinkingCursor = FALSE;
1771     ChangeCaret();
1772     }
1773     break;
1774 doda 3311 case 34: // WYULCURM
1775 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1776     ts.CursorShape = IdBlkCur;
1777     ChangeCaret();
1778     }
1779     break;
1780 maya 3227 }
1781     }
1782    
1783 doda 3742 void CS_n_Mode() // DSR
1784 maya 3227 {
1785     char Report[16];
1786 doda 3471 int Y, len;
1787 maya 3227
1788     switch (Param[1]) {
1789     case 5:
1790 doda 3311 /* Device Status Report -> Ready */
1791 doda 4024 SendCSIstr("0n", 0);
1792 maya 3227 break;
1793     case 6:
1794     /* Cursor Position Report */
1795     Y = CursorY+1;
1796     if ((StatusLine>0) &&
1797     (Y==NumOfLines))
1798     Y = 1;
1799 doda 3471 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%u;%uR", CLocale, Y, CursorX+1);
1800     SendCSIstr(Report, len);
1801 maya 3227 break;
1802     }
1803     }
1804    
1805 doda 3742 void CSSetAttr() // SGR
1806 maya 3227 {
1807     int i, P;
1808    
1809     UpdateStr();
1810     for (i=1 ; i<=NParam ; i++)
1811     {
1812     P = Param[i];
1813     if (P<0) P = 0;
1814     switch (P) {
1815     case 0: /* Clear all */
1816 doda 4070 if (CharAttr.Attr2 & Attr2Protect) {
1817     CharAttr = DefCharAttr;
1818     CharAttr.Attr2 |= Attr2Protect;
1819     }
1820     else {
1821     CharAttr = DefCharAttr;
1822     }
1823 maya 3227 BuffSetCurCharAttr(CharAttr);
1824     break;
1825    
1826     case 1: /* Bold */
1827     CharAttr.Attr |= AttrBold;
1828     BuffSetCurCharAttr(CharAttr);
1829     break;
1830    
1831     case 4: /* Under line */
1832     CharAttr.Attr |= AttrUnder;
1833     BuffSetCurCharAttr(CharAttr);
1834     break;
1835    
1836     case 5: /* Blink */
1837     CharAttr.Attr |= AttrBlink;
1838     BuffSetCurCharAttr(CharAttr);
1839     break;
1840    
1841     case 7: /* Reverse */
1842     CharAttr.Attr |= AttrReverse;
1843     BuffSetCurCharAttr(CharAttr);
1844     break;
1845    
1846     case 22: /* Bold off */
1847     CharAttr.Attr &= ~ AttrBold;
1848     BuffSetCurCharAttr(CharAttr);
1849     break;
1850    
1851     case 24: /* Under line off */
1852     CharAttr.Attr &= ~ AttrUnder;
1853     BuffSetCurCharAttr(CharAttr);
1854     break;
1855    
1856     case 25: /* Blink off */
1857     CharAttr.Attr &= ~ AttrBlink;
1858     BuffSetCurCharAttr(CharAttr);
1859     break;
1860    
1861     case 27: /* Reverse off */
1862     CharAttr.Attr &= ~ AttrReverse;
1863     BuffSetCurCharAttr(CharAttr);
1864     break;
1865    
1866     case 30:
1867     case 31:
1868     case 32:
1869     case 33:
1870     case 34:
1871     case 35:
1872     case 36:
1873     case 37: /* text color */
1874     CharAttr.Attr2 |= Attr2Fore;
1875     CharAttr.Fore = P - 30;
1876     BuffSetCurCharAttr(CharAttr);
1877     break;
1878    
1879     case 38: /* text color (256color mode) */
1880     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1881     i++;
1882     if (i < NParam) {
1883     P = Param[++i];
1884     if (P<0) {
1885     P = 0;
1886     }
1887     CharAttr.Attr2 |= Attr2Fore;
1888     CharAttr.Fore = P;
1889     BuffSetCurCharAttr(CharAttr);
1890     }
1891     }
1892     break;
1893    
1894     case 39: /* Reset text color */
1895     CharAttr.Attr2 &= ~ Attr2Fore;
1896     CharAttr.Fore = AttrDefaultFG;
1897     BuffSetCurCharAttr(CharAttr);
1898     break;
1899    
1900     case 40:
1901     case 41:
1902     case 42:
1903     case 43:
1904     case 44:
1905     case 45:
1906     case 46:
1907     case 47: /* Back color */
1908     CharAttr.Attr2 |= Attr2Back;
1909     CharAttr.Back = P - 40;
1910     BuffSetCurCharAttr(CharAttr);
1911     break;
1912    
1913     case 48: /* Back color (256color mode) */
1914     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1915     i++;
1916     if (i < NParam) {
1917     P = Param[++i];
1918     if (P<0) {
1919     P = 0;
1920     }
1921     CharAttr.Attr2 |= Attr2Back;
1922     CharAttr.Back = P;
1923     BuffSetCurCharAttr(CharAttr);
1924     }
1925     }
1926     break;
1927    
1928     case 49: /* Reset back color */
1929     CharAttr.Attr2 &= ~ Attr2Back;
1930     CharAttr.Back = AttrDefaultBG;
1931     BuffSetCurCharAttr(CharAttr);
1932     break;
1933    
1934     case 90:
1935     case 91:
1936     case 92:
1937     case 93:
1938     case 94:
1939     case 95:
1940     case 96:
1941     case 97: /* aixterm style text color */
1942     if (ts.ColorFlag & CF_AIXTERM16) {
1943     CharAttr.Attr2 |= Attr2Fore;
1944     CharAttr.Fore = P - 90 + 8;
1945     BuffSetCurCharAttr(CharAttr);
1946     }
1947     break;
1948    
1949     case 100:
1950     if (! (ts.ColorFlag & CF_AIXTERM16)) {
1951     /* Reset text and back color */
1952     CharAttr.Attr2 &= ~ (Attr2Fore | Attr2Back);
1953     CharAttr.Fore = AttrDefaultFG;
1954     CharAttr.Back = AttrDefaultBG;
1955     BuffSetCurCharAttr(CharAttr);
1956     break;
1957     }
1958     /* fall through to aixterm style back color */
1959    
1960     case 101:
1961     case 102:
1962     case 103:
1963     case 104:
1964     case 105:
1965     case 106:
1966     case 107: /* aixterm style back color */
1967     if (ts.ColorFlag & CF_AIXTERM16) {
1968     CharAttr.Attr2 |= Attr2Back;
1969     CharAttr.Back = P - 100 + 8;
1970     BuffSetCurCharAttr(CharAttr);
1971     }
1972     break;
1973     }
1974     }
1975     }
1976    
1977     void CSSetScrollRegion()
1978     {
1979     if ((StatusLine>0) &&
1980     (CursorY==NumOfLines-1))
1981     {
1982     MoveCursor(0,CursorY);
1983     return;
1984     }
1985     if (Param[1]<1) Param[1] =1;
1986     if ((NParam < 2) | (Param[2]<1))
1987     Param[2] = NumOfLines-StatusLine;
1988     Param[1]--;
1989     Param[2]--;
1990     if (Param[1] > NumOfLines-1-StatusLine)
1991     Param[1] = NumOfLines-1-StatusLine;
1992     if (Param[2] > NumOfLines-1-StatusLine)
1993     Param[2] = NumOfLines-1-StatusLine;
1994     if (Param[1] >= Param[2]) return;
1995     CursorTop = Param[1];
1996     CursorBottom = Param[2];
1997     if (RelativeOrgMode) MoveCursor(0,CursorTop);
1998     else MoveCursor(0,0);
1999     }
2000    
2001     void CSSunSequence() /* Sun terminal private sequences */
2002     {
2003 doda 3471 int x, y, len;
2004 doda 3487 char Report[TitleBuffSize*2+10];
2005 maya 3227
2006     switch (Param[1]) {
2007 doda 3302 case 1: // De-iconify window
2008 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
2009     DispShowWindow(WINDOW_RESTORE);
2010 doda 3302 break;
2011     case 2: // Iconify window
2012 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
2013     DispShowWindow(WINDOW_MINIMIZE);
2014 doda 3302 break;
2015     case 3: // set window position
2016 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2017     if (NParam < 2) Param[2] = 0;
2018     if (NParam < 3) Param[3] = 0;
2019     DispMoveWindow(Param[2], Param[3]);
2020     }
2021 doda 3297 break;
2022 doda 3466 case 4: // set window size
2023 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2024     if (NParam < 2) Param[2] = 0;
2025     if (NParam < 3) Param[3] = 0;
2026     DispResizeWin(Param[3], Param[2]);
2027     }
2028 doda 3464 break;
2029 doda 3311 case 5: // Raise window
2030 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
2031     DispShowWindow(WINDOW_RAISE);
2032 doda 3309 break;
2033 doda 3311 case 6: // Lower window
2034 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
2035     DispShowWindow(WINDOW_LOWER);
2036 doda 3309 break;
2037 doda 3311 case 7: // Refresh window
2038 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
2039     DispShowWindow(WINDOW_REFRESH);
2040 doda 3310 break;
2041 maya 3227 case 8: /* set terminal size */
2042 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2043     if ((Param[2]<=1) || (NParam<2)) Param[2] = 24;
2044     if ((Param[3]<=1) || (NParam<3)) Param[3] = 80;
2045     ChangeTerminalSize(Param[3],Param[2]);
2046     }
2047 maya 3227 break;
2048 doda 3302 case 9: // Maximize/Restore window
2049 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
2050     if (NParam < 2 || Param[2] == 0) {
2051     DispShowWindow(WINDOW_RESTORE);
2052     }
2053 doda 3489 else if (Param[2] == 1) {
2054 doda 3485 DispShowWindow(WINDOW_MAXIMIZE);
2055     }
2056 doda 3302 }
2057     break;
2058 doda 3466 case 11: // Report window state
2059 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2060     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%dt", CLocale, DispWindowIconified()?2:1);
2061     SendCSIstr(Report, len);
2062     }
2063 doda 3466 break;
2064 doda 3469 case 13: // Report window position
2065 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2066     DispGetWindowPos(&x, &y);
2067     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "3;%d;%dt", CLocale, x, y);
2068     SendCSIstr(Report, len);
2069     }
2070 doda 3469 break;
2071 doda 4259 case 14: /* get window size */
2072 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2073 doda 4250 DispGetWindowSize(&x, &y);
2074     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "4;%d;%dt", CLocale, y, x);
2075     SendCSIstr(Report, len);
2076 doda 3485 }
2077 maya 3227 break;
2078     case 18: /* get terminal size */
2079 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2080     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "8;%u;%u;t", CLocale,
2081     NumOfLines-StatusLine, NumOfColumns);
2082     SendCSIstr(Report, len);
2083     }
2084 maya 3227 break;
2085 doda 3475 case 19: // Report display size (character)
2086 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2087     DispGetRootWinSize(&x, &y);
2088     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "9;%d;%dt", CLocale, y, x);
2089     SendCSIstr(Report, len);
2090     }
2091 doda 3475 break;
2092 doda 3487 case 20: // Report icon label
2093 doda 3747 switch (ts.WindowFlag & WF_TITLEREPORT) {
2094 doda 3774 case IdTitleReportIgnore:
2095 doda 3747 // nothing to do
2096     break;
2097 doda 3774 case IdTitleReportAccept:
2098 doda 3747 switch (ts.AcceptTitleChangeRequest) {
2099     case IdTitleChangeRequestOff:
2100 doda 3487 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2101 doda 3747 break;
2102     case IdTitleChangeRequestAhead:
2103     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, cv.TitleRemote, ts.Title);
2104     break;
2105     case IdTitleChangeRequestLast:
2106     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, ts.Title, cv.TitleRemote);
2107     break;
2108     default:
2109     if (cv.TitleRemote[0] == 0) {
2110     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2111     }
2112     else {
2113     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, cv.TitleRemote);
2114     }
2115     }
2116     SendOSCstr(Report, len);
2117     break;
2118     default: // IdTitleReportEmpty:
2119 doda 4024 SendOSCstr("L", 0);
2120 doda 3747 break;
2121 doda 3487 }
2122     break;
2123     case 21: // Report window title
2124 doda 3747 switch (ts.WindowFlag & WF_TITLEREPORT) {
2125 doda 3774 case IdTitleReportIgnore:
2126 doda 3747 // nothing to do
2127     break;
2128 doda 3774 case IdTitleReportAccept:
2129 doda 3747 switch (ts.AcceptTitleChangeRequest) {
2130     case IdTitleChangeRequestOff:
2131 doda 3487 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2132 doda 3747 break;
2133     case IdTitleChangeRequestAhead:
2134     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, cv.TitleRemote, ts.Title);
2135     break;
2136     case IdTitleChangeRequestLast:
2137     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, ts.Title, cv.TitleRemote);
2138     break;
2139     default:
2140     if (cv.TitleRemote[0] == 0) {
2141     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2142     }
2143     else {
2144     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, cv.TitleRemote);
2145     }
2146     }
2147     SendOSCstr(Report, len);
2148     break;
2149     default: // IdTitleReportEmpty:
2150 doda 4024 SendOSCstr("l", 0);
2151 doda 3747 break;
2152 doda 3487 }
2153     break;
2154 maya 3227 }
2155     }
2156    
2157 doda 4278 void CSLT(BYTE b)
2158     {
2159     switch (b) {
2160     case 'r':
2161     if (CanUseIME()) {
2162     SetIMEOpenStatus(IMEstat);
2163     }
2164     break;
2165    
2166     case 's':
2167     if (CanUseIME()) {
2168     IMEstat = GetIMEOpenStatus();
2169     }
2170     break;
2171    
2172     case 't':
2173     if (CanUseIME()) {
2174     SetIMEOpenStatus(Param[1] == 1);
2175     }
2176     break;
2177     }
2178     }
2179    
2180 doda 4162 void CSEQ(BYTE b)
2181     {
2182 doda 4217 char Report[16];
2183     int len;
2184    
2185 doda 4162 switch (b) {
2186     case 'c': /* Tertiary terminal report (Tertiary DA) */
2187     if (Param[1] < 1) {
2188 doda 4217 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "!|%8s", CLocale, ts.TerminalUID);
2189     SendDCSstr(Report, len);
2190 doda 4162 }
2191     break;
2192     }
2193     }
2194    
2195 maya 3227 void CSGT(BYTE b)
2196     {
2197     switch (b) {
2198 doda 3311 case 'c': /* second terminal report (Secondary DA) */
2199 doda 3472 if (Param[1] < 1) {
2200 doda 4024 SendCSIstr(">32;100;2c", 0); /* VT382 */
2201 doda 3472 }
2202 maya 3227 break;
2203 doda 4101 case 'J': // IO-8256 terminal
2204     if (Param[1]==3) {
2205     if (Param[2] < 1 || NParam < 2) Param[2] = 1;
2206     if (Param[3] < 1 || NParam < 3) Param[3] = 1;
2207 doda 4199 if (Param[4] < 1 || NParam < 4) Param[4] = NumOfLines-StatusLine;
2208     if (Param[5] < 1 || NParam < 5) Param[5] = NumOfColumns;
2209 doda 4101 BuffEraseBox(Param[3]-1, Param[2]-1, Param[5]-1, Param[4]-1);
2210 maya 3227 }
2211     break;
2212 doda 4101 case 'K': // IO-8256 terminal
2213     switch (Param[1]) {
2214     case 3:
2215     if (Param[2] < 1 || NParam < 2) Param[2] = 1;
2216     if (Param[3] < 1 || NParam < 3) Param[3] = 1;
2217     BuffEraseCharsInLine(Param[2]-1, Param[3]-Param[2]+1);
2218     break;
2219     case 5:
2220     if (NParam < 2) Param[2] = 0;
2221     if (NParam < 3) Param[3] = 0;
2222     switch (Param[2]) {
2223     case 3:
2224     case 4:
2225     case 5:
2226     case 6: // Draw Line
2227     BuffDrawLine(CharAttr, Param[2], Param[3]);
2228     break;
2229    
2230     case 12: // Text color
2231     if ((Param[3]>=0) && (Param[3]<=7)) {
2232     switch (Param[3]) {
2233     case 3: CharAttr.Fore = IdBlue; break;
2234     case 4: CharAttr.Fore = IdCyan; break;
2235     case 5: CharAttr.Fore = IdYellow; break;
2236     case 6: CharAttr.Fore = IdMagenta; break;
2237     default: CharAttr.Fore = Param[3]; break;
2238     }
2239     CharAttr.Attr2 |= Attr2Fore;
2240     BuffSetCurCharAttr(CharAttr);
2241 maya 3227 }
2242 doda 4101 break;
2243     }
2244     break;
2245 maya 3227 }
2246     break;
2247     }
2248     }
2249    
2250 doda 3742 void CSQExchangeColor() // DECSCNM / Visual Bell
2251 maya 3227 {
2252     COLORREF ColorRef;
2253    
2254     BuffUpdateScroll();
2255    
2256     if (ts.ColorFlag & CF_REVERSECOLOR) {
2257     ColorRef = ts.VTColor[0];
2258     ts.VTColor[0] = ts.VTReverseColor[0];
2259     ts.VTReverseColor[0] = ColorRef;
2260     ColorRef = ts.VTColor[1];
2261     ts.VTColor[1] = ts.VTReverseColor[1];
2262     ts.VTReverseColor[1] = ColorRef;
2263     }
2264     else {
2265     ColorRef = ts.VTColor[0];
2266     ts.VTColor[0] = ts.VTColor[1];
2267     ts.VTColor[1] = ColorRef;
2268     }
2269    
2270     ColorRef = ts.VTBoldColor[0];
2271     ts.VTBoldColor[0] = ts.VTBoldColor[1];
2272     ts.VTBoldColor[1] = ColorRef;
2273    
2274     ColorRef = ts.VTBlinkColor[0];
2275     ts.VTBlinkColor[0] = ts.VTBlinkColor[1];
2276     ts.VTBlinkColor[1] = ColorRef;
2277    
2278     ColorRef = ts.URLColor[0];
2279     ts.URLColor[0] = ts.URLColor[1];
2280     ts.URLColor[1] = ColorRef;
2281    
2282     ts.ColorFlag ^= CF_REVERSEVIDEO;
2283    
2284     #ifdef ALPHABLEND_TYPE2
2285 doda 3715 BGExchangeColor();
2286 maya 3227 #endif
2287     DispChangeBackground();
2288     UpdateWindow(HVTWin);
2289     }
2290    
2291 doda 3802 void CSQChangeColumnMode(int width) // DECCOLM
2292     {
2293     ChangeTerminalSize(width, NumOfLines-StatusLine);
2294 doda 3804 if ((ts.TermFlag & TF_CLEARONRESIZE) == 0) {
2295     MoveCursor(0, 0);
2296     BuffClearScreen();
2297     UpdateWindow(HVTWin);
2298     }
2299 doda 3802 }
2300    
2301 doda 3742 void CSQ_h_Mode() // DECSET
2302 maya 3227 {
2303     int i;
2304    
2305     for (i = 1 ; i<=NParam ; i++)
2306     switch (Param[i]) {
2307 doda 3742 case 1: AppliCursorMode = TRUE; break; // DECCKM
2308 doda 3802 case 3: CSQChangeColumnMode(132); break; // DECCOLM
2309 doda 3742 case 5: /* Reverse Video (DECSCNM) */
2310 maya 3227 if (!(ts.ColorFlag & CF_REVERSEVIDEO))
2311     CSQExchangeColor(); /* Exchange text/back color */
2312     break;
2313 doda 3742 case 6: // DECOM
2314 doda 3485 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2315 maya 3227 MoveCursor(0,CursorY);
2316     else {
2317     RelativeOrgMode = TRUE;
2318     MoveCursor(0,CursorTop);
2319     }
2320     break;
2321 doda 3742 case 7: AutoWrapMode = TRUE; break; // DECAWM
2322     case 8: AutoRepeatMode = TRUE; break; // DECARM
2323     case 9: /* X10 Mouse Tracking */
2324 maya 3227 if (ts.MouseEventTracking)
2325     MouseReportMode = IdMouseTrackX10;
2326     break;
2327 doda 3742 case 12: /* att610 cursor blinking */
2328 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
2329     ts.NonblinkingCursor = FALSE;
2330     ChangeCaret();
2331     }
2332     break;
2333 doda 3742 case 19: PrintEX = TRUE; break; // DECPEX
2334     case 25: DispEnableCaret(TRUE); break; // cursor on (DECTCEM)
2335     case 38: // DECTEK
2336 maya 3227 if (ts.AutoWinSwitch>0)
2337     ChangeEmu = IdTEK; /* Enter TEK Mode */
2338     break;
2339 doda 3743 case 47: // Alternate Screen Buffer
2340     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2341     BuffSaveScreen();
2342     AltScr = TRUE;
2343     }
2344     break;
2345 maya 3227 case 59:
2346     if (ts.Language==IdJapanese)
2347     { /* kanji terminal */
2348     Gn[0] = IdASCII;
2349     Gn[1] = IdKatakana;
2350     Gn[2] = IdKatakana;
2351     Gn[3] = IdKanji;
2352     Glr[0] = 0;
2353     if ((ts.KanjiCode==IdJIS) &&
2354     (ts.JIS7Katakana==0))
2355     Glr[1] = 2; // 8-bit katakana
2356     else
2357     Glr[1] = 3;
2358     }
2359     break;
2360 doda 3742 case 66: AppliKeyMode = TRUE; break; // DECNKM
2361     case 67: ts.BSKey = IdBS; break; // DECBKM
2362     case 1000: // Mouse Tracking
2363 maya 3227 if (ts.MouseEventTracking)
2364     MouseReportMode = IdMouseTrackVT200;
2365     break;
2366 doda 3742 case 1001: // Hilite Mouse Tracking
2367 maya 3227 if (ts.MouseEventTracking)
2368     MouseReportMode = IdMouseTrackVT200Hl;
2369     break;
2370 doda 3742 case 1002: // Button-Event Mouse Tracking
2371 maya 3227 if (ts.MouseEventTracking)
2372     MouseReportMode = IdMouseTrackBtnEvent;
2373     break;
2374 doda 3742 case 1003: // Any-Event Mouse Tracking
2375 maya 3227 if (ts.MouseEventTracking)
2376     MouseReportMode = IdMouseTrackAllEvent;
2377     break;
2378 doda 3742 case 1004: // Focus Report
2379 maya 3227 if (ts.MouseEventTracking)
2380     FocusReportMode = TRUE;
2381     break;
2382 doda 3744 case 1047: // Alternate Screen Buffer
2383     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2384     BuffSaveScreen();
2385     AltScr = TRUE;
2386     }
2387     break;
2388     case 1048: // Save Cursor Position (Alternate Screen Buffer)
2389     if (ts.TermFlag & TF_ALTSCR) {
2390     SaveCursor();
2391     }
2392 doda 3800 break;
2393 doda 3744 case 1049: // Alternate Screen Buffer
2394     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2395     SaveCursor();
2396     BuffSaveScreen();
2397     BuffClearScreen();
2398     AltScr = TRUE;
2399     }
2400 doda 3872 break;
2401     case 2004: // Bracketed Paste Mode
2402     BracketedPaste = TRUE;
2403     break;
2404 doda 4271 case 7727: // mintty Application Escape Mode
2405     AppliEscapeMode = TRUE;
2406     break;
2407 doda 4293 case 7786: // Wheel to Cursor translation
2408     if (ts.TranslateWheelToCursor) {
2409     AcceptWheelToCursor = TRUE;
2410     }
2411     break;
2412 doda 4420 case 14001: // NetTerm mouse mode
2413     if (ts.MouseEventTracking)
2414     MouseReportMode = IdMouseTrackNetTerm;
2415     break;
2416 doda 3744 }
2417 maya 3227 }
2418    
2419 doda 4041 void CSQ_i_Mode() // DECMC
2420 maya 3227 {
2421     if (Param[1]==-1) Param[1] = 0;
2422     switch (Param[1]) {
2423     case 1:
2424 doda 4397 if (ts.TermFlag&TF_PRINTERCTRL) {
2425     OpenPrnFile();
2426     BuffDumpCurrentLine(LF);
2427     if (! AutoPrintMode)
2428     ClosePrnFile();
2429     }
2430 maya 3227 break;
2431     /* auto print mode off */
2432     case 4:
2433     if (AutoPrintMode)
2434     {
2435     ClosePrnFile();
2436     AutoPrintMode = FALSE;
2437     }
2438     break;
2439     /* auto print mode on */
2440     case 5:
2441 doda 4397 if (ts.TermFlag&TF_PRINTERCTRL) {
2442     if (! AutoPrintMode)
2443     {
2444     OpenPrnFile();
2445     AutoPrintMode = TRUE;
2446     }
2447 maya 3227 }
2448     break;
2449     }
2450     }
2451    
2452 doda 3742 void CSQ_l_Mode() // DECRST
2453 maya 3227 {
2454     int i;
2455    
2456     for (i = 1 ; i <= NParam ; i++)
2457     switch (Param[i]) {
2458 doda 3742 case 1: AppliCursorMode = FALSE; break; // DECCKM
2459 doda 3802 case 3: CSQChangeColumnMode(80); break; // DECCOLM
2460 doda 3742 case 5: /* Normal Video (DECSCNM) */
2461 maya 3227 if (ts.ColorFlag & CF_REVERSEVIDEO)
2462     CSQExchangeColor(); /* Exchange text/back color */
2463     break;
2464 doda 3742 case 6: // DECOM
2465 doda 3485 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2466 maya 3227 MoveCursor(0,CursorY);
2467     else {
2468     RelativeOrgMode = FALSE;
2469     MoveCursor(0,0);
2470     }
2471     break;
2472 doda 3742 case 7: AutoWrapMode = FALSE; break; // DECAWM
2473     case 8: AutoRepeatMode = FALSE; break; // DECARM
2474     case 9: MouseReportMode = IdMouseTrackNone; break; /* X10 Mouse Tracking */
2475     case 12: /* att610 cursor blinking */
2476 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
2477     ts.NonblinkingCursor = TRUE;
2478     ChangeCaret();
2479     }
2480     break;
2481 doda 3742 case 19: PrintEX = FALSE; break; // DECPEX
2482     case 25: DispEnableCaret(FALSE); break; // cursor off (DECTCEM)
2483 doda 3743 case 47: // Alternate Screen Buffer
2484     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2485     BuffRestoreScreen();
2486     AltScr = FALSE;
2487     }
2488     break;
2489 maya 3227 case 59:
2490     if (ts.Language==IdJapanese)
2491     { /* katakana terminal */
2492     Gn[0] = IdASCII;
2493     Gn[1] = IdKatakana;
2494     Gn[2] = IdKatakana;
2495     Gn[3] = IdKanji;
2496     Glr[0] = 0;
2497     if ((ts.KanjiCode==IdJIS) &&
2498     (ts.JIS7Katakana==0))
2499     Glr[1] = 2; // 8-bit katakana
2500     else
2501     Glr[1] = 3;
2502     }
2503     break;
2504 doda 3742 case 66: AppliKeyMode = FALSE; break; // DECNKM
2505     case 67: ts.BSKey = IdDEL; break; // DECBKM
2506     case 1000: // Mouse Tracking
2507     case 1001: // Hilite Mouse Tracking
2508     case 1002: // Button-Event Mouse Tracking
2509 doda 3997 case 1003: // Any-Event Mouse Tracking
2510     MouseReportMode = IdMouseTrackNone;
2511     break;
2512 doda 3742 case 1004: FocusReportMode = FALSE; break; // Focus Report
2513 doda 3744 case 1047: // Alternate Screen Buffer
2514     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2515     BuffClearScreen();
2516     BuffRestoreScreen();
2517     AltScr = FALSE;
2518     }
2519     break;
2520     case 1048: // Save Cursor Position (Alternate Screen Buffer)
2521     if (ts.TermFlag & TF_ALTSCR) {
2522     RestoreCursor();
2523     }
2524     break;
2525     case 1049: // Alternate Screen Buffer
2526     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2527     BuffClearScreen();
2528     BuffRestoreScreen();
2529 doda 3812 AltScr = FALSE;
2530 doda 3744 RestoreCursor();
2531     }
2532     break;
2533 doda 3872 case 2004: // Bracketed Paste Mode
2534     BracketedPaste = FALSE;
2535     break;
2536 doda 4271 case 7727: // mintty Application Escape Mode
2537     AppliEscapeMode = FALSE;
2538     break;
2539 doda 4293 case 7786: // Wheel to Cursor translation
2540     AcceptWheelToCursor = FALSE;
2541     break;
2542 doda 4420 case 14001: // NetTerm mouse mode
2543     MouseReportMode = IdMouseTrackNone;
2544     break;
2545 maya 3227 }
2546     }
2547