Skip to content

Commit

Permalink
使用可能文字コードの整理 #306
Browse files Browse the repository at this point in the history
- コマンドラインで使用できる文字コード指定を修正
- 不要関数など削除
  - GetLanguageList(), KanjiCodeTranslate()
  • Loading branch information
zmatsuo committed Sep 22, 2024
1 parent 0d67397 commit 7be6d6e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 95 deletions.
91 changes: 40 additions & 51 deletions teraterm/common/ttlib_charset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,41 @@
#include <stdlib.h>
#include <string.h>

#include "codeconv.h"
#include "tttypes_charset.h"

#include "ttlib_charset.h"

static const TKanjiList KanjiList[] = {
{ /*IdUtf8,*/ IdUTF8, "UTF-8", "UTF-8" },
{ /*IdEnglish,*/ IdISO8859_1, "English/ISO8859-1", "ISO8859-1" },
{ /*IdEnglish,*/ IdISO8859_2, "English/ISO8859-2", "ISO8859-2" },
{ /*IdEnglish,*/ IdISO8859_3, "English/ISO8859-3", "ISO8859-3" },
{ /*IdEnglish,*/ IdISO8859_4, "English/ISO8859-4", "ISO8859-4" },
{ /*IdEnglish,*/ IdISO8859_5, "English/ISO8859-5", "ISO8859-5" },
{ /*IdEnglish,*/ IdISO8859_6, "English/ISO8859-6", "ISO8859-6" },
{ /*IdEnglish,*/ IdISO8859_7, "English/ISO8859-7", "ISO8859-7" },
{ /*IdEnglish,*/ IdISO8859_8, "English/ISO8859-8", "ISO8859-8" },
{ /*IdEnglish,*/ IdISO8859_9, "English/ISO8859-9", "ISO8859-9" },
{ /*IdEnglish,*/ IdISO8859_10, "English/ISO8859-10", "ISO8859-10" },
{ /*IdEnglish,*/ IdISO8859_11, "English/ISO8859-11", "ISO8859-11" },
{ /*IdEnglish,*/ IdISO8859_13, "English/ISO8859-13", "ISO8859-13" },
{ /*IdEnglish,*/ IdISO8859_14, "English/ISO8859-14", "ISO8859-14" },
{ /*IdEnglish,*/ IdISO8859_15, "English/ISO8859-15", "ISO8859-15" },
{ /*IdEnglish,*/ IdISO8859_16, "English/ISO8859-16", "ISO8859-16" },
// { /*IdJapanese,*/ IdUTF8, "Japanese/UTF-8", "UTF-8" },
{ /*IdJapanese,*/ IdSJIS, "Japanese/SJIS (CP932)", "SJIS" },
{ /*IdJapanese,*/ IdEUC, "Japanese/EUC", "EUC" },
{ /*IdJapanese,*/ IdJIS, "Japanese/JIS", "JIS" },
{ /*IdRussian,*/ IdWindows, "Russian/Windows (CP1251)", "Windows(CP1251)" },
{ /*IdRussian,*/ IdKOI8, "Russian/KOI8-R", "KOI8-R" },
{ /*IdRussian,*/ Id866, "Russian/CP866", "CP866" },
{ /*IdRussian,*/ IdISO, "Russian/ISO 8859-5", "ISO8859-5" },
{ /*IdKorean,*/ IdKoreanCP949, "Korean/KS5601 (CP949)", "KS5601" },
// { /*IdKorean,*/ IdUTF8, "Korean/UTF-8", "UTF-8" },
{ /*IdChinese,*/ IdCnGB2312, "Chinese/GB2312 (CP936)", "GB2312" },
{ /*IdChinese,*/ IdCnBig5, "Chinese/Big5 (CP950)", "BIG5" },
// { /*IdChinese,*/ IdUTF8, "Chinese/UTF-8", "UTF-8" },
// coding GUI INI
{ IdUTF8, "UTF-8", "UTF-8" },
{ IdISO8859_1, "ISO8859-1", "ISO8859-1" },
{ IdISO8859_2, "ISO8859-2", "ISO8859-2" },
{ IdISO8859_3, "ISO8859-3", "ISO8859-3" },
{ IdISO8859_4, "ISO8859-4", "ISO8859-4" },
{ IdISO8859_5, "ISO8859-5", "ISO8859-5" },
{ IdISO8859_6, "ISO8859-6", "ISO8859-6" },
{ IdISO8859_7, "ISO8859-7", "ISO8859-7" },
{ IdISO8859_8, "ISO8859-8", "ISO8859-8" },
{ IdISO8859_9, "ISO8859-9", "ISO8859-9" },
{ IdISO8859_10, "ISO8859-10", "ISO8859-10" },
{ IdISO8859_11, "ISO8859-11", "ISO8859-11" },
{ IdISO8859_13, "ISO8859-13", "ISO8859-13" },
{ IdISO8859_14, "ISO8859-14", "ISO8859-14" },
{ IdISO8859_15, "ISO8859-15", "ISO8859-15" },
{ IdISO8859_16, "ISO8859-16", "ISO8859-16" },
{ IdSJIS, "SJIS (CP932)", "SJIS" },
{ IdEUC, NULL, "EUC-JP" },
{ IdEUC, "EUC", "EUC" },
{ IdJIS, "JIS", "JIS" },
{ IdWindows, "Windows (CP1251)", "Windows(CP1251)" },
{ IdKOI8, "KOI8-R", "KOI8-R" },
{ Id866, "CP866", "CP866" },
// { IdISO, NULL, "ISO8859-5" },
{ IdISO8859_5, NULL, "ISO8859-5" },
{ IdKoreanCP949, "KS5601 (CP949)", "KS5601" },
{ IdCnGB2312, "GB2312 (CP936)", "GB2312" },
{ IdCnBig5, "Big5 (CP950)", "BIG5" },
};

