OSDN Git Service

[Refactor] #37353 ULTRIX のプリプロを削除 / Removed preprocessor ULTRIX
[hengband/hengband.git] / src / util.c
index da3acc7..b26f9a8 100644 (file)
  * are included in all such copies.  Other copyrights may also apply.
  */
 
-/* Purpose: Angband utilities -BEN- */
+ /* Purpose: Angband utilities -BEN- */
 
 #include "angband.h"
+#include "core.h"
+#include "term.h"
 #include "util.h"
+#include "files.h"
 #include "monsterrace-hook.h"
 #include "view-mainwindow.h"
 #include "quest.h"
 #include "floor.h"
 #include "world.h"
 #include "cmd-dump.h"
+#include "japanese.h"
+#include "player-class.h"
 
+/*!
+ * 10進数から16進数への変換テーブル /
+ * Global array for converting numbers to uppercase hecidecimal digit
+ * This array can also be used to convert a number to an octal digit
+ */
+const char hexsym[16] =
+{
+       '0', '1', '2', '3', '4', '5', '6', '7',
+       '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
+};
+
+/*
+ * Keymaps for each "mode" associated with each keypress.
+ */
+concptr keymap_act[KEYMAP_MODES][256];
+
+/*
+ * The next "free" index to use
+ */
+u32b message__next;
+
+/*
+ * The index of the oldest message (none yet)
+ */
+u32b message__last;
+
+/*
+ * The next "free" offset
+ */
+u32b message__head;
+
+/*
+ * The offset to the oldest used char (none yet)
+ */
+u32b message__tail;
+
+/*
+ * The array of offsets, by index [MESSAGE_MAX]
+ */
+u32b *message__ptr;
+
+/*
+ * The array of chars, by offset [MESSAGE_BUF]
+ */
+char *message__buf;
+
+bool msg_flag;                 /* Used in msg_print() for "buffering" */
+
+/*
+ * Number of active macros.
+ */
+s16b macro__num;
+
+/*
+ * Array of macro patterns [MACRO_MAX]
+ */
+concptr *macro__pat;
+
+/*
+ * Array of macro actions [MACRO_MAX]
+ */
+concptr *macro__act;
+
+/*
+ * Array of macro types [MACRO_MAX]
+ */
+bool *macro__cmd;
+
+/*
+ * Current macro action [1024]
+ */
+char *macro__buf;
+
+bool get_com_no_macros = FALSE;        /* Expand macros in "get_com" or not */
+
+bool inkey_base;               /* See the "inkey()" function */
+bool inkey_xtra;               /* See the "inkey()" function */
+bool inkey_scan;               /* See the "inkey()" function */
+bool inkey_flag;               /* See the "inkey()" function */
+
+bool use_menu;
+
+pos_list tmp_pos;
+
+/*
+ * The number of quarks
+ */
+STR_OFFSET quark__num;
+
+/*
+ * The pointers to the quarks [QUARK_MAX]
+ */
+concptr *quark__str;
 
 static int num_more = 0;
 
 /* Save macro trigger string for use in inkey_special() */
 static char inkey_macro_trigger_string[1024];
 
-#if 0
-#ifndef HAS_STRICMP
+int max_macrotrigger = 0; /*!< 現在登録中のマクロ(トリガー)の数 */
+concptr macro_template = NULL; /*!< Angband設定ファイルのT: タグ情報から読み込んだ長いTコードを処理するために利用する文字列ポインタ */
+concptr macro_modifier_chr; /*!< &x# で指定されるマクロトリガーに関する情報を記録する文字列ポインタ */
+concptr macro_modifier_name[MAX_MACRO_MOD]; /*!< マクロ上で取り扱う特殊キーを文字列上で表現するためのフォーマットを記録した文字列ポインタ配列 */
+concptr macro_trigger_name[MAX_MACRO_TRIG]; /*!< マクロのトリガーコード */
+concptr macro_trigger_keycode[2][MAX_MACRO_TRIG];  /*!< マクロの内容 */
 
-/*
- * For those systems that don't have "stricmp()"
- *
- * Compare the two strings "a" and "b" ala "strcmp()" ignoring case.
- */
-int stricmp(concptr a, concptr b)
-{
-       concptr s1, s2;
-       char z1, z2;
+s16b command_cmd;              /* Current "Angband Command" */
+COMMAND_ARG command_arg;       /*!< 各種コマンドの汎用的な引数として扱う / Gives argument of current command */
+COMMAND_NUM command_rep;       /*!< 各種コマンドの汎用的なリピート数として扱う / Gives repetition of current command */
+DIRECTION command_dir;         /*!< 各種コマンドの汎用的な方向値処理として扱う/ Gives direction of current command */
+s16b command_see;              /* See "object1.c" */
+s16b command_wrk;              /* See "object1.c" */
+TERM_LEN command_gap = 999;         /* See "object1.c" */
+s16b command_new;              /* Command chaining from inven/equip view */
 
-       /* Scan the strings */
-       for (s1 = a, s2 = b; TRUE; s1++, s2++)
-       {
-               z1 = FORCEUPPER(*s1);
-               z2 = FORCEUPPER(*s2);
-               if (z1 < z2) return (-1);
-               if (z1 > z2) return (1);
-               if (!z1) return (0);
-       }
-}
 
-#endif /* HAS_STRICMP */
-#endif /* 0 */
 
 #ifdef SET_UID
 
@@ -121,14 +210,12 @@ void user_name(char *buf, int id)
                (void)strcpy(buf, pw->pw_name);
                buf[16] = '\0';
 
-#ifdef CAPITALIZE_USER_NAME
                /* Hack -- capitalize the user name */
 #ifdef JP
                if (!iskanji(buf[0]))
 #endif
                        if (islower(buf[0]))
                                buf[0] = toupper(buf[0]);
-#endif /* CAPITALIZE_USER_NAME */
 
                return;
        }
@@ -164,34 +251,22 @@ void user_name(char *buf, int id)
  * path, and a leading "tilde" to indicate a special directory, and default to a
  * relative path, but MSDOS uses a leading "drivename plus colon" to indicate the
  * use of a "special drive", and then the rest of the path is parsed "normally",
- * and MACINTOSH uses a leading colon to indicate a relative path, and an embedded
- * colon to indicate a "drive plus absolute path", and finally defaults to a file
- * in the current working directory, which may or may not be defined.
+ * and an embedded colon to indicate a "drive plus absolute path", and finally
+ * defaults to a file in the current working directory, which may or may not be defined.
  *
  * We should probably parse a leading "~~/" as referring to "ANGBAND_DIR". (?)
  */
 
 
-#ifdef ACORN
-
-
-/*
- * Most of the "file" routines for "ACORN" should be in "main-acn.c"
- */
-
-
-#else /* ACORN */
-
-
 #ifdef SET_UID
 
