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