Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/vtterm.c

Parent Directory Parent Directory | Revision Log Revision Log


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