OSDN Git Service

生い立ちエディタ用のテンプレートをファイルで定義できるようにした。(@nothereさん提供)
authoriks <iks@0568b783-4c39-0410-ac80-bf13821ea2a2>
Thu, 3 Apr 2003 22:30:25 +0000 (22:30 +0000)
committeriks <iks@0568b783-4c39-0410-ac80-bf13821ea2a2>
Thu, 3 Apr 2003 22:30:25 +0000 (22:30 +0000)
src/birth.c
src/externs.h
src/files.c

index 9bf32a3..4be95a5 100644 (file)
@@ -5230,6 +5230,128 @@ static bool get_chara_limits(void)
 }
 #endif
 
+static char histpref_buf[240];
+
+void add_history_from_pref_line(cptr t)
+{
+       int  line_size = strlen(t);
+       int  limit = (sizeof histpref_buf) - 1;
+       int  i;
+
+       for (i = strlen(histpref_buf); *t && (i < limit); t++)
+       {
+#ifdef JP
+               if (iskanji(*t) || isprint(*t))
+#else
+               if (isprint(*t))
+#endif
+               {
+#ifdef JP
+                       if (iskanji(*t))
+                       {
+                               if (i + 1 >= limit) break;
+                               histpref_buf[i++] = *(t++);
+                       }
+#endif
+                       histpref_buf[i++] = *t;
+               }
+       }
+
+       /* Terminate */
+       histpref_buf[(i < limit) ? i : limit] = '\0';
+}
+
+
+static bool do_cmd_histpref(void)
+{
+       char buf[80];
+       errr err;
+       int i, j, n;
+       char *s, *t;
+       char temp[64 * 4];
+
+#ifdef JP
+       if (!get_check("À¸¤¤Î©¤ÁÀßÄê¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤·¤Þ¤¹¤«? ")) return FALSE;
+#else
+       if (!get_check("Load background history preference file? ")) return FALSE;
+#endif
+
+       /* Init buffer */
+       histpref_buf[0] = '\0';
+
+#ifdef JP
+       sprintf(buf, "histedit-%s.prf", player_name);
+#else
+       sprintf(buf, "histpref-%s.prf", player_name);
+#endif
+       err = process_histpref_file(buf);
+
+       /* Process 'hist????.prf' if 'hist????-<name>.prf' doesn't exist */
+       if (0 > err)
+       {
+#ifdef JP
+               strcpy(buf, "histedit.prf");
+#else
+               strcpy(buf, "histpref.prf");
+#endif
+               err = process_histpref_file(buf);
+       }
+
+       if (err)
+       {
+#ifdef JP
+               msg_print("À¸¤¤Î©¤ÁÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
+               msg_print("histedit.prf¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó¡£");
+#else
+               msg_print("Failed to load background history preference.");
+               msg_print("Can't find histpref.prf");
+#endif
+               msg_print(NULL);
+
+               /* Terminate buffer */
+               histpref_buf[0] = '\0';
+               return FALSE;
+       }
+
+       /* Clear the previous history strings */
+       for (i = 0; i < 4; i++) p_ptr->history[i][0] = '\0';
+
+       /* Skip leading spaces */
+       for (s = histpref_buf; *s == ' '; s++) /* loop */;
+
+       /* Get apparent length */
+       n = strlen(s);
+
+       /* Kill trailing spaces */
+       while ((n > 0) && (s[n - 1] == ' ')) s[--n] = '\0';
+
+       roff_to_buf(s, 60, temp, sizeof(temp));
+       t = temp;
+       for (i = 0; i < 4; i++)
+       {
+               if (t[0] == 0) break;
+               else
+               {
+                       strcpy(p_ptr->history[i], t);
+                       t += strlen(t) + 1;
+               }
+       }
+
+       /* Turn 0 to space */
+       for (i = 0; i < 4; i++)
+       {
+               for (j = 0; p_ptr->history[i][j]; j++) /* loop */;
+
+               for (; j < 59; j++) p_ptr->history[i][j] = ' ';
+               p_ptr->history[i][59] = '\0';
+       }
+
+       /* Terminate buffer */
+       histpref_buf[0] = '\0';
+
+       return TRUE;
+}
+
 /*
  *  Character background edit-mode
  */
@@ -5256,8 +5378,10 @@ static void edit_history(void)
        display_player(1);
 #ifdef JP
        c_put_str(TERM_L_GREEN, "(¥­¥ã¥é¥¯¥¿¡¼¤ÎÀ¸¤¤Î©¤Á - ÊÔ½¸¥â¡¼¥É)", 11, 20);
+       put_str("[ 2/4/6/8¤Ç°ÜÆ°¡¢Enter¤Ç½ªÎ»¡¢Ctrl-F¤Ç¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß ]", 17, 10);
 #else
        c_put_str(TERM_L_GREEN, "(Character Background - Edit Mode)", 11, 20);
+       put_str("[ 2/4/6/8 for Move, Enter for End, Ctrl-F for Read pref ]", 17, 10);
 #endif
 
        while (TRUE)
@@ -5325,10 +5449,24 @@ static void edit_history(void)
                }
                else if (c == '\r')
                {
+                       Term_erase(0, 11, 255);
+                       Term_erase(0, 17, 255);
+#ifdef JP
+                       put_str("(¥­¥ã¥é¥¯¥¿¡¼¤ÎÀ¸¤¤Î©¤Á - ÊÔ½¸ºÑ¤ß)", 11, 20);
+#else
+                       put_str("(Character Background - Edited)", 11, 20);
+#endif
                        break;
                }
                else if (c == ESCAPE)
                {
+                       clear_from(11);
+#ifdef JP
+                       put_str("(¥­¥ã¥é¥¯¥¿¡¼¤ÎÀ¸¤¤Î©¤Á)", 11, 25);
+#else
+                       put_str("(Character Background)", 11, 25);
+#endif
+
                        for (i = 0; i < 4; i++)
                        {
                                sprintf(p_ptr->history[i], "%s", old_history[i]);
@@ -5336,6 +5474,15 @@ static void edit_history(void)
                        }
                        break;
                }
