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