/**
Expand All @@ -89,8 +90,8 @@ const TKanjiList *GetKanjiList(int index)
const char *GetKanjiCodeStr(int kanji_code)
{
for (int i = 0; i < _countof(KanjiList); i++) {
if (KanjiList[i].coding == kanji_code) {
return KanjiList[i].KanjiCode;
if (KanjiList[i].coding == kanji_code && KanjiList[i].CodeStrINI != NULL) {
return KanjiList[i].CodeStrINI;
}
}
return "UTF-8";
Expand All @@ -111,35 +112,23 @@ int GetKanjiCodeFromStr(const char *kanji_code_str)
}

for (int i = 0; i < _countof(KanjiList); i++) {
if (strcmp(KanjiList[i].KanjiCode, kanji_code_str) == 0) {
if (KanjiList[i].CodeStrINI != NULL && strcmp(KanjiList[i].CodeStrINI, kanji_code_str) == 0) {
return KanjiList[i].coding;
}
}
return IdUTF8;
}

/**
* KanjiCodeTranslate(KanjiCodeID(source)) returns KanjiCodeID
*
* @param[in] kcode (IdSJIS, IdEUC, ... IdKOI8 ... ) (IdKanjiCode)
* @return 存在する漢字コードを返す
*
* 漢字コードが妥当かチェックする
* - iniファイルの読み込み時
* - 設定でlangを切り替えた時
*/
int KanjiCodeTranslate(int kcode)
int GetKanjiCodeFromStrW(const wchar_t *kanji_code_strW)
{
// 組み合わせが存在している?
for (int i = 0; i < _countof(KanjiList); i++) {
if (KanjiList[i].coding == kcode) {
// 存在している
return kcode;
}
if (kanji_code_strW == NULL || kanji_code_strW[0] == 0) {
return IdUTF8;
}

assert(0); // ありえない
return IdUTF8;
char *kanji_code_str = ToCharW(kanji_code_strW);
int r = GetKanjiCodeFromStr(kanji_code_str);
free(kanji_code_str);
return r;
}

/**
Expand Down
16 changes: 6 additions & 10 deletions teraterm/common/ttlib_charset.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,27 @@

#include <windows.h>

#include "tttypes_charset.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
int language;
const char *str;
} TLanguageList;

typedef struct {
int coding;
const char *CodeName;
const char *KanjiCode;
IdKanjiCode coding; // 内部のコード
const char *CodeStrGUI; // GUIで表示する文字列
const char *CodeStrINI; // iniファイル、コマンドラインの文字列
} TKanjiList;

const TLanguageList *GetLanguageList(int index);
const char *GetLanguageStr(int language);
int GetLanguageFromStr(const char *language_str);

const TKanjiList *GetKanjiList(int index);
const char *GetKanjiCodeStr(int kanji_code);
int GetKanjiCodeFromStr(const char *kanji_code_str);
int GetKanjiCodeFromStrW(const wchar_t *kanji_code_strW);

int KanjiCodeToISO8859Part(int kanjicode);
int KanjiCodeTranslate(int kcode);

BOOL LangIsEnglish(WORD kanji_code);
BOOL LangIsJapanese(WORD kanji_code);
Expand Down
24 changes: 17 additions & 7 deletions teraterm/teraterm/coding_pp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,25 @@ static INT_PTR CALLBACK Proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)

int recv_index = 0;
int send_index = 0;
for (int i = 0;; i++) {
const TKanjiList *p = GetKanjiList(i);
int i = 0;
while(1) {
const TKanjiList *p = GetKanjiList(i++);
if (p == NULL) {
break;
}
LRESULT index = SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_ADDSTRING, 0, (LPARAM)p->CodeName);
if (p->CodeStrGUI == NULL) {
continue;
}
LRESULT index = SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_ADDSTRING, 0, (LPARAM)p->CodeStrGUI);
SendDlgItemMessageA(hWnd, IDC_TERMKANJI, CB_SETITEMDATA, index, (LPARAM)p->coding);
if (ts->KanjiCode == p->coding) {
recv_index = i;
recv_index = index;
}

index = SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_ADDSTRING, 0, (LPARAM)p->CodeName);
index = SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_ADDSTRING, 0, (LPARAM)p->CodeStrGUI);
SendDlgItemMessageA(hWnd, IDC_TERMKANJISEND, CB_SETITEMDATA, index, (LPARAM)p->coding);
if (ts->KanjiCodeSend == p->coding) {
send_index = i;
send_index = index;
}
}
ExpandCBWidth(hWnd, IDC_TERMKANJI);
Expand Down Expand Up @@ -242,8 +246,14 @@ static INT_PTR CALLBACK Proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)

// character width (現在の値)
SetDropDownList(hWnd, IDC_AMBIGUOUS_WIDTH_COMBO, CellWidthList, ts->UnicodeAmbiguousWidth == 1 ? 1 : 2);
CheckDlgButton(hWnd, IDC_EMOJI_WIDTH_CHECK, ts->UnicodeEmojiOverride ? BST_CHECKED : BST_UNCHECKED);
SetDropDownList(hWnd, IDC_EMOJI_WIDTH_COMBO, CellWidthList, ts->UnicodeEmojiWidth == 1 ? 1 : 2);
if (ts->UnicodeEmojiOverride) {
CheckDlgButton(hWnd, IDC_EMOJI_WIDTH_CHECK, BST_CHECKED);
EnableWindow(GetDlgItem(hWnd, IDC_EMOJI_WIDTH_COMBO), TRUE);
} else {
CheckDlgButton(hWnd, IDC_EMOJI_WIDTH_CHECK, BST_UNCHECKED);
EnableWindow(GetDlgItem(hWnd, IDC_EMOJI_WIDTH_COMBO), FALSE);
}

return TRUE;
}
Expand Down
32 changes: 5 additions & 27 deletions teraterm/ttpset/ttset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3737,26 +3737,11 @@ void PASCAL _ParseParam(wchar_t *Param, PTTSet ts, PCHAR DDETopic)
ts->KeyCnfFNW = f;
}
}
else if ((_wcsnicmp(Temp, L"/KR=", 4) == 0) ||
(_wcsnicmp(Temp, L"/KT=", 4) == 0)) { /* kanji code */
if (_wcsicmp(&Temp[4], L"UTF8") == 0 ||
_wcsicmp(&Temp[4], L"UTF-8") == 0)
c = IdUTF8;
else if (_wcsicmp(&Temp[4], L"SJIS") == 0 ||
_wcsicmp(&Temp[4], L"KS5601") == 0)
c = IdSJIS;
else if (_wcsicmp(&Temp[4], L"EUC") == 0)
c = IdEUC;
else if (_wcsicmp(&Temp[4], L"JIS") == 0)
c = IdJIS;
else
c = -1;
if (c != -1) {
if (_wcsnicmp(Temp, L"/KR=", 4) == 0)
ts->KanjiCode = c;
else
ts->KanjiCodeSend = c;
}
else if (_wcsnicmp(Temp, L"/KR=", 4) == 0) {
ts->KanjiCode = GetKanjiCodeFromStrW(&Temp[4]);
}
else if (_wcsnicmp(Temp, L"/KT=", 4) == 0) {
ts->KanjiCodeSend = GetKanjiCodeFromStrW(&Temp[4]);
}
else if (_wcsnicmp(Temp, L"/L=", 3) == 0) { /* log file */
wchar_t *log_dir = GetTermLogDir(ts);
Expand Down Expand Up @@ -3896,13 +3881,6 @@ void PASCAL _ParseParam(wchar_t *Param, PTTSet ts, PCHAR DDETopic)
cur = next;
}

// Language が変更されたかもしれないので、
// KanjiCode/KanjiCodeSend をチェックする
{
ts->KanjiCode = KanjiCodeTranslate(ts->KanjiCode);
ts->KanjiCodeSend = KanjiCodeTranslate(ts->KanjiCodeSend);
}

if ((DDETopic != NULL) && (DDETopic[0] != 0)) {
free(ts->MacroFNW);
ts->MacroFNW = NULL;
Expand Down

0 comments on commit 7be6d6e

Please sign in to comment.