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 7277 - (hide annotations) (download) (as text)
Wed Nov 21 09:12:57 2018 UTC (5 years, 4 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 138249 byte(s)
端末サイズ変更時に DECLRMM のリセットを行わないようにした。

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