}
#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
*/
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)
}
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]);
}
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--;
}
+ /* 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)
{
}
+#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;
/* 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;
/* This is not original pref line... */
if (err)
{
- if (!read_pickpref)
- break;
+ if (preftype != PREF_TYPE_PICKPREF)
+ break;
err = process_pickpref_file_line(buf);
}
}
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;
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 */
/* 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;