Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/vtterm.c

Parent Directory Parent Directory | Revision Log Revision Log


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