OSDN Git Service

Vanillaにならって、キャラクターの状態を表わすグローバル変数の多くを
[hengband/hengband.git] / src / util.c
index aa64f61..781a3c3 100644 (file)
 
 static int num_more = 0;
 
-#ifndef HAS_MEMSET
-
-/*
- * For those systems that don't have "memset()"
- *
- * Set the value of each of 'n' bytes starting at 's' to 'c', return 's'
- * If 'n' is negative, you will erase a whole lot of memory.
- */
-char *memset(char *s, int c, huge n)
-{
-       char *t;
-       for (t = s; len--; ) *t++ = c;
-       return (s);
-}
-
-#endif
-
-
 #if 0
 #ifndef HAS_STRICMP
 
@@ -57,7 +39,7 @@ int stricmp(cptr a, cptr b)
 
 #ifdef SET_UID
 
-# ifndef HAS_USLEEP
+# ifndef HAVE_USLEEP
 
 /*
  * For those systems that don't have "usleep()" but need it.
@@ -109,10 +91,12 @@ int usleep(huge usecs)
 
 
 /*
-* Hack -- External functions
-*/
-extern struct passwd *getpwuid();
-extern struct passwd *getpwnam();
+ * Hack -- External functions
+ */
+#ifdef SET_UID
+extern struct passwd *getpwuid(uid_t uid);
+extern struct passwd *getpwnam(const char *name);
+#endif
 
 
 /*
@@ -120,7 +104,6 @@ extern struct passwd *getpwnam();
  */
 void user_name(char *buf, int id)
 {
-#ifdef SET_UID
        struct passwd *pw;
 
        /* Look up the user name */
@@ -140,7 +123,6 @@ void user_name(char *buf, int id)
 
                return;
        }
-#endif /* SET_UID */
 
        /* Oops.  Hack -- default to "PLAYER" */
        strcpy(buf, "PLAYER");
@@ -371,10 +353,13 @@ FILE *my_fopen(cptr file, cptr mode)
        if (path_parse(buf, 1024, file)) return (NULL);
 
 #if defined(MACINTOSH) && defined(MAC_MPW)
-       /* setting file type/creator -- AR */
-       tempfff = fopen(buf, mode);
-       fsetfileinfo(file, _fcreator, _ftype);
-       fclose(tempfff);
+       if (strchr(mode, 'w'))
+       {
+               /* setting file type/creator */
+               tempfff = fopen(buf, mode);
+               fsetfileinfo(file, _fcreator, _ftype);
+               fclose(tempfff);
+       }
 #endif
 
        /* Attempt to fopen the file anyway */
@@ -408,7 +393,7 @@ FILE *my_fopen_temp(char *buf, int max)
        int fd;
 
        /* Prepare the buffer for mkstemp */
-       (void)strnfmt(buf, max, "%s", "/tmp/anXXXXXX");
+       strncpy(buf, "/tmp/anXXXXXX", max);
 
        /* Secure creation of a temporary file */
        fd = mkstemp(buf);
@@ -808,9 +793,6 @@ errr fd_seek(int fd, huge n)
        p = lseek(fd, n, SEEK_SET);
 
        /* Failure */
-       if (p < 0) return (1);
-
-       /* Failure */
        if (p != n) return (1);
 
        /* Success */
@@ -1277,7 +1259,7 @@ void text_to_ascii(char *buf, cptr str)
 }
 
 
