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 8383 - (hide annotations) (download) (as text)
Thu Nov 21 11:29:48 2019 UTC (4 years, 4 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 141541 byte(s)
xterm の ED/DECSED 3 (スクロールバッファクリア) に対応

Ticket: #39568

問題:
  clear コマンドでスクロールバッファの内容が消えない。

対応:
  xterm の ED/DESED 3 (スクロールバッファクリア) に対応した。
  有効/無効を設定出来るようにした。clear コマンドでスクロールバッファが
  クリアされない事を望む人が多いようなので、デフォルトでは off とする。

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