-/*
- * Extract a "parsed" path from an initial filename
- * Normally, we simply copy the filename into the buffer
- * But leading tilde symbols must be handled in a special way
- * Replace "~user/" by the home directory of the user named "user"
- * Replace "~/" by the home directory of the current user
- */
+ /*
 * Extract a "parsed" path from an initial filename
 * Normally, we simply copy the filename into the buffer
 * But leading tilde symbols must be handled in a special way
 * Replace "~user/" by the home directory of the user named "user"
 * Replace "~/" by the home directory of the current user
 */
 errr path_parse(char *buf, int max, concptr file)
 {
        concptr         u, s;
@@ -203,23 +278,23 @@ errr path_parse(char *buf, int max, concptr file)
        buf[0] = '\0';
 
        /* No file? */
-       if (!file) return (-1);
+       if (!file) return -1;
 
        /* File needs no parsing */
        if (file[0] != '~')
        {
                (void)strnfmt(buf, max, "%s", file);
-               return (0);
+               return 0;
        }
 
        /* Point at the user */
-       u = file+1;
+       u = file + 1;
 
        /* Look for non-user portion of the file */
        s = my_strstr(u, PATH_SEP);
 
        /* Hack -- no long user names */
-       if (s && (s >= u + sizeof(user))) return (1);
+       if (s && (s >= u + sizeof(user))) return 1;
 
        /* Extract a user name */
        if (s)
@@ -238,38 +313,31 @@ errr path_parse(char *buf, int max, concptr file)
        else pw = getpwuid(getuid());
 
        /* Nothing found? */
-       if (!pw) return (1);
+       if (!pw) return 1;
 
        /* Make use of the info */
        if (s) strnfmt(buf, max, "%s%s", pw->pw_dir, s);
        else strnfmt(buf, max, "%s", pw->pw_dir);
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 
 #else /* SET_UID */
 
 
-/*
- * Extract a "parsed" path from an initial filename
- *
- * This requires no special processing on simple machines,
- * except for verifying the size of the filename.
- */
+ /*
 * Extract a "parsed" path from an initial filename
 *
 * This requires no special processing on simple machines,
 * except for verifying the size of the filename.
 */
 errr path_parse(char *buf, int max, concptr file)
 {
        /* Accept the filename */
        (void)strnfmt(buf, max, "%s", file);
-
-#if defined(MAC_MPW) && defined(CARBON)
-     /* Fix it according to the current operating system */
-    convert_pathname(buf);
-#endif /* MAC_MPW && CARBON */
-
-       /* Success */
-       return (0);
+       return 0;
 }
 
 
@@ -290,7 +358,7 @@ static errr path_temp(char *buf, int max)
        /* Temp file */
        s = tmpnam(NULL);
 
-       if (!s) return (-1);
+       if (!s) return -1;
 
        /* Format to length */
 #if !defined(WIN32) || (defined(_MSC_VER) && (_MSC_VER >= 1900))
@@ -300,13 +368,18 @@ static errr path_temp(char *buf, int max)
 #endif
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 #endif
 
-/*
- * Create a new path by appending a file (or directory) to a path.
+/*!
+ * @brief ファイル入出力のためのパス生成する。/ Create a new path by appending a file (or directory) to a path.
+ * @param buf ファイルのフルを返すバッファ
+ * @param max bufのサイズ
+ * @param path ファイルパス
+ * @param file ファイル名
+ * @return エラーコード(ただし常に0を返す)
  *
  * This requires no special processing on simple machines, except
  * for verifying the size of the filename, but note the ability to
@@ -349,7 +422,7 @@ errr path_build(char *buf, int max, concptr path, concptr file)
        }
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 
@@ -360,14 +433,14 @@ FILE *my_fopen(concptr file, concptr mode)
 {
        char buf[1024];
 
-#if defined(MAC_MPW) || defined(MACH_O_CARBON)
+#if defined(MACH_O_CARBON)
        FILE *tempfff;
 #endif
 
        /* Hack -- Try to parse the path */
        if (path_parse(buf, 1024, file)) return (NULL);
 
-#if defined(MAC_MPW) || defined(MACH_O_CARBON)
+#if defined(MACH_O_CARBON)
        if (my_strchr(mode, 'w'))
        {
                /* setting file type/creator */
@@ -388,19 +461,16 @@ FILE *my_fopen(concptr file, concptr mode)
 errr my_fclose(FILE *fff)
 {
        /* Require a file */
-       if (!fff) return (-1);
+       if (!fff) return -1;
 
        /* Close, check for error */
-       if (fclose(fff) == EOF) return (1);
+       if (fclose(fff) == EOF) return 1;
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 
-#endif /* ACORN */
-
-
 #ifdef HAVE_MKSTEMP
 
 FILE *my_fopen_temp(char *buf, int max)
@@ -426,8 +496,6 @@ FILE *my_fopen_temp(char *buf, int max)
 {
        /* Generate a temporary filename */
        if (path_temp(buf, max)) return (NULL);
-
-       /* Open the file */
        return (my_fopen(buf, "w"));
 }
 
@@ -457,7 +525,7 @@ errr my_fgets(FILE *fff, char *buf, huge n)
                /* Convert weirdness */
                for (s = tmp; *s; s++)
                {
-#if defined(MACINTOSH) || defined(MACH_O_CARBON)
+#if defined(MACH_O_CARBON)
 
                        /*
                         * Be nice to the Macintosh, where a file can have Mac or Unix
@@ -466,7 +534,7 @@ errr my_fgets(FILE *fff, char *buf, huge n)
                         */
                        if (*s == '\r') *s = '\n';
 
-#endif /* MACINTOSH || MACH_O_CARBON */
+#endif /* MACH_O_CARBON */
 
                        /* Handle newline */
                        if (*s == '\n')
@@ -475,7 +543,7 @@ errr my_fgets(FILE *fff, char *buf, huge n)
                                buf[i] = '\0';
 
                                /* Success */
-                               return (0);
+                               return 0;
                        }
 
                        /* Handle tabs */
@@ -520,14 +588,14 @@ errr my_fgets(FILE *fff, char *buf, huge n)
                buf[i] = '\0';
 
                /* Success */
-               return (0);
+               return 0;
        }
 
        /* Nothing */
        buf[0] = '\0';
 
        /* Failure */
-       return (1);
+       return 1;
 }
 
 
@@ -545,57 +613,32 @@ errr my_fputs(FILE *fff, concptr buf, huge n)
        (void)fprintf(fff, "%s\n", buf);
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 
-#ifdef ACORN
-
-
-/*
- * Most of the "file" routines for "ACORN" should be in "main-acn.c"
- *
- * Many of them can be rewritten now that only "fd_open()" and "fd_make()"
- * and "my_fopen()" should ever create files.
- */
-
-
-#else /* ACORN */
-
-
-/*
- * The Macintosh is a little bit brain-dead sometimes
- */
-#ifdef MACINTOSH
-# define open(N,F,M) \
-((M), open((char*)(N),F))
-# define write(F,B,S) \
-write(F,(char*)(B),S)
-#endif /* MACINTOSH */
-
-
-/*
- * Several systems have no "O_BINARY" flag
- */
+ /*
+  * Several systems have no "O_BINARY" flag
+  */
 #ifndef O_BINARY
 # define O_BINARY 0
 #endif /* O_BINARY */
 
 
-/*
- * Hack -- attempt to delete a file
- */
+  /*
  * Hack -- attempt to delete a file
  */
 errr fd_kill(concptr file)
 {
        char buf[1024];
 
        /* Hack -- Try to parse the path */
-       if (path_parse(buf, 1024, file)) return (-1);
+       if (path_parse(buf, 1024, file)) return -1;
 
        /* Remove */
        (void)remove(buf);
 
-       return (0);
+       return 0;
 }
 
 
@@ -608,15 +651,15 @@ errr fd_move(concptr file, concptr what)
        char aux[1024];
 
        /* Hack -- Try to parse the path */
-       if (path_parse(buf, 1024, file)) return (-1);
+       if (path_parse(buf, 1024, file)) return -1;
 
        /* Hack -- Try to parse the path */
-       if (path_parse(aux, 1024, what)) return (-1);
+       if (path_parse(aux, 1024, what)) return -1;
 
        /* Rename */
        (void)rename(buf, aux);
 
-       return (0);
+       return 0;
 }
 
 
@@ -631,18 +674,18 @@ errr fd_copy(concptr file, concptr what)
        int src_fd, dst_fd;
 
        /* Hack -- Try to parse the path */
-       if (path_parse(buf, 1024, file)) return (-1);
+       if (path_parse(buf, 1024, file)) return -1;
 
        /* Hack -- Try to parse the path */
-       if (path_parse(aux, 1024, what)) return (-1);
+       if (path_parse(aux, 1024, what)) return -1;
 
        /* Open source file */
        src_fd = fd_open(buf, O_RDONLY);
-       if (src_fd < 0) return (-1);
+       if (src_fd < 0) return -1;
 
        /* Open destination file */
-       dst_fd = fd_open(aux, O_WRONLY|O_TRUNC|O_CREAT);
-       if (dst_fd < 0) return (-1);
+       dst_fd = fd_open(aux, O_WRONLY | O_TRUNC | O_CREAT);
+       if (dst_fd < 0) return -1;
 
        /* Copy */
        while ((read_num = read(src_fd, buf, 1024)) > 0)
@@ -666,7 +709,7 @@ errr fd_copy(concptr file, concptr what)
        fd_close(src_fd);
        fd_close(dst_fd);
 
-       return (0);
+       return 0;
 }
 
 /*
@@ -679,9 +722,9 @@ int fd_make(concptr file, BIT_FLAGS mode)
        char buf[1024];
 
        /* Hack -- Try to parse the path */
-       if (path_parse(buf, 1024, file)) return (-1);
+       if (path_parse(buf, 1024, file)) return -1;
 