-bool trigger_ascii_to_text(char **bufptr, cptr *strptr)
+static bool trigger_ascii_to_text(char **bufptr, cptr *strptr)
 {
        char *s = *bufptr;
        cptr str = *strptr;
@@ -1627,21 +1609,6 @@ errr macro_add(cptr pat, cptr act)
 
 
 /*
- * Initialize the "macro" package
- */
-errr macro_init(void)
-{
-       /* Macro patterns */
-       C_MAKE(macro__pat, MACRO_MAX, cptr);
-
-       /* Macro actions */
-       C_MAKE(macro__act, MACRO_MAX, cptr);
-
-       /* Success */
-       return (0);
-}
-
-/*
  * Local variable -- we are inside a "macro action"
  *
  * Do not match any macros until "ascii 30" is found.
@@ -1746,6 +1713,8 @@ static char inkey_aux(void)
        /* Inside "macro trigger" */
        if (parse_under) return (ch);
 
+       /* Parse special key only */
+       if (inkey_special && ch != 31) return (ch);
 
        /* Save the first key, advance */
        buf[p++] = ch;
@@ -1957,7 +1926,7 @@ char inkey(void)
                ch = *inkey_next++;
 
                /* Cancel the various "global parameters" */
-               inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE;
+               inkey_base = inkey_xtra = inkey_flag = inkey_scan = inkey_special = FALSE;
 
                /* Accept result */
                return (ch);
@@ -1973,7 +1942,7 @@ char inkey(void)
        if (inkey_hack && ((ch = (*inkey_hack)(inkey_xtra)) != 0))
        {
                /* Cancel the various "global parameters" */
-               inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE;
+               inkey_base = inkey_xtra = inkey_flag = inkey_scan = inkey_special = FALSE;
 
                /* Accept result */
                return (ch);
@@ -2158,7 +2127,7 @@ char inkey(void)
 
 
        /* Cancel the various "global parameters" */
-       inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE;
+       inkey_base = inkey_xtra = inkey_flag = inkey_scan = inkey_special = FALSE;
 
        /* Return the keypress */
        return (ch);
@@ -2605,7 +2574,7 @@ static void msg_flush(int x)
        }
        now_damaged = FALSE;
 
-       if (!alive || !nagasu)
+       if (!p_ptr->playing || !nagasu)
        {
                /* Pause for response */
 #ifdef JP
@@ -3317,8 +3286,9 @@ bool get_check(cptr prompt)
 /*
  * Verify something with the user strictly
  *
- * mode & 0x01 : force user to answer "YES" or "N"
- * mode & 0x02 : don't allow ESCAPE key
+ * mode & CHECK_OKAY_CANCEL : force user to answer 'O'kay or 'C'ancel
+ * mode & CHECK_NO_ESCAPE   : don't allow ESCAPE key
+ * mode & CHECK_NO_HISTORY  : no message_add
  */
 bool get_check_strict(cptr prompt, int mode)
 {
@@ -3336,11 +3306,11 @@ bool get_check_strict(cptr prompt, int mode)
        msg_print(NULL);
 
        if (!rogue_like_commands)
-               mode &= ~1;
+               mode &= ~CHECK_OKAY_CANCEL;
 
 
        /* Hack -- Build a "useful" prompt */
-       if (mode & 1)
+       if (mode & CHECK_OKAY_CANCEL)
        {
 #ifdef JP
                /* (79-8)¥Ð¥¤¥È¤Î»ØÄê, prompt¤¬Ä¹¤«¤Ã¤¿¾ì¹ç, 
@@ -3348,12 +3318,13 @@ bool get_check_strict(cptr prompt, int mode)
                   ±Ñ¸ì¤ÎÊý¤Îstrncpy¤È¤Ï°ã¤¦¤Î¤ÇÃí°Õ.
                   else¤ÎÊý¤Îʬ´ô¤âƱÍÍ. --henkma
                */
-               mb_strlcpy(buf, prompt, 80-8);
+               mb_strlcpy(buf, prompt, 80-15);
 #else
-               strncpy(buf, prompt, 79-8);
+               strncpy(buf, prompt, 79-15);
                buf[79-8]='\0';
 #endif
-               strcat(buf, "[yes/no]");
+               strcat(buf, "[(O)k/(C)ancel]");
+
        }
        else
        {
@@ -3369,43 +3340,42 @@ bool get_check_strict(cptr prompt, int mode)
        /* Prompt for it */
        prt(buf, 0, 0);
 
+       if (!(mode & CHECK_NO_HISTORY))
+       {
+               /* HACK : Add the line to message buffer */
+               message_add(buf);
+               p_ptr->window |= (PW_MESSAGE);
+               window_stuff();
+       }
+
        /* Get an acceptable answer */
        while (TRUE)
        {
                i = inkey();
-
-               if (i == 'y' || i == 'Y')
+               if (mode & CHECK_OKAY_CANCEL)
                {
-                       if (!(mode & 1))
+                       if ( i == 'o' || i == 'O' )
+                       {
+                               i = 'Y';
                                break;
-                       else
+                       }
+               }
+               else if (i == 'y' || i == 'Y')
+               {
+                               break;
+               }
+               if (!(mode & CHECK_NO_ESCAPE) && (i == ESCAPE)) break;
+               if ( mode & CHECK_OKAY_CANCEL )
+               {
+                       if ( i == 'c' || i == 'C' )
                        {
-#ifdef JP
-                               prt("y (YES¤ÈÆþÎϤ·¤Æ¤¯¤À¤µ¤¤)", 0, strlen(buf));
-#else
-                               prt("y (Please answer YES.)", 0, strlen(buf));
-#endif
-                               i = inkey();
-                               if (i == 'e' || i == 'E')
-                               {
-#ifdef JP
-                                       prt("e (YES¤ÈÆþÎϤ·¤Æ¤¯¤À¤µ¤¤)", 0, strlen(buf)+1);
-#else
-                                       prt("e (Please answer YES.)", 0, strlen(buf)+1);
-#endif
-                                       i = inkey();
-                                       if (i == 's' || i == 'S')
-                                       {
-                                               i = 'y';
-                                               break;
-                                       }
-                                       prt("", 0, strlen(buf)+1);
-                               }
-                               prt("", 0, strlen(buf));
+                               break;
                        }
                }
-               if (!(mode & 2) && (i == ESCAPE)) break;
-               if (strchr("Nn", i)) break;
+               else if (i == 'n' || i == 'N')
+               {
+                               break;
+               }
                bell();
        }
 
@@ -3953,7 +3923,7 @@ static char inkey_from_menu(void)
 
                /* Get a command */
                sub_cmd = inkey();
-               if ((sub_cmd == ' ') || (sub_cmd == 'x') || (sub_cmd == 'X') || (sub_cmd == '\r'))
+               if ((sub_cmd == ' ') || (sub_cmd == 'x') || (sub_cmd == 'X') || (sub_cmd == '\r') || (sub_cmd == '\n'))
                {
                        if (menu_info[menu][num].fin)
                        {
@@ -4831,43 +4801,63 @@ void roff_to_buf(cptr str, int maxlen, char *tbuf)
        int write_pt = 0;
        int line_len = 0;
        int word_punct = 0;
-       unsigned char ch[3];
+       char ch[3];
        ch[2] = '\0';
 
        while (str[read_pt])
        {
 #ifdef JP
+               bool kinsoku = FALSE;
                bool kanji;
 #endif
+               int ch_len = 1;
+
+               /* Prepare one character */
                ch[0] = str[read_pt];
                ch[1] = '\0';
 #ifdef JP
                kanji  = iskanji(ch[0]);
+
                if (kanji)
+               {
                        ch[1] = str[read_pt+1];
-               if (!kanji && !isprint(ch[0]))
+                       ch_len = 2;
+
+                       if (strcmp(ch, "¡£") == 0 ||
+                           strcmp(ch, "¡¢") == 0 ||
+                           strcmp(ch, "¥£") == 0 ||
+                           strcmp(ch, "¡¼") == 0)
+                               kinsoku = TRUE;
+               }
+               else if (!isprint(ch[0]))
                        ch[0] = ' ';
 #else
                if (!isprint(ch[0]))
                        ch[0] = ' ';
 #endif
 
-               if (line_len >= maxlen - 1 || str[read_pt] == '\n')
+               if (line_len + ch_len > maxlen - 1 || str[read_pt] == '\n')
                {
                        int word_len;
 
                        /* return to better wrapping point. */
                        /* Space character at the end of the line need not to be printed. */
                        word_len = read_pt - word_punct;
-                       if (ch[0] != ' ' && word_len < line_len/2)
+#ifdef JP
+                       if (kanji && !kinsoku)
+                               /* nothing */ ;
+                       else
+#endif
+                       if (ch[0] == ' ' || word_len >= line_len/2)
+                               read_pt++;
+                       else
                        {
                                read_pt = word_punct;
                                if (str[word_punct] == ' ')
                                        read_pt++;
                                write_pt -= word_len;
                        }
-                       else
-                               read_pt++;
+
                        tbuf[write_pt++] = '\0';
                        line_len = 0;
                        word_punct = read_pt;
@@ -4876,10 +4866,7 @@ void roff_to_buf(cptr str, int maxlen, char *tbuf)
                if (ch[0] == ' ')
                        word_punct = read_pt;
 #ifdef JP
-               if (kanji &&
-                   strcmp((char *)ch, "¡£") != 0 && strcmp((char *)ch, "¡¢") != 0 &&
-                   strcmp((char *)ch, "¥£") != 0 && strcmp((char *)ch, "¡¼") != 0)
-                       word_punct = read_pt;
+               if (!kinsoku) word_punct = read_pt;
 #endif
                tbuf[write_pt++] = ch[0];
                line_len++;