• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonwindowsphpgamebathyscaphegui翻訳comegattwitterframeworkbtronvb.net計画中(planning stage)testdomarduinodirectxpreviewerゲームエンジン

nkfのGitリポジトリのfork


Commit MetaInfo

Revisión7b023c499dd520e7a50c7cfff9e210c03b073397 (tree)
Tiempo2006-03-25 00:14:32
AutorNARUSE, Yui <naruse@user...>
CommiterNARUSE, Yui

Log Message

* Add codeset ISO-2022-JP-1, ISO-2022-P-3
* Fix JIS X 0213 conversion

Cambiar Resumen

Diferencia incremental

--- a/nkf.c
+++ b/nkf.c
@@ -39,9 +39,9 @@
3939 ** E-Mail: furukawa@tcp-ip.or.jp
4040 ** まで御連絡をお願いします。
4141 ***********************************************************************/
42-/* $Id: nkf.c,v 1.93 2006/03/14 15:55:58 naruse Exp $ */
42+/* $Id: nkf.c,v 1.94 2006/03/24 06:14:32 naruse Exp $ */
4343 #define NKF_VERSION "2.0.6"
44-#define NKF_RELEASE_DATE "2006-03-14"
44+#define NKF_RELEASE_DATE "2006-03-24"
4545 #include "config.h"
4646
4747 #define COPY_RIGHT \
@@ -191,9 +191,9 @@
191191 #define X0201 2
192192 #define ISO8859_1 8
193193 #define NO_X0201 3
194-#define X0212 0x2844
195-#define X0213_1 0x2850
196-#define X0213_2 0x2850
194+#define X0212 0x2844
195+#define X0213_1 0x284F
196+#define X0213_2 0x2850
197197
198198 /* Input Assumption */
199199
@@ -1154,6 +1154,17 @@ options(cp)
11541154 codeset[i] = 0;
11551155 if(strcmp(codeset, "ISO-2022-JP") == 0){
11561156 input_f = JIS_INPUT;
1157+ }else if(strcmp(codeset, "ISO-2022-JP-1") == 0){
1158+ input_f = JIS_INPUT;
1159+#ifdef X0212_ENABLE
1160+ x0212_f = TRUE;
1161+#endif
1162+ }else if(strcmp(codeset, "ISO-2022-JP-3") == 0){
1163+ input_f = JIS_INPUT;
1164+#ifdef X0212_ENABLE
1165+ x0212_f = TRUE;
1166+#endif
1167+ x0213_f = TRUE;
11571168 }else if(strcmp(codeset, "SHIFT_JIS") == 0){
11581169 input_f = SJIS_INPUT;
11591170 if (x0201_f==NO_X0201) x0201_f=TRUE;
@@ -1164,10 +1175,10 @@ options(cp)
11641175 input_f = SJIS_INPUT;
11651176 x0201_f = FALSE;
11661177 #ifdef SHIFTJIS_CP932
1167- cp51932_f = TRUE;
1178+ cp51932_f = TRUE;
11681179 #endif
11691180 #ifdef UTF8_OUTPUT_ENABLE
1170- ms_ucs_map_f = UCS_MAP_CP932;
1181+ ms_ucs_map_f = UCS_MAP_CP932;
11711182 #endif
11721183 }else if(strcmp(codeset, "EUCJP") == 0 ||
11731184 strcmp(codeset, "EUC-JP") == 0){
@@ -1176,10 +1187,10 @@ options(cp)
11761187 input_f = JIS_INPUT;
11771188 x0201_f = FALSE;
11781189 #ifdef SHIFTJIS_CP932
1179- cp51932_f = TRUE;
1190+ cp51932_f = TRUE;
11801191 #endif
11811192 #ifdef UTF8_OUTPUT_ENABLE
1182- ms_ucs_map_f = UCS_MAP_CP932;
1193+ ms_ucs_map_f = UCS_MAP_CP932;
11831194 #endif
11841195 }else if(strcmp(codeset, "EUC-JP-MS") == 0 ||
11851196 strcmp(codeset, "EUCJP-MS") == 0 ||
@@ -1187,27 +1198,27 @@ options(cp)
11871198 input_f = JIS_INPUT;
11881199 x0201_f = FALSE;
11891200 #ifdef SHIFTJIS_CP932
1190- cp51932_f = FALSE;
1201+ cp51932_f = FALSE;
11911202 #endif
11921203 #ifdef UTF8_OUTPUT_ENABLE
1193- ms_ucs_map_f = UCS_MAP_MS;
1204+ ms_ucs_map_f = UCS_MAP_MS;
11941205 #endif
11951206 }else if(strcmp(codeset, "EUC-JP-ASCII") == 0 ||
11961207 strcmp(codeset, "EUCJP-ASCII") == 0){
11971208 input_f = JIS_INPUT;
11981209 x0201_f = FALSE;
11991210 #ifdef SHIFTJIS_CP932
1200- cp51932_f = FALSE;
1211+ cp51932_f = FALSE;
12011212 #endif
12021213 #ifdef UTF8_OUTPUT_ENABLE
1203- ms_ucs_map_f = UCS_MAP_ASCII;
1214+ ms_ucs_map_f = UCS_MAP_ASCII;
12041215 #endif
12051216 }else if(strcmp(codeset, "SHIFT_JISX0213") == 0){
12061217 input_f = SJIS_INPUT;
12071218 x0213_f = TRUE;
12081219 #ifdef SHIFTJIS_CP932
1209- cp51932_f = FALSE;
1210- cp932inv_f = FALSE;
1220+ cp51932_f = FALSE;
1221+ cp932inv_f = FALSE;
12111222 #endif
12121223 if (x0201_f==NO_X0201) x0201_f=TRUE;
12131224 }else if(strcmp(codeset, "EUC-JISX0213") == 0){
@@ -1215,8 +1226,8 @@ options(cp)
12151226 x0201_f = FALSE;
12161227 x0213_f = TRUE;
12171228 #ifdef SHIFTJIS_CP932
1218- cp51932_f = FALSE;
1219- cp932inv_f = FALSE;
1229+ cp51932_f = FALSE;
1230+ cp932inv_f = FALSE;
12201231 #endif
12211232 #ifdef UTF8_INPUT_ENABLE
12221233 }else if(strcmp(codeset, "UTF-8") == 0 ||
@@ -1251,6 +1262,32 @@ options(cp)
12511262 codeset[i] = 0;
12521263 if(strcmp(codeset, "ISO-2022-JP") == 0){
12531264 output_conv = j_oconv;
1265+ }else if(strcmp(codeset, "ISO-2022-JP-1") == 0){
1266+ output_conv = j_oconv;
1267+#ifdef X0212_ENABLE
1268+ x0212_f = TRUE;
1269+#endif
1270+#ifdef SHIFTJIS_CP932
1271+ cp51932_f = FALSE;
1272+#endif
1273+ }else if(strcmp(codeset, "ISO-2022-JP-3") == 0){
1274+ output_conv = j_oconv;
1275+#ifdef X0212_ENABLE
1276+ x0212_f = TRUE;
1277+#endif
1278+ x0213_f = TRUE;
1279+#ifdef SHIFTJIS_CP932
1280+ cp51932_f = FALSE;
1281+#endif
1282+ }else if(strcmp(codeset, "ISO-2022-JP-MS") == 0){
1283+ output_conv = j_oconv;
1284+ x0201_f = FALSE;
1285+#ifdef X0212_ENABLE
1286+ x0212_f = TRUE;
1287+#endif
1288+#ifdef SHIFTJIS_CP932
1289+ cp51932_f = FALSE;
1290+#endif
12541291 }else if(strcmp(codeset, "SHIFT_JIS") == 0){
12551292 output_conv = s_oconv;
12561293 }else if(strcmp(codeset, "WINDOWS-31J") == 0 ||
@@ -1264,7 +1301,7 @@ options(cp)
12641301 cp932inv_f = TRUE;
12651302 #endif
12661303 #ifdef UTF8_OUTPUT_ENABLE
1267- ms_ucs_map_f = UCS_MAP_CP932;
1304+ ms_ucs_map_f = UCS_MAP_CP932;
12681305 #endif
12691306 }else if(strcmp(codeset, "EUCJP") == 0 ||
12701307 strcmp(codeset, "EUC-JP") == 0){
@@ -1276,7 +1313,7 @@ options(cp)
12761313 cp51932_f = TRUE;
12771314 #endif
12781315 #ifdef UTF8_OUTPUT_ENABLE
1279- ms_ucs_map_f = UCS_MAP_CP932;
1316+ ms_ucs_map_f = UCS_MAP_CP932;
12801317 #endif
12811318 }else if(strcmp(codeset, "EUC-JP-MS") == 0 ||
12821319 strcmp(codeset, "EUCJP-MS") == 0 ||
@@ -1303,7 +1340,7 @@ options(cp)
13031340 cp51932_f = FALSE;
13041341 #endif
13051342 #ifdef UTF8_OUTPUT_ENABLE
1306- ms_ucs_map_f = UCS_MAP_ASCII;
1343+ ms_ucs_map_f = UCS_MAP_ASCII;
13071344 #endif
13081345 }else if(strcmp(codeset, "SHIFT_JISX0213") == 0){
13091346 output_conv = s_oconv;
@@ -2483,7 +2520,8 @@ kanji_convert(f)
24832520 /* look like bogus code */
24842521 NEXT;
24852522 }
2486- } else if (input_mode == X0208) {
2523+ } else if (input_mode == X0208 || input_mode == X0212 ||
2524+ input_mode == X0213_1 || input_mode == X0213_2) {
24872525 /* in case of Kanji shifted */
24882526 c2 = c1;
24892527 NEXT;
@@ -2557,6 +2595,14 @@ kanji_convert(f)
25572595 shift_mode = FALSE;
25582596 NEXT;
25592597 #endif /* X0212_ENABLE */
2598+ } else if (c1 == (X0213_1&0x7F)){
2599+ input_mode = X0213_1;
2600+ shift_mode = FALSE;
2601+ NEXT;
2602+ } else if (c1 == (X0213_2&0x7F)){
2603+ input_mode = X0213_2;
2604+ shift_mode = FALSE;
2605+ NEXT;
25602606 } else {
25612607 /* could be some special code */
25622608 (*oconv)(0, ESC);
@@ -2652,21 +2698,31 @@ kanji_convert(f)
26522698 SEND;
26532699 }
26542700 /* send: */
2655- if (input_mode == X0208)
2656- (*oconv)(c2, c1); /* this is JIS, not SJIS/EUC case */
2701+ switch(input_mode){
2702+ case ASCII:
2703+ if ((*iconv)(c2, c1, 0) < 0){ /* can be EUC/SJIS */
2704+ int c0 = (*i_getc)(f);
2705+ if (c0 != EOF){
2706+ code_status(c0);
2707+ (*iconv)(c2, c1, c0);
2708+ }
2709+ }
2710+ break;
2711+ case X0208:
2712+ case X0213_1:
2713+ (*oconv)(c2, c1); /* this is JIS, not SJIS/EUC case */
2714+ break;
26572715 #ifdef X0212_ENABLE
2658- else if (input_mode == X0212)
2659- (*oconv)((0x8f << 8) | c2, c1);
2716+ case X0212:
2717+ (*oconv)((0x8f << 8) | c2, c1);
2718+ break;
26602719 #endif /* X0212_ENABLE */
2661- else if (input_mode)
2662- (*oconv)(input_mode, c1); /* other special case */
2663- else if ((*iconv)(c2, c1, 0) < 0){ /* can be EUC/SJIS */
2664- int c0 = (*i_getc)(f);
2665- if (c0 != EOF){
2666- code_status(c0);
2667- (*iconv)(c2, c1, c0);
2668- }
2669- }
2720+ case X0213_2:
2721+ (*oconv)((0x8f << 8) | c2, c1);
2722+ break;
2723+ default:
2724+ (*oconv)(input_mode, c1); /* other special case */
2725+ }
26702726
26712727 c2 = 0;
26722728 continue;
@@ -2800,8 +2856,6 @@ push_hold_buf(c2)
28002856 return ((hold_count >= HOLD_SIZE*2) ? EOF : hold_count);
28012857 }
28022858
2803-const int shift_jisx0213_s1a3_table[5][2] ={ { 1, 8}, { 3, 4}, { 5,12}, {13,14}, {15, 0} };
2804-
28052859 int s2e_conv(c2, c1, p2, p1)
28062860 int c2, c1;
28072861 int *p2, *p1;
@@ -2809,6 +2863,7 @@ int s2e_conv(c2, c1, p2, p1)
28092863 #if defined(SHIFTJIS_CP932) || defined(X0212_ENABLE)
28102864 int val;
28112865 #endif
2866+ STATIC const int shift_jisx0213_s1a3_table[5][2] ={ { 1, 8}, { 3, 4}, { 5,12}, {13,14}, {15, 0} };
28122867 #ifdef SHIFTJIS_CP932
28132868 if (cp51932_f && CP932_TABLE_BEGIN <= c2 && c2 <= CP932_TABLE_END){
28142869 extern const unsigned short shiftjis_cp932[3][189];
@@ -2820,7 +2875,7 @@ int s2e_conv(c2, c1, p2, p1)
28202875 }
28212876 #endif /* SHIFTJIS_CP932 */
28222877 #ifdef X0212_ENABLE
2823- if (!x0213_f && x0212_f && 0xfa <= c2 && c2 <= 0xfc){
2878+ if (!x0213_f && 0xfa <= c2 && c2 <= 0xfc){
28242879 extern const unsigned short shiftjis_x0212[3][189];
28252880 val = shiftjis_x0212[c2 - 0xfa][c1 - 0x40];
28262881 if (val){
@@ -2857,9 +2912,7 @@ int s2e_conv(c2, c1, p2, p1)
28572912 }
28582913
28592914 #ifdef X0212_ENABLE
2860- if (x0212_f){
2861- c2 = x0212_unshift(c2);
2862- }
2915+ c2 = x0212_unshift(c2);
28632916 #endif
28642917 if (p2) *p2 = c2;
28652918 if (p1) *p1 = c1;
@@ -3649,7 +3702,6 @@ e2s_conv(c2, c1, p2, p1)
36493702 int val = 0;
36503703 const unsigned short *ptr;
36513704 extern const unsigned short *const x0212_shiftjis[];
3652- ndx = c2 & 0x7f;
36533705 ptr = x0212_shiftjis[ndx - 0x21];
36543706 if (ptr){
36553707 val = ptr[(c1 & 0x7f) - 0x21];
@@ -3761,16 +3813,20 @@ j_oconv(c2, c1)
37613813 if(x0213_f){
37623814 if(output_mode!=X0213_2){
37633815 output_mode = X0213_2;
3816+ (*o_putc)(ESC);
3817+ (*o_putc)('$');
3818+ (*o_putc)('(');
3819+ (*o_putc)(X0213_2&0x7F);
37643820 }
37653821 }else{
37663822 if(output_mode!=X0212){
37673823 output_mode = X0212;
3824+ (*o_putc)(ESC);
3825+ (*o_putc)('$');
3826+ (*o_putc)('(');
3827+ (*o_putc)(X0212&0x7F);
37683828 }
37693829 }
3770- (*o_putc)(ESC);
3771- (*o_putc)('$');
3772- (*o_putc)('(');
3773- (*o_putc)(output_mode & 0x7F);
37743830 (*o_putc)(c2 & 0x7f);
37753831 (*o_putc)(c1);
37763832 #endif
@@ -3797,13 +3853,14 @@ j_oconv(c2, c1)
37973853 }
37983854 (*o_putc)(c1);
37993855 } else {
3856+ if(c2<0x20 || 0x7e<c2 || c1<0x20 || 0x7e<c1) return;
38003857 if(x0213_f){
38013858 if (output_mode!=X0213_1) {
38023859 output_mode = X0213_1;
38033860 (*o_putc)(ESC);
38043861 (*o_putc)('$');
38053862 (*o_putc)('(');
3806- (*o_putc)(output_mode & 0x7F);
3863+ (*o_putc)(X0213_1&0x7F);
38073864 }
38083865 }else if (output_mode != X0208) {
38093866 output_mode = X0208;
@@ -3811,10 +3868,6 @@ j_oconv(c2, c1)
38113868 (*o_putc)('$');
38123869 (*o_putc)(kanji_intro);
38133870 }
3814- if (c1<0x20 || 0x7e<c1)
3815- return;
3816- if (c2<0x20 || 0x7e<c2)
3817- return;
38183871 (*o_putc)(c2);
38193872 (*o_putc)(c1);
38203873 }