* XXX XXX XXX Consider the use of "savetty()" and "resetty()".
*/
-#include "angband.h"
+#include "system/angband.h"
+#include "game-option/runtime-arguments.h"
+#include "game-option/special-options.h"
#include "io/exit-panic.h"
-#include "files.h"
-#include "gameterm.h"
+#include "io/files-util.h"
+#include "main/sound-definitions-table.h"
+#include "main/sound-of-music.h"
+#include "term/gameterm.h"
+#include "term/term-color-types.h"
+#include "util/angband-files.h"
+#include "view/display-map.h"
#ifdef USE_GCU
/*
* Include the proper "header" file
*/
-# include <curses.h>
+#include <curses.h>
+#include <iconv.h>
typedef struct term_data term_data;
struct term_data
{
- term t;
+ term_type t;
WINDOW *win;
};
#define MAX_TERM_DATA 4
static term_data data[MAX_TERM_DATA];
-
+static iconv_t iconv_to_sys;
+static iconv_t iconv_to_gui;
/*
* Hack -- try to guess which systems use what commands
* Mega-Hack -- try to guess when "POSIX" is available.
* If the user defines two of these, we will probably crash.
*/
-#if !defined(USE_TERMIO) && !defined(USE_TCHARS)
+#if !defined(USE_TCHARS)
# if defined(_POSIX_VERSION)
# define USE_TPOSIX
# else
/* #define nonl() */
/* #define nl() */
- /*
- * Standard sound names
- */
-static const concptr angband_sound_name[SOUND_MAX] =
-{
- "dummy",
- "hit",
- "miss",
- "flee",
- "drop",
- "kill",
- "level",
- "death",
- "study",
- "teleport",
- "shoot",
- "quaff",
- "zap",
- "walk",
- "tpother",
- "hitwall",
- "eat",
- "store1",
- "store2",
- "store3",
- "store4",
- "dig",
- "opendoor",
- "shutdoor",
- "tplevel",
- "scroll",
- "buy",
- "sell",
- "warn",
- "rocket",
- "n_kill",
- "u_kill",
- "quest",
- "heal",
- "x_heal",
- "bite",
- "claw",
- "m_spell",
- "summon",
- "breath",
- "ball",
- "m_heal",
- "atkspell",
- "evil",
- "touch",
- "sting",
- "crush",
- "slime",
- "wail",
- "winner",
- "fire",
- "acid",
- "elec",
- "cold",
- "illegal",
- "fail",
- "wakeup",
- "invuln",
- "fall",
- "pain",
- "destitem",
- "moan",
- "show",
- "unused",
- "explode",
- "glass",
- "reflect",
-};
-
static concptr ANGBAND_DIR_XTRA_SOUND;
/*
nl();
/* Hack -- make sure the cursor is visible */
- Term_xtra(TERM_XTRA_SHAPE, 1);
+ term_xtra(TERM_XTRA_SHAPE, 1);
/* Flush the curses buffer */
(void)refresh();
/*
* Init the "curses" system
*/
-static void Term_init_gcu(term *t)
+static void Term_init_gcu(term_type *t)
{
term_data *td = (term_data *)(t->data);
/*
* Nuke the "curses" system
*/
-static void Term_nuke_gcu(term *t)
+static void Term_nuke_gcu(term_type *t)
{
term_data *td = (term_data *)(t->data);
if (--active != 0) return;
/* Hack -- make sure the cursor is visible */
- Term_xtra(TERM_XTRA_SHAPE, 1);
+ term_xtra(TERM_XTRA_SHAPE, 1);
#ifdef A_COLOR
/* Reset colors to defaults */
keymap_norm();
}
+/*
+ * Convert to EUC-JP
+ */
+static void convert_to_sys(char *buf)
+{
+ size_t inlen = strlen(buf);
+ size_t outlen = inlen;
+ char tmp[outlen + 1];
+
+ char *inbuf = buf;
+ char *outbuf = tmp;
+ size_t res;
+ res = iconv(iconv_to_sys, 0, 0, 0, 0);
+ if(res == (size_t)-1) return;
+ res = iconv(iconv_to_sys, &inbuf, &inlen, &outbuf, &outlen);
+ if(res == (size_t)-1) return;
+ res = iconv(iconv_to_sys, 0, 0, &outbuf, &outlen);
+ if(res == (size_t)-1) return;
+
+ outbuf[0] = '\0';
+ strcpy(buf, tmp);
+}
+
+/*
+ * Push multiple keys reversal
+ */
+static void term_string_push(char *buf)
+{
+ int i, l = strlen(buf);
+ for (i = l; i >= 0; i--)
+ term_key_push(buf[i]);
+}
+
#ifdef USE_GETCH
/*
/* Wait */
if (v)
{
+ char buf[256];
+ char *bp = buf;
+
/* Paranoia -- Wait for it */
nodelay(stdscr, FALSE);
/* Get a keypress */
i = getch();
- /* Mega-Hack -- allow graceful "suspend" */
- for (k = 0; (k < 10) && (i == ERR); k++) i = getch();
-
/* Broken input is special */
if (i == ERR) exit_game_panic(p_ptr);
if (i == EOF) exit_game_panic(p_ptr);
+
+ *bp++ = (char)i;
+
+ /* Do not wait for it */
+ nodelay(stdscr, TRUE);
+
+ while((i = getch()) != EOF)
+ {
+ if (i == ERR) exit_game_panic(p_ptr);
+ *bp++ = (char)i;
+ if (bp == &buf[255]) break;
+ }
+
+ /* Wait for it next time */
+ nodelay(stdscr, FALSE);
+
+ *bp = '\0';
+ convert_to_sys(buf);
+ term_string_push(buf);
}
/* Do not wait */
/* None ready */
if (i == ERR) return (1);
if (i == EOF) return (1);
- }
- /* Enqueue the keypress */
- Term_keypress(i);
+ /* Enqueue the keypress */
+ term_key_push(i);
+ }
/* Success */
return (0);
{
int i, k;
- char buf[2];
+ char buf[256];
/* Wait */
if (v)
{
+ char *bp = buf;
+
/* Wait for one byte */
- i = read(0, buf, 1);
+ i = read(0, bp++, 1);
/* Hack -- Handle bizarre "errors" */
if ((i <= 0) && (errno != EINTR)) exit_game_panic(p_ptr);
+
+ /* Get the current flags for stdin */
+ k = fcntl(0, F_GETFL, 0);
+
+ /* Oops */
+ if (k < 0) return (1);
+
+ /* Tell stdin not to block */
+ if (fcntl(0, F_SETFL, k | O_NDELAY) >= 0)
+ {
+ if ((i = read(0, bp, 254)) > 0)
+ {
+ bp += i;
+ }
+
+ /* Replace the flags for stdin */
+ if (fcntl(0, F_SETFL, k)) return (1);
+ }
+
+ bp[0] = '\0';
+ convert_to_sys(buf);
+ term_string_push(buf);
}
/* Do not wait */
/* Replace the flags for stdin */
if (fcntl(0, F_SETFL, k)) return (1);
- }
- /* Ignore "invalid" keys */
- if ((i != 1) || (!buf[0])) return (1);
+ /* Ignore "invalid" keys */
+ if ((i != 1) || (!buf[0])) return (1);
- /* Enqueue the keypress */
- Term_keypress(buf[0]);
+ /* Enqueue the keypress */
+ term_key_push(buf[0]);
+ }
/* Success */
return (0);
{
term_data *td = (term_data *)(Term->data);
- int i;
-
- char text[81];
+ char intext[n];
+ char text[80 * 3 + 1];
+ size_t inlen = n;
+ size_t outlen = sizeof(text);
+ char *inbuf = intext;
+ char *outbuf = text;
+ size_t res;
#ifdef USE_NCURSES_ACS
/* do we have colors + 16 ? */
}
#endif
+ /* Copy to char array because of iconv's warning by const char pointer */
+ memcpy(intext, s, (size_t)n);
+
/* Obtain a copy of the text */
- for (i = 0; i < n; i++) text[i] = s[i];
- text[n] = 0;
+ res = iconv(iconv_to_gui, 0, 0, 0, 0);
+ if(res == (size_t)-1) return (-1);
+ res = iconv(iconv_to_gui, &inbuf, &inlen, &outbuf, &outlen);
+ if(res == (size_t)-1) return (-1);
+ res = iconv(iconv_to_gui, 0, 0, &outbuf, &outlen);
+ if(res == (size_t)-1) return (-1);
+
+ if(outlen == 0) return (-1);
+ *outbuf = '\0';
/* Move the cursor and dump the string */
wmove(td->win, y, x);
static errr term_data_init(term_data *td, int rows, int cols, int y, int x)
{
- term *t = &td->t;
+ term_type *t = &td->t;
/* Make sure the window has a positive size */
if (rows <= 0 || cols <= 0) return (0);
t->data = td;
/* Activate it */
- Term_activate(t);
+ term_activate(t);
/* Success */
/* Unused */
(void)str;
- /* Exit curses */
- endwin();
+ /* Exit curses */
+ endwin();
+
+ iconv_close(iconv_to_sys);
+ iconv_close(iconv_to_gui);
}
setlocale(LC_ALL, "");
+ iconv_to_sys = iconv_open("EUC-JP", "");
+ if(iconv_to_sys == (iconv_t)-1) return (-1);
+ iconv_to_gui = iconv_open("", "EUC-JP");
+ if(iconv_to_gui == (iconv_t)-1) return (-1);
/* Build the "sound" path */
path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
}
/* Activate the "Angband" window screen */
- Term_activate(&data[0].t);
+ term_activate(&data[0].t);
/* Store */
term_screen = &data[0].t;