X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fjapanese.c;h=4e0c0b1a2ddcdcedf45d899e8b73b6c92e5d30ec;hb=b3317ce27a28a6d78ffccf52460ab56d95c83e09;hp=01f2efae7ff06a1572f6a4e8e45642b34e1ced82;hpb=c7b2453c02694e8bb0588d7688fe66b64972558a;p=hengband%2Fhengband.git
diff --git a/src/japanese.c b/src/japanese.c
index 01f2efae7..4e0c0b1a2 100644
--- a/src/japanese.c
+++ b/src/japanese.c
@@ -1,5 +1,8 @@
-/* File: japanese.c */
-
+/*!
+ * @file japanese.c
+ * @brief æ¥æ¬èªå¦çé¢æ°
+ * @date 2014/07/07
+ */
#include "angband.h"
@@ -9,8 +12,8 @@ typedef struct convert_key convert_key;
struct convert_key
{
- cptr key1;
- cptr key2;
+ concptr key1;
+ concptr key2;
};
static const convert_key s2j_table[] = {
@@ -53,20 +56,26 @@ static const convert_key s2j_table[] = {
{NULL,NULL}
};
-/* ã·ã³ããªã³ãæ¥æ¬èªã®èªã¿ã«å¤æãã */
-void sindarin_to_kana(char *kana, const char *sindarin)
+/*!
+ * @brief ã·ã³ããªã³ãæ¥æ¬èªã®èªã¿ã«å¤æãã
+ * @param kana å¤æå¾ã®æ¥æ¬èªæååãã¤ã³ã¿
+ * @param sindarin å¤æåã®ã·ã³ããªã³æååãã¤ã³ã¿
+ * @return ãªã
+ * @details
+ */
+void sindarin_to_kana(char *kana, concptr sindarin)
{
char buf[256];
int idx;
sprintf(kana, "%s$", sindarin);
for (idx = 0; kana[idx]; idx++)
- if (isupper(kana[idx])) kana[idx] = tolower(kana[idx]);
+ if (isupper(kana[idx])) kana[idx] = (char)tolower(kana[idx]);
for (idx = 0; s2j_table[idx].key1 != NULL; idx++)
{
- cptr pat1 = s2j_table[idx].key1;
- cptr pat2 = s2j_table[idx].key2;
+ concptr pat1 = s2j_table[idx].key1;
+ concptr pat2 = s2j_table[idx].key2;
int len = strlen(pat1);
char *src = kana;
char *dest = buf;
@@ -105,11 +114,10 @@ void sindarin_to_kana(char *kana, const char *sindarin)
}
-/*æ¥æ¬èªåè©æ´»ç¨ (æã¤ï¼æã£ã¦,æã¡ etc) */
-/* JVERB_AND: æ®´ã,è¹´ã > æ®´ã,è¹´ã */
-/* JVERB_TO: æ®´ã,è¹´ã > æ®´ã£ã¦è¹´ã */
-/* JVERB_OR: æ®´ã,è¹´ã > æ®´ã£ããè¹´ã£ãã */
-
+/*! æ¥æ¬èªåè©æ´»ç¨ (æã¤ï¼æã£ã¦,æã¡ etc)
+ * JVERB_AND: æ®´ã,è¹´ã > æ®´ã,è¹´ã
+ * JVERB_TO: æ®´ã,è¹´ã > æ®´ã£ã¦è¹´ã
+ * JVERB_OR: æ®´ã,è¹´ã > æ®´ã£ããè¹´ã£ãã */
static const struct jverb_table_t {
const char* from;
const char* to[3];
@@ -145,7 +153,15 @@ static const struct jverb_table_t {
{ NULL, {"ããã¦", "ãã¨ã«ãã", "ãã¨ã"}},
};
-void jverb(const char *in , char *out , int flag)
+/*!
+ * @brief jverb_table_tã«å¾ã£ã¦åè©ãæ´»ç¨ãã
+ * @param in å¤æå
æååãã¤ã³ã¿
+ * @param out å¤æå
æååãã¤ã³ã¿
+ * @param flag å¤æ種é¡ãæå®(JVERB_AND/JVERB_TO/JVERB_OR)
+ * @return ãªã
+ * @details
+ */
+void jverb(concptr in, char *out, int flag)
{
const struct jverb_table_t * p;
int in_len = strlen(in);
@@ -164,9 +180,11 @@ void jverb(const char *in , char *out , int flag)
strcpy(&out[in_len], p->to[flag - 1]);
}
-
-/*
- * Convert SJIS string to EUC string
+/*!
+ * @brief æåã³ã¼ããSJISããEUCã«å¤æãã / Convert SJIS string to EUC string
+ * @param str å¤æããæååã®ãã¤ã³ã¿
+ * @return ãªã
+ * @details
*/
void sjis2euc(char *str)
{
@@ -208,8 +226,11 @@ void sjis2euc(char *str)
}
-/*
- * Convert EUC string to SJIS string
+/*!
+ * @brief æåã³ã¼ããEUCããSJISã«å¤æãã / Convert EUC string to SJIS string
+ * @param str å¤æããæååã®ãã¤ã³ã¿
+ * @return ãªã
+ * @details
*/
void euc2sjis(char *str)
{
@@ -252,14 +273,14 @@ void euc2sjis(char *str)
}
-/*
- * strãç°å¢ã«åã£ãæåã³ã¼ãã«å¤æããå¤æåã®æåã³ã¼ããè¿ãã
- * strã®é·ãã«å¶éã¯ãªãã
- *
- * 0: Unknown
- * 1: ASCII (Never known to be ASCII in this function.)
- * 2: EUC
- * 3: SJIS
+/*!
+ * @brief strãç°å¢ã«åã£ãæåã³ã¼ãã«å¤æããå¤æåã®æåã³ã¼ããè¿ããstrã®é·ãã«å¶éã¯ãªãã
+ * @param str å¤æããæååã®ãã¤ã³ã¿
+ * @return
+ * 0: Unknown
+ * 1: ASCII (Never known to be ASCII in this function.)
+ * 2: EUC
+ * 3: SJIS
*/
byte codeconv(char *str)
{
@@ -343,8 +364,13 @@ byte codeconv(char *str)
return code;
}
-/* æååsã®xãã¤ãç®ãæ¼¢åã®1ãã¤ãç®ãã©ããå¤å®ãã */
-bool iskanji2(cptr s, int x)
+/*!
+ * @brief æååsã®xãã¤ãç®ãæ¼¢åã®1ãã¤ãç®ãã©ããå¤å®ãã
+ * @param s å¤å®ããæååã®ãã¤ã³ã¿
+ * @param x å¤å®ããä½ç½®(ãã¤ã)
+ * @return æ¼¢åã®1ãã¤ãç®ãªãã°TRUE
+ */
+bool iskanji2(concptr s, int x)
{
int i;
@@ -362,7 +388,7 @@ bool iskanji2(cptr s, int x)
* @param str å¤å®ããæååã¸ã®ãã¤ã³ã¿
* @return æååã®æåã³ã¼ããASCIIãªãTRUEãããã§ãªããã°FALSE
*/
-static bool is_ascii_str(cptr str)
+static bool is_ascii_str(concptr str)
{
for (;*str; str++) {
if (!(0x00 < *str && *str <= 0x7f))
@@ -376,7 +402,7 @@ static bool is_ascii_str(cptr str)
* @param str å¤å®ããæååã¸ã®ãã¤ã³ã¿
* @return æååã®æåã³ã¼ããUTF-8ãªãTRUEãããã§ãªããã°FALSE
*/
-static bool is_utf8_str(cptr str)
+static bool is_utf8_str(concptr str)
{
const unsigned char* p;
for (p = (const unsigned char*)str; *p; p++) {
@@ -398,6 +424,44 @@ static bool is_utf8_str(cptr str)
#if defined(EUC)
#include
+
+static const struct ms_to_jis_unicode_conv_t {
+ char from[3];
+ char to[3];
+} ms_to_jis_unicode_conv[] = {
+ {{0xef, 0xbd, 0x9e}, {0xe3, 0x80, 0x9c}}, /* FULLWIDTH TILDE -> WAVE DASH */
+ {{0xef, 0xbc, 0x8d}, {0xe2, 0x88, 0x92}}, /* FULLWIDTH HYPHEN-MINUS -> MINUS SIGN */
+};
+
+/*!
+ * @brief EUCãã·ã¹ãã ã³ã¼ãã§ããç°å¢ä¸åãã«UTF-8ããå¤æå¦çãè¡ããµãã«ã¼ãã³
+ * @param str å¤æããæååã®ãã¤ã³ã¿
+ * @return ãªã
+ */
+static void ms_to_jis_unicode(char* str)
+{
+ unsigned char* p;
+ for (p = (unsigned char*)str; *p; p++) {
+ int subseq_num = 0;
+ if (0x00 < *p && *p <= 0x7f) continue;
+
+ if ((*p & 0xe0) == 0xc0) subseq_num = 1;
+ if ((*p & 0xf0) == 0xe0) {
+ int i;
+ for (i = 0; i < sizeof(ms_to_jis_unicode_conv) / sizeof(ms_to_jis_unicode_conv[0]); ++ i) {
+ const struct ms_to_jis_unicode_conv_t *c = &ms_to_jis_unicode_conv[i];
+ if (memcmp(p, c->from, 3) == 0) {
+ memcpy(p, c->to, 3);
+ }
+ }
+ subseq_num = 2;
+ }
+ if ((*p & 0xf8) == 0xf0) subseq_num = 3;
+
+ p += subseq_num;
+ }
+}
+
#elif defined(SJIS) && defined(WINDOWS)
#include
#endif
@@ -412,12 +476,15 @@ static bool utf8_to_sys(char* utf8_str, char* sys_str_buffer, size_t sys_str_buf
{
#if defined(EUC)
- iconv_t cd = iconv_open("EUC-JP", "UTF-8");
- size_t utf8_len = strlen(utf8_str) + 1; /* include termination character */
- char *from = utf8_str;
- int ret = iconv(cd, &from, &utf8_len, &sys_str_buffer, &sys_str_buflen);
- iconv_close(cd);
- return (ret >= 0);
+ iconv_t cd = iconv_open("EUC-JP", "UTF-8");
+ size_t utf8_len = strlen(utf8_str) + 1; /* include termination character */
+ char *from = utf8_str;
+ int ret;
+
+ ms_to_jis_unicode(utf8_str);
+ ret = iconv(cd, &from, &utf8_len, &sys_str_buffer, &sys_str_buflen);
+ iconv_close(cd);
+ return (ret >= 0);
#elif defined(SJIS) && defined(WINDOWS)