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