-#if defined(MAC_MPW) || defined(MACH_O_CARBON)
+#if defined(MACH_O_CARBON)
        {
                int fdes;
                /* Create the file, fail if exists, write-only, binary */
@@ -709,7 +752,7 @@ int fd_open(concptr file, int flags)
        char buf[1024];
 
        /* Hack -- Try to parse the path */
-       if (path_parse(buf, 1024, file)) return (-1);
+       if (path_parse(buf, 1024, file)) return -1;
 
        /* Attempt to open the file */
        return (open(buf, flags | O_BINARY, 0));
@@ -727,7 +770,7 @@ errr fd_lock(int fd, int what)
        what = what ? what : 0;
 
        /* Verify the fd */
-       if (fd < 0) return (-1);
+       if (fd < 0) return -1;
 
 #ifdef SET_UID
 
@@ -746,7 +789,7 @@ errr fd_lock(int fd, int what)
        else
        {
                /* Lock the score file */
-               if (lockf(fd, F_LOCK, 0) != 0) return (1);
+               if (lockf(fd, F_LOCK, 0) != 0) return 1;
        }
 
 #  endif
@@ -766,7 +809,7 @@ errr fd_lock(int fd, int what)
        else
        {
                /* Lock the score file */
-               if (flock(fd, LOCK_EX) != 0) return (1);
+               if (flock(fd, LOCK_EX) != 0) return 1;
        }
 
 #  endif
@@ -776,7 +819,7 @@ errr fd_lock(int fd, int what)
 #endif
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 
@@ -788,16 +831,16 @@ errr fd_seek(int fd, huge n)
        huge p;
 
        /* Verify fd */
-       if (fd < 0) return (-1);
+       if (fd < 0) return -1;
 
        /* Seek to the given position */
        p = lseek(fd, n, SEEK_SET);
 
        /* Failure */
-       if (p != n) return (1);
+       if (p != n) return 1;
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 
@@ -810,15 +853,15 @@ errr fd_chop(int fd, huge n)
        n = n ? n : 0;
 
        /* Verify the fd */
-       if (fd < 0) return (-1);
+       if (fd < 0) return -1;
 
-#if defined(ULTRIX) || defined(NeXT)
+#if defined(NeXT)
        /* Truncate */
        ftruncate(fd, n);
 #endif
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 
@@ -828,7 +871,7 @@ errr fd_chop(int fd, huge n)
 errr fd_read(int fd, char *buf, huge n)
 {
        /* Verify the fd */
-       if (fd < 0) return (-1);
+       if (fd < 0) return -1;
 
 #ifndef SET_UID
 
@@ -836,7 +879,7 @@ errr fd_read(int fd, char *buf, huge n)
        while (n >= 16384)
        {
                /* Read a piece */
-               if (read(fd, buf, 16384) != 16384) return (1);
+               if (read(fd, buf, 16384) != 16384) return 1;
 
                /* Shorten the task */
                buf += 16384;
@@ -848,10 +891,10 @@ errr fd_read(int fd, char *buf, huge n)
 #endif
 
        /* Read the final piece */
-       if (read(fd, buf, n) != (int)n) return (1);
+       if (read(fd, buf, n) != (int)n) return 1;
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 
@@ -861,7 +904,7 @@ errr fd_read(int fd, char *buf, huge n)
 errr fd_write(int fd, concptr buf, huge n)
 {
        /* Verify the fd */
-       if (fd < 0) return (-1);
+       if (fd < 0) return -1;
 
 #ifndef SET_UID
 
@@ -869,7 +912,7 @@ errr fd_write(int fd, concptr buf, huge n)
        while (n >= 16384)
        {
                /* Write a piece */
-               if (write(fd, buf, 16384) != 16384) return (1);
+               if (write(fd, buf, 16384) != 16384) return 1;
 
                /* Shorten the task */
                buf += 16384;
@@ -881,10 +924,10 @@ errr fd_write(int fd, concptr buf, huge n)
 #endif
 
        /* Write the final piece */
-       if (write(fd, buf, n) != (int)n) return (1);
+       if (write(fd, buf, n) != (int)n) return 1;
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 
@@ -894,22 +937,17 @@ errr fd_write(int fd, concptr buf, huge n)
 errr fd_close(int fd)
 {
        /* Verify the fd */
-       if (fd < 0) return (-1);
+       if (fd < 0) return -1;
 
        /* Close */
        (void)close(fd);
 
-       return (0);
+       return 0;
 }
 
 
-#endif /* ACORN */
-
-
-
-
 /*
- * Important note about "colors" 
+ * Important note about "colors"
  *
  * The "TERM_*" color definitions list the "composition" of each
  * "Angband color" in terms of "quarters" of each of the three color
@@ -954,9 +992,9 @@ errr fd_close(int fd)
  */
 
 
-/*
- * Move the cursor
- */
+ /*
 * Move the cursor
 */
 void move_cursor(int row, int col)
 {
        Term_gotoxy(col, row);
@@ -969,7 +1007,7 @@ void move_cursor(int row, int col)
  */
 static char octify(uint i)
 {
-       return (hexsym[i%8]);
+       return (hexsym[i % 8]);
 }
 
 /*
@@ -977,7 +1015,7 @@ static char octify(uint i)
  */
 static char hexify(uint i)
 {
-       return (hexsym[i%16]);
+       return (hexsym[i % 16]);
 }
 
 
@@ -987,7 +1025,7 @@ static char hexify(uint i)
 static int deoct(char c)
 {
        if (isdigit(c)) return (D2I(c));
-       return (0);
+       return 0;
 }
 
 /*
@@ -998,7 +1036,7 @@ static int dehex(char c)
        if (isdigit(c)) return (D2I(c));
        if (islower(c)) return (A2I(c) + 10);
        if (isupper(c)) return (A2I(tolower(c)) + 10);
-       return (0);
+       return 0;
 }
 
 
@@ -1012,9 +1050,9 @@ static int my_stricmp(concptr a, concptr b)
        {
                z1 = FORCEUPPER(*s1);
                z2 = FORCEUPPER(*s2);
-               if (z1 < z2) return (-1);
-               if (z1 > z2) return (1);
-               if (!z1) return (0);
+               if (z1 < z2) return -1;
+               if (z1 > z2) return 1;
+               if (!z1) return 0;
        }
 }
 
@@ -1028,9 +1066,9 @@ static int my_strnicmp(concptr a, concptr b, int n)
        {
                z1 = FORCEUPPER(*s1);
                z2 = FORCEUPPER(*s2);
-               if (z1 < z2) return (-1);
-               if (z1 > z2) return (1);
-               if (!z1) return (0);
+               if (z1 < z2) return -1;
+               if (z1 > z2) return 1;
+               if (!z1) return 0;
        }
        return 0;
 }
@@ -1048,19 +1086,19 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr)
 
        if (macro_template == NULL)
                return;
-       
+
        for (i = 0; macro_modifier_chr[i]; i++)
                mod_status[i] = FALSE;
        str++;
 
        /* Examine modifier keys */
-       while (1)
+       while (TRUE)
        {
-               for (i=0; macro_modifier_chr[i]; i++)
+               for (i = 0; macro_modifier_chr[i]; i++)
                {
                        len = strlen(macro_modifier_name[i]);
-                       
-                       if(!my_strnicmp(str, macro_modifier_name[i], len))
+
+                       if (!my_strnicmp(str, macro_modifier_name[i], len))
                                break;
                }
                if (!macro_modifier_chr[i]) break;
@@ -1101,7 +1139,7 @@ static void trigger_text_to_ascii(char **bufptr, concptr *strptr)
                char ch = macro_template[i];
                int j;
 
-               switch(ch)
+               switch (ch)
                {
                case '&':
                        for (j = 0; macro_modifier_chr[j]; j++) {
@@ -1154,88 +1192,88 @@ void text_to_ascii(char *buf, concptr str)
                        }
                        else
 
-                       /* Hex-mode XXX */
-                       if (*str == 'x')
-                       {
-                               *s = 16 * (char)dehex(*++str);
-                               *s++ += (char)dehex(*++str);
-                       }
+                               /* Hex-mode XXX */
+                               if (*str == 'x')
+                               {
+                                       *s = 16 * (char)dehex(*++str);
+                                       *s++ += (char)dehex(*++str);
+                               }
 
                        /* Hack -- simple way to specify "backslash" */
-                       else if (*str == '\\')
-                       {
-                               *s++ = '\\';
-                       }
+                               else if (*str == '\\')
+                               {
+                                       *s++ = '\\';
+                               }
 
                        /* Hack -- simple way to specify "caret" */
-                       else if (*str == '^')
-                       {
-                               *s++ = '^';
-                       }
+                               else if (*str == '^')
+                               {
+                                       *s++ = '^';
+                               }
 
                        /* Hack -- simple way to specify "space" */
-                       else if (*str == 's')
-                       {
-                               *s++ = ' ';
-                       }
+                               else if (*str == 's')
+                               {
+                                       *s++ = ' ';
+                               }
 
                        /* Hack -- simple way to specify Escape */
-                       else if (*str == 'e')
-                       {
-                               *s++ = ESCAPE;
-                       }
+                               else if (*str == 'e')
+                               {
+                                       *s++ = ESCAPE;
+                               }
 
                        /* Backspace */
-                       else if (*str == 'b')
-                       {
-                               *s++ = '\b';
-                       }
+                               else if (*str == 'b')
+                               {
+                                       *s++ = '\b';
+                               }
 
                        /* Newline */
-                       else if (*str == 'n')
-                       {
-                               *s++ = '\n';
-                       }
+                               else if (*str == 'n')
+                               {
+                                       *s++ = '\n';
+                               }
 
                        /* Return */
-                       else if (*str == 'r')
-                       {
-                               *s++ = '\r';
-                       }
+                               else if (*str == 'r')
+                               {
+                                       *s++ = '\r';
+                               }
 
                        /* Tab */
-                       else if (*str == 't')
-                       {
-                               *s++ = '\t';
-                       }
+                               else if (*str == 't')
+                               {
+                                       *s++ = '\t';
+                               }
 
                        /* Octal-mode */
-                       else if (*str == '0')
-                       {
-                               *s = 8 * (char)deoct(*++str);
-                               *s++ += (char)deoct(*++str);
-                       }
+                               else if (*str == '0')
+                               {
+                                       *s = 8 * (char)deoct(*++str);
+                                       *s++ += (char)deoct(*++str);
+                               }
 
                        /* Octal-mode */
-                       else if (*str == '1')
-                       {
-                               *s = 64 + 8 * (char)deoct(*++str);
-                               *s++ += (char)deoct(*++str);
-                       }
+                               else if (*str == '1')
+                               {
+                                       *s = 64 + 8 * (char)deoct(*++str);
+                                       *s++ += (char)deoct(*++str);
+                               }
 
                        /* Octal-mode */
-                       else if (*str == '2')
-                       {
-                               *s = 64 * 2 + 8 * (char)deoct(*++str);
-                               *s++ += (char)deoct(*++str);
-                       }
+                               else if (*str == '2')
+                               {
+                                       *s = 64 * 2 + 8 * (char)deoct(*++str);
+                                       *s++ += (char)deoct(*++str);
+                               }
 
                        /* Octal-mode */
-                       else if (*str == '3')
-                       {
-                               *s = 64 * 3 + 8 * (char)deoct(*++str);
-                               *s++ += (char)deoct(*++str);
-                       }
+                               else if (*str == '3')
+                               {
+                                       *s = 64 * 3 + 8 * (char)deoct(*++str);
+                                       *s++ += (char)deoct(*++str);
+                               }
 
                        /* Skip the final char */
                        str++;
@@ -1279,14 +1317,14 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr)
                int j;
                char ch = macro_template[i];
 
-               switch(ch)
+               switch (ch)
                {
                case '&':
                        while ((tmp = my_strchr(macro_modifier_chr, *str)) != 0)
                        {
                                j = (int)(tmp - macro_modifier_chr);
                                tmp = macro_modifier_name[j];
-                               while(*tmp) *s++ = *tmp++;
+                               while (*tmp) *s++ = *tmp++;
                                str++;
                        }
                        break;
@@ -1305,7 +1343,7 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr)
        for (i = 0; i < max_macrotrigger; i++)
        {
                if (!my_stricmp(key_code, macro_trigger_keycode[0][i])
-                   || !my_stricmp(key_code, macro_trigger_keycode[1][i]))
+                       || !my_stricmp(key_code, macro_trigger_keycode[1][i]))
                        break;
        }
        if (i == max_macrotrigger)
@@ -1315,7 +1353,7 @@ static bool trigger_ascii_to_text(char **bufptr, concptr *strptr)
        while (*tmp) *s++ = *tmp++;
 
        *s++ = ']';
-       
+
        *bufptr = s;
        *strptr = str;
        return TRUE;
@@ -1337,7 +1375,7 @@ void ascii_to_text(char *buf, concptr str)
                /* Macro Trigger */
                if (i == 31)
                {
-                       if(!trigger_ascii_to_text(&s, &str))
+                       if (!trigger_ascii_to_text(&s, &str))
                        {
                                *s++ = '^';
                                *s++ = '_';
@@ -1345,69 +1383,69 @@ void ascii_to_text(char *buf, concptr str)
                }
                else
 
-               if (i == ESCAPE)
-               {
-                       *s++ = '\\';
-                       *s++ = 'e';
-               }
-               else if (i == ' ')
-               {
-                       *s++ = '\\';
-                       *s++ = 's';
-               }
-               else if (i == '\b')
-               {
-                       *s++ = '\\';
-                       *s++ = 'b';
-               }
-               else if (i == '\t')
-               {
-                       *s++ = '\\';
-                       *s++ = 't';
-               }
-               else if (i == '\n')
-               {
-                       *s++ = '\\';
-                       *s++ = 'n';
-               }
-               else if (i == '\r')
-               {
-                       *s++ = '\\';
-                       *s++ = 'r';
-               }
-               else if (i == '^')
-               {
-                       *s++ = '\\';
-                       *s++ = '^';
-               }
-               else if (i == '\\')
-               {
-                       *s++ = '\\';
-                       *s++ = '\\';
-               }
-               else if (i < 32)
-               {
-                       *s++ = '^';
-                       *s++ = i + 64;
-               }
-               else if (i < 127)
-               {
-                       *s++ = i;
-               }
-               else if (i < 64)
-               {
-                       *s++ = '\\';
-                       *s++ = '0';
-                       *s++ = octify(i / 8);
-                       *s++ = octify(i % 8);
-               }
-               else
-               {
-                       *s++ = '\\';
-                       *s++ = 'x';
-                       *s++ = hexify(i / 16);
-                       *s++ = hexify(i % 16);
-               }
+                       if (i == ESCAPE)
+                       {
+                               *s++ = '\\';
+                               *s++ = 'e';
+                       }
+                       else if (i == ' ')
+                       {
+                               *s++ = '\\';
+                               *s++ = 's';
+                       }
+                       else if (i == '\b')
+                       {
+                               *s++ = '\\';
+                               *s++ = 'b';
+                       }
+                       else if (i == '\t')
+                       {
+                               *s++ = '\\';
+                               *s++ = 't';
+                       }
+                       else if (i == '\n')
+                       {
+                               *s++ = '\\';
+                               *s++ = 'n';
+                       }
+                       else if (i == '\r')
+                       {
+                               *s++ = '\\';
+                               *s++ = 'r';
+                       }
+                       else if (i == '^')
+                       {
+                               *s++ = '\\';
+                               *s++ = '^';
+                       }
+                       else if (i == '\\')
+                       {
+                               *s++ = '\\';
+                               *s++ = '\\';
+                       }
+                       else if (i < 32)
+                       {
+                               *s++ = '^';
+                               *s++ = i + 64;
+                       }
+                       else if (i < 127)
+                       {
+                               *s++ = i;
+                       }
+                       else if (i < 64)
+                       {
+                               *s++ = '\\';
+                               *s++ = '0';
+                               *s++ = octify(i / 8);
+                               *s++ = octify(i % 8);
+                       }
+                       else
+                       {
+                               *s++ = '\\';
+                               *s++ = 'x';
+                               *s++ = hexify(i / 16);
+                               *s++ = hexify(i % 16);
+                       }
        }
 
        /* Terminate */
@@ -1426,9 +1464,9 @@ void ascii_to_text(char *buf, concptr str)
 
 
 
-/*
- * Determine if any macros have ever started with a given character.
- */
+ /*
 * Determine if any macros have ever started with a given character.
 */
 static bool macro__use[256];
 
 
@@ -1442,7 +1480,7 @@ sint macro_find_exact(concptr pat)
        /* Nothing possible */
        if (!macro__use[(byte)(pat[0])])
        {
-               return (-1);
+               return -1;
        }
 
        /* Scan the macros */
@@ -1456,7 +1494,7 @@ sint macro_find_exact(concptr pat)
        }
 
        /* No matches */
-       return (-1);
+       return -1;
 }
 
 
@@ -1470,7 +1508,7 @@ static sint macro_find_check(concptr pat)
        /* Nothing possible */
        if (!macro__use[(byte)(pat[0])])
        {
-               return (-1);
+               return -1;
        }
 
        /* Scan the macros */
@@ -1484,7 +1522,7 @@ static sint macro_find_check(concptr pat)
        }
 
        /* Nothing */
-       return (-1);
+       return -1;
 }
 
 
@@ -1498,7 +1536,7 @@ static sint macro_find_maybe(concptr pat)
        /* Nothing possible */
        if (!macro__use[(byte)(pat[0])])
        {
-               return (-1);
+               return -1;
        }
 
        /* Scan the macros */
@@ -1515,7 +1553,7 @@ static sint macro_find_maybe(concptr pat)
        }
 
        /* Nothing */
-       return (-1);
+       return -1;
 }
 
 
