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 5324 - (hide annotations) (download) (as text)
Mon Jun 17 12:14:30 2013 UTC (10 years, 9 months ago) by doda
File MIME type: text/x-csrc
File size: 129033 byte(s)
DECLRMM/DECSLRMに仮対応
差分が大きくなってきたのでとりあえずコミット。まだ直さないといけない所があるけれど。

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