| 40 |
#endif |
#endif |
| 41 |
#include <stdlib.h> |
#include <stdlib.h> |
| 42 |
#include <crtdbg.h> |
#include <crtdbg.h> |
|
#include <tchar.h> |
|
| 43 |
#include <assert.h> |
#include <assert.h> |
| 44 |
|
|
| 45 |
#include "buffer.h" |
#include "buffer.h" |
| 108 |
static BOOL RectangleMode; |
static BOOL RectangleMode; |
| 109 |
static BOOL BracketedPaste; |
static BOOL BracketedPaste; |
| 110 |
|
|
| 111 |
char BracketStart[] = "\033[200~"; |
static char BracketStart[] = "\033[200~"; |
| 112 |
char BracketEnd[] = "\033[201~"; |
static char BracketEnd[] = "\033[201~"; |
| 113 |
int BracketStartLen = (sizeof(BracketStart)-1); |
static int BracketStartLen = (sizeof(BracketStart)-1); |
| 114 |
int BracketEndLen = (sizeof(BracketEnd)-1); |
static int BracketEndLen = (sizeof(BracketEnd)-1); |
| 115 |
|
|
| 116 |
static int VTlevel; |
static int VTlevel; |
| 117 |
|
|
| 118 |
BOOL AcceptWheelToCursor; |
static BOOL AcceptWheelToCursor; |
| 119 |
|
|
| 120 |
// save/restore cursor |
// save/restore cursor |
| 121 |
typedef struct { |
typedef struct { |
| 128 |
typedef TStatusBuff *PStatusBuff; |
typedef TStatusBuff *PStatusBuff; |
| 129 |
|
|
| 130 |
// currently only used for AUTO CR/LF receive mode |
// currently only used for AUTO CR/LF receive mode |
| 131 |
BYTE PrevCharacter; |
static BYTE PrevCharacter; |
| 132 |
BOOL PrevCRorLFGeneratedCRLF; // indicates that previous CR or LF really generated a CR+LF |
static BOOL PrevCRorLFGeneratedCRLF; // indicates that previous CR or LF really generated a CR+LF |
| 133 |
|
|
| 134 |
BYTE LastPutCharacter; |
static BYTE LastPutCharacter; |
| 135 |
|
|
| 136 |
// status buffer for main screen & status line |
// status buffer for main screen & status line |
| 137 |
static TStatusBuff SBuff1, SBuff2, SBuff3; |
static TStatusBuff SBuff1, SBuff2, SBuff3; |
| 138 |
|
|
| 139 |
static BOOL ESCFlag, JustAfterESC; |
static BOOL ESCFlag, JustAfterESC; |
| 140 |
static BOOL KanjiIn; |
static BOOL KanjiIn; // TRUE = MBCSの1byte目を受信している |
| 141 |
static BOOL EUCkanaIn, EUCsupIn; |
static BOOL EUCkanaIn, EUCsupIn; |
| 142 |
static int EUCcount; |
static int EUCcount; |
| 143 |
static BOOL Special; |
static BOOL Special; |
| 157 |
struct tstack *next; |
struct tstack *next; |
| 158 |
} TStack; |
} TStack; |
| 159 |
typedef TStack *PTStack; |
typedef TStack *PTStack; |
| 160 |
PTStack TitleStack = NULL; |
static PTStack TitleStack = NULL; |
| 161 |
|
|
| 162 |
/* user defined keys */ |
/* user defined keys */ |
| 163 |
static BOOL WaitKeyId, WaitHi; |
static BOOL WaitKeyId, WaitHi; |
| 213 |
|
|
| 214 |
static _locale_t CLocale = NULL; |
static _locale_t CLocale = NULL; |
| 215 |
|
|
| 216 |
#if UNICODE_INTERNAL_BUFF |
typedef struct { |
| 217 |
// 内部コード unicode版 |
BOOL log_cr_hold; |
| 218 |
static void UnicodeToCP932(unsigned int code); |
int log_code; |
| 219 |
#endif |
int log_cr_type; |
| 220 |
|
} vtterm_work_t; |
| 221 |
|
|
| 222 |
|
static vtterm_work_t vtterm_work; |
| 223 |
|
|
| 224 |
void ClearParams() |
void ClearParams() |
| 225 |
{ |
{ |
| 358 |
BeepSuppressTime = BeepStartTime - ts.BeepSuppressTime * 1000; |
BeepSuppressTime = BeepStartTime - ts.BeepSuppressTime * 1000; |
| 359 |
BeepStartTime -= (ts.BeepOverUsedTime * 1000); |
BeepStartTime -= (ts.BeepOverUsedTime * 1000); |
| 360 |
BeepOverUsedCount = ts.BeepOverUsedCount; |
BeepOverUsedCount = ts.BeepOverUsedCount; |
| 361 |
|
|
| 362 |
|
{ |
| 363 |
|
vtterm_work_t *vtterm = &vtterm_work; |
| 364 |
|
vtterm->log_cr_hold = FALSE; |
| 365 |
|
vtterm->log_code = 0; |
| 366 |
|
vtterm->log_cr_type = 0; |
| 367 |
|
} |
| 368 |
} |
} |
| 369 |
|
|
| 370 |
void ResetCharSet() |
void ResetCharSet() |
| 451 |
MoveCursor(MainX, MainY); // move to main screen |
MoveCursor(MainX, MainY); // move to main screen |
| 452 |
} |
} |
| 453 |
|
|
| 454 |
|
static void Log1Byte(BYTE b) |
| 455 |
|
{ |
| 456 |
|
LogPut1(b); |
| 457 |
|
} |
| 458 |
|
|
| 459 |
|
static void Log1UTF32(vtterm_work_t *vtterm, unsigned int u32) |
| 460 |
|
{ |
| 461 |
|
switch(vtterm->log_code) { |
| 462 |
|
default: |
| 463 |
|
case 0: { |
| 464 |
|
// UTF-8 |
| 465 |
|
char u8[4]; |
| 466 |
|
size_t u8_len = UTF32ToUTF8(u32, u8, _countof(u8)); |
| 467 |
|
size_t i; |
| 468 |
|
for (i = 0; i < u8_len; i++) { |
| 469 |
|
Log1Byte(u8[i]); |
| 470 |
|
} |
| 471 |
|
break; |
| 472 |
|
} |
| 473 |
|
case 1: |
| 474 |
|
case 2: { |
| 475 |
|
// UTF-16 |
| 476 |
|
wchar_t u16[2]; |
| 477 |
|
size_t u16_len = UTF32ToUTF16(u32, u16, _countof(u16)); |
| 478 |
|
size_t i; |
| 479 |
|
for (i = 0; i < u16_len; i++) { |
| 480 |
|
if (vtterm->log_code == 1) { |
| 481 |
|
// UTF-16LE |
| 482 |
|
Log1Byte(u16[i] & 0xff); |
| 483 |
|
Log1Byte((u16[i] >> 8) & 0xff); |
| 484 |
|
} |
| 485 |
|
else { |
| 486 |
|
// UTF-16BE |
| 487 |
|
Log1Byte(u16[i] & 0xff); |
| 488 |
|
Log1Byte((u16[i] >> 8) & 0xff); |
| 489 |
|
} |
| 490 |
|
} |
| 491 |
|
} |
| 492 |
|
} |
| 493 |
|
} |
| 494 |
|
|
| 495 |
|
static void Log1NewLine(vtterm_work_t *vtterm) |
| 496 |
|
{ |
| 497 |
|
switch(vtterm->log_cr_type) { |
| 498 |
|
case 0: |
| 499 |
|
// CR + LF |
| 500 |
|
Log1UTF32(vtterm, CR); |
| 501 |
|
Log1UTF32(vtterm, LF); |
| 502 |
|
break; |
| 503 |
|
case 1: |
| 504 |
|
// CR |
| 505 |
|
Log1UTF32(vtterm, CR); |
| 506 |
|
break; |
| 507 |
|
case 2: |
| 508 |
|
// LF |
| 509 |
|
Log1UTF32(vtterm, LF); |
| 510 |
|
break; |
| 511 |
|
} |
| 512 |
|
} |
| 513 |
|
|
| 514 |
|
static void OutputLogUTF32(unsigned int u32) |
| 515 |
|
{ |
| 516 |
|
vtterm_work_t *vtterm = &vtterm_work; |
| 517 |
|
|
| 518 |
|
if (cv.HLogBuf == 0) { |
| 519 |
|
// ログは取っていない, 何もしない |
| 520 |
|
return; |
| 521 |
|
} |
| 522 |
|
|
| 523 |
|
// 改行コードをチェック |
| 524 |
|
// CR hold 入力 改行出力 CR hold 変更 |
| 525 |
|
// ------------+-------+-----------+------------ |
| 526 |
|
// なし CR 0 セットする |
| 527 |
|
// なし LF 1 変化なし |
| 528 |
|
// なし その他 0 変化なし |
| 529 |
|
// あり CR 1 変化なし(ホールドしたまま) |
| 530 |
|
// あり LF 1 クリアする |
| 531 |
|
// あり その他 1 クリアする |
| 532 |
|
if (vtterm->log_cr_hold == FALSE) { |
| 533 |
|
if (u32 == CR) { |
| 534 |
|
vtterm->log_cr_hold = TRUE; |
| 535 |
|
return; |
| 536 |
|
} |
| 537 |
|
else if (u32 == LF) { |
| 538 |
|
Log1NewLine(vtterm); |
| 539 |
|
return; |
| 540 |
|
} |
| 541 |
|
else { |
| 542 |
|
// 改行特になし |
| 543 |
|
} |
| 544 |
|
} |
| 545 |
|
else { |
| 546 |
|
if (u32 == CR) { |
| 547 |
|
Log1NewLine(vtterm); |
| 548 |
|
return; |
| 549 |
|
} |
| 550 |
|
else if (u32 == LF) { |
| 551 |
|
vtterm->log_cr_hold = FALSE; |
| 552 |
|
Log1NewLine(vtterm); |
| 553 |
|
return; |
| 554 |
|
} |
| 555 |
|
else { |
| 556 |
|
vtterm->log_cr_hold = FALSE; |
| 557 |
|
Log1NewLine(vtterm); |
| 558 |
|
} |
| 559 |
|
} |
| 560 |
|
|
| 561 |
|
Log1UTF32(vtterm, u32); |
| 562 |
|
} |
| 563 |
|
|
| 564 |
|
static void OutputLogByte(BYTE b) |
| 565 |
|
{ |
| 566 |
|
if (cv.HLogBuf!=0) { |
| 567 |
|
OutputLogUTF32(b); |
| 568 |
|
} |
| 569 |
|
} |
| 570 |
|
|
| 571 |
void MoveToStatusLine() |
void MoveToStatusLine() |
| 572 |
{ |
{ |
| 573 |
MainX = CursorX; |
MainX = CursorX; |
| 687 |
if (CursorX == CursorLeftM || CursorX == 0) { |
if (CursorX == CursorLeftM || CursorX == 0) { |
| 688 |
if (CursorY > 0 && (ts.TermFlag & TF_BACKWRAP)) { |
if (CursorY > 0 && (ts.TermFlag & TF_BACKWRAP)) { |
| 689 |
MoveCursor(CursorRightM, CursorY-1); |
MoveCursor(CursorRightM, CursorY-1); |
| 690 |
if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS); |
if (cv.HLogBuf!=0 && !ts.LogTypePlainText) OutputLogByte(BS); |
| 691 |
} |
} |
| 692 |
} |
} |
| 693 |
else if (CursorX > 0) { |
else if (CursorX > 0) { |
| 694 |
MoveCursor(CursorX-1, CursorY); |
MoveCursor(CursorX-1, CursorY); |
| 695 |
if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS); |
if (cv.HLogBuf!=0 && !ts.LogTypePlainText) OutputLogByte(BS); |
| 696 |
} |
} |
| 697 |
} |
} |
| 698 |
|
|
| 699 |
static void CarriageReturn(BOOL logFlag) |
static void CarriageReturn(BOOL logFlag) |
| 700 |
{ |
{ |
| 701 |
if (!ts.EnableContinuedLineCopy || logFlag) |
if (!ts.EnableContinuedLineCopy || logFlag) |
| 702 |
if (cv.HLogBuf!=0) Log1Byte(CR); |
if (cv.HLogBuf!=0) OutputLogByte(CR); |
| 703 |
|
|
| 704 |
if (RelativeOrgMode || CursorX > CursorLeftM) |
if (RelativeOrgMode || CursorX > CursorLeftM) |
| 705 |
MoveCursor(CursorLeftM, CursorY); |
MoveCursor(CursorLeftM, CursorY); |
| 717 |
BuffDumpCurrentLine(b); |
BuffDumpCurrentLine(b); |
| 718 |
|
|
| 719 |
if (!ts.EnableContinuedLineCopy || logFlag) |
if (!ts.EnableContinuedLineCopy || logFlag) |
| 720 |
if (cv.HLogBuf!=0) Log1Byte(LF); |
if (cv.HLogBuf!=0) OutputLogByte(LF); |
| 721 |
|
|
| 722 |
if (CursorY < CursorBottom) |
if (CursorY < CursorBottom) |
| 723 |
MoveCursor(CursorX,CursorY+1); |
MoveCursor(CursorX,CursorY+1); |
| 743 |
Wrap = FALSE; |
Wrap = FALSE; |
| 744 |
} |
} |
| 745 |
CursorForwardTab(1, AutoWrapMode); |
CursorForwardTab(1, AutoWrapMode); |
| 746 |
if (cv.HLogBuf!=0) Log1Byte(HT); |
if (cv.HLogBuf!=0) OutputLogByte(HT); |
| 747 |
} |
} |
| 748 |
|
|
| 749 |
void RepeatChar(BYTE b, int count) |
void RepeatChar(BYTE b, int count) |
| 807 |
} |
} |
| 808 |
} |
} |
| 809 |
|
|
| 810 |
void PutChar(BYTE b) |
static void PutChar(BYTE b) |
| 811 |
{ |
{ |
| 812 |
BOOL SpecialNew; |
BOOL SpecialNew; |
| 813 |
TCharAttr CharAttrTmp; |
TCharAttr CharAttrTmp; |
| 844 |
if (__isascii(b) && !isprint(b)) { |
if (__isascii(b) && !isprint(b)) { |
| 845 |
// ASCII文字で、非表示な文字はログ採取しない。 |
// ASCII文字で、非表示な文字はログ採取しない。 |
| 846 |
} else { |
} else { |
| 847 |
Log1Byte(b); |
OutputLogByte(b); |
| 848 |
} |
} |
| 849 |
} else { |
} else { |
| 850 |
Log1Byte(b); |
OutputLogByte(b); |
| 851 |
} |
} |
| 852 |
} |
} |
| 853 |
|
|
| 940 |
CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0; |
CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0; |
| 941 |
} |
} |
| 942 |
|
|
| 943 |
if (cv.HLogBuf!=0) Log1Byte(b); |
if (cv.HLogBuf!=0) OutputLogByte(b); |
| 944 |
/* |
/* |
| 945 |
if (ts.LogTypePlainText && __isascii(b) && !isprint(b)) { |
if (ts.LogTypePlainText && __isascii(b) && !isprint(b)) { |
| 946 |
// ASCII文字で、非表示な文字はログ採取しない。 |
// ASCII文字で、非表示な文字はログ採取しない。 |
| 947 |
} else { |
} else { |
| 948 |
if (cv.HLogBuf!=0) Log1Byte(b); |
if (cv.HLogBuf!=0) OutputLogByte(b); |
| 949 |
} |
} |
| 950 |
*/ |
*/ |
| 951 |
|
|
| 971 |
} |
} |
| 972 |
} |
} |
| 973 |
|
|
| 974 |
|
/** |
| 975 |
|
* mbcsを出力 |
| 976 |
|
*/ |
| 977 |
static void PutKanji(BYTE b) |
static void PutKanji(BYTE b) |
| 978 |
{ |
{ |
| 979 |
int LineEnd; |
int LineEnd; |
| 1036 |
Wrap = FALSE; |
Wrap = FALSE; |
| 1037 |
|
|
| 1038 |
if (cv.HLogBuf!=0) { |
if (cv.HLogBuf!=0) { |
| 1039 |
Log1Byte(HIBYTE(Kanji)); |
OutputLogByte(HIBYTE(Kanji)); |
| 1040 |
Log1Byte(LOBYTE(Kanji)); |
OutputLogByte(LOBYTE(Kanji)); |
| 1041 |
} |
} |
| 1042 |
|
|
| 1043 |
if (Special) { |
if (Special) { |
| 5089 |
} |
} |
| 5090 |
} |
} |
| 5091 |
|
|
| 5092 |
void XsProcClipboard(PCHAR buff) |
static void XsProcClipboard(PCHAR buff) |
| 5093 |
{ |
{ |
| 5094 |
int len, blen; |
int len, blen; |
| 5095 |
char *p, *cbbuff, hdr[20], notify_buff[256], notify_title[MAX_UIMSG]; |
char *p, *cbbuff, hdr[20], notify_buff[256], notify_title[MAX_UIMSG]; |
| 5247 |
} |
} |
| 5248 |
} |
} |
| 5249 |
|
|
| 5250 |
void XSequence(BYTE b) |
static void XSequence(BYTE b) |
| 5251 |
{ |
{ |
| 5252 |
static char *StrBuff = NULL; |
static char *StrBuff = NULL; |
| 5253 |
static unsigned int StrLen = 0, StrBuffSize = 0; |
static unsigned int StrLen = 0, StrBuffSize = 0; |
| 5537 |
} |
} |
| 5538 |
|
|
| 5539 |
/** |
/** |
| 5540 |
|
* unicode(UTF-32,wchar_t)をバッファへ書き込む |
| 5541 |
|
* ログにも書き込む |
| 5542 |
|
* |
| 5543 |
|
* 元は UnicodeToCP932() だった |
| 5544 |
|
* |
| 5545 |
|
* PutChar() の UTF-32版 |
| 5546 |
|
*/ |
| 5547 |
|
static void PutU32(unsigned int code) |
| 5548 |
|
{ |
| 5549 |
|
unsigned short cset; |
| 5550 |
|
int LineEnd; |
| 5551 |
|
|
| 5552 |
|
TCharAttr CharAttrTmp; |
| 5553 |
|
CharAttrTmp = CharAttr; |
| 5554 |
|
if (code <= US) { |
| 5555 |
|
// U+0000 .. U+001f |
| 5556 |
|
// C0制御文字, C0 Coontrols |
| 5557 |
|
ParseControl(code); |
| 5558 |
|
return; |
| 5559 |
|
} else if ((0x80<=code) && (code<=0x9F)) { |
| 5560 |
|
// U+0080 .. u+009f |
| 5561 |
|
// C1制御文字, C1 Controls |
| 5562 |
|
ParseControl(code); |
| 5563 |
|
return; |
| 5564 |
|
} |
| 5565 |
|
|
| 5566 |
|
{ |
| 5567 |
|
int r; |
| 5568 |
|
BOOL is_update; |
| 5569 |
|
|
| 5570 |
|
// UnicodeからDEC特殊文字へのマッピング |
| 5571 |
|
if (ts.UnicodeDecSpMapping) { |
| 5572 |
|
cset = UTF32ToDecSp(code); |
| 5573 |
|
if (((cset >> 8) & ts.UnicodeDecSpMapping) != 0) { |
| 5574 |
|
code = cset & 0xff; |
| 5575 |
|
CharAttrTmp.Attr |= AttrSpecial; |
| 5576 |
|
} |
| 5577 |
|
} |
| 5578 |
|
|
| 5579 |
|
if ((CharAttrTmp.Attr & AttrSpecial) == 0) { |
| 5580 |
|
if (Special) { |
| 5581 |
|
UpdateStr(); |
| 5582 |
|
Special = FALSE; |
| 5583 |
|
} |
| 5584 |
|
} else { |
| 5585 |
|
if (!Special) { |
| 5586 |
|
UpdateStr(); |
| 5587 |
|
Special = TRUE; |
| 5588 |
|
} |
| 5589 |
|
} |
| 5590 |
|
|
| 5591 |
|
if (CursorX > CursorRightM) |
| 5592 |
|
LineEnd = NumOfColumns - 1; |
| 5593 |
|
else |
| 5594 |
|
LineEnd = CursorRightM; |
| 5595 |
|
|
| 5596 |
|
// Wrap処理、カーソル移動 |
| 5597 |
|
if (Wrap) { |
| 5598 |
|
// 現在 Wrap 状態 |
| 5599 |
|
if (!BuffIsCombiningCharacter(CursorX, CursorY, code)) { |
| 5600 |
|
// 文字コードが結合文字ではない = カーソルが移動する |
| 5601 |
|
|
| 5602 |
|
// カーソル位置に行継続アトリビュートを追加 |
| 5603 |
|
TCharAttr t = BuffGetCursorCharAttr(CursorX, CursorY); |
| 5604 |
|
t.Attr |= AttrLineContinued; |
| 5605 |
|
t.AttrEx = t.Attr; |
| 5606 |
|
BuffSetCursorCharAttr(CursorX, CursorY, t); |
| 5607 |
|
|
| 5608 |
|
// 行継続アトリビュートをつける |
| 5609 |
|
CharAttrTmp.Attr |= AttrLineContinued; |
| 5610 |
|
CharAttrTmp.AttrEx = CharAttrTmp.Attr; |
| 5611 |
|
|
| 5612 |
|
// 次の行の行頭へ |
| 5613 |
|
CarriageReturn(FALSE); |
| 5614 |
|
LineFeed(LF,FALSE); |
| 5615 |
|
} |
| 5616 |
|
} |
| 5617 |
|
|
| 5618 |
|
// バッファに文字を入れる |
| 5619 |
|
// BuffPutUnicode()した戻り値で文字のセル数を知ることができる |
| 5620 |
|
// エラー時はカーソル位置を検討する |
| 5621 |
|
is_update = FALSE; |
| 5622 |
|
CharAttrTmp.AttrEx = CharAttrTmp.Attr; |
| 5623 |
|
retry: |
| 5624 |
|
r = BuffPutUnicode(code, CharAttrTmp, InsertMode); |
| 5625 |
|
if (r == -1) { |
| 5626 |
|
// 文字全角で行末、入力できない |
| 5627 |
|
|
| 5628 |
|
if (AutoWrapMode) { |
| 5629 |
|
// 自動改行 |
| 5630 |
|
// 、wrap処理 |
| 5631 |
|
CharAttrTmp = CharAttr; |
| 5632 |
|
CharAttrTmp.Attr |= AttrLineContinued; |
| 5633 |
|
CharAttrTmp.AttrEx = CharAttrTmp.Attr | AttrPadding; |
| 5634 |
|
// AutoWrapMode |
| 5635 |
|
// ts.EnableContinuedLineCopy |
| 5636 |
|
//if (CursorX != LineEnd){ |
| 5637 |
|
//&& BuffIsHalfWidthFromCode(&ts, code)) { |
| 5638 |
|
|
| 5639 |
|
// full width出力が半分出力にならないように0x20を出力 |
| 5640 |
|
BuffPutUnicode(0x20, CharAttrTmp, FALSE); |
| 5641 |
|
CharAttrTmp.AttrEx = CharAttrTmp.AttrEx & ~AttrPadding; |
| 5642 |
|
|
| 5643 |
|
// 次の行の行頭へ |
| 5644 |
|
CarriageReturn(FALSE); |
| 5645 |
|
LineFeed(LF,FALSE); |
| 5646 |
|
} |
| 5647 |
|
else { |
| 5648 |
|
// 行頭に戻す |
| 5649 |
|
CursorX = 0; |
| 5650 |
|
} |
| 5651 |
|
|
| 5652 |
|
//CharAttrTmp.Attr &= ~AttrLineContinued; |
| 5653 |
|
goto retry; |
| 5654 |
|
} |
| 5655 |
|
else if (r == 0) { |
| 5656 |
|
// カーソルの移動なし,結合文字,合字など |
| 5657 |
|
// Wrap は変化しない |
| 5658 |
|
UpdateStr(); // 「ほ」->「ぽ」など、変化することがあるので描画する |
| 5659 |
|
} else if (r == 1) { |
| 5660 |
|
// 半角(1セル) |
| 5661 |
|
if (CursorX + 0 == CursorRightM || CursorX >= NumOfColumns - 1) { |
| 5662 |
|
UpdateStr(); |
| 5663 |
|
Wrap = AutoWrapMode; |
| 5664 |
|
} else { |
| 5665 |
|
MoveRight(); |
| 5666 |
|
Wrap = FALSE; |
| 5667 |
|
} |
| 5668 |
|
} else if (r == 2) { |
| 5669 |
|
// 全角(2セル) |
| 5670 |
|
if (CursorX + 1 == CursorRightM || CursorX + 1 >= NumOfColumns - 1) { |
| 5671 |
|
MoveRight(); // 全角の右側にカーソル移動 |
| 5672 |
|
UpdateStr(); |
| 5673 |
|
Wrap = AutoWrapMode; |
| 5674 |
|
} else { |
| 5675 |
|
MoveRight(); |
| 5676 |
|
MoveRight(); |
| 5677 |
|
Wrap = FALSE; |
| 5678 |
|
} |
| 5679 |
|
} |
| 5680 |
|
else { |
| 5681 |
|
assert(FALSE); |
| 5682 |
|
} |
| 5683 |
|
} |
| 5684 |
|
|
| 5685 |
|
// ログを出力 |
| 5686 |
|
OutputLogUTF32(code); |
| 5687 |
|
} |
| 5688 |
|
|
| 5689 |
|
/** |
| 5690 |
* IsDBCSLeadByteEx() とほぼ同じ |
* IsDBCSLeadByteEx() とほぼ同じ |
| 5691 |
* ismbblead() の拡張 |
* ismbblead() の拡張 |
| 5692 |
*/ |
*/ |
| 5892 |
{ |
{ |
| 5893 |
// bはsjisの半角カタカナ |
// bはsjisの半角カタカナ |
| 5894 |
unsigned long u32 = CP932ToUTF32(b); |
unsigned long u32 = CP932ToUTF32(b); |
| 5895 |
UnicodeToCP932(u32); |
PutU32(u32); |
| 5896 |
} |
} |
| 5897 |
return TRUE; |
return TRUE; |
| 5898 |
#endif |
#endif |
| 5958 |
#if UNICODE_INTERNAL_BUFF |
#if UNICODE_INTERNAL_BUFF |
| 5959 |
// bはsjisの半角カタカナ |
// bはsjisの半角カタカナ |
| 5960 |
unsigned long u32 = CP932ToUTF32(b); |
unsigned long u32 = CP932ToUTF32(b); |
| 5961 |
UnicodeToCP932(u32); |
PutU32(u32); |
| 5962 |
#else |
#else |
| 5963 |
PutChar(b); // katakana |
PutChar(b); // katakana |
| 5964 |
#endif |
#endif |
| 6135 |
} |
} |
| 6136 |
} |
} |
| 6137 |
|
|
|
// unicode(UTF-32,wchar_t)をバッファへ書き込む |
|
|
// TODO @@ |
|
|
#if UNICODE_INTERNAL_BUFF |
|
|
// 内部コード unicode版 |
|
|
static void UnicodeToCP932(unsigned int code) |
|
|
{ |
|
|
unsigned short cset; |
|
|
int LineEnd; |
|
|
|
|
|
TCharAttr CharAttrTmp; |
|
|
CharAttrTmp = CharAttr; |
|
|
if (code <= US) { |
|
|
// C0 |
|
|
ParseControl(code); |
|
|
#if 0 |
|
|
} else if ((0x80<=code) && (code<=0x9F)) { |
|
|
// C1 |
|
|
ParseControl(code); |
|
|
} else if (code < 0x20) { |
|
|
PutChar(code); |
|
|
#endif |
|
|
#if 0 |
|
|
} else if (code <= 0xff) { |
|
|
PutChar(code); |
|
|
#endif |
|
|
} else { |
|
|
int r; |
|
|
BOOL is_update; |
|
|
|
|
|
// UnicodeからDEC特殊文字へのマッピング |
|
|
if (ts.UnicodeDecSpMapping) { |
|
|
cset = UTF32ToDecSp(code); |
|
|
if (((cset >> 8) & ts.UnicodeDecSpMapping) != 0) { |
|
|
code = cset & 0xff; |
|
|
CharAttrTmp.Attr |= AttrSpecial; |
|
|
} |
|
|
} |
|
|
|
|
|
if ((CharAttrTmp.Attr & AttrSpecial) == 0) { |
|
|
if (Special) { |
|
|
UpdateStr(); |
|
|
Special = FALSE; |
|
|
} |
|
|
} else { |
|
|
if (!Special) { |
|
|
UpdateStr(); |
|
|
Special = TRUE; |
|
|
} |
|
|
} |
|
|
|
|
|
if (CursorX > CursorRightM) |
|
|
LineEnd = NumOfColumns - 1; |
|
|
else |
|
|
LineEnd = CursorRightM; |
|
|
|
|
|
// Wrap処理、カーソル移動 |
|
|
if (Wrap) { |
|
|
// 現在 Wrap 状態 |
|
|
if (!BuffIsCombiningCharacter(CursorX, CursorY, code)) { |
|
|
// 文字コードが結合文字ではない = カーソルが移動する |
|
|
|
|
|
// カーソル位置に行継続アトリビュートを追加 |
|
|
TCharAttr t = BuffGetCursorCharAttr(CursorX, CursorY); |
|
|
t.Attr |= AttrLineContinued; |
|
|
t.AttrEx = t.Attr; |
|
|
BuffSetCursorCharAttr(CursorX, CursorY, t); |
|
|
|
|
|
// 行継続アトリビュートをつける |
|
|
CharAttrTmp.Attr |= AttrLineContinued; |
|
|
CharAttrTmp.AttrEx = CharAttrTmp.Attr; |
|
|
|
|
|
// 次の行の行頭へ |
|
|
CarriageReturn(FALSE); |
|
|
LineFeed(LF,FALSE); |
|
|
} |
|
|
} |
|
|
|
|
|
// バッファに文字を入れる |
|
|
// BuffPutUnicode()した戻り値で文字のセル数を知ることができる |
|
|
// エラー時はカーソル位置を検討する |
|
|
is_update = FALSE; |
|
|
CharAttrTmp.AttrEx = CharAttrTmp.Attr; |
|
|
retry: |
|
|
r = BuffPutUnicode(code, CharAttrTmp, InsertMode); |
|
|
if (r == -1) { |
|
|
// 文字全角で行末、入力できない |
|
|
|
|
|
if (AutoWrapMode) { |
|
|
// 自動改行 |
|
|
// 、wrap処理 |
|
|
CharAttrTmp = CharAttr; |
|
|
CharAttrTmp.Attr |= AttrLineContinued; |
|
|
CharAttrTmp.AttrEx = CharAttrTmp.Attr | AttrPadding; |
|
|
// AutoWrapMode |
|
|
// ts.EnableContinuedLineCopy |
|
|
//if (CursorX != LineEnd){ |
|
|
//&& BuffIsHalfWidthFromCode(&ts, code)) { |
|
|
|
|
|
// full width出力が半分出力にならないように0x20を出力 |
|
|
BuffPutUnicode(0x20, CharAttrTmp, FALSE); |
|
|
CharAttrTmp.AttrEx = CharAttrTmp.AttrEx & ~AttrPadding; |
|
|
|
|
|
// 次の行の行頭へ |
|
|
CarriageReturn(FALSE); |
|
|
LineFeed(LF,FALSE); |
|
|
} |
|
|
else { |
|
|
// 行頭に戻す |
|
|
CursorX = 0; |
|
|
} |
|
|
|
|
|
//CharAttrTmp.Attr &= ~AttrLineContinued; |
|
|
goto retry; |
|
|
} |
|
|
else if (r == 0) { |
|
|
// カーソルの移動なし,結合文字,合字など |
|
|
// Wrap は変化しない |
|
|
UpdateStr(); // 「ほ」->「ぽ」など、変化することがあるので描画する |
|
|
} else if (r == 1) { |
|
|
// 半角(1セル) |
|
|
if (CursorX + 0 == CursorRightM || CursorX >= NumOfColumns - 1) { |
|
|
UpdateStr(); |
|
|
Wrap = AutoWrapMode; |
|
|
} else { |
|
|
MoveRight(); |
|
|
Wrap = FALSE; |
|
|
} |
|
|
} else if (r == 2) { |
|
|
// 全角(2セル) |
|
|
if (CursorX + 1 == CursorRightM || CursorX + 1 >= NumOfColumns - 1) { |
|
|
MoveRight(); // 全角の右側にカーソル移動 |
|
|
UpdateStr(); |
|
|
Wrap = AutoWrapMode; |
|
|
} else { |
|
|
MoveRight(); |
|
|
MoveRight(); |
|
|
Wrap = FALSE; |
|
|
} |
|
|
} |
|
|
else { |
|
|
assert(FALSE); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#else |
|
|
|
|
|
// unicode(UTF-32)をバッファ(t.CodePage)へ書き込む |
|
|
static void UnicodeToCP932(unsigned int code) |
|
|
{ |
|
|
size_t mblen; |
|
|
char mbchar[2]; |
|
|
|
|
|
// UnicodeからDEC特殊文字へのマッピング |
|
|
if (ts.UnicodeDecSpMapping) { |
|
|
unsigned short cset; |
|
|
cset = UTF32ToDecSp(code); |
|
|
if (((cset >> 8) & ts.UnicodeDecSpMapping) != 0) { |
|
|
PutDecSp(cset & 0xff); |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
// Unicode -> 内部コード(ts.CodePage)へ変換して出力 |
|
|
mblen = UTF32ToMBCP(code, ts.CodePage, mbchar, 2); |
|
|
#if 1 // U+203e OVERLINE 特別処理 |
|
|
if (code == 0x203e && ts.CodePage == 932) { |
|
|
// U+203eは0x7e'~'に変換される |
|
|
// 無理やり漢字出力する |
|
|
mbchar[0] = 0; // この0のため、クリップボードに文字列がうまく入らない |
|
|
mbchar[1] = 0x7e; |
|
|
mblen = 2; |
|
|
} |
|
|
#endif |
|
|
switch (mblen) { |
|
|
case 0: |
|
|
PutChar('?'); |
|
|
if (ts.UnknownUnicodeCharaAsWide) { |
|
|
PutChar('?'); |
|
|
} |
|
|
break; |
|
|
case 1: |
|
|
PutChar(mbchar[0]); |
|
|
break; |
|
|
case 2: |
|
|
default: |
|
|
Kanji = mbchar[0] << 8; |
|
|
PutKanji(mbchar[1]); |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
// UTF-8で受信データを処理する(sub) |
|
|
#if UNICODE_INTERNAL_BUFF |
|
|
static BOOL ParseFirstUTF8Sub(BYTE b) |
|
|
{ |
|
|
if (b<=US) |
|
|
ParseControl(b); |
|
|
else if ((b>=0x20) && (b<=0x7E)) |
|
|
PutChar(b); |
|
|
else if ((b>=0x80) && (b<=0x9F)) |
|
|
ParseControl(b); |
|
|
else if (b>=0xA0) |
|
|
PutChar(b); |
|
|
return TRUE; |
|
|
} |
|
|
#endif |
|
|
|
|
| 6138 |
// UTF-8で受信データを処理する |
// UTF-8で受信データを処理する |
| 6139 |
// returns TRUE if b is processed |
// returns TRUE if b is processed |
| 6140 |
// (actually allways returns TRUE) |
// (actually allways returns TRUE) |
| 6158 |
// 1バイト目がC1制御文字(0x80-0x9f)の場合も同様。 |
// 1バイト目がC1制御文字(0x80-0x9f)の場合も同様。 |
| 6159 |
if (count == 0 || count == 1) { |
if (count == 0 || count == 1) { |
| 6160 |
if (proc_combining == 1 && can_combining == 1) { |
if (proc_combining == 1 && can_combining == 1) { |
| 6161 |
UnicodeToCP932(first_code); |
PutU32(first_code); |
| 6162 |
can_combining = 0; |
can_combining = 0; |
| 6163 |
} |
} |
| 6164 |
|
|
| 6165 |
if (count == 1) { |
if (count == 1) { |
|
//#if UNICODE_INTERNAL_BUFF |
|
|
#if 0 |
|
|
ParseFirstUTF8Sub(buf[0]); |
|
|
#else |
|
| 6166 |
ParseASCII(buf[0]); |
ParseASCII(buf[0]); |
|
#endif |
|
| 6167 |
} |
} |
|
//#if UNICODE_INTERNAL_BUFF |
|
|
#if 0 |
|
|
ParseFirstUTF8Sub(b); |
|
|
#else |
|
| 6168 |
ParseASCII(b); |
ParseASCII(b); |
|
#endif |
|
| 6169 |
count = 0; // reset counter |
count = 0; // reset counter |
| 6170 |
return TRUE; |
return TRUE; |
| 6171 |
} |
} |
| 6181 |
if ((buf[1] & 0xc0) == 0x80) { |
if ((buf[1] & 0xc0) == 0x80) { |
| 6182 |
|
|
| 6183 |
if (proc_combining == 1 && can_combining == 1) { |
if (proc_combining == 1 && can_combining == 1) { |
| 6184 |
UnicodeToCP932(first_code); |
PutU32(first_code); |
| 6185 |
can_combining = 0; |
can_combining = 0; |
| 6186 |
} |
} |
| 6187 |
|
|
| 6188 |
code = ((buf[0] & 0x1f) << 6); |
code = ((buf[0] & 0x1f) << 6); |
| 6189 |
code |= ((buf[1] & 0x3f)); |
code |= ((buf[1] & 0x3f)); |
| 6190 |
|
|
| 6191 |
UnicodeToCP932(code); |
PutU32(code); |
| 6192 |
} |
} |
| 6193 |
else { |
else { |
| 6194 |
ParseASCII(buf[0]); |
ParseASCII(buf[0]); |
| 6235 |
first_code_index = UnicodeGetIndexOfCombiningFirstCode(code); |
first_code_index = UnicodeGetIndexOfCombiningFirstCode(code); |
| 6236 |
if (first_code_index != -1) { |
if (first_code_index != -1) { |
| 6237 |
// 1つめの文字はそのまま出力する |
// 1つめの文字はそのまま出力する |
| 6238 |
UnicodeToCP932(first_code); |
PutU32(first_code); |
| 6239 |
|
|
| 6240 |
can_combining = 1; |
can_combining = 1; |
| 6241 |
first_code = code; |
first_code = code; |
| 6243 |
return (TRUE); |
return (TRUE); |
| 6244 |
} |
} |
| 6245 |
|
|
| 6246 |
UnicodeToCP932(first_code); |
PutU32(first_code); |
| 6247 |
UnicodeToCP932(code); |
PutU32(code); |
| 6248 |
count = 0; |
count = 0; |
| 6249 |
return (TRUE); |
return (TRUE); |
| 6250 |
} |
} |
| 6251 |
} |
} |
| 6252 |
} |
} |
| 6253 |
|
|
| 6254 |
UnicodeToCP932(code); |
PutU32(code); |
| 6255 |
|
|
| 6256 |
skip: |
skip: |
| 6257 |
count = 0; |
count = 0; |
| 6272 |
code |= ((buf[2] & 0x3f) << 6); |
code |= ((buf[2] & 0x3f) << 6); |
| 6273 |
code |= (buf[3] & 0x3f); |
code |= (buf[3] & 0x3f); |
| 6274 |
|
|
| 6275 |
UnicodeToCP932(code); |
PutU32(code); |
| 6276 |
count = 0; |
count = 0; |
| 6277 |
return TRUE; |
return TRUE; |
| 6278 |
} else { |
} else { |