@@ -1529,7 +1567,7 @@ static sint macro_find_ready(concptr pat)
        /* Nothing possible */
        if (!macro__use[(byte)(pat[0])])
        {
-               return (-1);
+               return -1;
        }
 
        /* Scan the macros */
@@ -1556,15 +1594,15 @@ static sint macro_find_ready(concptr pat)
  * Add a macro definition (or redefinition).
  *
  * We should use "act == NULL" to "remove" a macro, but this might make it
- * impossible to save the "removal" of a macro definition.  
+ * impossible to save the "removal" of a macro definition.
  *
  * We should consider refusing to allow macros which contain existing macros,
  * or which are contained in existing macros, because this would simplify the
- * macro analysis code.  
+ * macro analysis code.
  *
  * We should consider removing the "command macro" crap, and replacing it
  * with some kind of "powerful keymap" ability, but this might make it hard
- * to change the "roguelike" option from inside the game.  
+ * to change the "roguelike" option from inside the game.
  */
 errr macro_add(concptr pat, concptr act)
 {
@@ -1572,7 +1610,7 @@ errr macro_add(concptr pat, concptr act)
 
 
        /* Paranoia -- require data */
-       if (!pat || !act) return (-1);
+       if (!pat || !act) return -1;
 
 
        /* Look for any existing macro */
@@ -1602,7 +1640,7 @@ errr macro_add(concptr pat, concptr act)
        macro__use[(byte)(pat[0])] = TRUE;
 
        /* Success */
-       return (0);
+       return 0;
 }
 
 
@@ -1679,92 +1717,89 @@ errr play_music(int type, int val)
 /*
  * Hack -- Select floor music.
  */
-void select_floor_music(void)
+void select_floor_music(player_type *player_ptr)
 {
-       int i;
-       /* No sound */
        if (!use_music) return;
 
-       if(p_ptr->ambush_flag)
+       if (player_ptr->ambush_flag)
        {
-               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_AMBUSH);
-               return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_AMBUSH)) return;
        }
 
-       if(p_ptr->wild_mode)
+       if (player_ptr->wild_mode)
        {
-               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_WILD);
-               return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_WILD)) return;
        }
 
-       if(p_ptr->inside_arena)
+       if (player_ptr->current_floor_ptr->inside_arena)
        {
-               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_ARENA);
-               return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_ARENA)) return;
        }
 
-       if(p_ptr->inside_battle)
+       if (player_ptr->phase_out)
        {
-               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BATTLE);
-               return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BATTLE)) return;
        }
 
-       if(p_ptr->inside_quest)
+       if (player_ptr->current_floor_ptr->inside_quest)
        {
-               if(play_music(TERM_XTRA_MUSIC_QUEST, p_ptr->inside_quest))
-               {
-                       play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST);
-               }
-               return;
+               if (!play_music(TERM_XTRA_MUSIC_QUEST, player_ptr->current_floor_ptr->inside_quest)) return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST)) return;
        }
 
-       for(i = 0; i < max_q_idx; i++)
-       { // TODO マクロで類似条件を統合すること
-               if(quest[i].status == QUEST_STATUS_TAKEN &&
-                       (quest[i].type == QUEST_TYPE_KILL_LEVEL || quest[i].type == QUEST_TYPE_RANDOM) &&
-                        quest[i].level == current_floor_ptr->dun_level && p_ptr->dungeon_idx == quest[i].dungeon)
+       if (player_ptr->dungeon_idx)
+       {
+               if (player_ptr->feeling == 2)
                {
-                       if(play_music(TERM_XTRA_MUSIC_QUEST, i)) 
-                       {
-                               play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST);
-                       }
-                       return;
+                       if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_FEEL2)) return;
+               }
+               else if (player_ptr->feeling >= 3 && player_ptr->feeling <= 5)
+               {
+                       if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_FEEL1)) return;
                }
-       }
-
-       if(p_ptr->dungeon_idx)
-       {
-               if(p_ptr->feeling == 2) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_FEEL2);
-               else if(p_ptr->feeling >= 3 && p_ptr->feeling <= 5) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_FEEL1);
                else
                {
-                       if(play_music(TERM_XTRA_MUSIC_DUNGEON, p_ptr->dungeon_idx))
+                       if (!play_music(TERM_XTRA_MUSIC_DUNGEON, player_ptr->dungeon_idx)) return;
+
+                       if (player_ptr->current_floor_ptr->dun_level < 40)
+                       {
+                               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_LOW)) return;
+                       }
+                       else if (player_ptr->current_floor_ptr->dun_level < 80)
+                       {
+                               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_MED)) return;
+                       }
+                       else
                        {
-                               if(current_floor_ptr->dun_level < 40) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_LOW);
-                               else if(current_floor_ptr->dun_level < 80) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_MED);
-                               else play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_HIGH);
+                               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DUN_HIGH)) return;
                        }
                }
-               return;
        }
 
-       if(p_ptr->town_num)
+       if (player_ptr->town_num)
        {
-               if(play_music(TERM_XTRA_MUSIC_TOWN, p_ptr->town_num))
-               {
-                       play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_TOWN);
-               }
+               if (!play_music(TERM_XTRA_MUSIC_TOWN, player_ptr->town_num)) return;
+               if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_TOWN)) return;
                return;
        }
 
