+ * Convert to EUC-JP
+ */
+#ifdef USE_XIM
+static void convert_to_euc(char *buf)
+{
+ size_t inlen = strlen(buf);
+ size_t outlen = inlen + 1;
+ char tmp[outlen];
+
+ iconv_t iconvd = iconv_open("EUC-JP", "UTF-8");
+ char *inbuf = buf;
+ char *outbuf = tmp;
+ iconv(iconvd, &inbuf, &inlen, &outbuf, &outlen);
+ iconv_close(iconvd);
+
+ int i, l = strlen(tmp);
+ for (i = 0; i < l; i++)
+ buf[i] = tmp[i];
+ buf[l] = '\0';
+}
+#endif
+
+// ゲーム側へキーを送る
+static void send_key(const char key)
+{
+ // Windows ドライバと同様、自前でキューを操作する。
+ // 逆順に term_key_push() する方法だと長い日本語を入力したときにテキストの
+ // 順序が入れ替わってしまう。
+
+ // キーバッファが一杯なら入力を捨てる
+ const int head_nxt = Term->key_head + 1 == Term->key_size ? 0 : Term->key_head + 1;
+ if(head_nxt == Term->key_tail) {
+ plog_fmt("key buffer overflow, ignoring key 0x%02X", key);
+ return;
+ }
+
+ Term->key_queue[Term->key_head] = key;
+ Term->key_head = head_nxt;
+}
+
+// ゲーム側へキー列を送る
+static void send_keys(const char* const keys)
+{
+ for(const char* p = keys; *p != '\0'; ++p)
+ send_key(*p);
+}
+
+/*