Skip to content

Commit

Permalink
クリップボードの送信データを送信文字コードで送信するよう修正した
Browse files Browse the repository at this point in the history
- OSC 52
- 修正前は、送信文字コード UTF-8 以外の時は、常にACPでエンコードされていた
  - 送信文字コードが UTF-8 の時は、UTF-8 だった
  • Loading branch information
zmatsuo committed Sep 9, 2024
1 parent a3f6609 commit d9d0923
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 36 deletions.
7 changes: 4 additions & 3 deletions doc/en/html/about/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ <h2 id="teraterm">Tera Term</h2>

<h3 id="teraterm_5.4">YYYY.MM.DD (Ver 5.4 not released yet)</h3>
<ul class="history">
<!--li>Changes
<li>Changes
<ul>
<li></li>
<li>changed to use transmit character code when sending clipboard (OSC 52).<br>
Before fix, when transmit character code is not UTF-8, it used ACP.</li>
</ul>
</li-->
</li>

<!--li>Bug fixes
<ul>
Expand Down
7 changes: 4 additions & 3 deletions doc/ja/html/about/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ <h2 id="teraterm">Tera Term</h2>

<h3 id="teraterm_5.4">YYYY.MM.DD (Ver 5.4 not released yet)</h3>
<ul class="history">
<!--li>変更
<li>変更
<ul>
<li></li>
<li>クリップボードの送信(OSC 52)時、送信文字コードで送信するように変更した<br>
修正前はUTF-8 以外の時、ACPで送信していた。</li>
</ul>
</li-->
</li>

<!--li>バグ修正
<ul>
Expand Down
55 changes: 54 additions & 1 deletion teraterm/common/makeoutputstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void MakeOutputStringInit(
* @param TempStr 出力文字ptr
* @param TempLen_ 出力文字長
* @param ControlOut 文字検査/出力関数
* @param cv
* @param data ControlOut へ渡すデータ
* @retval 入力文字列から使用した文字数
*/
size_t MakeOutputString(
Expand Down Expand Up @@ -331,3 +331,56 @@ size_t MakeOutputString(
*TempLen_ = TempLen;
return output_char_count;
}

char *MakeOutputStringConvW(
wchar_t const *strW,
WORD Language,
WORD kanji_code,
WORD KanjiIn,
WORD KanjiOut,
BOOL jis7katakana,
size_t *len)
{
OutputCharState *h = MakeOutputStringCreate();
MakeOutputStringInit(h, Language, kanji_code, KanjiIn, KanjiOut, jis7katakana);

size_t strW_len = wcslen(strW);
size_t str_len = strW_len;
char *str = (char *)malloc(str_len);
size_t str_pos = 0;

size_t i = 0;
while (i < strW_len) {
char tmp_str[8];
size_t tmp_len;
size_t output_char_count = MakeOutputString(h, &strW[i], strW_len - i, tmp_str, &tmp_len, NULL, NULL);
memcpy(&str[str_pos], &tmp_str, tmp_len);
str_pos += tmp_len;
i += output_char_count;
}

MakeOutputStringDestroy(h);

str[str_pos++] = 0;
if (len != NULL) {
*len = str_pos - 1;
}

return str;
}

char *MakeOutputStringConvU8(
const char *strU8,
WORD Language,
WORD kanji_code,
WORD KanjiIn,
WORD KanjiOut,
BOOL jis7katakana,
size_t *len)
{
wchar_t *strW = ToWcharU8(strU8);
char *str = MakeOutputStringConvW(
strW, Language, kanji_code, KanjiIn, KanjiOut, jis7katakana, len);
free(strW);
return str;
}
22 changes: 22 additions & 0 deletions teraterm/common/makeoutputstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ size_t MakeOutputString(
BOOL (*ControlOut)(unsigned int u32, BOOL check_only, char *TempStr, size_t *StrLen, void *data),
void *data);

/**
* Unicodeを指定文字コードに変換する
* codeconv.h ではできない JIS コードへの変換可
*
* @param[in] strW 元文字列
* @param[out] len 変換文字列長 (NULLのとき値を返さない)
* @return 変換文字列
*/
char *MakeOutputStringConvW(
const wchar_t *strW,
WORD Language, WORD kanji_code, WORD KanjiIn, WORD KanjiOut,BOOL jis7katakana,
size_t *len);

/**
* Unicodeを指定文字コードに変換する
* MakeOutputStringConvW()のUTF-8版
*/
char *MakeOutputStringConvU8(
const char *strU8,
WORD Language, WORD kanji_code, WORD KanjiIn, WORD KanjiOut,BOOL jis7katakana,
size_t *len);

#ifdef __cplusplus
}
#endif
3 changes: 2 additions & 1 deletion teraterm/teraterm/clipboar.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "sendmem.h"
#include "clipboarddlg.h"
#include "tttypes_charset.h"
#include "makeoutputstring.h"

#include "clipboar.h"

Expand Down Expand Up @@ -345,7 +346,7 @@ void CBStartPasteB64(HWND HWin, PCHAR header, PCHAR footer)
str_mb = ToU8W(str_w);
}
else {
str_mb = ToCharW(str_w);
str_mb = MakeOutputStringConvW(str_w, 0, ts.KanjiCodeSend, 0, 0, 0, NULL);
}

if (str_mb == NULL) {
Expand Down
29 changes: 1 addition & 28 deletions ttssh2/ttxssh/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -7079,34 +7079,7 @@ void sanitize_str(buffer_t *buff, unsigned char *src, size_t srclen)
static char *ConvertReceiveStr(TComVar *cv, char *strU8, size_t *len)
{
TTTSet *pts = cv->ts;

OutputCharState *h = MakeOutputStringCreate();
MakeOutputStringInit(h, pts->Language, pts->KanjiCode, 0,0,0);

wchar_t *strW = ToWcharU8(strU8);
size_t strW_len = wcslen(strW);
size_t str_len = strW_len;
char *str = (char *)malloc(str_len);
size_t str_pos = 0;

size_t i = 0;
while (i < strW_len) {
char tmp_str[8];
size_t tmp_len;
size_t output_char_count = MakeOutputString(h, &strW[i], strW_len - i, tmp_str, &tmp_len, NULL, cv);
memcpy(&str[str_pos], &tmp_str, tmp_len);
str_pos += tmp_len;
i += output_char_count;
}

MakeOutputStringDestroy(h);

str[str_pos++] = 0;
*len = str_pos - 1;

free(strW);

return str;
return MakeOutputStringConvU8(strU8, pts->Language, pts->KanjiCode, 0, 0, 0, len);
}

/*
Expand Down

0 comments on commit d9d0923

Please sign in to comment.