-       if(!current_floor_ptr->dun_level)
+       if (!player_ptr->current_floor_ptr->dun_level)
        {
-               if(p_ptr->lev >= 45) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD3);
-               else if(p_ptr->lev >= 25) play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD2);
-               else play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD1);
-               return;
+               if (player_ptr->lev >= 45)
+               {
+                       if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD3)) return;
+               }
+               else if (player_ptr->lev >= 25)
+               {
+                       if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD2)) return;
+               }
+               else
+               {
+                       if (!play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FIELD1)) return;
+               }
        }
-       
+
+       play_music(TERM_XTRA_MUSIC_MUTE, 0);
 }
 
 
@@ -1784,7 +1819,7 @@ void select_floor_music(void)
  * Only 500 (0+1+2+...+29+30) milliseconds may elapse between each key in
  * the macro trigger sequence.  If a key sequence forms the "prefix" of a
  * macro trigger, 500 milliseconds must pass before the key sequence is
- * known not to be that macro trigger.  
+ * known not to be that macro trigger.
  */
 static char inkey_aux(void)
 {
@@ -1811,7 +1846,7 @@ static char inkey_aux(void)
        else
        {
                /* Wait for a keypress */
-               (void) (Term_inkey(&ch, TRUE, TRUE));
+               (void)(Term_inkey(&ch, TRUE, TRUE));
        }
 
 
@@ -1883,7 +1918,7 @@ static char inkey_aux(void)
                while (p > 0)
                {
                        /* Push the key, notice over-flow */
-                       if (Term_key_push(buf[--p])) return (0);
+                       if (Term_key_push(buf[--p])) return 0;
                }
 
                /* Wait for (and remove) a pending key */
@@ -1904,7 +1939,7 @@ static char inkey_aux(void)
        while (p > n)
        {
                /* Push the key, notice over-flow */
-               if (Term_key_push(buf[--p])) return (0);
+               if (Term_key_push(buf[--p])) return 0;
        }
 
 
@@ -1912,7 +1947,7 @@ static char inkey_aux(void)
        parse_macro = TRUE;
 
        /* Push the "end of macro action" key */
-       if (Term_key_push(30)) return (0);
+       if (Term_key_push(30)) return 0;
 
 
        /* Access the macro action */
@@ -1925,12 +1960,12 @@ static char inkey_aux(void)
        while (n > 0)
        {
                /* Push the key, notice over-flow */
-               if (Term_key_push(act[--n])) return (0);
+               if (Term_key_push(act[--n])) return 0;
        }
 
 
        /* Hack -- Force "inkey()" to call us again */
-       return (0);
+       return 0;
 }
 
 
@@ -1960,9 +1995,8 @@ static void forget_macro_action(void)
        parse_macro = FALSE;
 }
 
-
 /*
- * Mega-Hack -- special "inkey_next" pointer.  
+ * Mega-Hack -- special "inkey_next" pointer.
  *
  * This special pointer allows a sequence of keys to be "inserted" into
  * the stream of keys returned by "inkey()".  This key sequence will not
@@ -1971,21 +2005,6 @@ static void forget_macro_action(void)
  */
 static concptr inkey_next = NULL;
 
-
-#ifdef ALLOW_BORG
-
-/*
- * Mega-Hack -- special "inkey_hack" hook.  
- *
- * This special function hook allows the "Borg" (see elsewhere) to take
- * control of the "inkey()" function, and substitute in fake keypresses.
- */
-char (*inkey_hack)(int flush_first) = NULL;
-
-#endif /* ALLOW_BORG */
-
-
-
 /*
  * Get a keypress from the user.
  *
@@ -2041,7 +2060,7 @@ char (*inkey_hack)(int flush_first) = NULL;
  * is only requested (via "Term_inkey()") when "angband_term[0]" is active.
  *
  * Mega-Hack -- This function is used as the entry point for clearing the
- * "signal_count" variable, and of the "character_saved" variable.
+ * "signal_count" variable, and of the "current_world_ptr->character_saved" variable.
  *
  * Hack -- Note the use of "inkey_next" to allow "keymaps" to be processed.
  *
@@ -2072,22 +2091,6 @@ char inkey(void)
        /* Forget pointer */
        inkey_next = NULL;
 
