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 7983 - (hide annotations) (download) (as text)
Sun Aug 18 02:57:16 2019 UTC (4 years, 7 months ago) by yutakapon
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 139757 byte(s)
r7978 の再修正。setlocaleが失敗した場合は、現在にANSIコードページを設定する。

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     UpdateStr();
797     Wrap = AutoWrapMode;
798     }
799 maya 3227 }
800    
801     void PutDebugChar(BYTE b)
802     {
803 yutakapon 3637 static BYTE buff[3];
804 doda 5589 int i;
805     BOOL svInsertMode, svAutoWrapMode;
806     BYTE svCharAttr;
807 yutakapon 3637
808 doda 5589 if (DebugFlag!=DEBUG_FLAG_NOUT) {
809     svInsertMode = InsertMode;
810     svAutoWrapMode = AutoWrapMode;
811 doda 5588 InsertMode = FALSE;
812     AutoWrapMode = TRUE;
813 maya 3227
814 doda 5589 svCharAttr = CharAttr.Attr;
815     if (CharAttr.Attr != AttrDefault) {
816     UpdateStr();
817     CharAttr.Attr = AttrDefault;
818     }
819    
820 doda 5588 if (DebugFlag==DEBUG_FLAG_HEXD) {
821     _snprintf(buff, 3, "%02X", (unsigned int) b);
822 yutakapon 3637
823 doda 5589 for (i=0; i<2; i++)
824 doda 5588 PutChar(buff[i]);
825     PutChar(' ');
826     }
827     else if (DebugFlag==DEBUG_FLAG_NORM) {
828 yutakapon 3637
829 doda 5588 if ((b & 0x80) == 0x80) {
830     UpdateStr();
831     CharAttr.Attr = AttrReverse;
832     b = b & 0x7f;
833     }
834 maya 3227
835 doda 5588 if (b<=US) {
836     PutChar('^');
837     PutChar((char)(b+0x40));
838     }
839     else if (b==DEL) {
840     PutChar('<');
841     PutChar('D');
842     PutChar('E');
843     PutChar('L');
844     PutChar('>');
845     }
846     else
847     PutChar(b);
848     }
849 maya 3227
850 doda 5589 if (CharAttr.Attr != svCharAttr) {
851 doda 5588 UpdateStr();
852 doda 5589 CharAttr.Attr = svCharAttr;
853 doda 5588 }
854 doda 5589 InsertMode = svInsertMode;
855     AutoWrapMode = svAutoWrapMode;
856 yutakapon 3637 }
857 maya 3227 }
858    
859     void PrnParseControl(BYTE b) // printer mode
860     {
861 doda 6802 switch (b) {
862     case NUL:
863     return;
864     case SO:
865 doda 6913 if ((ts.ISO2022Flag & ISO2022_SO) && ! DirectPrn) {
866 doda 6802 if ((ts.Language==IdJapanese) &&
867     (ts.KanjiCode==IdJIS) &&
868     (ts.JIS7Katakana==1) &&
869     ((ts.TermFlag & TF_FIXEDJIS)!=0))
870     {
871     Gn[1] = IdKatakana;
872     }
873     Glr[0] = 1; /* LS1 */
874     return;
875     }
876     break;
877     case SI:
878 doda 6913 if ((ts.ISO2022Flag & ISO2022_SI) && ! DirectPrn) {
879 doda 6802 Glr[0] = 0; /* LS0 */
880     return;
881     }
882     break;
883     case DC1:
884     case DC3:
885     return;
886     case ESC:
887     ICount = 0;
888     JustAfterESC = TRUE;
889     ParseMode = ModeESC;
890     WriteToPrnFile(0, TRUE); // flush prn buff
891     return;
892     case CSI:
893     if (! Accept8BitCtrl) {
894     PutChar(b); /* Disp C1 char in VT100 mode */
895     return;
896     }
897     ClearParams();
898     FirstPrm = TRUE;
899     ParseMode = ModeCSI;
900     WriteToPrnFile(0, TRUE); // flush prn buff
901     WriteToPrnFile(b, FALSE);
902     return;
903     }
904     /* send the uninterpreted character to printer */
905     WriteToPrnFile(b, TRUE);
906 maya 3227 }
907    
908     void ParseControl(BYTE b)
909     {
910 doda 6802 if (PrinterMode) { // printer mode
911     PrnParseControl(b);
912     return;
913     }
914 maya 3227
915 doda 6802 if (b>=0x80) { /* C1 char */
916     if (ts.Language==IdEnglish) { /* English mode */
917     if (!Accept8BitCtrl) {
918     PutChar(b); /* Disp C1 char in VT100 mode */
919     return;
920     }
921     }
922     else { /* Japanese mode */
923     if ((ts.TermFlag & TF_ACCEPT8BITCTRL)==0) {
924     return; /* ignore C1 char */
925     }
926     /* C1 chars are interpreted as C0 chars in VT100 mode */
927     if (VTlevel < 2) {
928     b = b & 0x7F;
929     }
930     }
931     }
932     switch (b) {
933     /* C0 group */
934     case ENQ:
935     CommBinaryOut(&cv, &(ts.Answerback[0]), ts.AnswerbackLen);
936     break;
937     case BEL:
938     if (ts.Beep != IdBeepOff)
939     RingBell(ts.Beep);
940     break;
941     case BS:
942     BackSpace();
943     break;
944     case HT:
945     Tab();
946     break;
947     case LF:
948 maya 3227 if (ts.CRReceive == IdLF) {
949 maya 4893 // ���M�������s�R�[�h�� LF ���������A�T�[�o���� LF ���������������������������A
950     // CR+LF���������������������B
951     // cf. http://www.neocom.ca/forum/viewtopic.php?t=216
952     // (2007.1.21 yutaka)
953 maya 3227 CarriageReturn(TRUE);
954     LineFeed(b, TRUE);
955     break;
956     }
957 maya 4893 else if (ts.CRReceive == IdAUTO) {
958     // 9th Apr 2012: AUTO CR/LF mode (tentner)
959     // a CR or LF will generated a CR+LF, if the next character is the opposite, it will be ignored
960     if(PrevCharacter != CR || !PrevCRorLFGeneratedCRLF) {
961     CarriageReturn(TRUE);
962     LineFeed(b, TRUE);
963     PrevCRorLFGeneratedCRLF = TRUE;
964     }
965     else {
966     PrevCRorLFGeneratedCRLF = FALSE;
967     }
968     break;
969     }
970 maya 3227
971 doda 6802 case VT:
972     LineFeed(b, TRUE);
973     break;
974 maya 3227
975 doda 6802 case FF:
976     if ((ts.AutoWinSwitch>0) && JustAfterESC) {
977     CommInsert1Byte(&cv, b);
978     CommInsert1Byte(&cv, ESC);
979     ChangeEmu = IdTEK; /* Enter TEK Mode */
980     }
981     else
982     LineFeed(b, TRUE);
983     break;
984     case CR:
985     if (ts.CRReceive == IdAUTO) {
986     // 9th Apr 2012: AUTO CR/LF mode (tentner)
987     // a CR or LF will generated a CR+LF, if the next character is the opposite, it will be ignored
988     if(PrevCharacter != LF || !PrevCRorLFGeneratedCRLF) {
989     CarriageReturn(TRUE);
990     LineFeed(b, TRUE);
991     PrevCRorLFGeneratedCRLF = TRUE;
992     }
993     else {
994     PrevCRorLFGeneratedCRLF = FALSE;
995     }
996     }
997     else {
998     CarriageReturn(TRUE);
999     if (ts.CRReceive==IdCRLF) {
1000     CommInsert1Byte(&cv, LF);
1001     }
1002     }
1003     break;
1004     case SO: /* LS1 */
1005 doda 6913 if (ts.ISO2022Flag & ISO2022_SO) {
1006 doda 6804 if ((ts.Language==IdJapanese) &&
1007     (ts.KanjiCode==IdJIS) &&
1008     (ts.JIS7Katakana==1) &&
1009     ((ts.TermFlag & TF_FIXEDJIS)!=0))
1010     {
1011     Gn[1] = IdKatakana;
1012     }
1013 maya 3227
1014 doda 6804 Glr[0] = 1;
1015     }
1016 doda 6802 break;
1017     case SI: /* LS0 */
1018 doda 6913 if (ts.ISO2022Flag & ISO2022_SI) {
1019 doda 6804 Glr[0] = 0;
1020     }
1021 doda 6802 break;
1022     case DLE:
1023     if ((ts.FTFlag & FT_BPAUTO)!=0)
1024     ParseMode = ModeDLE; /* Auto B-Plus activation */
1025     break;
1026     case CAN:
1027     if ((ts.FTFlag & FT_ZAUTO)!=0)
1028     ParseMode = ModeCAN; /* Auto ZMODEM activation */
1029     // else if (ts.AutoWinSwitch>0)
1030     // ChangeEmu = IdTEK; /* Enter TEK Mode */
1031     else
1032     ParseMode = ModeFirst;
1033     break;
1034     case SUB:
1035     ParseMode = ModeFirst;
1036     break;
1037     case ESC:
1038     ICount = 0;
1039     JustAfterESC = TRUE;
1040     ParseMode = ModeESC;
1041     break;
1042     case FS:
1043     case GS:
1044     case RS:
1045     case US:
1046     if (ts.AutoWinSwitch>0) {
1047     CommInsert1Byte(&cv, b);
1048     ChangeEmu = IdTEK; /* Enter TEK Mode */
1049     }
1050     break;
1051 maya 3227
1052 doda 6802 /* C1 char */
1053     case IND:
1054     LineFeed(0, TRUE);
1055     break;
1056     case NEL:
1057     LineFeed(0, TRUE);
1058     CarriageReturn(TRUE);
1059     break;
1060     case HTS:
1061     if (ts.TabStopFlag & TABF_HTS8)
1062     SetTabStop();
1063     break;
1064     case RI:
1065     CursorUpWithScroll();
1066     break;
1067     case SS2:
1068 doda 6913 if (ts.ISO2022Flag & ISO2022_SS2) {
1069     GLtmp = 2;
1070     SSflag = TRUE;
1071     }
1072 doda 6802 break;
1073     case SS3:
1074 doda 6913 if (ts.ISO2022Flag & ISO2022_SS3) {
1075     GLtmp = 3;
1076     SSflag = TRUE;
1077     }
1078 doda 6802 break;
1079     case DCS:
1080     ClearParams();
1081     ESCFlag = FALSE;
1082     ParseMode = ModeDCS;
1083     break;
1084     case SOS:
1085     ESCFlag = FALSE;
1086     ParseMode = ModeIgnore;
1087     break;
1088     case CSI:
1089     ClearParams();
1090     FirstPrm = TRUE;
1091     ParseMode = ModeCSI;
1092     break;
1093     case OSC:
1094     ClearParams();
1095     ParseMode = ModeXS;
1096     break;
1097     case PM:
1098     case APC:
1099     ESCFlag = FALSE;
1100     ParseMode = ModeIgnore;
1101     break;
1102     }
1103 maya 3227 }
1104    
1105     void SaveCursor()
1106     {
1107 doda 6802 int i;
1108     PStatusBuff Buff;
1109 maya 3227
1110 doda 6802 if (isCursorOnStatusLine)
1111     Buff = &SBuff2; // for status line
1112     else if (AltScr)
1113     Buff = &SBuff3; // for alternate screen
1114     else
1115     Buff = &SBuff1; // for main screen
1116 maya 3227
1117 doda 6802 Buff->CursorX = CursorX;
1118     Buff->CursorY = CursorY;
1119     Buff->Attr = CharAttr;
1120    
1121     Buff->Glr[0] = Glr[0];
1122     Buff->Glr[1] = Glr[1];
1123     for (i=0 ; i<=3; i++)
1124     Buff->Gn[i] = Gn[i];
1125    
1126     Buff->AutoWrapMode = AutoWrapMode;
1127     Buff->RelativeOrgMode = RelativeOrgMode;
1128 maya 3227 }
1129    
1130 doda 6802 void RestoreCursor()
1131 maya 3227 {
1132 doda 6802 int i;
1133     PStatusBuff Buff;
1134 maya 3227
1135 doda 6802 UpdateStr();
1136 maya 3227
1137 doda 6802 if (isCursorOnStatusLine)
1138     Buff = &SBuff2; // for status line
1139     else if (AltScr)
1140     Buff = &SBuff3; // for alternate screen
1141     else
1142     Buff = &SBuff1; // for main screen
1143    
1144     if (Buff->CursorX > NumOfColumns-1)
1145     Buff->CursorX = NumOfColumns-1;
1146     if (Buff->CursorY > NumOfLines-1-StatusLine)
1147     Buff->CursorY = NumOfLines-1-StatusLine;
1148     MoveCursor(Buff->CursorX, Buff->CursorY);
1149    
1150     CharAttr = Buff->Attr;
1151     BuffSetCurCharAttr(CharAttr);
1152    
1153     Glr[0] = Buff->Glr[0];
1154     Glr[1] = Buff->Glr[1];
1155     for (i=0 ; i<=3; i++)
1156     Gn[i] = Buff->Gn[i];
1157    
1158     AutoWrapMode = Buff->AutoWrapMode;
1159     RelativeOrgMode = Buff->RelativeOrgMode;
1160 maya 3227 }
1161    
1162     void AnswerTerminalType()
1163     {
1164 doda 6802 char Tmp[50];
1165 maya 3227
1166 doda 6802 if (ts.TerminalID<IdVT320 || !Send8BitMode)
1167     strncpy_s(Tmp, sizeof(Tmp),"\033[?", _TRUNCATE);
1168     else
1169     strncpy_s(Tmp, sizeof(Tmp),"\233?", _TRUNCATE);
1170 maya 3227
1171 doda 6802 switch (ts.TerminalID) {
1172     case IdVT100:
1173     strncat_s(Tmp,sizeof(Tmp),"1;2",_TRUNCATE);
1174     break;
1175     case IdVT100J:
1176     strncat_s(Tmp,sizeof(Tmp),"5;2",_TRUNCATE);
1177     break;
1178     case IdVT101:
1179     strncat_s(Tmp,sizeof(Tmp),"1;0",_TRUNCATE);
1180     break;
1181     case IdVT102:
1182     strncat_s(Tmp,sizeof(Tmp),"6",_TRUNCATE);
1183     break;
1184     case IdVT102J:
1185     strncat_s(Tmp,sizeof(Tmp),"15",_TRUNCATE);
1186     break;
1187     case IdVT220J:
1188     strncat_s(Tmp,sizeof(Tmp),"62;1;2;5;6;7;8",_TRUNCATE);
1189     break;
1190     case IdVT282:
1191     strncat_s(Tmp,sizeof(Tmp),"62;1;2;4;5;6;7;8;10;11",_TRUNCATE);
1192     break;
1193     case IdVT320:
1194     strncat_s(Tmp,sizeof(Tmp),"63;1;2;6;7;8",_TRUNCATE);
1195     break;
1196     case IdVT382:
1197     strncat_s(Tmp,sizeof(Tmp),"63;1;2;4;5;6;7;8;10;15",_TRUNCATE);
1198     break;
1199     case IdVT420:
1200     strncat_s(Tmp,sizeof(Tmp),"64;1;2;7;8;9;15;18;21",_TRUNCATE);
1201     break;
1202     case IdVT520:
1203     strncat_s(Tmp,sizeof(Tmp),"65;1;2;7;8;9;12;18;19;21;23;24;42;44;45;46",_TRUNCATE);
1204     break;
1205     case IdVT525:
1206     strncat_s(Tmp,sizeof(Tmp),"65;1;2;7;9;12;18;19;21;22;23;24;42;44;45;46",_TRUNCATE);
1207     break;
1208     }
1209     strncat_s(Tmp,sizeof(Tmp),"c",_TRUNCATE);
1210 maya 3227
1211 doda 6802 CommBinaryOut(&cv,Tmp,strlen(Tmp)); /* Report terminal ID */
1212 maya 3227 }
1213    
1214     void ESCSpace(BYTE b)
1215     {
1216 doda 6802 switch (b) {
1217     case 'F': // S7C1T
1218     Send8BitMode = FALSE;
1219     break;
1220     case 'G': // S8C1T
1221     if (VTlevel >= 2) {
1222     Send8BitMode = TRUE;
1223     }
1224     break;
1225     }
1226 maya 3227 }
1227    
1228     void ESCSharp(BYTE b)
1229     {
1230 doda 6802 switch (b) {
1231     case '8': /* Fill screen with "E" (DECALN) */
1232     BuffUpdateScroll();
1233     BuffFillWithE();
1234     CursorTop = 0;
1235     CursorBottom = NumOfLines-1-StatusLine;
1236     CursorLeftM = 0;
1237     CursorRightM = NumOfColumns - 1;
1238     MoveCursor(0, 0);
1239     ParseMode = ModeFirst;
1240     break;
1241     }
1242 maya 3227 }
1243    
1244     /* select double byte code set */
1245     void ESCDBCSSelect(BYTE b)
1246     {
1247 doda 6802 int Dist;
1248 maya 3227
1249 doda 6802 if (ts.Language!=IdJapanese) return;
1250 maya 3227
1251 doda 6802 switch (ICount) {
1252     case 1:
1253     if ((b=='@') || (b=='B'))
1254     {
1255     Gn[0] = IdKanji; /* Kanji -> G0 */
1256     if ((ts.TermFlag & TF_AUTOINVOKE)!=0)
1257     Glr[0] = 0; /* G0->GL */
1258     }
1259     break;
1260     case 2:
1261     /* Second intermediate char must be
1262     '(' or ')' or '*' or '+'. */
1263     Dist = (IntChar[2]-'(') & 3; /* G0 - G3 */
1264     if ((b=='1') || (b=='3') ||
1265     (b=='@') || (b=='B'))
1266     {
1267     Gn[Dist] = IdKanji; /* Kanji -> G0-3 */
1268     if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
1269     (Dist==0))
1270     Glr[0] = 0; /* G0->GL */
1271     }
1272     break;
1273     }
1274 maya 3227 }
1275    
1276     void ESCSelectCode(BYTE b)
1277     {
1278 doda 6802 switch (b) {
1279     case '0':
1280     if (ts.AutoWinSwitch>0)
1281     ChangeEmu = IdTEK; /* enter TEK mode */
1282     break;
1283     }
1284 maya 3227 }
1285    
1286 doda 6802 /* select single byte code set */
1287 maya 3227 void ESCSBCSSelect(BYTE b)
1288     {
1289 doda 6802 int Dist;
1290 maya 3227
1291 doda 6802 /* Intermediate char must be '(' or ')' or '*' or '+'. */
1292     Dist = (IntChar[1]-'(') & 3; /* G0 - G3 */
1293 maya 3227
1294 doda 6802 switch (b) {
1295     case '0': Gn[Dist] = IdSpecial; break;
1296     case '<': Gn[Dist] = IdASCII; break;
1297     case '>': Gn[Dist] = IdASCII; break;
1298     case 'A': Gn[Dist] = IdASCII; break;
1299     case 'B': Gn[Dist] = IdASCII; break;
1300     case 'H': Gn[Dist] = IdASCII; break;
1301     case 'I':
1302     if (ts.Language==IdJapanese)
1303     Gn[Dist] = IdKatakana;
1304     break;
1305     case 'J': Gn[Dist] = IdASCII; break;
1306     }
1307 maya 3227
1308 doda 6802 if (((ts.TermFlag & TF_AUTOINVOKE)!=0) && (Dist==0))
1309     Glr[0] = 0; /* G0->GL */
1310 maya 3227 }
1311    
1312     void PrnParseEscape(BYTE b) // printer mode
1313     {
1314 doda 6802 int i;
1315 maya 3227
1316 doda 6802 ParseMode = ModeFirst;
1317     switch (ICount) {
1318     /* no intermediate char */
1319     case 0:
1320     switch (b) {
1321     case '[': /* CSI */
1322     ClearParams();
1323     FirstPrm = TRUE;
1324     WriteToPrnFile(ESC,FALSE);
1325     WriteToPrnFile('[',FALSE);
1326     ParseMode = ModeCSI;
1327     return;
1328     } /* end of case Icount=0 */
1329     break;
1330     /* one intermediate char */
1331     case 1:
1332     switch (IntChar[1]) {
1333     case '$':
1334     if (! DirectPrn) {
1335     ESCDBCSSelect(b);
1336     return;
1337     }
1338     break;
1339     case '(':
1340     case ')':
1341     case '*':
1342     case '+':
1343     if (! DirectPrn) {
1344     ESCSBCSSelect(b);
1345     return;
1346     }
1347     break;
1348     }
1349     break;
1350     /* two intermediate char */
1351     case 2:
1352     if ((! DirectPrn) &&
1353     (IntChar[1]=='$') &&
1354     ('('<=IntChar[2]) &&
1355     (IntChar[2]<='+'))
1356     {
1357     ESCDBCSSelect(b);
1358     return;
1359     }
1360     break;
1361     }
1362     // send the uninterpreted sequence to printer
1363     WriteToPrnFile(ESC,FALSE);
1364     for (i=1; i<=ICount; i++)
1365     WriteToPrnFile(IntChar[i],FALSE);
1366     WriteToPrnFile(b,TRUE);
1367 maya 3227 }
1368    
1369     void ParseEscape(BYTE b) /* b is the final char */
1370     {
1371 doda 6802 if (PrinterMode) { // printer mode
1372     PrnParseEscape(b);
1373     return;
1374     }
1375 maya 3227
1376 doda 6802 switch (ICount) {
1377     case 0: /* no intermediate char */
1378     switch (b) {
1379     case '6': // DECBI
1380     if (CursorY >= CursorTop && CursorY <= CursorBottom &&
1381     CursorX >= CursorLeftM && CursorX <= CursorRightM) {
1382     if (CursorX == CursorLeftM)
1383     BuffScrollRight(1);
1384     else
1385     MoveCursor(CursorX-1, CursorY);
1386     }
1387     break;
1388     case '7': SaveCursor(); break;
1389     case '8': RestoreCursor(); break;
1390     case '9': // DECFI
1391     if (CursorY >= CursorTop && CursorY <= CursorBottom &&
1392     CursorX >= CursorLeftM && CursorX <= CursorRightM) {
1393     if (CursorX == CursorRightM)
1394     BuffScrollLeft(1);
1395     else
1396     MoveCursor(CursorX+1, CursorY);
1397     }
1398     break;
1399     case '=': AppliKeyMode = TRUE; break;
1400     case '>': AppliKeyMode = FALSE; break;
1401     case 'D': /* IND */
1402     LineFeed(0,TRUE);
1403     break;
1404     case 'E': /* NEL */
1405     MoveCursor(0,CursorY);
1406     LineFeed(0,TRUE);
1407     break;
1408     case 'H': /* HTS */
1409     if (ts.TabStopFlag & TABF_HTS7)
1410     SetTabStop();
1411     break;
1412     case 'M': /* RI */
1413     CursorUpWithScroll();
1414     break;
1415     case 'N': /* SS2 */
1416 doda 6913 if (ts.ISO2022Flag & ISO2022_SS2) {
1417     GLtmp = 2;
1418     SSflag = TRUE;
1419     }
1420 doda 6802 break;
1421     case 'O': /* SS3 */
1422 doda 6913 if (ts.ISO2022Flag & ISO2022_SS3) {
1423     GLtmp = 3;
1424     SSflag = TRUE;
1425     }
1426 doda 6802 break;
1427     case 'P': /* DCS */
1428     ClearParams();
1429     ESCFlag = FALSE;
1430     ParseMode = ModeDCS;
1431     return;
1432     case 'X': /* SOS */
1433     case '^': /* APC */
1434     case '_': /* PM */
1435     ESCFlag = FALSE;
1436     ParseMode = ModeIgnore;
1437     return;
1438     case 'Z': /* DECID */
1439     AnswerTerminalType();
1440     break;
1441     case '[': /* CSI */
1442     ClearParams();
1443     FirstPrm = TRUE;
1444     ParseMode = ModeCSI;
1445     return;
1446     case '\\': break; /* ST */
1447     case ']': /* XTERM sequence (OSC) */
1448     ClearParams();
1449     ParseMode = ModeXS;
1450     return;
1451     case 'c': /* Hardware reset */
1452     HideStatusLine();
1453     ResetTerminal();
1454     ClearUserKey();
1455     ClearBuffer();
1456     if (ts.PortType==IdSerial) // reset serial port
1457     CommResetSerial(&ts, &cv, TRUE);
1458     break;
1459     case 'g': /* Visual Bell (screen original?) */
1460     RingBell(IdBeepVisual);
1461     break;
1462 doda 6913 case 'n': /* LS2 */
1463     if (ts.ISO2022Flag & ISO2022_LS2) {
1464     Glr[0] = 2;
1465     }
1466     break;
1467     case 'o': /* LS3 */
1468     if (ts.ISO2022Flag & ISO2022_LS3) {
1469     Glr[0] = 3;
1470     }
1471     break;
1472     case '|': /* LS3R */
1473     if (ts.ISO2022Flag & ISO2022_LS3R) {
1474     Glr[1] = 3;
1475     }
1476     break;
1477     case '}': /* LS2R */
1478     if (ts.ISO2022Flag & ISO2022_LS2R) {
1479     Glr[1] = 2;
1480     }
1481     break;
1482     case '~': /* LS1R */
1483     if (ts.ISO2022Flag & ISO2022_LS1R) {
1484     Glr[1] = 1;
1485     }
1486     break;
1487 doda 6802 }
1488     break;
1489     /* end of case Icount=0 */
1490    
1491     case 1: /* one intermediate char */
1492     switch (IntChar[1]) {
1493     case ' ': ESCSpace(b); break;
1494     case '#': ESCSharp(b); break;
1495     case '$': ESCDBCSSelect(b); break;
1496     case '%': break;
1497     case '(':
1498     case ')':
1499     case '*':
1500     case '+':
1501     ESCSBCSSelect(b);
1502     break;
1503     }
1504     break;
1505    
1506     case 2: /* two intermediate char */
1507     if ((IntChar[1]=='$') && ('('<=IntChar[2]) && (IntChar[2]<='+'))
1508     ESCDBCSSelect(b);
1509     else if ((IntChar[1]=='%') && (IntChar[2]=='!'))
1510     ESCSelectCode(b);
1511     break;
1512     }
1513     ParseMode = ModeFirst;
1514 maya 3227 }
1515    
1516     void EscapeSequence(BYTE b)
1517     {
1518 doda 6173 if (b<=US)
1519     ParseControl(b);
1520     else if ((b>=0x20) && (b<=0x2F)) {
1521 doda 6174 // TODO: ICount �� IntCharMax ���B�������A������ IntChar ���u����������������?
1522 doda 6173 if (ICount<IntCharMax)
1523     ICount++;
1524     IntChar[ICount] = b;
1525     }
1526     else if ((b>=0x30) && (b<=0x7E))
1527     ParseEscape(b);
1528     else if ((b>=0x80) && (b<=0x9F))
1529     ParseControl(b);
1530     else if (b>=0xA0) {
1531     ParseMode=ModeFirst;
1532     ParseFirst(b);
1533     }
1534 maya 3227
1535 doda 6173 JustAfterESC = FALSE;
1536 maya 3227 }
1537    
1538 doda 6174 #define CheckParamVal(p,m) \
1539     if ((p) == 0) { \
1540     (p) = 1; \
1541     } \
1542     else if ((p) > (m) || p < 0) { \
1543     (p) = (m); \
1544     }
1545    
1546     #define CheckParamValMax(p,m) \
1547     if ((p) > (m) || p <= 0) { \
1548     (p) = (m); \
1549     }
1550    
1551     #define RequiredParams(n) \
1552     if ((n) > 1) { \
1553     while (NParam < n) { \
1554     NParam++; \
1555     Param[NParam] = 0; \
1556     NSParam[NParam] = 0; \
1557     } \
1558     }
1559    
1560 doda 6173 void CSInsertCharacter() // ICH
1561     {
1562     // Insert space characters at cursor
1563 doda 6174 CheckParamVal(Param[1], NumOfColumns);
1564 maya 3227
1565 doda 6173 BuffUpdateScroll();
1566 doda 6174 BuffInsertSpace(Param[1]);
1567 doda 6173 }
1568 maya 3227
1569 doda 5429 void CSCursorUp(BOOL AffectMargin) // CUU / VPB
1570     {
1571     int topMargin, NewY;
1572 maya 3227
1573 doda 6174 CheckParamVal(Param[1], CursorY);
1574 maya 3227
1575 doda 5429 if (AffectMargin && CursorY >= CursorTop)
1576     topMargin = CursorTop;
1577     else
1578     topMargin = 0;
1579 maya 3227
1580 doda 5429 NewY = CursorY - Param[1];
1581     if (NewY < topMargin)
1582     NewY = topMargin;
1583 maya 3227
1584 doda 5429 MoveCursor(CursorX, NewY);
1585     }
1586 maya 3227
1587 doda 5429 void CSCursorUp1() // CPL
1588     {
1589     MoveCursor(CursorLeftM, CursorY);
1590     CSCursorUp(TRUE);
1591     }
1592 maya 3227
1593 doda 5429 void CSCursorDown(BOOL AffectMargin) // CUD / VPR
1594     {
1595     int bottomMargin, NewY;
1596    
1597     if (AffectMargin && CursorY <= CursorBottom)
1598     bottomMargin = CursorBottom;
1599     else
1600     bottomMargin = NumOfLines-StatusLine-1;
1601    
1602 doda 6174 CheckParamVal(Param[1], bottomMargin);
1603    
1604 doda 5429 NewY = CursorY + Param[1];
1605     if (NewY > bottomMargin)
1606     NewY = bottomMargin;
1607    
1608     MoveCursor(CursorX, NewY);
1609     }
1610    
1611     void CSCursorDown1() // CNL
1612     {
1613     MoveCursor(CursorLeftM, CursorY);
1614     CSCursorDown(TRUE);
1615     }
1616    
1617 maya 3227 void CSScreenErase()
1618     {
1619     BuffUpdateScroll();
1620     switch (Param[1]) {
1621 doda 6173 case 0:
1622 maya 3227 // <ESC>[H(Cursor in left upper corner)�������J�[�\�������������w�������������A
1623     // <ESC>[J��<ESC>[2J�����������������A�����������A���s�o�b�t�@���X�N���[���A�E�g
1624     // �����������������B(2005.5.29 yutaka)
1625     // �R���t�B�O���[�V�������������������������������B(2008.5.3 yutaka)
1626 doda 6435 if (ts.ScrollWindowClearScreen &&
1627 maya 3227 (CursorX == 0 && CursorY == 0)) {
1628 doda 6173 // Erase screen (scroll out)
1629 maya 3227 BuffClearScreen();
1630     UpdateWindow(HVTWin);
1631    
1632     } else {
1633 doda 6173 // Erase characters from cursor to the end of screen
1634 maya 3227 BuffEraseCurToEnd();
1635     }
1636     break;
1637    
1638 doda 6173 case 1:
1639     // Erase characters from home to cursor
1640 maya 3227 BuffEraseHomeToCur();
1641     break;
1642    
1643 doda 6173 case 2:
1644     // Erase screen (scroll out)
1645 maya 3227 BuffClearScreen();
1646     UpdateWindow(HVTWin);
1647 doda 5564 if (ClearThenHome && !isCursorOnStatusLine) {
1648     if (RelativeOrgMode) {
1649     MoveCursor(0, 0);
1650     }
1651     else {
1652     MoveCursor(CursorLeftM, CursorTop);
1653     }
1654     }
1655 maya 3227 break;
1656     }
1657     }
1658    
1659 doda 4070 void CSQSelScreenErase()
1660     {
1661     BuffUpdateScroll();
1662     switch (Param[1]) {
1663 doda 6173 case 0:
1664     // Erase characters from cursor to end
1665 doda 4070 BuffSelectedEraseCurToEnd();
1666     break;
1667    
1668 doda 6173 case 1:
1669     // Erase characters from home to cursor
1670 doda 4070 BuffSelectedEraseHomeToCur();
1671     break;
1672    
1673 doda 6173 case 2:
1674     // Erase entire screen
1675 doda 4070 BuffSelectedEraseScreen();
1676     break;
1677     }
1678     }
1679    
1680 doda 6173 void CSInsertLine()
1681     {
1682     // Insert lines at current position
1683     int Count, YEnd;
1684 maya 3227
1685 doda 6174 if (CursorY < CursorTop || CursorY > CursorBottom) {
1686 doda 6173 return;
1687 doda 6174 }
1688 maya 3227
1689 doda 6174 CheckParamVal(Param[1], NumOfLines);
1690    
1691 doda 6173 Count = Param[1];
1692 maya 3227
1693 doda 6173 YEnd = CursorBottom;
1694     if (CursorY > YEnd)
1695     YEnd = NumOfLines-1-StatusLine;
1696 doda 6174
1697 doda 6173 if (Count > YEnd+1 - CursorY)
1698     Count = YEnd+1 - CursorY;
1699 maya 3227
1700 doda 6173 BuffInsertLines(Count,YEnd);
1701     }
1702 maya 3227
1703 doda 6173 void CSLineErase()
1704     {
1705     BuffUpdateScroll();
1706     switch (Param[1]) {
1707     case 0: /* erase char from cursor to end of line */
1708     BuffEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1709     break;
1710 doda 4070
1711 doda 6173 case 1: /* erase char from start of line to cursor */
1712     BuffEraseCharsInLine(0,CursorX+1);
1713     break;
1714 maya 3227
1715 doda 6173 case 2: /* erase entire line */
1716     BuffEraseCharsInLine(0,NumOfColumns);
1717     break;
1718     }
1719     }
1720 maya 3227
1721 doda 6173 void CSQSelLineErase()
1722     {
1723     BuffUpdateScroll();
1724     switch (Param[1]) {
1725     case 0: /* erase char from cursor to end of line */
1726     BuffSelectedEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1727     break;
1728 maya 3227
1729 doda 6173 case 1: /* erase char from start of line to cursor */
1730     BuffSelectedEraseCharsInLine(0,CursorX+1);
1731     break;
1732 maya 3227
1733 doda 6173 case 2: /* erase entire line */
1734     BuffSelectedEraseCharsInLine(0,NumOfColumns);
1735     break;
1736     }
1737     }
1738 maya 3227
1739 doda 6173 void CSDeleteNLines()
1740     // Delete lines from current line
1741     {
1742     int Count, YEnd;
1743 maya 3227
1744 doda 6174 if (CursorY < CursorTop || CursorY > CursorBottom) {
1745 doda 6173 return;
1746 doda 6174 }
1747    
1748     CheckParamVal(Param[1], NumOfLines);
1749 doda 6173 Count = Param[1];
1750 maya 3227
1751 doda 6173 YEnd = CursorBottom;
1752     if (CursorY > YEnd)
1753     YEnd = NumOfLines-1-StatusLine;
1754 doda 6174
1755 doda 6173 if (Count > YEnd+1-CursorY)
1756     Count = YEnd+1-CursorY;
1757 doda 6174
1758 doda 6173 BuffDeleteLines(Count,YEnd);
1759     }
1760 maya 3227
1761 doda 6173 void CSDeleteCharacter() // DCH
1762     {
1763     // Delete characters in current line from cursor
1764 doda 6174 CheckParamVal(Param[1], NumOfColumns);
1765 maya 3227
1766 doda 6173 BuffUpdateScroll();
1767     BuffDeleteChars(Param[1]);
1768     }
1769 maya 3227
1770 doda 6173 void CSEraseCharacter() // ECH
1771     {
1772 doda 6174 CheckParamVal(Param[1], NumOfColumns);
1773    
1774 doda 6173 BuffUpdateScroll();
1775     BuffEraseChars(Param[1]);
1776     }
1777    
1778     void CSScrollUp()
1779     {
1780 doda 6174 // TODO: �X�N���[���������l���[���s�����������������v����
1781     CheckParamVal(Param[1], INT_MAX);
1782    
1783 doda 6173 BuffUpdateScroll();
1784     BuffRegionScrollUpNLines(Param[1]);
1785     }
1786    
1787     void CSScrollDown()
1788     {
1789 doda 6174 CheckParamVal(Param[1], NumOfLines);
1790    
1791 doda 6173 BuffUpdateScroll();
1792     BuffRegionScrollDownNLines(Param[1]);
1793     }
1794    
1795     void CSForwardTab()
1796     {
1797 doda 6174 CheckParamVal(Param[1], NumOfColumns);
1798 doda 6173 CursorForwardTab(Param[1], AutoWrapMode);
1799     }
1800    
1801     void CSBackwardTab()
1802     {
1803 doda 6174 CheckParamVal(Param[1], NumOfColumns);
1804 doda 6173 CursorBackwardTab(Param[1]);
1805     }
1806    
1807 doda 5324 void CSMoveToColumnN() // CHA / HPA
1808     {
1809 doda 6174 CheckParamVal(Param[1], NumOfColumns);
1810 maya 3227
1811 doda 5324 Param[1]--;
1812 maya 3227
1813 doda 5324 if (RelativeOrgMode) {
1814     if (CursorLeftM + Param[1] > CursorRightM )
1815     MoveCursor(CursorRightM, CursorY);
1816     else
1817     MoveCursor(CursorLeftM + Param[1], CursorY);
1818     }
1819     else {
1820     MoveCursor(Param[1], CursorY);
1821     }
1822     }
1823 maya 3227
1824 doda 5429 void CSCursorRight(BOOL AffectMargin) // CUF / HPR
1825 doda 5324 {
1826 doda 5429 int NewX, rightMargin;
1827 doda 5324
1828 doda 6174 CheckParamVal(Param[1], NumOfColumns);
1829 doda 5324
1830 doda 6174 if (AffectMargin && CursorX <= CursorRightM) {
1831 doda 5429 rightMargin = CursorRightM;
1832 doda 6174 }
1833     else {
1834 doda 5429 rightMargin = NumOfColumns-1;
1835 doda 6174 }
1836 doda 5429
1837 doda 5324 NewX = CursorX + Param[1];
1838 doda 5429 if (NewX > rightMargin)
1839     NewX = rightMargin;
1840 doda 5324
1841     MoveCursor(NewX, CursorY);
1842     }
1843    
1844 doda 5429 void CSCursorLeft(BOOL AffectMargin) // CUB / HPB
1845 doda 5324 {
1846 doda 5429 int NewX, leftMargin;
1847 doda 5324
1848 doda 6174 CheckParamVal(Param[1], NumOfColumns);
1849 doda 5324
1850 doda 6174 if (AffectMargin && CursorX >= CursorLeftM) {
1851 doda 5429 leftMargin = CursorLeftM;
1852 doda 6174 }
1853     else {
1854 doda 5429 leftMargin = 0;
1855 doda 6174 }
1856 doda 5324
1857 doda 5429 NewX = CursorX - Param[1];
1858 doda 6174 if (NewX < leftMargin) {
1859 doda 5429 NewX = leftMargin;
1860 doda 6174 }
1861 doda 5324
1862     MoveCursor(NewX, CursorY);
1863     }
1864    
1865 doda 6174 void CSMoveToLineN() // VPA
1866 doda 6173 {
1867 doda 6174 CheckParamVal(Param[1], NumOfLines-StatusLine);
1868    
1869 doda 6173 if (RelativeOrgMode) {
1870     if (CursorTop+Param[1]-1 > CursorBottom)
1871     MoveCursor(CursorX,CursorBottom);
1872     else
1873     MoveCursor(CursorX,CursorTop+Param[1]-1);
1874     }
1875     else {
1876     if (Param[1] > NumOfLines-StatusLine)
1877     MoveCursor(CursorX,NumOfLines-1-StatusLine);
1878     else
1879     MoveCursor(CursorX,Param[1]-1);
1880     }
1881 doda 6602 Fallbacked = FALSE;
1882 doda 6173 }
1883 maya 3227
1884 doda 5324 void CSMoveToXY() // CUP / HVP
1885     {
1886     int NewX, NewY;
1887 maya 3227
1888 doda 6174 RequiredParams(2);
1889     CheckParamVal(Param[1], NumOfLines-StatusLine);
1890     CheckParamVal(Param[2], NumOfColumns);
1891 maya 3227
1892 doda 5324 NewY = Param[1] - 1;
1893     NewX = Param[2] - 1;
1894    
1895     if (isCursorOnStatusLine)
1896     NewY = CursorY;
1897     else if (RelativeOrgMode) {
1898     NewX += CursorLeftM;
1899     if (NewX > CursorRightM)
1900     NewX = CursorRightM;
1901    
1902     NewY += CursorTop;
1903     if (NewY > CursorBottom)
1904     NewY = CursorBottom;
1905     }
1906     else {
1907     if (NewY > NumOfLines-1-StatusLine)
1908     NewY = NumOfLines-1-StatusLine;
1909     }
1910    
1911     MoveCursor(NewX, NewY);
1912 doda 6602 Fallbacked = FALSE;
1913 doda 5324 }
1914    
1915 doda 6173 void CSDeleteTabStop()
1916     {
1917     ClearTabStop(Param[1]);
1918     }
1919 maya 3227
1920 doda 6173 void CS_h_Mode() // SM
1921     {
1922     switch (Param[1]) {
1923     case 2: // KAM
1924     KeybEnabled = FALSE; break;
1925     case 4: // IRM
1926     InsertMode = TRUE; break;
1927     case 12: // SRM
1928     ts.LocalEcho = 0;
1929     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1930     TelChangeEcho();
1931     break;
1932     case 20: // LF/NL
1933     LFMode = TRUE;
1934     ts.CRSend = IdCRLF;
1935     cv.CRSend = IdCRLF;
1936     break;
1937     case 33: // WYSTCURM
1938     if (ts.WindowFlag & WF_CURSORCHANGE) {
1939     ts.NonblinkingCursor = TRUE;
1940     ChangeCaret();
1941     }
1942     break;
1943     case 34: // WYULCURM
1944     if (ts.WindowFlag & WF_CURSORCHANGE) {
1945     ts.CursorShape = IdHCur;
1946     ChangeCaret();
1947     }
1948     break;
1949     }
1950     }
1951 maya 3227
1952 doda 6173 void CS_i_Mode() // MC
1953     {
1954     switch (Param[1]) {
1955     /* print screen */
1956     // PrintEX -- TRUE: print screen
1957     // FALSE: scroll region
1958     case 0:
1959     if (ts.TermFlag&TF_PRINTERCTRL) {
1960     BuffPrint(! PrintEX);
1961     }
1962     break;
1963     /* printer controller mode off */
1964     case 4: break; /* See PrnParseCS() */
1965     /* printer controller mode on */
1966     case 5:
1967     if (ts.TermFlag&TF_PRINTERCTRL) {
1968     if (! AutoPrintMode)
1969     OpenPrnFile();
1970     DirectPrn = (ts.PrnDev[0]!=0);
1971     PrinterMode = TRUE;
1972     }
1973     break;
1974 doda 4397 }
1975 doda 6173 }
1976    
1977     void CS_l_Mode() // RM
1978     {
1979     switch (Param[1]) {
1980     case 2: // KAM
1981     KeybEnabled = TRUE; break;
1982     case 4: // IRM
1983     InsertMode = FALSE; break;
1984     case 12: // SRM
1985     ts.LocalEcho = 1;
1986     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1987     TelChangeEcho();
1988     break;
1989     case 20: // LF/NL
1990     LFMode = FALSE;
1991     ts.CRSend = IdCR;
1992     cv.CRSend = IdCR;
1993     break;
1994     case 33: // WYSTCURM
1995     if (ts.WindowFlag & WF_CURSORCHANGE) {
1996     ts.NonblinkingCursor = FALSE;
1997     ChangeCaret();
1998     }
1999     break;
2000     case 34: // WYULCURM
2001     if (ts.WindowFlag & WF_CURSORCHANGE) {
2002     ts.CursorShape = IdBlkCur;
2003     ChangeCaret();
2004     }
2005     break;
2006 doda 4397 }
2007 doda 6173 }
2008 maya 3227
2009 doda 6173 void CS_n_Mode() // DSR
2010     {
2011     char Report[16];
2012     int X, Y, len;
2013 maya 3227
2014 doda 6173 switch (Param[1]) {
2015     case 5:
2016     /* Device Status Report -> Ready */
2017     SendCSIstr("0n", 0);
2018     break;
2019     case 6:
2020     /* Cursor Position Report */
2021     if (isCursorOnStatusLine) {
2022     X = CursorX + 1;
2023     Y = 1;
2024     }
2025     else if (RelativeOrgMode) {
2026     X = CursorX - CursorLeftM + 1;
2027     Y = CursorY - CursorTop + 1;
2028     }
2029     else {
2030     X = CursorX + 1;
2031     Y = CursorY+1;
2032     }
2033     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%u;%uR", CLocale, Y, X);
2034     SendCSIstr(Report, len);
2035     break;
2036 doda 5336 }
2037 doda 6173 }
2038 maya 3227
2039 doda 5095 void ParseSGRParams(PCharAttr attr, PCharAttr mask, int start)
2040 maya 3227 {
2041 doda 5073 int i, j, P, r, g, b, color;
2042 doda 5095 TCharAttr dummy;
2043 maya 3227
2044 doda 5095 if (mask == NULL) {
2045     mask = &dummy;
2046     }
2047    
2048 doda 6173 for (i=start ; i<=NParam ; i++) {
2049 maya 3227 P = Param[i];
2050     switch (P) {
2051 doda 6173 case 0: /* Clear all */
2052 doda 5095 attr->Attr = DefCharAttr.Attr;
2053     attr->Attr2 = DefCharAttr.Attr2 | (attr->Attr2&Attr2Protect);
2054     attr->Fore = DefCharAttr.Fore;
2055     attr->Back = DefCharAttr.Back;
2056     mask->Attr = AttrSgrMask;
2057     mask->Attr2 = Attr2ColorMask;
2058 maya 3227 break;
2059    
2060 doda 6173 case 1: /* Bold */
2061 doda 5095 attr->Attr |= AttrBold;
2062     mask->Attr |= AttrBold;
2063 maya 3227 break;
2064    
2065 doda 6173 case 4: /* Under line */
2066 doda 5095 attr->Attr |= AttrUnder;
2067     mask->Attr |= AttrUnder;
2068 maya 3227 break;
2069    
2070 doda 6173 case 5: /* Blink */
2071 doda 5095 attr->Attr |= AttrBlink;
2072     mask->Attr |= AttrBlink;
2073 maya 3227 break;
2074    
2075 doda 6173 case 7: /* Reverse */
2076 doda 5095 attr->Attr |= AttrReverse;
2077     mask->Attr |= AttrReverse;
2078 maya 3227 break;
2079    
2080 doda 6173 case 22: /* Bold off */
2081 doda 5095 attr->Attr &= ~ AttrBold;
2082     mask->Attr |= AttrBold;
2083 maya 3227 break;
2084    
2085 doda 6173 case 24: /* Under line off */
2086 doda 5095 attr->Attr &= ~ AttrUnder;
2087     mask->Attr |= AttrUnder;
2088 maya 3227 break;
2089    
2090 doda 6173 case 25: /* Blink off */
2091 doda 5095 attr->Attr &= ~ AttrBlink;
2092     mask->Attr |= AttrBlink;
2093 maya 3227 break;
2094    
2095 doda 6173 case 27: /* Reverse off */
2096 doda 5095 attr->Attr &= ~ AttrReverse;
2097     mask->Attr |= AttrReverse;
2098 maya 3227 break;
2099    
2100 doda 6173 case 30:
2101     case 31:
2102     case 32:
2103     case 33:
2104     case 34:
2105     case 35:
2106     case 36:
2107     case 37: /* text color */
2108 doda 5095 attr->Attr2 |= Attr2Fore;
2109     mask->Attr2 |= Attr2Fore;
2110     attr->Fore = P - 30;
2111 maya 3227 break;
2112    
2113 doda 6173 case 38: /* text color (256color mode) */
2114 doda 5073 if (ts.ColorFlag & CF_XTERM256) {
2115     /*
2116     * Change foreground color. accept following formats.
2117     *
2118     * 38 ; 2 ; r ; g ; b
2119     * 38 ; 2 : r : g : b
2120     * 38 : 2 : r : g : b
2121     * 38 ; 5 ; idx
2122     * 38 ; 5 : idx
2123     * 38 : 5 : idx
2124     *
2125     */
2126     color = -1;
2127     j = 0;
2128     if (NSParam[i] > 0) {
2129     P = SubParam[i][1];
2130     j++;
2131     }
2132     else if (i < NParam) {
2133     P = Param[i+1];
2134     if (P == 2 || P == 5) {
2135     i++;
2136     }
2137     }
2138     switch (P) {
2139 doda 6173 case 2:
2140 doda 5073 r = g = b = 0;
2141     if (NSParam[i] > 0) {
2142     if (j < NSParam[i]) {
2143     r = SubParam[i][++j];
2144     if (j < NSParam[i]) {
2145     g = SubParam[i][++j];
2146     }
2147     if (j < NSParam[i]) {
2148     b = SubParam[i][++j];
2149     }
2150     color = DispFindClosestColor(r, g, b);
2151     }
2152     }
2153     else if (i < NParam && NSParam[i+1] > 0) {
2154     r = Param[++i];
2155     g = SubParam[i][1];
2156     if (NSParam[i] > 1) {
2157     b = SubParam[i][2];
2158     }
2159     color = DispFindClosestColor(r, g, b);
2160     }
2161     else if (i+2 < NParam) {
2162     r = Param[++i];
2163     g = Param[++i];
2164     b = Param[++i];
2165     color = DispFindClosestColor(r, g, b);
2166     }
2167     break;
2168 doda 6173 case 5:
2169 doda 5073 if (NSParam[i] > 0) {
2170     if (j < NSParam[i]) {
2171     color = SubParam[i][++j];
2172     }
2173     }
2174     else if (i < NParam) {
2175     color = Param[++i];
2176     }
2177     break;
2178     }
2179 doda 5077 if (color >= 0 && color < 256) {
2180 doda 5095 attr->Attr2 |= Attr2Fore;
2181     mask->Attr2 |= Attr2Fore;
2182     attr->Fore = color;
2183 maya 3227 }
2184     }
2185     break;
2186    
2187 doda 6173 case 39: /* Reset text color */
2188 doda 5095 attr->Attr2 &= ~ Attr2Fore;
2189     mask->Attr2 |= Attr2Fore;
2190     attr->Fore = AttrDefaultFG;
2191 maya 3227 break;
2192    
2193 doda 6173 case 40:
2194     case 41:
2195     case 42:
2196     case 43:
2197     case 44:
2198     case 45:
2199     case 46:
2200     case 47: /* Back color */
2201 doda 5095 attr->Attr2 |= Attr2Back;
2202     mask->Attr2 |= Attr2Back;
2203     attr->Back = P - 40;
2204 maya 3227 break;
2205    
2206 doda 6173 case 48: /* Back color (256color mode) */
2207 doda 5073 if (ts.ColorFlag & CF_XTERM256) {
2208     color = -1;
2209     j = 0;
2210     if (NSParam[i] > 0) {
2211     P = SubParam[i][1];
2212     j++;
2213     }
2214     else if (i < NParam) {
2215     P = Param[i+1];
2216     if (P == 2 || P == 5) {
2217     i++;
2218     }
2219     }
2220     switch (P) {
2221 doda 6173 case 2:
2222 doda 5073 r = g = b = 0;
2223     if (NSParam[i] > 0) {
2224     if (j < NSParam[i]) {
2225     r = SubParam[i][++j];
2226     if (j < NSParam[i]) {
2227     g = SubParam[i][++j];
2228     }
2229     if (j < NSParam[i]) {
2230     b = SubParam[i][++j];
2231     }
2232     color = DispFindClosestColor(r, g, b);
2233     }
2234     }
2235     else if (i < NParam && NSParam[i+1] > 0) {
2236     r = Param[++i];
2237     g = SubParam[i][1];
2238     if (NSParam[i] > 1) {
2239     b = SubParam[i][2];
2240     }
2241     color = DispFindClosestColor(r, g, b);
2242     }
2243     else if (i+2 < NParam) {
2244     r = Param[++i];
2245     g = Param[++i];
2246     b = Param[++i];
2247     color = DispFindClosestColor(r, g, b);
2248     }
2249     break;
2250 doda 6173 case 5:
2251 doda 5073 if (NSParam[i] > 0) {
2252     if (j < NSParam[i]) {
2253     color = SubParam[i][++j];
2254     }
2255     }
2256     else if (i < NParam) {
2257     color = Param[++i];
2258     }
2259     break;
2260     }
2261 doda 5077 if (color >= 0 && color < 256) {
2262 doda 5095 attr->Attr2 |= Attr2Back;
2263     mask->Attr2 |= Attr2Back;
2264     attr->Back = color;
2265 maya 3227 }
2266     }
2267     break;
2268    
2269 doda 6173 case 49: /* Reset back color */
2270 doda 5095 attr->Attr2 &= ~ Attr2Back;
2271     mask->Attr2 |= Attr2Back;
2272     attr->Back = AttrDefaultBG;
2273 maya 3227 break;
2274    
2275 doda 6173 case 90:
2276     case 91:
2277     case 92:
2278     case 93:
2279     case 94:
2280     case 95:
2281     case 96:
2282     case 97: /* aixterm style text color */
2283 maya 3227 if (ts.ColorFlag & CF_AIXTERM16) {
2284 doda 5095 attr->Attr2 |= Attr2Fore;
2285     mask->Attr2 |= Attr2Fore;
2286     attr->Fore = P - 90 + 8;
2287 maya 3227 }
2288     break;
2289    
2290 doda 6173 case 100:
2291 maya 3227 if (! (ts.ColorFlag & CF_AIXTERM16)) {
2292     /* Reset text and back color */
2293 doda 5095 attr->Attr2 &= ~ (Attr2Fore | Attr2Back);
2294     mask->Attr2 |= Attr2ColorMask;
2295     attr->Fore = AttrDefaultFG;
2296     attr->Back = AttrDefaultBG;
2297 maya 3227 break;
2298     }
2299     /* fall through to aixterm style back color */
2300    
2301 doda 6173 case 101:
2302     case 102:
2303     case 103:
2304     case 104:
2305     case 105:
2306     case 106:
2307     case 107: /* aixterm style back color */
2308 maya 3227 if (ts.ColorFlag & CF_AIXTERM16) {
2309 doda 5095 attr->Attr2 |= Attr2Back;
2310     mask->Attr2 |= Attr2Back;
2311     attr->Back = P - 100 + 8;
2312 maya 3227 }
2313     break;
2314     }
2315     }
2316     }
2317    
2318 doda 5095 void CSSetAttr() // SGR
2319     {
2320     UpdateStr();
2321     ParseSGRParams(&CharAttr, NULL, 1);
2322     BuffSetCurCharAttr(CharAttr);
2323     }
2324    
2325 doda 6173 void CSSetScrollRegion() // DECSTBM
2326     {
2327     if (isCursorOnStatusLine) {
2328     MoveCursor(0,CursorY);
2329     return;
2330     }
2331 doda 6174
2332     RequiredParams(2);
2333     CheckParamVal(Param[1], NumOfLines-StatusLine);
2334     CheckParamValMax(Param[2], NumOfLines-StatusLine);
2335    
2336     if (Param[1] >= Param[2])
2337     return;
2338    
2339     CursorTop = Param[1] - 1;
2340     CursorBottom = Param[2] - 1;
2341    
2342     if (RelativeOrgMode)
2343     // TODO: ���}�[�W���������������B�v���@�m�F�B
2344     MoveCursor(0, CursorTop);
2345     else
2346     MoveCursor(0, 0);
2347 doda 6173 }
2348 maya 3227
2349 doda 5502 void CSSetLRScrollRegion() // DECSLRM
2350 doda 5324 {
2351 doda 6174 // TODO: �X�e�[�^�X���C�������������m�F�B
2352 doda 5324 // if (isCursorOnStatusLine) {
2353     // MoveCursor(0,CursorY);
2354     // return;
2355     // }
2356    
2357 doda 6174 RequiredParams(2);
2358     CheckParamVal(Param[1], NumOfColumns);
2359     CheckParamValMax(Param[2], NumOfColumns);
2360 doda 5324
2361     if (Param[1] >= Param[2])
2362     return;
2363    
2364 doda 6174 CursorLeftM = Param[1] - 1;
2365     CursorRightM = Param[2] - 1;
2366 doda 5324
2367     if (RelativeOrgMode)
2368     MoveCursor(CursorLeftM, CursorTop);
2369     else
2370     MoveCursor(0, 0);
2371     }
2372    
2373 doda 6173 void CSSunSequence() /* Sun terminal private sequences */
2374     {
2375     int x, y, len;
2376     char Report[TitleBuffSize*2+10];
2377     PTStack t;
2378 maya 3227
2379 doda 6173 switch (Param[1]) {
2380     case 1: // De-iconify window
2381     if (ts.WindowFlag & WF_WINDOWCHANGE)
2382     DispShowWindow(WINDOW_RESTORE);
2383     break;
2384 doda 6174
2385 doda 6173 case 2: // Iconify window
2386     if (ts.WindowFlag & WF_WINDOWCHANGE)
2387     DispShowWindow(WINDOW_MINIMIZE);
2388     break;
2389 doda 6174
2390 doda 6173 case 3: // set window position
2391     if (ts.WindowFlag & WF_WINDOWCHANGE) {
2392 doda 6174 RequiredParams(3);
2393 doda 6173 DispMoveWindow(Param[2], Param[3]);
2394     }
2395     break;
2396 doda 6174
2397 doda 6173 case 4: // set window size
2398     if (ts.WindowFlag & WF_WINDOWCHANGE) {
2399 doda 6174 RequiredParams(3);
2400 doda 6173 DispResizeWin(Param[3], Param[2]);
2401     }
2402     break;
2403 doda 6174
2404 doda 6173 case 5: // Raise window
2405     if (ts.WindowFlag & WF_WINDOWCHANGE)
2406     DispShowWindow(WINDOW_RAISE);
2407     break;
2408 doda 6174
2409 doda 6173 case 6: // Lower window
2410     if (ts.WindowFlag & WF_WINDOWCHANGE)
2411     DispShowWindow(WINDOW_LOWER);
2412     break;
2413 doda 6174
2414 doda 6173 case 7: // Refresh window
2415     if (ts.WindowFlag & WF_WINDOWCHANGE)
2416     DispShowWindow(WINDOW_REFRESH);
2417     break;
2418 doda 6174
2419 doda 6173 case 8: /* set terminal size */
2420     if (ts.WindowFlag & WF_WINDOWCHANGE) {
2421 doda 6174 RequiredParams(3);
2422     if (Param[2] <= 1) Param[2] = 24;
2423     if (Param[3] <= 1) Param[3] = 80;
2424     ChangeTerminalSize(Param[3], Param[2]);
2425 doda 6173 }
2426     break;
2427 doda 6174
2428 doda 6173 case 9: // Maximize/Restore window
2429     if (ts.WindowFlag & WF_WINDOWCHANGE) {
2430 doda 6174 RequiredParams(2);
2431     if (Param[2] == 0) {
2432 doda 6173 DispShowWindow(WINDOW_RESTORE);
2433     }
2434     else if (Param[2] == 1) {
2435     DispShowWindow(WINDOW_MAXIMIZE);
2436     }
2437     }
2438     break;
2439 doda 6174
2440 doda 7274 case 10: // Full-screen
2441     /*
2442     * �{�������� PuTTY ���������t���X�N���[�����[�h�������������������A
2443     * �������������������������������p����
2444     */
2445     if (ts.WindowFlag & WF_WINDOWCHANGE) {
2446     RequiredParams(2);
2447     switch (Param[2]) {
2448     case 0:
2449     DispShowWindow(WINDOW_RESTORE);
2450     break;
2451     case 1:
2452     DispShowWindow(WINDOW_MAXIMIZE);
2453     break;
2454     case 2:
2455     DispShowWindow(WINDOW_TOGGLE_MAXIMIZE);
2456     break;
2457     }
2458     }
2459     break;
2460    
2461 doda 6173 case 11: // Report window state
2462     if (ts.WindowFlag & WF_WINDOWREPORT) {
2463     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%dt", CLocale, DispWindowIconified()?2:1);
2464     SendCSIstr(Report, len);
2465     }
2466     break;
2467 doda 6174
2468 doda 6173 case 13: // Report window position
2469     if (ts.WindowFlag & WF_WINDOWREPORT) {
2470 doda 7271 RequiredParams(2);
2471     switch (Param[2]) {
2472     case 0:
2473     case 1:
2474     DispGetWindowPos(&x, &y, FALSE);
2475     break;
2476     case 2:
2477     DispGetWindowPos(&x, &y, TRUE);
2478     break;
2479     default: