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 4827 - (hide annotations) (download) (as text)
Mon Feb 6 01:34:34 2012 UTC (12 years, 2 months ago) by doda
File MIME type: text/x-csrc
File size: 109836 byte(s)
break を入れ忘れて、Alternate Screen Buffer が暴発していた。orz

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