+               else if (c == KTRL('F'))
+               {
+                       if (do_cmd_histpref())
+                       {
+#ifdef JP
+                               if ((x > 0) && (iskanji2(p_ptr->history[y], x - 1))) x--;
+#endif
+                       }
+               }
                else if (c == '\010')
                {
                        x--;
index 3b63654..f5aa992 100644 (file)
@@ -527,6 +527,7 @@ extern errr process_pickpref_file_line(char *buf);
 extern void do_cmd_edit_autopick(void);
 
 /* birth.c */
+extern void add_history_from_pref_line(cptr t);
 extern void player_birth(void);
 extern void get_max_stats(void);
 extern void player_outfit(void);
@@ -706,6 +707,7 @@ extern errr file_character(cptr name);
 extern errr process_pref_file_command(char *buf);
 extern errr process_pref_file(cptr name);
 extern errr process_pickpref_file(cptr name);
+extern errr process_histpref_file(cptr name);
 extern void print_equippy(void);
 extern errr check_time_init(void);
 extern errr check_load_init(void);
index 81198d0..5ed7488 100644 (file)
@@ -423,8 +423,17 @@ errr process_pref_file_command(char *buf)
        }
 
 
+       /* Mega-Hack -- read external player's history file */
+       /* Process "H:<history>" */
+       if (buf[0] == 'H')
+       {
+               add_history_from_pref_line(buf + 2);
+               return (0);
+       }
+
+
        /* Process "R:<num>:<a>/<c>" -- attr/char for monster races */
-       if (buf[0] == 'R')
+       else if (buf[0] == 'R')
        {
                if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
                {
@@ -1063,11 +1072,14 @@ static cptr process_pref_file_expr(char **sp, char *fp)
 }
 
 
+#define PREF_TYPE_NORMAL   0
+#define PREF_TYPE_PICKPREF 1
+#define PREF_TYPE_HISTPREF 2
 
 /*
  * Open the "user pref file" and parse it.
  */
-static errr process_pref_file_aux(cptr name, bool read_pickpref)
+static errr process_pref_file_aux(cptr name, bool preftype)
 {
        FILE *fp;
 
@@ -1138,11 +1150,19 @@ static errr process_pref_file_aux(cptr name, bool read_pickpref)
                /* Process "%:<file>" */
                if (buf[0] == '%')
                {
-                       /* Process that file if allowed */
-                       if (read_pickpref)
+                       /* Process that file if allowed */
+                       switch (preftype)
+                       {
+                       case PREF_TYPE_PICKPREF:
                                (void)process_pickpref_file(buf + 2);
-                       else
+                               break;
+                       case PREF_TYPE_HISTPREF:
+                               (void)process_histpref_file(buf + 2);
+                               break;
+                       default:
                                (void)process_pref_file(buf + 2);
+                               break;
+                       }
 
                        /* Continue */
                        continue;
@@ -1155,8 +1175,8 @@ static errr process_pref_file_aux(cptr name, bool read_pickpref)
                /* This is not original pref line... */
                if (err)
                {
-                       if (!read_pickpref)
-                               break;
+                       if (preftype != PREF_TYPE_PICKPREF)
+                               break;
                        err = process_pickpref_file_line(buf);
                }
        }
@@ -1204,7 +1224,7 @@ errr process_pref_file(cptr name)
        path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
 
        /* Process the system pref file */
-       err1 = process_pref_file_aux(buf, FALSE);
+       err1 = process_pref_file_aux(buf, PREF_TYPE_NORMAL);
 
        /* Stop at parser errors, but not at non-existing file */
        if (err1 > 0) return err1;
@@ -1214,7 +1234,7 @@ errr process_pref_file(cptr name)
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
        
        /* Process the user pref file */
-       err2 = process_pref_file_aux(buf, FALSE);
+       err2 = process_pref_file_aux(buf, PREF_TYPE_NORMAL);
 
 
        /* User file does not exist, but read system pref file */
@@ -7058,12 +7078,38 @@ errr process_pickpref_file(cptr name)
        /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
 
-       err = process_pref_file_aux(buf, TRUE);
+       err = process_pref_file_aux(buf, PREF_TYPE_PICKPREF);
 
        /* Result */
        return (err);
 }
 
+
+/*
+ * Process file for player's history editor.
+ */
+errr process_histpref_file(cptr name)
+{
+       char buf[1024];
+
+       errr err = 0;
+
+       /* Drop priv's */
+       safe_setuid_drop();
+
+       /* Build the filename */
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
+
+       err = process_pref_file_aux(buf, PREF_TYPE_HISTPREF);
+
+       /* Grab priv's */
+       safe_setuid_grab();
+
+       /* Result */
+       return (err);
+}
+
+
 static errr counts_seek(int fd, u32b where, bool flag)
 {
        huge seekpoint;