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