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 5316 - (hide annotations) (download) (as text)
Tue Jun 11 18:03:59 2013 UTC (10 years, 10 months ago) by doda
File MIME type: text/x-csrc
File size: 120982 byte(s)
Beepが多量に鳴らされた時に抑制するようにした。

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