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 6173 - (hide annotations) (download) (as text)
Mon Nov 30 09:30:33 2015 UTC (8 years, 4 months ago) by doda
File MIME type: text/x-csrc
File size: 131728 byte(s)
インデント修正。

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