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