OSDN Git Service

Add a monster, Young quicksilver dragon.
[hengband/hengband.git] / src / util.c
index 008a0ad..8935a34 100644 (file)
@@ -293,7 +293,11 @@ static errr path_temp(char *buf, int max)
        if (!s) return (-1);
 
        /* Format to length */
+#ifndef WIN32
        (void)strnfmt(buf, max, "%s", s);
+#else
+       (void)strnfmt(buf, max, ".%s", s);
+#endif
 
        /* Success */
        return (0);
@@ -657,7 +661,19 @@ errr fd_copy(cptr file, cptr what)
        /* Copy */
        while ((read_num = read(src_fd, buf, 1024)) > 0)
        {
-               write(dst_fd, buf, read_num);
+               int write_num = 0;
+               while (write_num < read_num)
+               {
+                       int ret = write(dst_fd, buf + write_num, read_num - write_num);
+                       if (ret < 0) {
+                               /* Close files */
+                               fd_close(src_fd);
+                               fd_close(dst_fd);
+
+                               return ret;
+                       }
+                       write_num += ret;
+               }
        }
 
        /* Close files */
@@ -1788,10 +1804,10 @@ static char inkey_aux(void)
                else
                {
                        /* Increase "wait" */
-                       w += 10;
+                       w += 1;
 
                        /* Excessive delay */
-                       if (w >= 100) break;
+                       if (w >= 10) break;
 
                        /* Delay */
                        Term_xtra(TERM_XTRA_DELAY, w);
@@ -2451,7 +2467,7 @@ void message_add(cptr str)
                }
 
                /* Limit the multiplier to 1000 */
-               if (buf && streq(buf, str) && (j < 1000))
+               if (streq(buf, str) && (j < 1000))
                {
                        j++;
 
@@ -3622,7 +3638,10 @@ bool get_com(cptr prompt, char *command, bool z_escape)
        prt(prompt, 0, 0);
 
        /* Get a key */
-       *command = inkey();
+       if (get_com_no_macros)
+               *command = inkey_special(FALSE);
+       else
+               *command = inkey();
 
        /* Clear the prompt */
        prt("", 0, 0);
@@ -4846,14 +4865,9 @@ static void swap(tag_type *a, tag_type *b)
 {
        tag_type temp;
 
-       temp.tag = a->tag;
-       temp.pointer = a->pointer;
-
-       a->tag = b->tag;
-       a->pointer = b->pointer;
-
-       b->tag = temp.tag;
-       b->pointer = temp.pointer;
+       temp = *a;
+       *a = *b;
+       *b = temp;
 }
 
 
@@ -5214,26 +5228,29 @@ size_t my_strcpy(char *buf, const char *src, size_t bufsize)
        const char *s = src;
        size_t len = 0;
 
-       /* reserve for NUL termination */
-       bufsize--;
+       if (bufsize > 0) {
+               /* reserve for NUL termination */
+               bufsize--;
 
-       /* Copy as many bytes as will fit */
-       while (len < bufsize)
-       {
-               if (iskanji(*s))
-               {
-                       if (len + 1 >= bufsize || !*(s+1)) break;
-                       *d++ = *s++;
-                       *d++ = *s++;
-                       len += 2;
-               }
-               else
+               /* Copy as many bytes as will fit */
+               while (*s && (len < bufsize))
                {
-                       *d++ = *s++;
-                       len++;
+                       if (iskanji(*s))
+                       {
+                               if (len + 1 >= bufsize || !*(s+1)) break;
+                               *d++ = *s++;
+                               *d++ = *s++;
+                               len += 2;
+                       }
+                       else
+                       {
+                               *d++ = *s++;
+                               len++;
+                       }
                }
+               *d = '\0';
        }
-       *d = '\0';
+
        while(*s++) len++;
 
        return len;
@@ -5318,7 +5335,7 @@ char *my_strstr(const char *haystack, const char *needle)
 
 
 /*
- * A copy of ANSI my_strchr()
+ * A copy of ANSI strchr()
  *
  * my_strchr() can handle Kanji strings correctly.
  */
@@ -5406,6 +5423,22 @@ int inkey_special(bool numpad_cursor)
                {TRUE, "KP_1]", SKEY_BOTTOM},
                {FALSE, NULL, 0},
        };
+
+       static const struct {
+               cptr keyname;
+               int keycode;
+       } gcu_special_key_list[] = {
+               {"A", SKEY_UP},
+               {"B", SKEY_DOWN},
+               {"C", SKEY_RIGHT},
+               {"D", SKEY_LEFT},
+               {"1~", SKEY_TOP},
+               {"4~", SKEY_BOTTOM},
+               {"5~", SKEY_PGUP},
+               {"6~", SKEY_PGDOWN},
+               {NULL, 0},
+       };
+
        char buf[1024];
        cptr str = buf;
        char key;
@@ -5494,6 +5527,19 @@ int inkey_special(bool numpad_cursor)
                }
        }
 
+       if (prefix(str, "\\e["))
+       {
+               str += 3;
+
+               for (i = 0; gcu_special_key_list[i].keyname; i++)
+               {
+                       if (streq(str, gcu_special_key_list[i].keyname))
+                       {
+                               return gcu_special_key_list[i].keycode;
+                       }
+               }
+       }
+
        /* No special key found? */
 
        /* Don't bother with this trigger no more */