-
-#ifdef ALLOW_BORG
-
-       /* Mega-Hack -- Use the special hook */
-       if (inkey_hack && ((ch = (*inkey_hack)(inkey_xtra)) != 0))
-       {
-               /* Cancel the various "global parameters" */
-               inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE;
-
-               /* Accept result */
-               return (ch);
-       }
-
-#endif /* ALLOW_BORG */
-
-
        /* Hack -- handle delayed "flush()" */
        if (inkey_xtra)
        {
@@ -2106,7 +2109,7 @@ char inkey(void)
        (void)Term_get_cursor(&v);
 
        /* Show the cursor if waiting, except sometimes in "command" mode */
-       if (!inkey_scan && (!inkey_flag || hilite_player || character_icky))
+       if (!inkey_scan && (!inkey_flag || hilite_player || current_world_ptr->character_icky))
        {
                /* Show the cursor */
                (void)Term_set_cursor(1);
@@ -2141,7 +2144,7 @@ char inkey(void)
                        Term_activate(angband_term[0]);
 
                        /* Mega-Hack -- reset saved flag */
-                       character_saved = FALSE;
+                       current_world_ptr->character_saved = FALSE;
 
                        /* Mega-Hack -- reset signal counter */
                        signal_count = 0;
@@ -2282,9 +2285,9 @@ char inkey(void)
  * Note that "quark zero" is NULL and should not be "dereferenced".
  */
 
-/*
- * Initialize the quark array
- */
+ /*
 * Initialize the quark array
 */
 void quark_init(void)
 {
        /* Quark variables */
@@ -2369,10 +2372,10 @@ concptr quark_str(STR_OFFSET i)
 
 
 
-/*!
- * @brief 保存中の過去ゲームメッセージの数を返す。 / How many messages are "available"?
- * @return 残っているメッセージの数
- */
+ /*!
 * @brief 保存中の過去ゲームメッセージの数を返す。 / How many messages are "available"?
 * @return 残っているメッセージの数
 */
 s32b message_num(void)
 {
        int last, next, n;
@@ -2452,7 +2455,7 @@ void message_add(concptr str)
 
                for (n = 0; n < 80; n++, t++)
                {
-                       if(iskanji(*t)) {
+                       if (iskanji(*t)) {
                                t++;
                                n++;
                        }
@@ -2464,10 +2467,11 @@ void message_add(concptr str)
                if (n == 60) n = 80;
 #endif
                splitted2 = str + n;
-               strncpy(splitted1, str ,n);
+               strncpy(splitted1, strn);
                splitted1[n] = '\0';
                str = splitted1;
-       } else {
+       }
+       else {
                splitted2 = NULL;
        }
 
@@ -2501,8 +2505,8 @@ void message_add(concptr str)
 
                /* Find multiple */
 #ifdef JP
-               for (t = buf; *t && (*t != '<' || (*(t+1) != 'x' )); t++) 
-                       if(iskanji(*t))t++;
+               for (t = buf; *t && (*t != '<' || (*(t + 1) != 'x')); t++)
+                       if (iskanji(*t))t++;
 #else
                for (t = buf; *t && (*t != '<'); t++);
 #endif
@@ -2516,7 +2520,7 @@ void message_add(concptr str)
                        *(t - 1) = '\0';
 
                        /* Get multiplier */
-                       j = atoi(t+2);
+                       j = atoi(t + 2);
                }
 
                /* Limit the multiplier to 1000 */
@@ -2631,7 +2635,7 @@ void message_add(concptr str)
                message__tail = message__head + n + 1;
 
                /* Advance tail while possible past first "nul" */
-               while (message__buf[message__tail-1]) message__tail++;
+               while (message__buf[message__tail - 1]) message__tail++;
 
                /* Kill all "dead" messages */
                for (i = message__last; TRUE; i++)
@@ -2690,7 +2694,7 @@ void message_add(concptr str)
        /* recursively add splitted message (added by Mogami) */
 end_of_message_add:
        if (splitted2 != NULL)
-         message_add(splitted2);
+               message_add(splitted2);
 }
 
 
@@ -2698,12 +2702,12 @@ end_of_message_add:
 /*
  * Hack -- flush
  */
-static void msg_flush(int x)
+static void msg_flush(player_type *player_ptr, int x)
 {
        byte a = TERM_L_BLUE;
        bool nagasu = FALSE;
 
-       if ((auto_more && !p_ptr->now_damaged) || num_more < 0){
+       if ((auto_more && !player_ptr->now_damaged) || num_more < 0) {
                int i;
                for (i = 0; i < 8; i++)
                {
@@ -2718,26 +2722,29 @@ static void msg_flush(int x)
                        nagasu = TRUE;
                }
        }
-       p_ptr->now_damaged = FALSE;
 
-       if (!p_ptr->playing || !nagasu)
+       player_ptr->now_damaged = FALSE;
+
+       if (!player_ptr->playing || !nagasu)
        {
                /* Pause for response */
                Term_putstr(x, 0, -1, a, _("-続く-", "-more-"));
 
                /* Get an acceptable keypress */
-               while (1)
+               while (TRUE)
                {
                        int cmd = inkey();
                        if (cmd == ESCAPE) {
-                           num_more = -9999; /*auto_moreのとき、全て流す。 */
-                           break;
-                       } else if (cmd == ' ') {
-                           num_more = 0; /*1画面だけ流す。 */
-                           break;
-                       } else if ((cmd == '\n') || (cmd == '\r')) {
-                           num_more--; /*1行だけ流す。 */
-                           break;
+                               num_more = -9999; /*auto_moreのとき、全て流す。 */
+                               break;
+                       }
+                       else if (cmd == ' ') {
+                               num_more = 0; /*1画面だけ流す。 */
+                               break;
+                       }
+                       else if ((cmd == '\n') || (cmd == '\r')) {
+                               num_more--; /*1行だけ流す。 */
+                               break;
                        }
                        if (quick_messages) break;
                        bell();
@@ -2802,7 +2809,7 @@ void msg_print(concptr msg)
        /* Hack -- flush when requested or needed */
        if (p && (!msg || ((p + n) > 72)))
        {
-               msg_flush(p);
+               msg_flush(p_ptr, p);
 
                /* Forget it */
                msg_flag = FALSE;
@@ -2829,7 +2836,7 @@ void msg_print(concptr msg)
        n = strlen(buf);
 
        /* Memorize the message */
-       if (character_generated) message_add(buf);
+       if (current_world_ptr->character_generated) message_add(buf);
 
        /* Analyze the buffer */
        t = buf;
@@ -2890,10 +2897,10 @@ void msg_print(concptr msg)
                Term_putstr(0, 0, split, TERM_WHITE, t);
 
                /* Flush it */
-               msg_flush(split + 1);
+               msg_flush(p_ptr, split + 1);
 
                /* Memorize the piece */
-               /* if (character_generated) message_add(t); */
+               /* if (current_world_ptr->character_generated) message_add(t); */
 
                /* Restore the split character */
                t[split] = oops;
@@ -2909,10 +2916,10 @@ void msg_print(concptr msg)
        Term_putstr(p, 0, n, TERM_WHITE, t);
 
        /* Memorize the tail */
-       /* if (character_generated) message_add(t); */
+       /* if (current_world_ptr->character_generated) message_add(t); */
 
        p_ptr->window |= (PW_MESSAGE);
-       update_output();
+       update_output(p_ptr);
 
        /* Remember the message */
        msg_flag = TRUE;
@@ -2928,6 +2935,7 @@ void msg_print(concptr msg)
        if (fresh_message) Term_fresh();
 }
 
+
 void msg_print_wizard(int cheat_type, concptr msg)
 {
        if (!cheat_room && cheat_type == CHEAT_DUNGEON) return;
@@ -2935,18 +2943,19 @@ void msg_print_wizard(int cheat_type, concptr msg)
        if (!cheat_hear && cheat_type == CHEAT_MONSTER) return;
        if (!cheat_xtra && cheat_type == CHEAT_MISC) return;
 
-       concptr cheat_mes[] = {"ITEM", "MONS", "DUNG", "MISC"};
+       concptr cheat_mes[] = { "ITEM", "MONS", "DUNG", "MISC" };
        char buf[1024];
        sprintf(buf, "WIZ-%s:%s", cheat_mes[cheat_type], msg);
        msg_print(buf);
 
        if (cheat_diary_output)
        {
-               do_cmd_write_nikki(NIKKI_WIZARD_LOG, 0, buf);
+               exe_write_diary(p_ptr, DIARY_WIZARD_LOG, 0, buf);
        }
 
 }
 
+
 /*
  * Hack -- prevent "accidents" in "screen_save()" or "screen_load()"
  */
@@ -2958,7 +2967,7 @@ static int screen_depth = 0;
  *
  * This function must match exactly one call to "screen_load()".
  */
-void screen_save(void)
+void screen_save()
 {
        /* Hack -- Flush messages */
        msg_print(NULL);
@@ -2967,7 +2976,7 @@ void screen_save(void)
        if (screen_depth++ == 0) Term_save();
 
        /* Increase "icky" depth */
-       character_icky++;
+       current_world_ptr->character_icky++;
 }
 
 
@@ -2976,7 +2985,7 @@ void screen_save(void)
  *
  * This function must match exactly one call to "screen_save()".
  */
-void screen_load(void)
+void screen_load()
 {
        /* Hack -- Flush messages */
        msg_print(NULL);
@@ -2985,7 +2994,7 @@ void screen_load(void)
        if (--screen_depth == 0) Term_load();
 
        /* Decrease "icky" depth */
-       character_icky--;
+       current_world_ptr->character_icky--;
 }
 
 
@@ -3016,10 +3025,10 @@ void msg_format(concptr fmt, ...)
  */
 void msg_format_wizard(int cheat_type, concptr fmt, ...)
 {
-       if(!cheat_room && cheat_type == CHEAT_DUNGEON) return;
-       if(!cheat_peek && cheat_type == CHEAT_OBJECT) return;
-       if(!cheat_hear && cheat_type == CHEAT_MONSTER) return;
-       if(!cheat_xtra && cheat_type == CHEAT_MISC) return;
+       if (!cheat_room && cheat_type == CHEAT_DUNGEON) return;
+       if (!cheat_peek && cheat_type == CHEAT_OBJECT) return;
+       if (!cheat_hear && cheat_type == CHEAT_MONSTER) return;
+       if (!cheat_xtra && cheat_type == CHEAT_MISC) return;
 
        va_list vp;
        char buf[1024];
@@ -3038,7 +3047,6 @@ void msg_format_wizard(int cheat_type, concptr fmt, ...)
 }
 
 
-
 /*
  * Display a string on the screen using an attribute.
  *
@@ -3101,7 +3109,7 @@ void prt(concptr str, TERM_LEN row, TERM_LEN col)
  * This function will correctly handle any width up to the maximum legal
  * value of 256, though it works best for a standard 80 character width.
  */
-void c_roff(byte a, concptr str)
+void c_roff(TERM_COLOR a, concptr str)
 {
        int x, y;
 
@@ -3116,7 +3124,7 @@ void c_roff(byte a, concptr str)
        (void)Term_locate(&x, &y);
 
        /* Hack -- No more space */
-       ify == h - 1 && x > w - 3) return;
+       if (y == h - 1 && x > w - 3) return;
 
        /* Process the string */
        for (s = str; *s; s++)
@@ -3134,7 +3142,7 @@ void c_roff(byte a, concptr str)
                        y++;
 
                        /* No more space */
-                       if( y == h ) break;
+                       if (y == h) break;
 
                        /* Clear line, move cursor */
                        Term_erase(x, y, 255);
@@ -3152,7 +3160,7 @@ void c_roff(byte a, concptr str)
 
                /* Wrap words as needed */
 #ifdef JP
-               if (( x >= ( (k_flag) ? w - 2 : w - 1 ) ) && (ch != ' '))
+               if ((x >= ((k_flag) ? w - 2 : w - 1)) && (ch != ' '))
 #else
                if ((x >= w - 1) && (ch != ' '))
 #endif
@@ -3167,45 +3175,42 @@ void c_roff(byte a, concptr str)
                        if (x < w)
 #ifdef JP
                        {
-                       /* 現在が半角文字の場合 */
-                       if( !k_flag )
+                               /* 現在が半角文字の場合 */
+                               if (!k_flag)
 #endif
-                       {
-                               /* Scan existing text */
-                               for (i = w - 2; i >= 0; i--)
                                {
-                                       /* Grab existing attr/char */
-                                       Term_what(i, y, &av[i], &cv[i]);
+                                       /* Scan existing text */
+                                       for (i = w - 2; i >= 0; i--)
+                                       {
+                                               /* Grab existing attr/char */
+                                               Term_what(i, y, &av[i], &cv[i]);
 
-                                       /* Break on space */
-                                       if (cv[i] == ' ') break;
+                                               /* Break on space */
+                                               if (cv[i] == ' ') break;
 
-                                       /* Track current word */
-                                       n = i;
+                                               /* Track current word */
+                                               n = i;
 #ifdef JP
-                                       if (cv[i] == '(') break;
+                                               if (cv[i] == '(') break;
 #endif
+                                       }
                                }
-                       }
 
 #ifdef JP
-                       else
-                       {
-                               /* 現在が全角文字のとき */
-                               /* 文頭が「。」「、」等になるときは、その1つ前の語で改行 */
-                               if (strncmp(s, "。", 2) == 0 || strncmp(s, "、", 2) == 0
-#if 0                   /* 一般的には「ィ」「ー」は禁則の対象外 */
-                                       || strncmp(s, "ィ", 2) == 0 || strncmp(s, "ー", 2) == 0
-#endif
-                              ){
-                                       Term_what(x  , y, &av[x  ], &cv[x  ]);
-                                       Term_what(x-1, y, &av[x-1], &cv[x-1]);
-                                       Term_what(x-2, y, &av[x-2], &cv[x-2]);
-                                       n = x - 2;
-                                       cv[ x ] = '\0';
+                               else
+                               {
+                                       /* 現在が全角文字のとき */
+                                       /* 文頭が「。」「、」等になるときは、その1つ前の語で改行 */
+                                       if (strncmp(s, "。", 2) == 0 || strncmp(s, "、", 2) == 0)
+                                       {
+                                               Term_what(x, y, &av[x], &cv[x]);
+                                               Term_what(x - 1, y, &av[x - 1], &cv[x - 1]);
+                                               Term_what(x - 2, y, &av[x - 2], &cv[x - 2]);
+                                               n = x - 2;
+                                               cv[x] = '\0';
+                                       }
                                }
                        }
-                       }
 #endif
                        /* Special case */
                        if (n == 0) n = w;
@@ -3218,7 +3223,7 @@ void c_roff(byte a, concptr str)
                        y++;
 
                        /* No more space */
-                       if( y == h ) break;
+                       if (y == h) break;
 
                        /* Clear line, move cursor */
                        Term_erase(x, y, 255);
@@ -3227,7 +3232,7 @@ void c_roff(byte a, concptr str)
                        for (i = n; i < w - 1; i++)
                        {
 #ifdef JP
-                               if( cv[i] == '\0' ) break;
+                               if (cv[i] == '\0') break;
 #endif
                                /* Dump */
                                Term_addch(av[i], cv[i]);
@@ -3239,7 +3244,7 @@ void c_roff(byte a, concptr str)
 
                /* Dump */
 #ifdef JP
-               Term_addch((byte)(a|0x10), ch);
+               Term_addch((byte)(a | 0x10), ch);
 #else
                Term_addch(a, ch);
 #endif
@@ -3251,7 +3256,7 @@ void c_roff(byte a, concptr str)
                        s++;
                        x++;
                        ch = *s;
-                       Term_addch((byte)(a|0x20), ch);
+                       Term_addch((byte)(a | 0x20), ch);
                }
 #endif
                /* Advance */
@@ -3371,7 +3376,7 @@ bool askfor_aux(char *buf, int len, bool numpad_cursor)
                                if (iskanji(buf[i])) next_pos++;
 #endif
 
-                               /* Is there the cursor at next position? */ 
+                               /* Is there the cursor at next position? */
                                if (next_pos >= pos) break;
 
                                /* Move to next */
@@ -3431,7 +3436,7 @@ bool askfor_aux(char *buf, int len, bool numpad_cursor)
                                if (iskanji(buf[i])) next_pos++;
 #endif
 
-                               /* Is there the cursor at next position? */ 
+                               /* Is there the cursor at next position? */
                                if (next_pos >= pos) break;
 
                                /* Move to next */
@@ -3615,29 +3620,29 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode)
        if (auto_more)
        {
                p_ptr->window |= PW_MESSAGE;
-               handle_stuff();
+               handle_stuff(p_ptr);
                num_more = 0;
        }
+
        msg_print(NULL);
 
        if (!rogue_like_commands)
                mode &= ~CHECK_OKAY_CANCEL;
 
-
        /* Hack -- Build a "useful" prompt */
        if (mode & CHECK_OKAY_CANCEL)
        {
-               my_strcpy(buf, prompt, sizeof(buf)-15);
+               my_strcpy(buf, prompt, sizeof(buf) - 15);
                strcat(buf, "[(O)k/(C)ancel]");
        }
        else if (mode & CHECK_DEFAULT_Y)
        {
-               my_strcpy(buf, prompt, sizeof(buf)-5);
+               my_strcpy(buf, prompt, sizeof(buf) - 5);
                strcat(buf, "[Y/n]");
        }
        else
        {
-               my_strcpy(buf, prompt, sizeof(buf)-5);
+               my_strcpy(buf, prompt, sizeof(buf) - 5);
                strcat(buf, "[y/n]");
        }
 
@@ -3649,7 +3654,7 @@ bool get_check_strict(concptr prompt, BIT_FLAGS mode)
                /* HACK : Add the line to message buffer */
                message_add(buf);
                p_ptr->window |= (PW_MESSAGE);
-               handle_stuff();
+               handle_stuff(p_ptr);
        }
 
        /* Get an acceptable answer */
@@ -3734,11 +3739,11 @@ bool get_com(concptr prompt, char *command, bool z_escape)
        prt("", 0, 0);
 
        /* Handle "cancel" */
-       if (*command == ESCAPE) return (FALSE);
-       if (z_escape && ((*command == 'z') || (*command == 'Z'))) return (FALSE);
+       if (*command == ESCAPE) return FALSE;
+       if (z_escape && ((*command == 'z') || (*command == 'Z'))) return FALSE;
 
        /* Success */
-       return (TRUE);
+       return TRUE;
 }
 
 
@@ -3790,7 +3795,6 @@ QUANTITY get_quantity(concptr prompt, QUANTITY max)
        /* Build a prompt if needed */
        if (!prompt)
        {
-               /* Build a prompt */
                sprintf(tmp, _("いくつですか (1-%d): ", "Quantity (1-%d): "), max);
 
                /* Use that prompt */
@@ -3839,7 +3843,7 @@ QUANTITY get_quantity(concptr prompt, QUANTITY max)
 
 
 /*
- * Pause for user response 
+ * Pause for user response
  */
 void pause_line(int row)
 {
@@ -4100,7 +4104,7 @@ menu_naiyou menu_info[10][10] =
                {"Identify symbol(/)", '/', TRUE},
                {"Show prev messages(^p)", KTRL('P'), TRUE},
                {"Current time(^t/')", KTRL('T'), TRUE},
-               {"Various informations(~)", '~', TRUE},
+               {"Various information(~)", '~', TRUE},
                {"Play record menu(|)", '|', TRUE},
                {"", 0, FALSE}
        },
@@ -4179,7 +4183,7 @@ special_menu_naiyou special_menu_info[] =
 };
 #endif
 
-static char inkey_from_menu(void)
+static char inkey_from_menu(player_type *player_ptr)
 {
        char cmd;
        int basey, basex;
@@ -4187,7 +4191,7 @@ static char inkey_from_menu(void)
        int menu = 0;
        bool kisuu;
 
-       if (p_ptr->y - panel_row_min > 10) basey = 2;
+       if (player_ptr->y - panel_row_min > 10) basey = 2;
        else basey = 13;
        basex = 15;
 
@@ -4196,38 +4200,39 @@ static char inkey_from_menu(void)
 
        screen_save();
 
-       while(1)
+       floor_type* floor_ptr = player_ptr->current_floor_ptr;
+       while (TRUE)
        {
                int i;
                char sub_cmd;
                concptr menu_name;
                if (!menu) old_num = num;
                put_str("+----------------------------------------------------+", basey, basex);
-               put_str("|                                                    |", basey+1, basex);
-               put_str("|                                                    |", basey+2, basex);
-               put_str("|                                                    |", basey+3, basex);
-               put_str("|                                                    |", basey+4, basex);
-               put_str("|                                                    |", basey+5, basex);
-               put_str("+----------------------------------------------------+", basey+6, basex);
-
-               for(i = 0; i < 10; i++)
+               put_str("|                                                    |", basey + 1, basex);
+               put_str("|                                                    |", basey + 2, basex);
+               put_str("|                                                    |", basey + 3, basex);
+               put_str("|                                                    |", basey + 4, basex);
+               put_str("|                                                    |", basey + 5, basex);
+               put_str("+----------------------------------------------------+", basey + 6, basex);
+
+               for (i = 0; i < 10; i++)
                {
                        int hoge;
                        if (!menu_info[menu][i].cmd) break;
                        menu_name = menu_info[menu][i].name;
-                       for(hoge = 0; ; hoge++)
+                       for (hoge = 0; ; hoge++)
                        {
                                if (!special_menu_info[hoge].name[0]) break;
                                if ((menu != special_menu_info[hoge].window) || (i != special_menu_info[hoge].number)) continue;
-                               switch(special_menu_info[hoge].jouken)
+                               switch (special_menu_info[hoge].jouken)
                                {
                                case MENU_CLASS:
-                                       if (p_ptr->pclass == special_menu_info[hoge].jouken_naiyou) menu_name = special_menu_info[hoge].name;
+                                       if (player_ptr->pclass == special_menu_info[hoge].jouken_naiyou) menu_name = special_menu_info[hoge].name;
                                        break;
                                case MENU_WILD:
-                                       if (!current_floor_ptr->dun_level && !p_ptr->inside_arena && !p_ptr->inside_quest)
+                                       if (!floor_ptr->dun_level && !floor_ptr->inside_arena && !floor_ptr->inside_quest)
                                        {
-                                               if ((byte)p_ptr->wild_mode == special_menu_info[hoge].jouken_naiyou) menu_name = special_menu_info[hoge].name;
+                                               if ((byte)player_ptr->wild_mode == special_menu_info[hoge].jouken_naiyou) menu_name = special_menu_info[hoge].name;
                                        }
                                        break;
                                default:
@@ -4238,10 +4243,10 @@ static char inkey_from_menu(void)
                }
                max_num = i;
                kisuu = max_num % 2;
-               put_str(_("》", "> "),basey + 1 + num / 2, basex + 2 + (num % 2) * 24);
+               put_str(_("》", "> "), basey + 1 + num / 2, basex + 2 + (num % 2) * 24);
 
                /* Place the cursor on the player */
-               move_cursor_relative(p_ptr->y, p_ptr->x);
+               move_cursor_relative(player_ptr->y, player_ptr->x);
 
                sub_cmd = inkey();
                if ((sub_cmd == ' ') || (sub_cmd == 'x') || (sub_cmd == 'X') || (sub_cmd == '\r') || (sub_cmd == '\n'))
@@ -4321,8 +4326,8 @@ static char inkey_from_menu(void)
 /*
  * Request a command from the user.
  *
- * Sets p_ptr->command_cmd, p_ptr->command_dir, p_ptr->command_rep,
- * p_ptr->command_arg.  May modify p_ptr->command_new.
+ * Sets player_ptr->command_cmd, player_ptr->command_dir, player_ptr->command_rep,
+ * player_ptr->command_arg.  May modify player_ptr->command_new.
  *
  * Note that "caret" ("^") is treated specially, and is used to
  * allow manual input of control characters.  This can be used
@@ -4335,9 +4340,9 @@ static char inkey_from_menu(void)
  * Note that this command is used both in the dungeon and in
  * stores, and must be careful to work in both situations.
  *
- * Note that "p_ptr->command_new" may not work any more.  
+ * Note that "player_ptr->command_new" may not work any more.
  */
-void request_command(int shopping)
+void request_command(player_type *player_ptr, int shopping)
 {
        int i;
 
@@ -4375,7 +4380,7 @@ void request_command(int shopping)
 
 
        /* Get command */
-       while (1)
+       while (TRUE)
        {
                /* Hack -- auto-commands */
                if (command_new)
@@ -4402,8 +4407,8 @@ void request_command(int shopping)
                        cmd = inkey();
 
                        if (!shopping && command_menu && ((cmd == '\r') || (cmd == '\n') || (cmd == 'x') || (cmd == 'X'))
-                           && !keymap_act[mode][(byte)(cmd)])
-                               cmd = inkey_from_menu();
+                               && !keymap_act[mode][(byte)(cmd)])
+                               cmd = inkey_from_menu(player_ptr);
                }
 
                /* Clear top line */
@@ -4422,7 +4427,7 @@ void request_command(int shopping)
                        prt(_("回数: ", "Count: "), 0, 0);
 
                        /* Get a command count */
-                       while (1)
+                       while (TRUE)
                        {
                                /* Get a new keypress */
                                cmd = inkey();
@@ -4578,7 +4583,7 @@ void request_command(int shopping)
                concptr s;
                if ((s = keymap_act[mode][i]) != NULL)
                {
-                       if (*s == command_cmd && *(s+1) == 0)
+                       if (*s == command_cmd && *(s + 1) == 0)
                        {
                                caretcmd = i;
                                break;
@@ -4594,7 +4599,7 @@ void request_command(int shopping)
        {
                concptr s;
 
-               object_type *o_ptr = &p_ptr->inventory_list[i];
+               object_type *o_ptr = &player_ptr->inventory_list[i];
                if (!o_ptr->k_idx) continue;
 
                /* No inscription */
@@ -4654,72 +4659,13 @@ bool is_a_vowel(int ch)
        case 'I':
        case 'O':
        case 'U':
-               return (TRUE);
-       }
-
-       return (FALSE);
-}
-
-
-
-#if 0
-
-/*
- * Replace the first instance of "target" in "buf" with "insert"
- * If "insert" is NULL, just remove the first instance of "target"
- * In either case, return TRUE if "target" is found.
- *
- * XXX Could be made more efficient, especially in the
- * case where "insert" is smaller than "target".
- */
-static bool insert_str(char *buf, concptr target, concptr insert)
-{
-       int   i, len;
-       int                b_len, t_len, i_len;
-
-       /* Attempt to find the target (modify "buf") */
-       buf = my_strstr(buf, target);
-
-       /* No target found */
-       if (!buf) return (FALSE);
-
-       /* Be sure we have an insertion string */
-       if (!insert) insert = "";
-
-       /* Extract some lengths */
-       t_len = strlen(target);
-       i_len = strlen(insert);
-       b_len = strlen(buf);
-
-       /* How much "movement" do we need? */
-       len = i_len - t_len;
-
-       /* We need less space (for insert) */
-       if (len < 0)
-       {
-               for (i = t_len; i < b_len; ++i) buf[i+len] = buf[i];
-       }
-
-       /* We need more space (for insert) */
-       else if (len > 0)
-       {
-               for (i = b_len-1; i >= t_len; --i) buf[i+len] = buf[i];
+               return TRUE;
        }
 
-       /* If movement occured, we need a new terminator */
-       if (len) buf[b_len+len] = '\0';
-
-       /* Now copy the insertion string */
-       for (i = 0; i < i_len; ++i) buf[i] = insert[i];
-
-       /* Successful operation */
-       return (TRUE);
+       return FALSE;
 }
 
 
-#endif
-
-
 /*
  * GH
  * Called from cmd4.c and a few other places. Just extracts
@@ -4803,13 +4749,13 @@ void repeat_push(COMMAND_CODE what)
 bool repeat_pull(COMMAND_CODE *what)
 {
        /* All out of keys */
-       if (repeat__idx == repeat__cnt) return (FALSE);
+       if (repeat__idx == repeat__cnt) return FALSE;
 
        /* Grab the next key, advance */
        *what = repeat__key[repeat__idx++];
 
        /* Success */
-       return (TRUE);
+       return TRUE;
 }
 
 void repeat_check(void)
@@ -4851,8 +4797,6 @@ void repeat_check(void)
 }
 
 
-#ifdef SORT_R_INFO
-
 /*
  * Array size for which InsertionSort
  * is used instead of QuickSort
@@ -4860,11 +4804,11 @@ void repeat_check(void)
 #define CUTOFF 4
 
 
-/*
- * Exchange two sort-entries
- * (should probably be coded inline
- * for speed increase)
- */
+ /*
 * Exchange two sort-entries
 * (should probably be coded inline
 * for speed increase)
 */
 static void swap(tag_type *a, tag_type *b)
 {
        tag_type temp;
@@ -4935,7 +4879,7 @@ static void quicksort(tag_type elements[], int left, int right)
        {
                pivot = median3(elements, left, right);
 
-               i = left; j = right -1;
+               i = left; j = right - 1;
 
                while (TRUE)
                {
@@ -4973,10 +4917,6 @@ void tag_sort(tag_type elements[], int number)
        quicksort(elements, 0, number - 1);
 }
 
-#endif /* SORT_R_INFO */
-
-#ifdef SUPPORT_GAMMA
-
 /* Table of gamma values */
 byte gamma_table[256];
 
@@ -5002,49 +4942,49 @@ static s16b gamma_helper[256] =
 };
 
 
-/* 
+/*
  * Build the gamma table so that floating point isn't needed.
- * 
+ *
  * Note gamma goes from 0->256.  The old value of 100 is now 128.
  */
 void build_gamma_table(int gamma)
 {
        int i, n;
-       
+
        /*
         * value is the current sum.
         * diff is the new term to add to the series.
         */
        long value, diff;
-       
+
        /* Hack - convergence is bad in these cases. */
        gamma_table[0] = 0;
        gamma_table[255] = 255;
-       
+
        for (i = 1; i < 255; i++)
        {
-               /* 
+               /*
                 * Initialise the Taylor series
                 *
                 * value and diff have been scaled by 256
                 */
-               
+
                n = 1;
                value = 256 * 256;
                diff = ((long)gamma_helper[i]) * (gamma - 256);
-               
+
                while (diff)
                {
                        value += diff;
                        n++;
-                       
-                       
+
+
                        /*
                         * Use the following identiy to calculate the gamma table.
                         * exp(x) = 1 + x + x^2/2 + x^3/(2*3) + x^4/(2*3*4) +...
                         *
                         * n is the current term number.
-                        * 
+                        *
                         * The gamma_helper array contains a table of
                         * ln(x/256) * 256
                         * This is used because a^b = exp(b*ln(a))
@@ -5061,8 +5001,8 @@ void build_gamma_table(int gamma)
                         */
                        diff = (((diff / 256) * gamma_helper[i]) * (gamma - 256)) / (256 * n);
                }
-               
-               /* 
+
+               /*
                 * Store the value in the table so that the
                 * floating point pow function isn't needed .
                 */
@@ -5070,8 +5010,6 @@ void build_gamma_table(int gamma)
        }
 }
 
-#endif /* SUPPORT_GAMMA */
-
 
 /*
  * Add a series of keypresses to the "queue".
@@ -5099,7 +5037,7 @@ errr type_string(concptr str, uint len)
        /* Activate the main window, as all pastes go there. */
        Term_activate(term_screen);
 
-       for (s = str; s < str+len; s++)
+       for (s = str; s < str + len; s++)
        {
                /* Catch end of string */
                if (*s == '\0') break;
@@ -5139,17 +5077,17 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize)
                ch[0] = str[read_pt];
                ch[1] = '\0';
 #ifdef JP
-               kanji  = iskanji(ch[0]);
+               kanji = iskanji(ch[0]);
 
                if (kanji)
                {
-                       ch[1] = str[read_pt+1];
+                       ch[1] = str[read_pt + 1];
                        ch_len = 2;
 
                        if (strcmp(ch, "。") == 0 ||
-                           strcmp(ch, "、") == 0 ||
-                           strcmp(ch, "ィ") == 0 ||
-                           strcmp(ch, "ー") == 0)
+                               strcmp(ch, "、") == 0 ||
+                               strcmp(ch, "ィ") == 0 ||
+                               strcmp(ch, "ー") == 0)
                                kinsoku = TRUE;
                }
                else if (!isprint(ch[0]))
@@ -5168,18 +5106,18 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize)
                        word_len = read_pt - word_punct;
 #ifdef JP
                        if (kanji && !kinsoku)
-                               /* nothing */ ;
+                               /* nothing */;
                        else
 #endif
-                       if (ch[0] == ' ' || word_len >= line_len/2)
-                               read_pt++;
-                       else
-                       {
-                               read_pt = word_punct;
-                               if (str[word_punct] == ' ')
+                               if (ch[0] == ' ' || word_len >= line_len / 2)
                                        read_pt++;
-                               write_pt -= word_len;
-                       }
+                               else
+                               {
+                                       read_pt = word_punct;
+                                       if (str[word_punct] == ' ')
+                                               read_pt++;
+                                       write_pt -= word_len;
+                               }
 
                        tbuf[write_pt++] = '\0';
                        line_len = 0;
@@ -5208,7 +5146,7 @@ void roff_to_buf(concptr str, int maxlen, char *tbuf, size_t bufsize)
 #endif
        }
        tbuf[write_pt] = '\0';
-       tbuf[write_pt+1] = '\0';
+       tbuf[write_pt + 1] = '\0';
 
        return;
 }
@@ -5241,7 +5179,7 @@ size_t my_strcpy(char *buf, concptr src, size_t bufsize)
                {
                        if (iskanji(*s))
                        {
-                               if (len + 1 >= bufsize || !*(s+1)) break;
+                               if (len + 1 >= bufsize || !*(s + 1)) break;
                                *d++ = *s++;
                                *d++ = *s++;
                                len += 2;
@@ -5255,7 +5193,7 @@ size_t my_strcpy(char *buf, concptr src, size_t bufsize)
                *d = '\0';
        }
 
-       while(*s++) len++;
+       while (*s++) len++;
 
        return len;
 
@@ -5321,9 +5259,9 @@ char *my_strstr(concptr haystack, concptr needle)
 
        if (l1 >= l2)
        {
-               for(i = 0; i <= l1 - l2; i++)
+               for (i = 0; i <= l1 - l2; i++)
                {
-                       if(!strncmp(haystack + i, needle, l2))
+                       if (!strncmp(haystack + i, needle, l2))
                                return (char *)haystack + i;
 
 #ifdef JP
@@ -5343,7 +5281,7 @@ char *my_strstr(concptr haystack, concptr needle)
  */
 char *my_strchr(concptr ptr, char ch)
 {
-       for ( ; *ptr != '\0'; ptr++)
+       for (; *ptr != '\0'; ptr++)
        {
                if (*ptr == ch) return (char *)ptr;
 
@@ -5511,7 +5449,7 @@ int inkey_special(bool numpad_cursor)
                for (i = 0; special_key_list[i].keyname; i++)
                {
                        if ((!special_key_list[i].numpad || numpad_cursor) &&
-                           streq(str, special_key_list[i].keyname))
+                               streq(str, special_key_list[i].keyname))
                        {
                                skey = special_key_list[i].keycode;
                                break;