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 4225 - (hide annotations) (download) (as text)
Fri Dec 17 06:10:40 2010 UTC (13 years, 3 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 96965 byte(s)
DECSTUI に対応。

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