• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision9598 (tree)
Time2021-12-12 01:31:48
Authorzmatsuo

Log Message

iso8859 8ビット文字コードを使用できるようにした

- ttpdlg/ttdlg.c 内の文字コード関連部分を common/ttlib_charset.cpp に移動
- 1byte文字コードテスト用ツールを追加

- tests/various_code_texts/dump_code.pl

- ttpcmnから../teraterm/unicode.c をリンクするようにした

- Visual Studio 2005
- Visual Studio 2019
- CMakeLists.txt

Change Summary

Incremental Difference

--- trunk/CMakeLists.txt (revision 9597)
+++ trunk/CMakeLists.txt (revision 9598)
@@ -66,8 +66,10 @@
6666 endif()
6767 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__USE_MINGW_ANSI_STDIO=0")
6868 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__USE_MINGW_ANSI_STDIO=0")
69- set(CMAKE_C_CXX_WARNING_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-sign-compare")
70- set(CMAKE_C_WARNING_FLAGS "${CMAKE_C_CXX_WARNING_FLAGS} -Wno-pointer-sign")
69+ if (NOT MORE_WARNING)
70+ set(CMAKE_C_CXX_WARNING_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-sign-compare")
71+ set(CMAKE_C_WARNING_FLAGS "${CMAKE_C_CXX_WARNING_FLAGS} -Wno-pointer-sign")
72+ endif()
7173 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_WARNING_FLAGS} -static -ffunction-sections -fdata-sections ${C_ONLY_FLAGS}")
7274 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_CXX_WARNING_FLAGS} -static -ffunction-sections -fdata-sections")
7375 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
--- trunk/teraterm/common/ttlib.h (revision 9597)
+++ trunk/teraterm/common/ttlib.h (revision 9598)
@@ -201,6 +201,7 @@
201201 void CreateBakupFile(const wchar_t *fname, const wchar_t *prev_str);
202202 BOOL ConvertIniFileCharCode(const wchar_t *fname, const wchar_t *bak_str);
203203 wchar_t *MakeISO8601Str(time_t t);
204+int KanjiCodeToISO8859Part(int kanjicode);
204205
205206 #ifdef __cplusplus
206207 }
--- trunk/teraterm/common/ttlib_charset.cpp (revision 9597)
+++ trunk/teraterm/common/ttlib_charset.cpp (revision 9598)
@@ -27,6 +27,8 @@
2727 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828 */
2929
30+#include <assert.h>
31+
3032 #include "tttypes_charset.h"
3133
3234 #include "ttlib_charset.h"
@@ -42,14 +44,28 @@
4244
4345 static const TKanjiList KanjiList[] = {
4446 { IdUtf8, IdUTF8, "UTF-8", "UTF-8" },
45- { IdEnglish, IdCodeEnglish, "English", "English" },
47+ { IdEnglish, IdISO8859_1, "English/ISO8859-1", "ISO8859-1" },
48+ { IdEnglish, IdISO8859_2, "English/ISO8859-2", "ISO8859-2" },
49+ { IdEnglish, IdISO8859_3, "English/ISO8859-3", "ISO8859-3" },
50+ { IdEnglish, IdISO8859_4, "English/ISO8859-4", "ISO8859-4" },
51+ { IdEnglish, IdISO8859_5, "English/ISO8859-5", "ISO8859-5" },
52+ { IdEnglish, IdISO8859_6, "English/ISO8859-6", "ISO8859-6" },
53+ { IdEnglish, IdISO8859_7, "English/ISO8859-7", "ISO8859-7" },
54+ { IdEnglish, IdISO8859_8, "English/ISO8859-8", "ISO8859-8" },
55+ { IdEnglish, IdISO8859_9, "English/ISO8859-9", "ISO8859-9" },
56+ { IdEnglish, IdISO8859_10, "English/ISO8859-10", "ISO8859-10" },
57+ { IdEnglish, IdISO8859_11, "English/ISO8859-11", "ISO8859-11" },
58+ { IdEnglish, IdISO8859_13, "English/ISO8859-13", "ISO8859-13" },
59+ { IdEnglish, IdISO8859_14, "English/ISO8859-14", "ISO8859-14" },
60+ { IdEnglish, IdISO8859_15, "English/ISO8859-15", "ISO8859-15" },
61+ { IdEnglish, IdISO8859_16, "English/ISO8859-16", "ISO8859-16" },
62+ { IdJapanese, IdUTF8, "Japanese/UTF-8", "UTF-8" },
4663 { IdJapanese, IdSJIS, "Japanese/SJIS (CP932)", "SJIS" },
4764 { IdJapanese, IdEUC, "Japanese/EUC", "EUC" },
4865 { IdJapanese, IdJIS, "Japanese/JIS", "JIS" },
49- { IdJapanese, IdUTF8, "Japanese/UTF-8", "UTF-8" },
50- { IdRussian, IdWindows, "Russian/Windows (CP1251)", "CP1251" },
66+ { IdRussian, IdWindows, "Russian/Windows (CP1251)", "Windows(CP1251)" },
5167 { IdRussian, IdKOI8, "Russian/KOI8-R", "KOI8-R" },
52- { IdRussian, Id866, "Russian/CP 866", "CP866" },
68+ { IdRussian, Id866, "Russian/CP866", "CP866" },
5369 { IdRussian, IdISO, "Russian/ISO 8859-5", "IS8859-5" },
5470 { IdKorean, IdKoreanCP51949, "Korean/KS5601 (CP51949)", "KS5601" },
5571 { IdKorean, IdUTF8, "Korean/UTF-8", "UTF-8" },
@@ -101,6 +117,8 @@
101117
102118 /**
103119 * 漢字コード文字列を取得
120+ * iniファイルに保存する漢字コード文字列用
121+ *
104122 * @param[in] language (=ts.Language)
105123 * IdJapanese, IdKorean, ...
106124 * @param[in] kanji_code (=ts.KanjiCode (receive) or ts.KanjiCodeSend)
@@ -120,6 +138,8 @@
120138
121139 /**
122140 * 漢字コードを取得
141+ * iniファイルに保存されている漢字コード文字列を漢字コードに変換する
142+
123143 * @param[in] language (=ts.Language)
124144 * IdJapanese, IdKorean, ...
125145 * @param[in] kanji_code_str
@@ -144,7 +164,7 @@
144164 /**
145165 * KanjiCodeTranslate(Language(dest), KanjiCodeID(source)) returns KanjiCodeID
146166 * @param[in] lang (IdEnglish, IdJapanese, IdRussian, ...)
147- * @param[in] kcode (IdSJIS, IdEUC, ... IdKOI8 ... )
167+ * @param[in] kcode (IdSJIS, IdEUC, ... IdKOI8 ... ) (IdKanjiCode)
148168 * @return langに存在する漢字コードを返す
149169 *
150170 * langに存在しない漢字コードを使用しないようこの関数を使用する
@@ -153,17 +173,58 @@
153173 */
154174 int KanjiCodeTranslate(int lang, int kcode)
155175 {
156- static const int Table[][5] = {
157- {1, 2, 3, 4, 5}, /* to English (dummy) */
158- {1, 2, 3, 4, 5}, /* to Japanese(dummy) */
159- {1, 2, 3, 4, 5}, /* to Russian (dummy) */
160- {1, 1, 1, 4, 5}, /* to Korean */
161- {4, 4, 4, 4, 5}, /* to Utf8 */
162- {1, 2, 2, 2, 2}, /* to Chinese */
176+ // 組み合わせが存在している?
177+ for (int i = 0; i < _countof(KanjiList); i++) {
178+ if (KanjiList[i].lang == lang &&
179+ KanjiList[i].coding == kcode) {
180+ // 存在している
181+ return kcode;
182+ }
183+ }
184+
185+ // リスト内の一番最初の漢字コードを返す
186+ for (int i = 0; i < _countof(KanjiList); i++) {
187+ if (KanjiList[i].lang == lang) {
188+ return KanjiList[i].coding;
189+ }
190+ }
191+
192+ assert(0); // ありえない
193+ return IdUTF8;
194+}
195+
196+/**
197+ * 漢字コードから ISO8859の部番号を返す
198+ * @param kanjicode IdISO8859-1...16
199+ * @return 1...16 ISO8859に関係ない漢字コードの場合は1を返す
200+ */
201+int KanjiCodeToISO8859Part(int kanjicode)
202+{
203+ static const struct {
204+ IdKanjiCode kanji_code;
205+ int iso8859_part;
206+ } list[] = {
207+ { IdISO8859_1, 1 },
208+ { IdISO8859_2, 2 },
209+ { IdISO8859_3, 3 },
210+ { IdISO8859_4, 4 },
211+ { IdISO8859_5, 5 },
212+ { IdISO8859_6, 6 },
213+ { IdISO8859_7, 7 },
214+ { IdISO8859_8, 8 },
215+ { IdISO8859_9, 9 },
216+ { IdISO8859_10, 10 },
217+ { IdISO8859_11, 11 },
218+ { IdISO8859_13, 13 },
219+ { IdISO8859_14, 14 },
220+ { IdISO8859_15, 15 },
221+ { IdISO8859_16, 16 },
163222 };
164- if (lang < 1 || lang > IdLangMax) lang = 1;
165- if (kcode < 1 || kcode > 5) kcode = 1;
166- lang--;
167- kcode--;
168- return Table[lang][kcode];
223+ for (size_t i = 0; i < _countof(list); i++) {
224+ if (list[i].kanji_code == kanjicode) {
225+ return list[i].iso8859_part;
226+ }
227+ }
228+ assert(FALSE);
229+ return 1;
169230 }
--- trunk/teraterm/common/tttypes_charset.h (revision 9597)
+++ trunk/teraterm/common/tttypes_charset.h (revision 9598)
@@ -42,7 +42,23 @@
4242 /* ts.KanjiCode, ts.KanjiCodeSend の値 */
4343
4444 // ts.Language == IdEnglish
45-#define IdCodeEnglish 1
45+typedef enum {
46+ IdISO8859_1,
47+ IdISO8859_2,
48+ IdISO8859_3,
49+ IdISO8859_4,
50+ IdISO8859_5,
51+ IdISO8859_6,
52+ IdISO8859_7,
53+ IdISO8859_8,
54+ IdISO8859_9,
55+ IdISO8859_10,
56+ IdISO8859_11,
57+ IdISO8859_13,
58+ IdISO8859_14,
59+ IdISO8859_15,
60+ IdISO8859_16,
61+} IdKanjiCode;
4662
4763 // ts.Language == IdJapanese
4864 #define IdSJIS 1
--- trunk/teraterm/teraterm/coding_pp.cpp (revision 9597)
+++ trunk/teraterm/teraterm/coding_pp.cpp (revision 9598)
@@ -183,7 +183,7 @@
183183 else if (lang == IdChinese && (coding == IdCnGB2312 || coding == IdCnBig5)) {
184184 ;
185185 }
186- else if (lang == IdEnglish && coding == IdCodeEnglish) {
186+ else if (lang == IdEnglish) {
187187 ;
188188 }
189189 else {
--- trunk/teraterm/teraterm/vtterm.c (revision 9597)
+++ trunk/teraterm/teraterm/vtterm.c (revision 9598)
@@ -62,6 +62,7 @@
6262 #include "vtterm.h"
6363
6464 #include "unicode_test.h"
65+// #define DEBUG_DUMP_INPUTCODE 1
6566
6667 static void ParseFirst(BYTE b);
6768
@@ -6227,6 +6228,23 @@
62276228 return FALSE;
62286229 }
62296230
6231+static BOOL ParseEnglish(BYTE b)
6232+{
6233+ unsigned short u16 = 0;
6234+ int part = KanjiCodeToISO8859Part(ts.KanjiCode);
6235+ int r = UnicodeFromISO8859(part, b, &u16);
6236+ if (r == 0) {
6237+ return FALSE;
6238+ }
6239+ if (u16 < 0x100) {
6240+ ParseASCII((BYTE)u16);
6241+ }
6242+ else {
6243+ PutU32(u16);
6244+ }
6245+ return TRUE;
6246+}
6247+
62306248 static void ParseFirst(BYTE b)
62316249 {
62326250 switch (ts.Language) {
@@ -6289,7 +6307,13 @@
62896307 }
62906308 }
62916309 break;
6310+ case IdEnglish: {
6311+ if (ParseEnglish(b)) {
6312+ return;
6313+ }
6314+ break;
62926315 }
6316+ }
62936317
62946318 if (SSflag) {
62956319 PutChar(b);
--- trunk/teraterm/ttpcmn/CMakeLists.txt (revision 9597)
+++ trunk/teraterm/ttpcmn/CMakeLists.txt (revision 9598)
@@ -15,7 +15,7 @@
1515 ttcmn_notify.cpp
1616 ttpcmn-version.rc
1717 ttpcmn.def
18- ${COMMON_SRC}
18+ ../teraterm/unicode.cpp
1919 )
2020
2121 if(SUPPORT_OLD_WINDOWS)
--- trunk/teraterm/ttpcmn/ttcmn.c (revision 9597)
+++ trunk/teraterm/ttpcmn/ttcmn.c (revision 9598)
@@ -51,6 +51,7 @@
5151 #include "win32helper.h"
5252 #include "asprintf.h"
5353 #include "fileread.h"
54+#include "../teraterm/unicode.h"
5455
5556 #include "ttcmn_dup.h"
5657
@@ -168,11 +169,12 @@
168169 static void ConvertIniFiles(const wchar_t *filelist[], const wchar_t *dir, const wchar_t *date_str)
169170 {
170171 while(1) {
172+ wchar_t *fname;
171173 if (*filelist == NULL) {
172174 break;
173175 }
174176
175- wchar_t *fname = NULL;
177+ fname = NULL;
176178 awcscats(&fname, dir, L"\\", *filelist, NULL);
177179 ConvertIniFileCharCode(fname, date_str);
178180 free(fname);
@@ -1349,7 +1351,10 @@
13491351 TempStr[TempLen++] = mb_char[1];
13501352 }
13511353 } else if (cv->Language == IdEnglish) {
1352- TempStr[TempLen++] = u32;
1354+ char byte;
1355+ int part = KanjiCodeToISO8859Part(states->KanjiCode);
1356+ int r = UnicodeToISO8859(part, u32, &byte);
1357+ TempStr[TempLen++] = byte;
13531358 } else {
13541359 assert(FALSE);
13551360 }
--- trunk/teraterm/ttpdlg/ttdlg.c (revision 9597)
+++ trunk/teraterm/ttpdlg/ttdlg.c (revision 9598)
@@ -109,65 +109,31 @@
109109 static const char *MetaList[] = {"off", "on", "left", "right", NULL};
110110 static const char *MetaList2[] = {"off", "on", NULL};
111111
112-// TODO ttlib_charset と統合を考える
113-typedef struct {
114- const char *name;
115- int code;
116-} TDropList;
117-
118-static const TDropList KanjiList[] = {
119- { "SJIS", IdSJIS },
120- { "EUC", IdEUC },
121- { "JIS", IdJIS },
122- { "UTF-8", IdUTF8 },
123- { NULL, 0 },
124-};
125-
126-static const TDropList RussList[] = {
127- { "Windows(CP1251)", IdWindows },
128- { "KOI8-R", IdKOI8 },
129- { "CP866", Id866 },
130- { "ISO 8859-5", IdISO },
131- { NULL, 0 },
132-};
133-
134-static const TDropList KoreanList[] = {
135- { "KS5601", IdKoreanCP51949 },
136- { "UTF-8", IdUTF8 },
137- { NULL, 0 },
138-};
139-
140-static const TDropList Utf8List[] = {
141- { "UTF-8", IdUTF8 },
142- { NULL, 0 },
143-};
144-
145-static const TDropList ChineseList[] = {
146- { "GB2312 (CP936)", IdCnGB2312 },
147- { "BIG5 (CP950)", IdCnBig5 },
148- { "UTF-8", IdUTF8 },
149- { NULL, 0 },
150-};
151-
152112 static const char *BaudList[] =
153113 {"110","300","600","1200","2400","4800","9600",
154114 "14400","19200","38400","57600","115200",
155115 "230400", "460800", "921600", NULL};
156116
157-static void SetKanjiCodeDropDownList(HWND HDlg, int id, const TDropList *list, int sel_code)
117+static void SetKanjiCodeDropDownList(HWND HDlg, int id, int language, int sel_code)
158118 {
159- int i = 0;
119+ int i;
160120 int sel_index = 0;
161121
162- while (list[i].name != NULL) {
163- const char *name = list[i].name;
164- int code = list[i].code;
165- int index = SendDlgItemMessageA(HDlg, id, CB_ADDSTRING, 0, (LPARAM)name);
166- SendDlgItemMessageA(HDlg, id, CB_SETITEMDATA, index, code);
167- if (code == sel_code) {
168- sel_index = i;
122+ for(i = 0;; i++) {
123+ int index;
124+ const TKanjiList *p = GetKanjiList(i);
125+ if (p == NULL) {
126+ break;
169127 }
170- i++;
128+ if (p->lang != language) {
129+ continue;
130+ }
131+
132+ index = SendDlgItemMessageA(HDlg, id, CB_ADDSTRING, 0, (LPARAM)p->KanjiCode);
133+ SendDlgItemMessageA(HDlg, id, CB_SETITEMDATA, index, p->coding);
134+ if (p->coding == sel_code) {
135+ sel_index = index;
136+ }
171137 }
172138 SendDlgItemMessage(HDlg, id, CB_SETCURSEL, sel_index, 0);
173139 }
@@ -280,13 +246,13 @@
280246
281247 SetRB(Dialog,ts->AutoWinSwitch,IDC_TERMAUTOSWITCH,IDC_TERMAUTOSWITCH);
282248
249+ SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJI, ts->Language, ts->KanjiCode);
250+ SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJISEND, ts->Language, ts->KanjiCodeSend);
283251 if (ts->Language==IdJapanese) {
284- SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJI, KanjiList, ts->KanjiCode);
285252 if ( ts->KanjiCode!=IdJIS ) {
286253 DisableDlgItem(Dialog,IDC_TERMKANA,IDC_TERMKANA);
287254 }
288255 SetRB(Dialog,ts->JIS7Katakana,IDC_TERMKANA,IDC_TERMKANA);
289- SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJISEND, KanjiList, ts->KanjiCodeSend);
290256 if ( ts->KanjiCodeSend!=IdJIS ) {
291257 DisableDlgItem(Dialog,IDC_TERMKANASEND,IDC_TERMKOUT);
292258 }
@@ -299,22 +265,6 @@
299265 SetDropDownList(Dialog,IDC_TERMKOUT,KanjiOutList,ts->KanjiOut);
300266 }
301267 }
302- else if (ts->Language==IdRussian) {
303- SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJI, RussList,ts->KanjiCode);
304- SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJISEND, RussList,ts->KanjiCodeSend);
305- }
306- else if (ts->Language==IdKorean) { // HKS
307- SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJI, KoreanList, ts->KanjiCode);
308- SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJISEND, KoreanList, ts->KanjiCodeSend);
309- }
310- else if (ts->Language==IdUtf8) {
311- SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJI, Utf8List, ts->KanjiCode);
312- SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJISEND, Utf8List, ts->KanjiCodeSend);
313- }
314- else if (ts->Language == IdChinese) {
315- SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJI, ChineseList, ts->KanjiCode);
316- SetKanjiCodeDropDownList(Dialog, IDC_TERMKANJISEND, ChineseList, ts->KanjiCodeSend);
317- }
318268 CenterWindow(Dialog, GetParent(Dialog));
319269 return TRUE;
320270
@@ -375,16 +325,16 @@
375325
376326 GetRB(Dialog,&ts->AutoWinSwitch,IDC_TERMAUTOSWITCH,IDC_TERMAUTOSWITCH);
377327
328+ if ((w = (WORD)GetCurSel(Dialog, IDC_TERMKANJI)) > 0) {
329+ w = (int)SendDlgItemMessageA(Dialog, IDC_TERMKANJI, CB_GETITEMDATA, w - 1, 0);
330+ ts->KanjiCode = w;
331+ }
332+ if ((w = (WORD)GetCurSel(Dialog, IDC_TERMKANJISEND)) > 0) {
333+ w = (int)SendDlgItemMessageA(Dialog, IDC_TERMKANJISEND, CB_GETITEMDATA, w - 1, 0);
334+ ts->KanjiCodeSend = w;
335+ }
378336 if (ts->Language==IdJapanese) {
379- if ((w = (WORD)GetCurSel(Dialog, IDC_TERMKANJI)) > 0) {
380- w = (int)SendDlgItemMessageA(Dialog, IDC_TERMKANJI, CB_GETITEMDATA, w - 1, 0);
381- ts->KanjiCode = w;
382- }
383337 GetRB(Dialog,&ts->JIS7Katakana,IDC_TERMKANA,IDC_TERMKANA);
384- if ((w = (WORD)GetCurSel(Dialog, IDC_TERMKANJISEND)) > 0) {
385- w = (int)SendDlgItemMessageA(Dialog, IDC_TERMKANJISEND, CB_GETITEMDATA, w - 1, 0);
386- ts->KanjiCodeSend = w;
387- }
388338 GetRB(Dialog,&ts->JIS7KatakanaSend,IDC_TERMKANASEND,IDC_TERMKANASEND);
389339 if ((w = (WORD)GetCurSel(Dialog, IDC_TERMKIN)) > 0) {
390340 ts->KanjiIn = w;
@@ -393,19 +343,7 @@
393343 ts->KanjiOut = w;
394344 }
395345 }
396- else if (ts->Language==IdKorean || // HKS
397- ts->Language==IdRussian ||
398- ts->Language==IdChinese ||
399- ts->Language==IdUtf8) {
400- if ((w = (WORD)GetCurSel(Dialog, IDC_TERMKANJI)) > 0) {
401- w = (int)SendDlgItemMessageA(Dialog, IDC_TERMKANJI, CB_GETITEMDATA, w - 1, 0);
402- ts->KanjiCode = w;
403- }
404- if ((w = (WORD)GetCurSel(Dialog, IDC_TERMKANJISEND)) > 0) {
405- w = (int)SendDlgItemMessageA(Dialog, IDC_TERMKANJISEND, CB_GETITEMDATA, w - 1, 0);
406- ts->KanjiCodeSend = w;
407- }
408-
346+ else {
409347 ts->JIS7KatakanaSend=0;
410348 ts->JIS7Katakana=0;
411349 ts->KanjiIn = 0;
@@ -3161,9 +3099,11 @@
31613099 case IdUtf8: // UTF-8 mode
31623100 case IdChinese:
31633101 case IdRussian: // Russian mode
3102+ case IdEnglish: // English mode
31643103 i = IDD_TERMDLGK;
31653104 break;
3166- default: // English mode
3105+ default:
3106+ // 使っていない
31673107 i = IDD_TERMDLG;
31683108 }
31693109
--- trunk/tests/various_code_texts/dump_code.pl (nonexistent)
+++ trunk/tests/various_code_texts/dump_code.pl (revision 9598)
@@ -0,0 +1,170 @@
1+use utf8;
2+use strict;
3+
4+use Getopt::Long 'GetOptions';
5+
6+my $code = "utf8";
7+my $usage = 0;
8+
9+GetOptions(
10+ 'code=s' => \$code,
11+ 'help' => \$usage,
12+);
13+
14+sub IsCL {
15+ my $ch = $_[0];
16+ if (0x00 <= $ch && $ch <= 0x1f) {
17+ return 1;
18+ }
19+ return 0;
20+}
21+
22+sub IsCR {
23+ my $ch = $_[0];
24+ if (0x80 <= $ch && $ch <= 0x9f) {
25+ return 1;
26+ }
27+ return 0;
28+}
29+
30+sub IsPrintableUTF8 {
31+ my $ch = $_[0];
32+ if (IsCL($ch) || IsCR($ch)) {
33+ return 0;
34+ }
35+ if ($ch == 0x7f) {
36+ # DEL
37+ return 0;
38+ }
39+ return 1;
40+}
41+
42+sub IsPrintableShiftJIS {
43+ my $ch = $_[0];
44+ if (IsCL($ch) || IsCR($ch)) {
45+ return 0;
46+ }
47+ if ($ch == 0x7f) {
48+ # DEL
49+ return 0;
50+ }
51+ if ($ch == 0x80 || $ch == 0xa0) {
52+ return 0;
53+ }
54+ if (0xe0 <= $ch && $ch <= 0xff) {
55+ return 0;
56+ }
57+ return 1;
58+}
59+
60+sub IsPrintableJIS {
61+ my $ch = $_[0];
62+ if (IsCL($ch) || IsCR($ch)) {
63+ return 0;
64+ }
65+ if ($ch == 0x7f) {
66+ # DEL
67+ return 0;
68+ }
69+ if (0x80 <= $ch && $ch <= 0xa0) {
70+ return 0;
71+ }
72+ if (0xe0 <= $ch && $ch <= 0xff) {
73+ return 0;
74+ }
75+ return 1;
76+}
77+
78+sub IsPrintableEUCJP {
79+ my $ch = $_[0];
80+ if (IsCL($ch)) {
81+ return 0;
82+ }
83+ if ($ch == 0x7f) {
84+ # DEL
85+ return 0;
86+ }
87+ if ($ch >= 0x80) {
88+ return 0;
89+ }
90+ return 1;
91+}
92+
93+my %check =
94+(
95+ 'utf8' => \&IsPrintableUTF8,
96+ 'utf8-bin' => \&IsPrintableUTF8,
97+ 'iso8859' => \&IsPrintableUTF8,
98+ 'iso646' => \&IsPrintableEUCJP,
99+ 'sjis' => \&IsPrintableShiftJIS,
100+ 'shift_jis' => \&IsPrintableShiftJIS,
101+ 'euc-jp' => \&IsPrintableEUCJP,
102+ 'jis' => \&IsPrintableJIS,
103+ );
104+
105+sub usage {
106+ print << 'EOS';
107+option:
108+ --code=[code]
109+EOS
110+ for my $key (sort keys %check) {
111+ print " $key\n";
112+ }
113+}
114+
115+if ($usage) {
116+ usage();
117+ exit(0);
118+}
119+
120+my $find = 0;
121+for my $key (sort keys %check) {
122+ if (index($key, lc($code)) != -1) {
123+ $find = 1;
124+ $code = $key;
125+ last;
126+ }
127+}
128+if ($find == 0) {
129+ print "check code\n";
130+ usage();
131+ exit(0);
132+}
133+printf("code=$code\n");
134+
135+# output
136+if ($code eq "utf8") {
137+ # utf8 encode
138+ binmode STDOUT, ":utf8";
139+} else {
140+ binmode STDOUT;
141+}
142+local $| = 1;
143+
144+print " |";
145+for (my $i = 0; $i < 16; $i++) {
146+ printf(" +%x|", $i);
147+}
148+print "\n";
149+printf("------+");
150+for (my $y = 0; $y < 15; $y++) {
151+ printf("---+");
152+}
153+print "---|\n";
154+for (my $y = 0; $y < 16; $y++) {
155+ printf(" 0x%01xX |", $y);
156+ for (my $x = 0; $x < 16; $x++) {
157+ my $c = $y * 0x10 + $x;
158+ my $ch = "-";
159+ if ($check{$code}->($c)) {
160+ $ch = chr($c);
161+ }
162+ printf(" %s |", $ch);
163+ #printf(" %02x|", $c);
164+ if ($ch == 0xa0) {
165+ exit(1);
166+ }
167+ }
168+ print "\n";
169+}
170+
Show on old repository browser