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 10344 - (hide annotations) (download) (as text)
Wed Nov 2 13:43:04 2022 UTC (17 months, 1 week ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 149389 byte(s)
__ismbblead(), __ismbbtrail() を ttlib_static_cpp.cpp へ移動

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