18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * linux/fs/nls/nls_euc-jp.c 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Added `OSF/JVC Recommended Code Set Conversion Specification 58c2ecf20Sopenharmony_ci * between Japanese EUC and Shift-JIS' support: <hirofumi@mail.parknet.co.jp> 68c2ecf20Sopenharmony_ci * (http://www.opengroup.or.jp/jvc/cde/sjis-euc-e.html) 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/kernel.h> 118c2ecf20Sopenharmony_ci#include <linux/string.h> 128c2ecf20Sopenharmony_ci#include <linux/nls.h> 138c2ecf20Sopenharmony_ci#include <linux/errno.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistatic struct nls_table *p_nls; 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define IS_SJIS_LOW_BYTE(l) ((0x40 <= (l)) && ((l) <= 0xFC) && ((l) != 0x7F)) 188c2ecf20Sopenharmony_ci/* JIS X 0208 (include NEC spesial characters) */ 198c2ecf20Sopenharmony_ci#define IS_SJIS_JISX0208(h, l) ((((0x81 <= (h)) && ((h) <= 0x9F)) \ 208c2ecf20Sopenharmony_ci || ((0xE0 <= (h)) && ((h) <= 0xEA))) \ 218c2ecf20Sopenharmony_ci && IS_SJIS_LOW_BYTE(l)) 228c2ecf20Sopenharmony_ci#define IS_SJIS_JISX0201KANA(c) ((0xA1 <= (c)) && ((c) <= 0xDF)) 238c2ecf20Sopenharmony_ci#define IS_SJIS_UDC_LOW(h, l) (((0xF0 <= (h)) && ((h) <= 0xF4)) \ 248c2ecf20Sopenharmony_ci && IS_SJIS_LOW_BYTE(l)) 258c2ecf20Sopenharmony_ci#define IS_SJIS_UDC_HI(h, l) (((0xF5 <= (h)) && ((h) <= 0xF9)) \ 268c2ecf20Sopenharmony_ci && IS_SJIS_LOW_BYTE(l)) 278c2ecf20Sopenharmony_ci#define IS_SJIS_IBM(h, l) (((0xFA <= (h)) && ((h) <= 0xFC)) \ 288c2ecf20Sopenharmony_ci && IS_SJIS_LOW_BYTE(l)) 298c2ecf20Sopenharmony_ci#define IS_SJIS_NECIBM(h, l) (((0xED <= (h)) && ((h) <= 0xEE)) \ 308c2ecf20Sopenharmony_ci && IS_SJIS_LOW_BYTE(l)) 318c2ecf20Sopenharmony_ci#define MAP_SJIS2EUC(sjis_hi, sjis_lo, sjis_p, euc_hi, euc_lo, euc_p) { \ 328c2ecf20Sopenharmony_ci if ((sjis_lo) >= 0x9F) { \ 338c2ecf20Sopenharmony_ci (euc_hi) = (sjis_hi) * 2 - (((sjis_p) * 2 - (euc_p)) - 1); \ 348c2ecf20Sopenharmony_ci (euc_lo) = (sjis_lo) + 2; \ 358c2ecf20Sopenharmony_ci } else { \ 368c2ecf20Sopenharmony_ci (euc_hi) = (sjis_hi) * 2 - ((sjis_p) * 2 - (euc_p)); \ 378c2ecf20Sopenharmony_ci (euc_lo) = (sjis_lo) + ((sjis_lo) >= 0x7F ? 0x60 : 0x61); \ 388c2ecf20Sopenharmony_ci } \ 398c2ecf20Sopenharmony_ci} while(0) 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define SS2 (0x8E) /* Single Shift 2 */ 428c2ecf20Sopenharmony_ci#define SS3 (0x8F) /* Single Shift 3 */ 438c2ecf20Sopenharmony_ci#define IS_EUC_BYTE(c) ((0xA1 <= (c)) && ((c) <= 0xFE)) 448c2ecf20Sopenharmony_ci#define IS_EUC_JISX0208(h, l) (IS_EUC_BYTE(h) && IS_EUC_BYTE(l)) 458c2ecf20Sopenharmony_ci#define IS_EUC_JISX0201KANA(h, l) (((h) == SS2) && (0xA1 <= (l) && (l) <= 0xDF)) 468c2ecf20Sopenharmony_ci#define IS_EUC_UDC_LOW(h, l) (((0xF5 <= (h)) && ((h) <= 0xFE)) \ 478c2ecf20Sopenharmony_ci && IS_EUC_BYTE(l)) 488c2ecf20Sopenharmony_ci#define IS_EUC_UDC_HI(h, l) IS_EUC_UDC_LOW(h, l) /* G3 block */ 498c2ecf20Sopenharmony_ci#define MAP_EUC2SJIS(euc_hi, euc_lo, euc_p, sjis_hi, sjis_lo, sjis_p) { \ 508c2ecf20Sopenharmony_ci if ((euc_hi) & 1) { \ 518c2ecf20Sopenharmony_ci (sjis_hi) = (euc_hi) / 2 + ((sjis_p) - (euc_p) / 2); \ 528c2ecf20Sopenharmony_ci (sjis_lo) = (euc_lo) - ((euc_lo) >= 0xE0 ? 0x60 : 0x61); \ 538c2ecf20Sopenharmony_ci } else { \ 548c2ecf20Sopenharmony_ci (sjis_hi) = (euc_hi) / 2 + (((sjis_p) - (euc_p) / 2) - 1); \ 558c2ecf20Sopenharmony_ci (sjis_lo) = (euc_lo) - 2; \ 568c2ecf20Sopenharmony_ci } \ 578c2ecf20Sopenharmony_ci} while(0) 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* SJIS IBM extended characters to EUC map */ 608c2ecf20Sopenharmony_cistatic const unsigned char sjisibm2euc_map[][2] = { 618c2ecf20Sopenharmony_ci {0xF3, 0xF3}, {0xF3, 0xF4}, {0xF3, 0xF5}, {0xF3, 0xF6}, {0xF3, 0xF7}, 628c2ecf20Sopenharmony_ci {0xF3, 0xF8}, {0xF3, 0xF9}, {0xF3, 0xFA}, {0xF3, 0xFB}, {0xF3, 0xFC}, 638c2ecf20Sopenharmony_ci {0xF3, 0xFD}, {0xF3, 0xFE}, {0xF4, 0xA1}, {0xF4, 0xA2}, {0xF4, 0xA3}, 648c2ecf20Sopenharmony_ci {0xF4, 0xA4}, {0xF4, 0xA5}, {0xF4, 0xA6}, {0xF4, 0xA7}, {0xF4, 0xA8}, 658c2ecf20Sopenharmony_ci {0xA2, 0xCC}, {0xA2, 0xC3}, {0xF4, 0xA9}, {0xF4, 0xAA}, {0xF4, 0xAB}, 668c2ecf20Sopenharmony_ci {0xF4, 0xAC}, {0xF4, 0xAD}, {0xA2, 0xE8}, {0xD4, 0xE3}, {0xDC, 0xDF}, 678c2ecf20Sopenharmony_ci {0xE4, 0xE9}, {0xE3, 0xF8}, {0xD9, 0xA1}, {0xB1, 0xBB}, {0xF4, 0xAE}, 688c2ecf20Sopenharmony_ci {0xC2, 0xAD}, {0xC3, 0xFC}, {0xE4, 0xD0}, {0xC2, 0xBF}, {0xBC, 0xF4}, 698c2ecf20Sopenharmony_ci {0xB0, 0xA9}, {0xB0, 0xC8}, {0xF4, 0xAF}, {0xB0, 0xD2}, {0xB0, 0xD4}, 708c2ecf20Sopenharmony_ci {0xB0, 0xE3}, {0xB0, 0xEE}, {0xB1, 0xA7}, {0xB1, 0xA3}, {0xB1, 0xAC}, 718c2ecf20Sopenharmony_ci {0xB1, 0xA9}, {0xB1, 0xBE}, {0xB1, 0xDF}, {0xB1, 0xD8}, {0xB1, 0xC8}, 728c2ecf20Sopenharmony_ci {0xB1, 0xD7}, {0xB1, 0xE3}, {0xB1, 0xF4}, {0xB1, 0xE1}, {0xB2, 0xA3}, 738c2ecf20Sopenharmony_ci {0xF4, 0xB0}, {0xB2, 0xBB}, {0xB2, 0xE6}, {0x00, 0x00}, {0xB2, 0xED}, 748c2ecf20Sopenharmony_ci {0xB2, 0xF5}, {0xB2, 0xFC}, {0xF4, 0xB1}, {0xB3, 0xB5}, {0xB3, 0xD8}, 758c2ecf20Sopenharmony_ci {0xB3, 0xDB}, {0xB3, 0xE5}, {0xB3, 0xEE}, {0xB3, 0xFB}, {0xF4, 0xB2}, 768c2ecf20Sopenharmony_ci {0xF4, 0xB3}, {0xB4, 0xC0}, {0xB4, 0xC7}, {0xB4, 0xD0}, {0xB4, 0xDE}, 778c2ecf20Sopenharmony_ci {0xF4, 0xB4}, {0xB5, 0xAA}, {0xF4, 0xB5}, {0xB5, 0xAF}, {0xB5, 0xC4}, 788c2ecf20Sopenharmony_ci {0xB5, 0xE8}, {0xF4, 0xB6}, {0xB7, 0xC2}, {0xB7, 0xE4}, {0xB7, 0xE8}, 798c2ecf20Sopenharmony_ci {0xB7, 0xE7}, {0xF4, 0xB7}, {0xF4, 0xB8}, {0xF4, 0xB9}, {0xB8, 0xCE}, 808c2ecf20Sopenharmony_ci {0xB8, 0xE1}, {0xB8, 0xF5}, {0xB8, 0xF7}, {0xB8, 0xF8}, {0xB8, 0xFC}, 818c2ecf20Sopenharmony_ci {0xB9, 0xAF}, {0xB9, 0xB7}, {0xBA, 0xBE}, {0xBA, 0xDB}, {0xCD, 0xAA}, 828c2ecf20Sopenharmony_ci {0xBA, 0xE1}, {0xF4, 0xBA}, {0xBA, 0xEB}, {0xBB, 0xB3}, {0xBB, 0xB8}, 838c2ecf20Sopenharmony_ci {0xF4, 0xBB}, {0xBB, 0xCA}, {0xF4, 0xBC}, {0xF4, 0xBD}, {0xBB, 0xD0}, 848c2ecf20Sopenharmony_ci {0xBB, 0xDE}, {0xBB, 0xF4}, {0xBB, 0xF5}, {0xBB, 0xF9}, {0xBC, 0xE4}, 858c2ecf20Sopenharmony_ci {0xBC, 0xED}, {0xBC, 0xFE}, {0xF4, 0xBE}, {0xBD, 0xC2}, {0xBD, 0xE7}, 868c2ecf20Sopenharmony_ci {0xF4, 0xBF}, {0xBD, 0xF0}, {0xBE, 0xB0}, {0xBE, 0xAC}, {0xF4, 0xC0}, 878c2ecf20Sopenharmony_ci {0xBE, 0xB3}, {0xBE, 0xBD}, {0xBE, 0xCD}, {0xBE, 0xC9}, {0xBE, 0xE4}, 888c2ecf20Sopenharmony_ci {0xBF, 0xA8}, {0xBF, 0xC9}, {0xC0, 0xC4}, {0xC0, 0xE4}, {0xC0, 0xF4}, 898c2ecf20Sopenharmony_ci {0xC1, 0xA6}, {0xF4, 0xC1}, {0xC1, 0xF5}, {0xC1, 0xFC}, {0xF4, 0xC2}, 908c2ecf20Sopenharmony_ci {0xC1, 0xF8}, {0xC2, 0xAB}, {0xC2, 0xA1}, {0xC2, 0xA5}, {0xF4, 0xC3}, 918c2ecf20Sopenharmony_ci {0xC2, 0xB8}, {0xC2, 0xBA}, {0xF4, 0xC4}, {0xC2, 0xC4}, {0xC2, 0xD2}, 928c2ecf20Sopenharmony_ci {0xC2, 0xD7}, {0xC2, 0xDB}, {0xC2, 0xDE}, {0xC2, 0xED}, {0xC2, 0xF0}, 938c2ecf20Sopenharmony_ci {0xF4, 0xC5}, {0xC3, 0xA1}, {0xC3, 0xB5}, {0xC3, 0xC9}, {0xC3, 0xB9}, 948c2ecf20Sopenharmony_ci {0xF4, 0xC6}, {0xC3, 0xD8}, {0xC3, 0xFE}, {0xF4, 0xC7}, {0xC4, 0xCC}, 958c2ecf20Sopenharmony_ci {0xF4, 0xC8}, {0xC4, 0xD9}, {0xC4, 0xEA}, {0xC4, 0xFD}, {0xF4, 0xC9}, 968c2ecf20Sopenharmony_ci {0xC5, 0xA7}, {0xC5, 0xB5}, {0xC5, 0xB6}, {0xF4, 0xCA}, {0xC5, 0xD5}, 978c2ecf20Sopenharmony_ci {0xC6, 0xB8}, {0xC6, 0xD7}, {0xC6, 0xE0}, {0xC6, 0xEA}, {0xC6, 0xE3}, 988c2ecf20Sopenharmony_ci {0xC7, 0xA1}, {0xC7, 0xAB}, {0xC7, 0xC7}, {0xC7, 0xC3}, {0xC7, 0xCB}, 998c2ecf20Sopenharmony_ci {0xC7, 0xCF}, {0xC7, 0xD9}, {0xF4, 0xCB}, {0xF4, 0xCC}, {0xC7, 0xE6}, 1008c2ecf20Sopenharmony_ci {0xC7, 0xEE}, {0xC7, 0xFC}, {0xC7, 0xEB}, {0xC7, 0xF0}, {0xC8, 0xB1}, 1018c2ecf20Sopenharmony_ci {0xC8, 0xE5}, {0xC8, 0xF8}, {0xC9, 0xA6}, {0xC9, 0xAB}, {0xC9, 0xAD}, 1028c2ecf20Sopenharmony_ci {0xF4, 0xCD}, {0xC9, 0xCA}, {0xC9, 0xD3}, {0xC9, 0xE9}, {0xC9, 0xE3}, 1038c2ecf20Sopenharmony_ci {0xC9, 0xFC}, {0xC9, 0xF4}, {0xC9, 0xF5}, {0xF4, 0xCE}, {0xCA, 0xB3}, 1048c2ecf20Sopenharmony_ci {0xCA, 0xBD}, {0xCA, 0xEF}, {0xCA, 0xF1}, {0xCB, 0xAE}, {0xF4, 0xCF}, 1058c2ecf20Sopenharmony_ci {0xCB, 0xCA}, {0xCB, 0xE6}, {0xCB, 0xEA}, {0xCB, 0xF0}, {0xCB, 0xF4}, 1068c2ecf20Sopenharmony_ci {0xCB, 0xEE}, {0xCC, 0xA5}, {0xCB, 0xF9}, {0xCC, 0xAB}, {0xCC, 0xAE}, 1078c2ecf20Sopenharmony_ci {0xCC, 0xAD}, {0xCC, 0xB2}, {0xCC, 0xC2}, {0xCC, 0xD0}, {0xCC, 0xD9}, 1088c2ecf20Sopenharmony_ci {0xF4, 0xD0}, {0xCD, 0xBB}, {0xF4, 0xD1}, {0xCE, 0xBB}, {0xF4, 0xD2}, 1098c2ecf20Sopenharmony_ci {0xCE, 0xBA}, {0xCE, 0xC3}, {0xF4, 0xD3}, {0xCE, 0xF2}, {0xB3, 0xDD}, 1108c2ecf20Sopenharmony_ci {0xCF, 0xD5}, {0xCF, 0xE2}, {0xCF, 0xE9}, {0xCF, 0xED}, {0xF4, 0xD4}, 1118c2ecf20Sopenharmony_ci {0xF4, 0xD5}, {0xF4, 0xD6}, {0x00, 0x00}, {0xF4, 0xD7}, {0xD0, 0xE5}, 1128c2ecf20Sopenharmony_ci {0xF4, 0xD8}, {0xD0, 0xE9}, {0xD1, 0xE8}, {0xF4, 0xD9}, {0xF4, 0xDA}, 1138c2ecf20Sopenharmony_ci {0xD1, 0xEC}, {0xD2, 0xBB}, {0xF4, 0xDB}, {0xD3, 0xE1}, {0xD3, 0xE8}, 1148c2ecf20Sopenharmony_ci {0xD4, 0xA7}, {0xF4, 0xDC}, {0xF4, 0xDD}, {0xD4, 0xD4}, {0xD4, 0xF2}, 1158c2ecf20Sopenharmony_ci {0xD5, 0xAE}, {0xF4, 0xDE}, {0xD7, 0xDE}, {0xF4, 0xDF}, {0xD8, 0xA2}, 1168c2ecf20Sopenharmony_ci {0xD8, 0xB7}, {0xD8, 0xC1}, {0xD8, 0xD1}, {0xD8, 0xF4}, {0xD9, 0xC6}, 1178c2ecf20Sopenharmony_ci {0xD9, 0xC8}, {0xD9, 0xD1}, {0xF4, 0xE0}, {0xF4, 0xE1}, {0xF4, 0xE2}, 1188c2ecf20Sopenharmony_ci {0xF4, 0xE3}, {0xF4, 0xE4}, {0xDC, 0xD3}, {0xDD, 0xC8}, {0xDD, 0xD4}, 1198c2ecf20Sopenharmony_ci {0xDD, 0xEA}, {0xDD, 0xFA}, {0xDE, 0xA4}, {0xDE, 0xB0}, {0xF4, 0xE5}, 1208c2ecf20Sopenharmony_ci {0xDE, 0xB5}, {0xDE, 0xCB}, {0xF4, 0xE6}, {0xDF, 0xB9}, {0xF4, 0xE7}, 1218c2ecf20Sopenharmony_ci {0xDF, 0xC3}, {0xF4, 0xE8}, {0xF4, 0xE9}, {0xE0, 0xD9}, {0xF4, 0xEA}, 1228c2ecf20Sopenharmony_ci {0xF4, 0xEB}, {0xE1, 0xE2}, {0xF4, 0xEC}, {0xF4, 0xED}, {0xF4, 0xEE}, 1238c2ecf20Sopenharmony_ci {0xE2, 0xC7}, {0xE3, 0xA8}, {0xE3, 0xA6}, {0xE3, 0xA9}, {0xE3, 0xAF}, 1248c2ecf20Sopenharmony_ci {0xE3, 0xB0}, {0xE3, 0xAA}, {0xE3, 0xAB}, {0xE3, 0xBC}, {0xE3, 0xC1}, 1258c2ecf20Sopenharmony_ci {0xE3, 0xBF}, {0xE3, 0xD5}, {0xE3, 0xD8}, {0xE3, 0xD6}, {0xE3, 0xDF}, 1268c2ecf20Sopenharmony_ci {0xE3, 0xE3}, {0xE3, 0xE1}, {0xE3, 0xD4}, {0xE3, 0xE9}, {0xE4, 0xA6}, 1278c2ecf20Sopenharmony_ci {0xE3, 0xF1}, {0xE3, 0xF2}, {0xE4, 0xCB}, {0xE4, 0xC1}, {0xE4, 0xC3}, 1288c2ecf20Sopenharmony_ci {0xE4, 0xBE}, {0xF4, 0xEF}, {0xE4, 0xC0}, {0xE4, 0xC7}, {0xE4, 0xBF}, 1298c2ecf20Sopenharmony_ci {0xE4, 0xE0}, {0xE4, 0xDE}, {0xE4, 0xD1}, {0xF4, 0xF0}, {0xE4, 0xDC}, 1308c2ecf20Sopenharmony_ci {0xE4, 0xD2}, {0xE4, 0xDB}, {0xE4, 0xD4}, {0xE4, 0xFA}, {0xE4, 0xEF}, 1318c2ecf20Sopenharmony_ci {0xE5, 0xB3}, {0xE5, 0xBF}, {0xE5, 0xC9}, {0xE5, 0xD0}, {0xE5, 0xE2}, 1328c2ecf20Sopenharmony_ci {0xE5, 0xEA}, {0xE5, 0xEB}, {0xF4, 0xF1}, {0xF4, 0xF2}, {0xF4, 0xF3}, 1338c2ecf20Sopenharmony_ci {0xE6, 0xE8}, {0xE6, 0xEF}, {0xE7, 0xAC}, {0xF4, 0xF4}, {0xE7, 0xAE}, 1348c2ecf20Sopenharmony_ci {0xF4, 0xF5}, {0xE7, 0xB1}, {0xF4, 0xF6}, {0xE7, 0xB2}, {0xE8, 0xB1}, 1358c2ecf20Sopenharmony_ci {0xE8, 0xB6}, {0xF4, 0xF7}, {0xF4, 0xF8}, {0xE8, 0xDD}, {0xF4, 0xF9}, 1368c2ecf20Sopenharmony_ci {0xF4, 0xFA}, {0xE9, 0xD1}, {0xF4, 0xFB}, {0xE9, 0xED}, {0xEA, 0xCD}, 1378c2ecf20Sopenharmony_ci {0xF4, 0xFC}, {0xEA, 0xDB}, {0xEA, 0xE6}, {0xEA, 0xEA}, {0xEB, 0xA5}, 1388c2ecf20Sopenharmony_ci {0xEB, 0xFB}, {0xEB, 0xFA}, {0xF4, 0xFD}, {0xEC, 0xD6}, {0xF4, 0xFE}, 1398c2ecf20Sopenharmony_ci}; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci#define IS_EUC_IBM2JISX0208(h, l) \ 1428c2ecf20Sopenharmony_ci (((h) == 0xA2 && (l) == 0xCC) || ((h) == 0xA2 && (l) == 0xE8)) 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci/* EUC to SJIS IBM extended characters map (G3 JIS X 0212 block) */ 1458c2ecf20Sopenharmony_cistatic struct { 1468c2ecf20Sopenharmony_ci unsigned short euc; 1478c2ecf20Sopenharmony_ci unsigned char sjis[2]; 1488c2ecf20Sopenharmony_ci} euc2sjisibm_jisx0212_map[] = { 1498c2ecf20Sopenharmony_ci {0xA2C3, {0xFA, 0x55}}, {0xB0A9, {0xFA, 0x68}}, {0xB0C8, {0xFA, 0x69}}, 1508c2ecf20Sopenharmony_ci {0xB0D2, {0xFA, 0x6B}}, {0xB0D4, {0xFA, 0x6C}}, {0xB0E3, {0xFA, 0x6D}}, 1518c2ecf20Sopenharmony_ci {0xB0EE, {0xFA, 0x6E}}, {0xB1A3, {0xFA, 0x70}}, {0xB1A7, {0xFA, 0x6F}}, 1528c2ecf20Sopenharmony_ci {0xB1A9, {0xFA, 0x72}}, {0xB1AC, {0xFA, 0x71}}, {0xB1BB, {0xFA, 0x61}}, 1538c2ecf20Sopenharmony_ci {0xB1BE, {0xFA, 0x73}}, {0xB1C8, {0xFA, 0x76}}, {0xB1D7, {0xFA, 0x77}}, 1548c2ecf20Sopenharmony_ci {0xB1D8, {0xFA, 0x75}}, {0xB1DF, {0xFA, 0x74}}, {0xB1E1, {0xFA, 0x7A}}, 1558c2ecf20Sopenharmony_ci {0xB1E3, {0xFA, 0x78}}, {0xB1F4, {0xFA, 0x79}}, {0xB2A3, {0xFA, 0x7B}}, 1568c2ecf20Sopenharmony_ci {0xB2BB, {0xFA, 0x7D}}, {0xB2E6, {0xFA, 0x7E}}, {0xB2ED, {0xFA, 0x80}}, 1578c2ecf20Sopenharmony_ci {0xB2F5, {0xFA, 0x81}}, {0xB2FC, {0xFA, 0x82}}, {0xB3B5, {0xFA, 0x84}}, 1588c2ecf20Sopenharmony_ci {0xB3D8, {0xFA, 0x85}}, {0xB3DB, {0xFA, 0x86}}, {0xB3DD, {0xFB, 0x77}}, 1598c2ecf20Sopenharmony_ci {0xB3E5, {0xFA, 0x87}}, {0xB3EE, {0xFA, 0x88}}, {0xB3FB, {0xFA, 0x89}}, 1608c2ecf20Sopenharmony_ci {0xB4C0, {0xFA, 0x8C}}, {0xB4C7, {0xFA, 0x8D}}, {0xB4D0, {0xFA, 0x8E}}, 1618c2ecf20Sopenharmony_ci {0xB4DE, {0xFA, 0x8F}}, {0xB5AA, {0xFA, 0x91}}, {0xB5AF, {0xFA, 0x93}}, 1628c2ecf20Sopenharmony_ci {0xB5C4, {0xFA, 0x94}}, {0xB5E8, {0xFA, 0x95}}, {0xB7C2, {0xFA, 0x97}}, 1638c2ecf20Sopenharmony_ci {0xB7E4, {0xFA, 0x98}}, {0xB7E7, {0xFA, 0x9A}}, {0xB7E8, {0xFA, 0x99}}, 1648c2ecf20Sopenharmony_ci {0xB8CE, {0xFA, 0x9E}}, {0xB8E1, {0xFA, 0x9F}}, {0xB8F5, {0xFA, 0xA0}}, 1658c2ecf20Sopenharmony_ci {0xB8F7, {0xFA, 0xA1}}, {0xB8F8, {0xFA, 0xA2}}, {0xB8FC, {0xFA, 0xA3}}, 1668c2ecf20Sopenharmony_ci {0xB9AF, {0xFA, 0xA4}}, {0xB9B7, {0xFA, 0xA5}}, {0xBABE, {0xFA, 0xA6}}, 1678c2ecf20Sopenharmony_ci {0xBADB, {0xFA, 0xA7}}, {0xBAE1, {0xFA, 0xA9}}, {0xBAEB, {0xFA, 0xAB}}, 1688c2ecf20Sopenharmony_ci {0xBBB3, {0xFA, 0xAC}}, {0xBBB8, {0xFA, 0xAD}}, {0xBBCA, {0xFA, 0xAF}}, 1698c2ecf20Sopenharmony_ci {0xBBD0, {0xFA, 0xB2}}, {0xBBDE, {0xFA, 0xB3}}, {0xBBF4, {0xFA, 0xB4}}, 1708c2ecf20Sopenharmony_ci {0xBBF5, {0xFA, 0xB5}}, {0xBBF9, {0xFA, 0xB6}}, {0xBCE4, {0xFA, 0xB7}}, 1718c2ecf20Sopenharmony_ci {0xBCED, {0xFA, 0xB8}}, {0xBCF4, {0xFA, 0x67}}, {0xBCFE, {0xFA, 0xB9}}, 1728c2ecf20Sopenharmony_ci {0xBDC2, {0xFA, 0xBB}}, {0xBDE7, {0xFA, 0xBC}}, {0xBDF0, {0xFA, 0xBE}}, 1738c2ecf20Sopenharmony_ci {0xBEAC, {0xFA, 0xC0}}, {0xBEB0, {0xFA, 0xBF}}, {0xBEB3, {0xFA, 0xC2}}, 1748c2ecf20Sopenharmony_ci {0xBEBD, {0xFA, 0xC3}}, {0xBEC9, {0xFA, 0xC5}}, {0xBECD, {0xFA, 0xC4}}, 1758c2ecf20Sopenharmony_ci {0xBEE4, {0xFA, 0xC6}}, {0xBFA8, {0xFA, 0xC7}}, {0xBFC9, {0xFA, 0xC8}}, 1768c2ecf20Sopenharmony_ci {0xC0C4, {0xFA, 0xC9}}, {0xC0E4, {0xFA, 0xCA}}, {0xC0F4, {0xFA, 0xCB}}, 1778c2ecf20Sopenharmony_ci {0xC1A6, {0xFA, 0xCC}}, {0xC1F5, {0xFA, 0xCE}}, {0xC1F8, {0xFA, 0xD1}}, 1788c2ecf20Sopenharmony_ci {0xC1FC, {0xFA, 0xCF}}, {0xC2A1, {0xFA, 0xD3}}, {0xC2A5, {0xFA, 0xD4}}, 1798c2ecf20Sopenharmony_ci {0xC2AB, {0xFA, 0xD2}}, {0xC2AD, {0xFA, 0x63}}, {0xC2B8, {0xFA, 0xD6}}, 1808c2ecf20Sopenharmony_ci {0xC2BA, {0xFA, 0xD7}}, {0xC2BF, {0xFA, 0x66}}, {0xC2C4, {0xFA, 0xD9}}, 1818c2ecf20Sopenharmony_ci {0xC2D2, {0xFA, 0xDA}}, {0xC2D7, {0xFA, 0xDB}}, {0xC2DB, {0xFA, 0xDC}}, 1828c2ecf20Sopenharmony_ci {0xC2DE, {0xFA, 0xDD}}, {0xC2ED, {0xFA, 0xDE}}, {0xC2F0, {0xFA, 0xDF}}, 1838c2ecf20Sopenharmony_ci {0xC3A1, {0xFA, 0xE1}}, {0xC3B5, {0xFA, 0xE2}}, {0xC3B9, {0xFA, 0xE4}}, 1848c2ecf20Sopenharmony_ci {0xC3C9, {0xFA, 0xE3}}, {0xC3D8, {0xFA, 0xE6}}, {0xC3FC, {0xFA, 0x64}}, 1858c2ecf20Sopenharmony_ci {0xC3FE, {0xFA, 0xE7}}, {0xC4CC, {0xFA, 0xE9}}, {0xC4D9, {0xFA, 0xEB}}, 1868c2ecf20Sopenharmony_ci {0xC4EA, {0xFA, 0xEC}}, {0xC4FD, {0xFA, 0xED}}, {0xC5A7, {0xFA, 0xEF}}, 1878c2ecf20Sopenharmony_ci {0xC5B5, {0xFA, 0xF0}}, {0xC5B6, {0xFA, 0xF1}}, {0xC5D5, {0xFA, 0xF3}}, 1888c2ecf20Sopenharmony_ci {0xC6B8, {0xFA, 0xF4}}, {0xC6D7, {0xFA, 0xF5}}, {0xC6E0, {0xFA, 0xF6}}, 1898c2ecf20Sopenharmony_ci {0xC6E3, {0xFA, 0xF8}}, {0xC6EA, {0xFA, 0xF7}}, {0xC7A1, {0xFA, 0xF9}}, 1908c2ecf20Sopenharmony_ci {0xC7AB, {0xFA, 0xFA}}, {0xC7C3, {0xFA, 0xFC}}, {0xC7C7, {0xFA, 0xFB}}, 1918c2ecf20Sopenharmony_ci {0xC7CB, {0xFB, 0x40}}, {0xC7CF, {0xFB, 0x41}}, {0xC7D9, {0xFB, 0x42}}, 1928c2ecf20Sopenharmony_ci {0xC7E6, {0xFB, 0x45}}, {0xC7EB, {0xFB, 0x48}}, {0xC7EE, {0xFB, 0x46}}, 1938c2ecf20Sopenharmony_ci {0xC7F0, {0xFB, 0x49}}, {0xC7FC, {0xFB, 0x47}}, {0xC8B1, {0xFB, 0x4A}}, 1948c2ecf20Sopenharmony_ci {0xC8E5, {0xFB, 0x4B}}, {0xC8F8, {0xFB, 0x4C}}, {0xC9A6, {0xFB, 0x4D}}, 1958c2ecf20Sopenharmony_ci {0xC9AB, {0xFB, 0x4E}}, {0xC9AD, {0xFB, 0x4F}}, {0xC9CA, {0xFB, 0x51}}, 1968c2ecf20Sopenharmony_ci {0xC9D3, {0xFB, 0x52}}, {0xC9E3, {0xFB, 0x54}}, {0xC9E9, {0xFB, 0x53}}, 1978c2ecf20Sopenharmony_ci {0xC9F4, {0xFB, 0x56}}, {0xC9F5, {0xFB, 0x57}}, {0xC9FC, {0xFB, 0x55}}, 1988c2ecf20Sopenharmony_ci {0xCAB3, {0xFB, 0x59}}, {0xCABD, {0xFB, 0x5A}}, {0xCAEF, {0xFB, 0x5B}}, 1998c2ecf20Sopenharmony_ci {0xCAF1, {0xFB, 0x5C}}, {0xCBAE, {0xFB, 0x5D}}, {0xCBCA, {0xFB, 0x5F}}, 2008c2ecf20Sopenharmony_ci {0xCBE6, {0xFB, 0x60}}, {0xCBEA, {0xFB, 0x61}}, {0xCBEE, {0xFB, 0x64}}, 2018c2ecf20Sopenharmony_ci {0xCBF0, {0xFB, 0x62}}, {0xCBF4, {0xFB, 0x63}}, {0xCBF9, {0xFB, 0x66}}, 2028c2ecf20Sopenharmony_ci {0xCCA5, {0xFB, 0x65}}, {0xCCAB, {0xFB, 0x67}}, {0xCCAD, {0xFB, 0x69}}, 2038c2ecf20Sopenharmony_ci {0xCCAE, {0xFB, 0x68}}, {0xCCB2, {0xFB, 0x6A}}, {0xCCC2, {0xFB, 0x6B}}, 2048c2ecf20Sopenharmony_ci {0xCCD0, {0xFB, 0x6C}}, {0xCCD9, {0xFB, 0x6D}}, {0xCDAA, {0xFA, 0xA8}}, 2058c2ecf20Sopenharmony_ci {0xCDBB, {0xFB, 0x6F}}, {0xCEBA, {0xFB, 0x73}}, {0xCEBB, {0xFB, 0x71}}, 2068c2ecf20Sopenharmony_ci {0xCEC3, {0xFB, 0x74}}, {0xCEF2, {0xFB, 0x76}}, {0xCFD5, {0xFB, 0x78}}, 2078c2ecf20Sopenharmony_ci {0xCFE2, {0xFB, 0x79}}, {0xCFE9, {0xFB, 0x7A}}, {0xCFED, {0xFB, 0x7B}}, 2088c2ecf20Sopenharmony_ci {0xD0E5, {0xFB, 0x81}}, {0xD0E9, {0xFB, 0x83}}, {0xD1E8, {0xFB, 0x84}}, 2098c2ecf20Sopenharmony_ci {0xD1EC, {0xFB, 0x87}}, {0xD2BB, {0xFB, 0x88}}, {0xD3E1, {0xFB, 0x8A}}, 2108c2ecf20Sopenharmony_ci {0xD3E8, {0xFB, 0x8B}}, {0xD4A7, {0xFB, 0x8C}}, {0xD4D4, {0xFB, 0x8F}}, 2118c2ecf20Sopenharmony_ci {0xD4E3, {0xFA, 0x5C}}, {0xD4F2, {0xFB, 0x90}}, {0xD5AE, {0xFB, 0x91}}, 2128c2ecf20Sopenharmony_ci {0xD7DE, {0xFB, 0x93}}, {0xD8A2, {0xFB, 0x95}}, {0xD8B7, {0xFB, 0x96}}, 2138c2ecf20Sopenharmony_ci {0xD8C1, {0xFB, 0x97}}, {0xD8D1, {0xFB, 0x98}}, {0xD8F4, {0xFB, 0x99}}, 2148c2ecf20Sopenharmony_ci {0xD9A1, {0xFA, 0x60}}, {0xD9C6, {0xFB, 0x9A}}, {0xD9C8, {0xFB, 0x9B}}, 2158c2ecf20Sopenharmony_ci {0xD9D1, {0xFB, 0x9C}}, {0xDCD3, {0xFB, 0xA2}}, {0xDCDF, {0xFA, 0x5D}}, 2168c2ecf20Sopenharmony_ci {0xDDC8, {0xFB, 0xA3}}, {0xDDD4, {0xFB, 0xA4}}, {0xDDEA, {0xFB, 0xA5}}, 2178c2ecf20Sopenharmony_ci {0xDDFA, {0xFB, 0xA6}}, {0xDEA4, {0xFB, 0xA7}}, {0xDEB0, {0xFB, 0xA8}}, 2188c2ecf20Sopenharmony_ci {0xDEB5, {0xFB, 0xAA}}, {0xDECB, {0xFB, 0xAB}}, {0xDFB9, {0xFB, 0xAD}}, 2198c2ecf20Sopenharmony_ci {0xDFC3, {0xFB, 0xAF}}, {0xE0D9, {0xFB, 0xB2}}, {0xE1E2, {0xFB, 0xB5}}, 2208c2ecf20Sopenharmony_ci {0xE2C7, {0xFB, 0xB9}}, {0xE3A6, {0xFB, 0xBB}}, {0xE3A8, {0xFB, 0xBA}}, 2218c2ecf20Sopenharmony_ci {0xE3A9, {0xFB, 0xBC}}, {0xE3AA, {0xFB, 0xBF}}, {0xE3AB, {0xFB, 0xC0}}, 2228c2ecf20Sopenharmony_ci {0xE3AF, {0xFB, 0xBD}}, {0xE3B0, {0xFB, 0xBE}}, {0xE3BC, {0xFB, 0xC1}}, 2238c2ecf20Sopenharmony_ci {0xE3BF, {0xFB, 0xC3}}, {0xE3C1, {0xFB, 0xC2}}, {0xE3D4, {0xFB, 0xCA}}, 2248c2ecf20Sopenharmony_ci {0xE3D5, {0xFB, 0xC4}}, {0xE3D6, {0xFB, 0xC6}}, {0xE3D8, {0xFB, 0xC5}}, 2258c2ecf20Sopenharmony_ci {0xE3DF, {0xFB, 0xC7}}, {0xE3E1, {0xFB, 0xC9}}, {0xE3E3, {0xFB, 0xC8}}, 2268c2ecf20Sopenharmony_ci {0xE3E9, {0xFB, 0xCB}}, {0xE3F1, {0xFB, 0xCD}}, {0xE3F2, {0xFB, 0xCE}}, 2278c2ecf20Sopenharmony_ci {0xE3F8, {0xFA, 0x5F}}, {0xE4A6, {0xFB, 0xCC}}, {0xE4BE, {0xFB, 0xD2}}, 2288c2ecf20Sopenharmony_ci {0xE4BF, {0xFB, 0xD6}}, {0xE4C0, {0xFB, 0xD4}}, {0xE4C1, {0xFB, 0xD0}}, 2298c2ecf20Sopenharmony_ci {0xE4C3, {0xFB, 0xD1}}, {0xE4C7, {0xFB, 0xD5}}, {0xE4CB, {0xFB, 0xCF}}, 2308c2ecf20Sopenharmony_ci {0xE4D0, {0xFA, 0x65}}, {0xE4D1, {0xFB, 0xD9}}, {0xE4D2, {0xFB, 0xDC}}, 2318c2ecf20Sopenharmony_ci {0xE4D4, {0xFB, 0xDE}}, {0xE4DB, {0xFB, 0xDD}}, {0xE4DC, {0xFB, 0xDB}}, 2328c2ecf20Sopenharmony_ci {0xE4DE, {0xFB, 0xD8}}, {0xE4E0, {0xFB, 0xD7}}, {0xE4E9, {0xFA, 0x5E}}, 2338c2ecf20Sopenharmony_ci {0xE4EF, {0xFB, 0xE0}}, {0xE4FA, {0xFB, 0xDF}}, {0xE5B3, {0xFB, 0xE1}}, 2348c2ecf20Sopenharmony_ci {0xE5BF, {0xFB, 0xE2}}, {0xE5C9, {0xFB, 0xE3}}, {0xE5D0, {0xFB, 0xE4}}, 2358c2ecf20Sopenharmony_ci {0xE5E2, {0xFB, 0xE5}}, {0xE5EA, {0xFB, 0xE6}}, {0xE5EB, {0xFB, 0xE7}}, 2368c2ecf20Sopenharmony_ci {0xE6E8, {0xFB, 0xEB}}, {0xE6EF, {0xFB, 0xEC}}, {0xE7AC, {0xFB, 0xED}}, 2378c2ecf20Sopenharmony_ci {0xE7AE, {0xFB, 0xEF}}, {0xE7B1, {0xFB, 0xF1}}, {0xE7B2, {0xFB, 0xF3}}, 2388c2ecf20Sopenharmony_ci {0xE8B1, {0xFB, 0xF4}}, {0xE8B6, {0xFB, 0xF5}}, {0xE8DD, {0xFB, 0xF8}}, 2398c2ecf20Sopenharmony_ci {0xE9D1, {0xFB, 0xFB}}, {0xE9ED, {0xFC, 0x40}}, {0xEACD, {0xFC, 0x41}}, 2408c2ecf20Sopenharmony_ci {0xEADB, {0xFC, 0x43}}, {0xEAE6, {0xFC, 0x44}}, {0xEAEA, {0xFC, 0x45}}, 2418c2ecf20Sopenharmony_ci {0xEBA5, {0xFC, 0x46}}, {0xEBFA, {0xFC, 0x48}}, {0xEBFB, {0xFC, 0x47}}, 2428c2ecf20Sopenharmony_ci {0xECD6, {0xFC, 0x4A}}, 2438c2ecf20Sopenharmony_ci}; 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci/* EUC to SJIS IBM extended characters map (G3 Upper block) */ 2468c2ecf20Sopenharmony_cistatic const unsigned char euc2sjisibm_g3upper_map[][2] = { 2478c2ecf20Sopenharmony_ci {0xFA, 0x40}, {0xFA, 0x41}, {0xFA, 0x42}, {0xFA, 0x43}, {0xFA, 0x44}, 2488c2ecf20Sopenharmony_ci {0xFA, 0x45}, {0xFA, 0x46}, {0xFA, 0x47}, {0xFA, 0x48}, {0xFA, 0x49}, 2498c2ecf20Sopenharmony_ci {0xFA, 0x4A}, {0xFA, 0x4B}, {0xFA, 0x4C}, {0xFA, 0x4D}, {0xFA, 0x4E}, 2508c2ecf20Sopenharmony_ci {0xFA, 0x4F}, {0xFA, 0x50}, {0xFA, 0x51}, {0xFA, 0x52}, {0xFA, 0x53}, 2518c2ecf20Sopenharmony_ci {0xFA, 0x56}, {0xFA, 0x57}, {0xFA, 0x58}, {0xFA, 0x59}, {0xFA, 0x5A}, 2528c2ecf20Sopenharmony_ci {0xFA, 0x62}, {0xFA, 0x6A}, {0xFA, 0x7C}, {0xFA, 0x83}, {0xFA, 0x8A}, 2538c2ecf20Sopenharmony_ci {0xFA, 0x8B}, {0xFA, 0x90}, {0xFA, 0x92}, {0xFA, 0x96}, {0xFA, 0x9B}, 2548c2ecf20Sopenharmony_ci {0xFA, 0x9C}, {0xFA, 0x9D}, {0xFA, 0xAA}, {0xFA, 0xAE}, {0xFA, 0xB0}, 2558c2ecf20Sopenharmony_ci {0xFA, 0xB1}, {0xFA, 0xBA}, {0xFA, 0xBD}, {0xFA, 0xC1}, {0xFA, 0xCD}, 2568c2ecf20Sopenharmony_ci {0xFA, 0xD0}, {0xFA, 0xD5}, {0xFA, 0xD8}, {0xFA, 0xE0}, {0xFA, 0xE5}, 2578c2ecf20Sopenharmony_ci {0xFA, 0xE8}, {0xFA, 0xEA}, {0xFA, 0xEE}, {0xFA, 0xF2}, {0xFB, 0x43}, 2588c2ecf20Sopenharmony_ci {0xFB, 0x44}, {0xFB, 0x50}, {0xFB, 0x58}, {0xFB, 0x5E}, {0xFB, 0x6E}, 2598c2ecf20Sopenharmony_ci {0xFB, 0x70}, {0xFB, 0x72}, {0xFB, 0x75}, {0xFB, 0x7C}, {0xFB, 0x7D}, 2608c2ecf20Sopenharmony_ci {0xFB, 0x7E}, {0xFB, 0x80}, {0xFB, 0x82}, {0xFB, 0x85}, {0xFB, 0x86}, 2618c2ecf20Sopenharmony_ci {0xFB, 0x89}, {0xFB, 0x8D}, {0xFB, 0x8E}, {0xFB, 0x92}, {0xFB, 0x94}, 2628c2ecf20Sopenharmony_ci {0xFB, 0x9D}, {0xFB, 0x9E}, {0xFB, 0x9F}, {0xFB, 0xA0}, {0xFB, 0xA1}, 2638c2ecf20Sopenharmony_ci {0xFB, 0xA9}, {0xFB, 0xAC}, {0xFB, 0xAE}, {0xFB, 0xB0}, {0xFB, 0xB1}, 2648c2ecf20Sopenharmony_ci {0xFB, 0xB3}, {0xFB, 0xB4}, {0xFB, 0xB6}, {0xFB, 0xB7}, {0xFB, 0xB8}, 2658c2ecf20Sopenharmony_ci {0xFB, 0xD3}, {0xFB, 0xDA}, {0xFB, 0xE8}, {0xFB, 0xE9}, {0xFB, 0xEA}, 2668c2ecf20Sopenharmony_ci {0xFB, 0xEE}, {0xFB, 0xF0}, {0xFB, 0xF2}, {0xFB, 0xF6}, {0xFB, 0xF7}, 2678c2ecf20Sopenharmony_ci {0xFB, 0xF9}, {0xFB, 0xFA}, {0xFB, 0xFC}, {0xFC, 0x42}, {0xFC, 0x49}, 2688c2ecf20Sopenharmony_ci {0xFC, 0x4B}, 2698c2ecf20Sopenharmony_ci}; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cistatic inline int sjisibm2euc(unsigned char *euc, const unsigned char sjis_hi, 2728c2ecf20Sopenharmony_ci const unsigned char sjis_lo); 2738c2ecf20Sopenharmony_cistatic inline int euc2sjisibm_jisx0212(unsigned char *sjis, const unsigned char euc_hi, 2748c2ecf20Sopenharmony_ci const unsigned char euc_lo); 2758c2ecf20Sopenharmony_cistatic inline int euc2sjisibm_g3upper(unsigned char *sjis, const unsigned char euc_hi, 2768c2ecf20Sopenharmony_ci const unsigned char euc_lo); 2778c2ecf20Sopenharmony_cistatic inline int euc2sjisibm(unsigned char *sjis, const unsigned char euc_hi, 2788c2ecf20Sopenharmony_ci const unsigned char euc_lo); 2798c2ecf20Sopenharmony_cistatic inline int sjisnec2sjisibm(unsigned char *sjisibm, 2808c2ecf20Sopenharmony_ci const unsigned char sjisnec_hi, 2818c2ecf20Sopenharmony_ci const unsigned char sjisnec_lo); 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci/* SJIS IBM extended characters to EUC */ 2848c2ecf20Sopenharmony_cistatic inline int sjisibm2euc(unsigned char *euc, const unsigned char sjis_hi, 2858c2ecf20Sopenharmony_ci const unsigned char sjis_lo) 2868c2ecf20Sopenharmony_ci{ 2878c2ecf20Sopenharmony_ci int index; 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci index = ((sjis_hi - 0xFA) * (0xFD - 0x40)) + (sjis_lo - 0x40); 2908c2ecf20Sopenharmony_ci if (IS_EUC_IBM2JISX0208(sjisibm2euc_map[index][0], 2918c2ecf20Sopenharmony_ci sjisibm2euc_map[index][1])) { 2928c2ecf20Sopenharmony_ci euc[0] = sjisibm2euc_map[index][0]; 2938c2ecf20Sopenharmony_ci euc[1] = sjisibm2euc_map[index][1]; 2948c2ecf20Sopenharmony_ci return 2; 2958c2ecf20Sopenharmony_ci } else { 2968c2ecf20Sopenharmony_ci euc[0] = SS3; 2978c2ecf20Sopenharmony_ci euc[1] = sjisibm2euc_map[index][0]; 2988c2ecf20Sopenharmony_ci euc[2] = sjisibm2euc_map[index][1]; 2998c2ecf20Sopenharmony_ci return 3; 3008c2ecf20Sopenharmony_ci } 3018c2ecf20Sopenharmony_ci} 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci/* EUC to SJIS IBM extended characters (G3 JIS X 0212 block) */ 3048c2ecf20Sopenharmony_cistatic inline int euc2sjisibm_jisx0212(unsigned char *sjis, const unsigned char euc_hi, 3058c2ecf20Sopenharmony_ci const unsigned char euc_lo) 3068c2ecf20Sopenharmony_ci{ 3078c2ecf20Sopenharmony_ci int index, min_index, max_index; 3088c2ecf20Sopenharmony_ci unsigned short euc; 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci min_index = 0; 3118c2ecf20Sopenharmony_ci max_index = ARRAY_SIZE(euc2sjisibm_jisx0212_map) - 1; 3128c2ecf20Sopenharmony_ci euc = (euc_hi << 8) | euc_lo; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci while (min_index <= max_index) { 3158c2ecf20Sopenharmony_ci index = (min_index + max_index) / 2; 3168c2ecf20Sopenharmony_ci if (euc < euc2sjisibm_jisx0212_map[index].euc) 3178c2ecf20Sopenharmony_ci max_index = index - 1; 3188c2ecf20Sopenharmony_ci else 3198c2ecf20Sopenharmony_ci min_index = index + 1; 3208c2ecf20Sopenharmony_ci if (euc == euc2sjisibm_jisx0212_map[index].euc) { 3218c2ecf20Sopenharmony_ci sjis[0] = euc2sjisibm_jisx0212_map[index].sjis[0]; 3228c2ecf20Sopenharmony_ci sjis[1] = euc2sjisibm_jisx0212_map[index].sjis[1]; 3238c2ecf20Sopenharmony_ci return 3; 3248c2ecf20Sopenharmony_ci } 3258c2ecf20Sopenharmony_ci } 3268c2ecf20Sopenharmony_ci return 0; 3278c2ecf20Sopenharmony_ci} 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci/* EUC to SJIS IBM extended characters (G3 Upper block) */ 3308c2ecf20Sopenharmony_cistatic inline int euc2sjisibm_g3upper(unsigned char *sjis, const unsigned char euc_hi, 3318c2ecf20Sopenharmony_ci const unsigned char euc_lo) 3328c2ecf20Sopenharmony_ci{ 3338c2ecf20Sopenharmony_ci int index; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci if (euc_hi == 0xF3) 3368c2ecf20Sopenharmony_ci index = ((euc_hi << 8) | euc_lo) - 0xF3F3; 3378c2ecf20Sopenharmony_ci else 3388c2ecf20Sopenharmony_ci index = ((euc_hi << 8) | euc_lo) - 0xF4A1 + 12; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci if ((index < 0) || (index >= ARRAY_SIZE(euc2sjisibm_g3upper_map))) 3418c2ecf20Sopenharmony_ci return 0; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci sjis[0] = euc2sjisibm_g3upper_map[index][0]; 3448c2ecf20Sopenharmony_ci sjis[1] = euc2sjisibm_g3upper_map[index][1]; 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci return 3; 3478c2ecf20Sopenharmony_ci} 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci/* EUC to SJIS IBM extended characters (G3 block) */ 3508c2ecf20Sopenharmony_cistatic inline int euc2sjisibm(unsigned char *sjis, const unsigned char euc_hi, 3518c2ecf20Sopenharmony_ci const unsigned char euc_lo) 3528c2ecf20Sopenharmony_ci{ 3538c2ecf20Sopenharmony_ci int n; 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci#if 0 3568c2ecf20Sopenharmony_ci if ((euc_hi == 0xA2) && (euc_lo == 0xCC)) { 3578c2ecf20Sopenharmony_ci sjis[0] = 0xFA; 3588c2ecf20Sopenharmony_ci sjis[1] = 0x54; 3598c2ecf20Sopenharmony_ci return 2; 3608c2ecf20Sopenharmony_ci } else if ((euc_hi == 0xA2) && (euc_lo == 0xE8)) { 3618c2ecf20Sopenharmony_ci sjis[0] = 0xFA; 3628c2ecf20Sopenharmony_ci sjis[1] = 0x5B; 3638c2ecf20Sopenharmony_ci return 2; 3648c2ecf20Sopenharmony_ci } 3658c2ecf20Sopenharmony_ci#endif 3668c2ecf20Sopenharmony_ci if ((n = euc2sjisibm_g3upper(sjis, euc_hi, euc_lo))) { 3678c2ecf20Sopenharmony_ci return n; 3688c2ecf20Sopenharmony_ci } else if ((n = euc2sjisibm_jisx0212(sjis, euc_hi, euc_lo))) { 3698c2ecf20Sopenharmony_ci return n; 3708c2ecf20Sopenharmony_ci } 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci return 0; 3738c2ecf20Sopenharmony_ci} 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci/* NEC/IBM extended characters to IBM extended characters */ 3768c2ecf20Sopenharmony_cistatic inline int sjisnec2sjisibm(unsigned char *sjisibm, 3778c2ecf20Sopenharmony_ci const unsigned char sjisnec_hi, 3788c2ecf20Sopenharmony_ci const unsigned char sjisnec_lo) 3798c2ecf20Sopenharmony_ci{ 3808c2ecf20Sopenharmony_ci int count; 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci if (! IS_SJIS_NECIBM(sjisnec_hi, sjisnec_lo)) 3838c2ecf20Sopenharmony_ci return 0; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci if ((sjisnec_hi == 0xEE) && (sjisnec_lo == 0xF9)) { 3868c2ecf20Sopenharmony_ci sjisibm[0] = 0x81; 3878c2ecf20Sopenharmony_ci sjisibm[1] = 0xCA; 3888c2ecf20Sopenharmony_ci return 2; 3898c2ecf20Sopenharmony_ci } 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci if ((sjisnec_hi == 0xEE) && (sjisnec_lo >= 0xEF)) { 3928c2ecf20Sopenharmony_ci count = (sjisnec_hi << 8 | sjisnec_lo) 3938c2ecf20Sopenharmony_ci - (sjisnec_lo <= 0xF9 ? 0xEEEF : (0xEEEF - 10)); 3948c2ecf20Sopenharmony_ci } else { 3958c2ecf20Sopenharmony_ci count = (sjisnec_hi - 0xED) * (0xFC - 0x40) 3968c2ecf20Sopenharmony_ci + (sjisnec_lo - 0x40) + (0x5C - 0x40); 3978c2ecf20Sopenharmony_ci if (sjisnec_lo >= 0x7F) 3988c2ecf20Sopenharmony_ci count--; 3998c2ecf20Sopenharmony_ci } 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci sjisibm[0] = 0xFA + (count / (0xFC - 0x40)); 4028c2ecf20Sopenharmony_ci sjisibm[1] = 0x40 + (count % (0xFC - 0x40)); 4038c2ecf20Sopenharmony_ci if (sjisibm[1] >= 0x7F) 4048c2ecf20Sopenharmony_ci sjisibm[1]++; 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci return 2; 4078c2ecf20Sopenharmony_ci} 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_cistatic int uni2char(const wchar_t uni, 4108c2ecf20Sopenharmony_ci unsigned char *out, int boundlen) 4118c2ecf20Sopenharmony_ci{ 4128c2ecf20Sopenharmony_ci int n; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci if (!p_nls) 4158c2ecf20Sopenharmony_ci return -EINVAL; 4168c2ecf20Sopenharmony_ci if ((n = p_nls->uni2char(uni, out, boundlen)) < 0) 4178c2ecf20Sopenharmony_ci return n; 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci /* translate SJIS into EUC-JP */ 4208c2ecf20Sopenharmony_ci if (n == 1) { 4218c2ecf20Sopenharmony_ci if (IS_SJIS_JISX0201KANA(out[0])) { 4228c2ecf20Sopenharmony_ci /* JIS X 0201 KANA */ 4238c2ecf20Sopenharmony_ci if (boundlen < 2) 4248c2ecf20Sopenharmony_ci return -ENAMETOOLONG; 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci out[1] = out[0]; 4278c2ecf20Sopenharmony_ci out[0] = SS2; 4288c2ecf20Sopenharmony_ci return 2; 4298c2ecf20Sopenharmony_ci } 4308c2ecf20Sopenharmony_ci } else if (n == 2) { 4318c2ecf20Sopenharmony_ci /* NEC/IBM extended characters to IBM extended characters */ 4328c2ecf20Sopenharmony_ci sjisnec2sjisibm(out, out[0], out[1]); 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci if (IS_SJIS_UDC_LOW(out[0], out[1])) { 4358c2ecf20Sopenharmony_ci /* User defined characters half low */ 4368c2ecf20Sopenharmony_ci MAP_SJIS2EUC(out[0], out[1], 0xF0, out[0], out[1], 0xF5); 4378c2ecf20Sopenharmony_ci } else if (IS_SJIS_UDC_HI(out[0], out[1])) { 4388c2ecf20Sopenharmony_ci /* User defined characters half high */ 4398c2ecf20Sopenharmony_ci unsigned char ch, cl; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci if (boundlen < 3) 4428c2ecf20Sopenharmony_ci return -ENAMETOOLONG; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci n = 3; ch = out[0]; cl = out[1]; 4458c2ecf20Sopenharmony_ci out[0] = SS3; 4468c2ecf20Sopenharmony_ci MAP_SJIS2EUC(ch, cl, 0xF5, out[1], out[2], 0xF5); 4478c2ecf20Sopenharmony_ci } else if (IS_SJIS_IBM(out[0], out[1])) { 4488c2ecf20Sopenharmony_ci /* IBM extended characters */ 4498c2ecf20Sopenharmony_ci unsigned char euc[3], i; 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci n = sjisibm2euc(euc, out[0], out[1]); 4528c2ecf20Sopenharmony_ci if (boundlen < n) 4538c2ecf20Sopenharmony_ci return -ENAMETOOLONG; 4548c2ecf20Sopenharmony_ci for (i = 0; i < n; i++) 4558c2ecf20Sopenharmony_ci out[i] = euc[i]; 4568c2ecf20Sopenharmony_ci } else if (IS_SJIS_JISX0208(out[0], out[1])) { 4578c2ecf20Sopenharmony_ci /* JIS X 0208 (include NEC special characters) */ 4588c2ecf20Sopenharmony_ci out[0] = (out[0]^0xA0)*2 + 0x5F; 4598c2ecf20Sopenharmony_ci if (out[1] > 0x9E) 4608c2ecf20Sopenharmony_ci out[0]++; 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci if (out[1] < 0x7F) 4638c2ecf20Sopenharmony_ci out[1] = out[1] + 0x61; 4648c2ecf20Sopenharmony_ci else if (out[1] < 0x9F) 4658c2ecf20Sopenharmony_ci out[1] = out[1] + 0x60; 4668c2ecf20Sopenharmony_ci else 4678c2ecf20Sopenharmony_ci out[1] = out[1] + 0x02; 4688c2ecf20Sopenharmony_ci } else { 4698c2ecf20Sopenharmony_ci /* Invalid characters */ 4708c2ecf20Sopenharmony_ci return -EINVAL; 4718c2ecf20Sopenharmony_ci } 4728c2ecf20Sopenharmony_ci } 4738c2ecf20Sopenharmony_ci else 4748c2ecf20Sopenharmony_ci return -EINVAL; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci return n; 4778c2ecf20Sopenharmony_ci} 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_cistatic int char2uni(const unsigned char *rawstring, int boundlen, 4808c2ecf20Sopenharmony_ci wchar_t *uni) 4818c2ecf20Sopenharmony_ci{ 4828c2ecf20Sopenharmony_ci unsigned char sjis_temp[2]; 4838c2ecf20Sopenharmony_ci int euc_offset, n; 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci if ( !p_nls ) 4868c2ecf20Sopenharmony_ci return -EINVAL; 4878c2ecf20Sopenharmony_ci if (boundlen <= 0) 4888c2ecf20Sopenharmony_ci return -ENAMETOOLONG; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci /* translate EUC-JP into SJIS */ 4918c2ecf20Sopenharmony_ci if (rawstring[0] > 0x7F) { 4928c2ecf20Sopenharmony_ci if (rawstring[0] == SS3) { 4938c2ecf20Sopenharmony_ci if (boundlen < 3) 4948c2ecf20Sopenharmony_ci return -EINVAL; 4958c2ecf20Sopenharmony_ci euc_offset = 3; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci if (IS_EUC_UDC_HI(rawstring[1], rawstring[2])) { 4988c2ecf20Sopenharmony_ci /* User defined characters half high */ 4998c2ecf20Sopenharmony_ci MAP_EUC2SJIS(rawstring[1], rawstring[2], 0xF5, 5008c2ecf20Sopenharmony_ci sjis_temp[0], sjis_temp[1], 0xF5); 5018c2ecf20Sopenharmony_ci } else if (euc2sjisibm(sjis_temp,rawstring[1],rawstring[2])) { 5028c2ecf20Sopenharmony_ci /* IBM extended characters */ 5038c2ecf20Sopenharmony_ci } else { 5048c2ecf20Sopenharmony_ci /* JIS X 0212 and Invalid characters*/ 5058c2ecf20Sopenharmony_ci return -EINVAL; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci /* 'GETA' with SJIS coding */ 5088c2ecf20Sopenharmony_ci /* sjis_temp[0] = 0x81; */ 5098c2ecf20Sopenharmony_ci /* sjis_temp[1] = 0xAC; */ 5108c2ecf20Sopenharmony_ci } 5118c2ecf20Sopenharmony_ci } else { 5128c2ecf20Sopenharmony_ci if (boundlen < 2) 5138c2ecf20Sopenharmony_ci return -EINVAL; 5148c2ecf20Sopenharmony_ci euc_offset = 2; 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci if (IS_EUC_JISX0201KANA(rawstring[0], rawstring[1])) { 5178c2ecf20Sopenharmony_ci /* JIS X 0201 KANA */ 5188c2ecf20Sopenharmony_ci sjis_temp[0] = rawstring[1]; 5198c2ecf20Sopenharmony_ci sjis_temp[1] = 0x00; 5208c2ecf20Sopenharmony_ci } else if (IS_EUC_UDC_LOW(rawstring[0], rawstring[1])) { 5218c2ecf20Sopenharmony_ci /* User defined characters half low */ 5228c2ecf20Sopenharmony_ci MAP_EUC2SJIS(rawstring[0], rawstring[1], 0xF5, 5238c2ecf20Sopenharmony_ci sjis_temp[0], sjis_temp[1], 0xF0); 5248c2ecf20Sopenharmony_ci } else if (IS_EUC_JISX0208(rawstring[0], rawstring[1])) { 5258c2ecf20Sopenharmony_ci /* JIS X 0208 (include NEC spesial characters) */ 5268c2ecf20Sopenharmony_ci sjis_temp[0] = ((rawstring[0]-0x5f)/2) ^ 0xA0; 5278c2ecf20Sopenharmony_ci if (!(rawstring[0] & 1)) 5288c2ecf20Sopenharmony_ci sjis_temp[1] = rawstring[1] - 0x02; 5298c2ecf20Sopenharmony_ci else if (rawstring[1] < 0xE0) 5308c2ecf20Sopenharmony_ci sjis_temp[1] = rawstring[1] - 0x61; 5318c2ecf20Sopenharmony_ci else 5328c2ecf20Sopenharmony_ci sjis_temp[1] = rawstring[1] - 0x60; 5338c2ecf20Sopenharmony_ci } else { 5348c2ecf20Sopenharmony_ci /* Invalid characters */ 5358c2ecf20Sopenharmony_ci return -EINVAL; 5368c2ecf20Sopenharmony_ci } 5378c2ecf20Sopenharmony_ci } 5388c2ecf20Sopenharmony_ci } else { 5398c2ecf20Sopenharmony_ci euc_offset = 1; 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci /* JIS X 0201 ROMAJI */ 5428c2ecf20Sopenharmony_ci sjis_temp[0] = rawstring[0]; 5438c2ecf20Sopenharmony_ci sjis_temp[1] = 0x00; 5448c2ecf20Sopenharmony_ci } 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ci if ( (n = p_nls->char2uni(sjis_temp, sizeof(sjis_temp), uni)) < 0) 5478c2ecf20Sopenharmony_ci return n; 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci return euc_offset; 5508c2ecf20Sopenharmony_ci} 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_cistatic struct nls_table table = { 5538c2ecf20Sopenharmony_ci .charset = "euc-jp", 5548c2ecf20Sopenharmony_ci .uni2char = uni2char, 5558c2ecf20Sopenharmony_ci .char2uni = char2uni, 5568c2ecf20Sopenharmony_ci}; 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_cistatic int __init init_nls_euc_jp(void) 5598c2ecf20Sopenharmony_ci{ 5608c2ecf20Sopenharmony_ci p_nls = load_nls("cp932"); 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci if (p_nls) { 5638c2ecf20Sopenharmony_ci table.charset2upper = p_nls->charset2upper; 5648c2ecf20Sopenharmony_ci table.charset2lower = p_nls->charset2lower; 5658c2ecf20Sopenharmony_ci return register_nls(&table); 5668c2ecf20Sopenharmony_ci } 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci return -EINVAL; 5698c2ecf20Sopenharmony_ci} 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_cistatic void __exit exit_nls_euc_jp(void) 5728c2ecf20Sopenharmony_ci{ 5738c2ecf20Sopenharmony_ci unregister_nls(&table); 5748c2ecf20Sopenharmony_ci unload_nls(p_nls); 5758c2ecf20Sopenharmony_ci} 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_cimodule_init(init_nls_euc_jp) 5788c2ecf20Sopenharmony_cimodule_exit(exit_nls_euc_jp) 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ciMODULE_LICENSE("Dual BSD/GPL"); 581