2 * @brief プレイヤーのインターフェイスに関するコマンドの実装 / Interface commands
4 * @author Mogami & Hourier
6 * remove_auto_dump(orig_file, mark)
7 * Remove the old automatic dump of type "mark".
8 * auto_dump_printf(fmt, ...)
9 * Dump a formatted string using fprintf().
10 * open_auto_dump(buf, mark)
11 * Open a file, remove old dump, and add new header.
12 * close_auto_dump(void)
13 * Add a footer, and close the file.
16 #include "io/read-pref-file.h"
17 #include "autopick/autopick-pref-processor.h"
18 #include "autopick/autopick-reader-writer.h"
19 #include "core/asking-player.h"
20 #include "io-dump/dump-remover.h"
21 #include "io/files-util.h"
22 #include "io/interpret-pref-file.h"
23 #include "io/pref-file-expressor.h"
24 #include "system/system-variables.h"
25 #include "util/angband-files.h"
26 #include "view/display-messages.h"
27 #include "world/world.h"
29 // todo コールバック関数に変更するので、いずれ消す.
30 #define PREF_TYPE_NORMAL 0
31 #define PREF_TYPE_AUTOPICK 1
32 #define PREF_TYPE_HISTPREF 2
34 char auto_dump_header[] = "# vvvvvvv== %s ==vvvvvvv";
35 char auto_dump_footer[] = "# ^^^^^^^== %s ==^^^^^^^";
37 // Mark strings for auto dump
39 // Variables for auto dump
40 static int auto_dump_line_num;
44 * @brief process_pref_fileのサブルーチン /
45 * Open the "user pref file" and parse it.
46 * @param creature_ptr プレーヤーへの参照ポインタ
47 * @param name 読み込むファイル名
48 * @param preftype prefファイルのタイプ
51 static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int preftype, void(*process_autopick_file_command)(char*))
54 fp = angband_fopen(name, "r");
62 while (angband_fgets(fp, buf, sizeof(buf)) == 0)
65 if (!buf[0]) continue;
70 if (iswspace(buf[0])) continue;
72 if (buf[0] == '#') continue;
75 /* Process "?:<expr>" */
76 if ((buf[0] == '?') && (buf[1] == ':'))
81 concptr v = process_pref_file_expr(creature_ptr, &s, &f);
82 bypass = streq(v, "0");
88 /* Process "%:<file>" */
91 static int depth_count = 0;
92 if (depth_count > 20) continue;
97 case PREF_TYPE_AUTOPICK:
98 (void)process_autopick_file(creature_ptr, buf + 2, process_autopick_file_command);
100 case PREF_TYPE_HISTPREF:
101 (void)process_histpref_file(creature_ptr, buf + 2, process_autopick_file_command);
104 (void)process_pref_file(creature_ptr, buf + 2, process_autopick_file_command);
112 err = interpret_pref_file(creature_ptr, buf);
115 if (preftype != PREF_TYPE_AUTOPICK)
118 (*process_autopick_file_command)(buf);
125 /* Print error message */
126 /* ToDo: Add better error messages */
127 msg_format(_("ファイル'%s'の%d行でエラー番号%dのエラー。", "Error %d in line %d of file '%s'."),
128 _(name, err), line, _(err, name));
129 msg_format(_("('%s'を解析中)", "Parsing '%s'"), old);
139 * @brief pref設定ファイルを読み込み設定を反映させる /
140 * Process the "user pref file" with the given name
141 * @param creature_ptr プレーヤーへの参照ポインタ
142 * @param name 読み込むファイル名
146 * See the functions above for a list of legal "commands".
147 * We also accept the special "?" and "%" directives, which
148 * allow conditional evaluation and filename inclusion.
151 errr process_pref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
154 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
156 errr err1 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL, process_autopick_file_command);
157 if (err1 > 0) return err1;
159 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
160 errr err2 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL, process_autopick_file_command);
161 if (err2 < 0 && !err1)
169 * @brief 自動拾いファイルを読み込む /
170 * @param creature_ptr プレーヤーへの参照ポインタ
174 errr process_autopick_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
177 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
178 errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_AUTOPICK, process_autopick_file_command);
184 * @brief プレイヤーの生い立ちファイルを読み込む /
185 * Process file for player's history editor.
186 * @param creature_ptr プレーヤーへの参照ポインタ
191 errr process_histpref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
193 bool old_character_xtra = current_world_ptr->character_xtra;
195 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
197 /* Hack -- prevent modification birth options in this file */
198 current_world_ptr->character_xtra = TRUE;
199 errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_HISTPREF, process_autopick_file_command);
200 current_world_ptr->character_xtra = old_character_xtra;
206 * @brief prfファイルのフォーマットに従った内容を出力する /
207 * Dump a formatted line, using "vstrnfmt()".
210 void auto_dump_printf(FILE *auto_dump_stream, concptr fmt, ...)
215 (void)vstrnfmt(buf, sizeof(buf), fmt, vp);
217 for (concptr p = buf; *p; p++)
219 if (*p == '\n') auto_dump_line_num++;
222 fprintf(auto_dump_stream, "%s", buf);
227 * @brief prfファイルをファイルオープンする /
228 * Open file to append auto dump.
230 * @param mark 出力するヘッダマーク
231 * @return ファイルポインタを取得できたらTRUEを返す
233 bool open_auto_dump(FILE **fpp, concptr buf, concptr mark)
235 char header_mark_str[80];
236 concptr auto_dump_mark = mark;
237 sprintf(header_mark_str, auto_dump_header, auto_dump_mark);
238 remove_auto_dump(buf, mark);
239 *fpp = angband_fopen(buf, "a");
242 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), buf);
247 fprintf(*fpp, "%s\n", header_mark_str);
248 auto_dump_line_num = 0;
249 auto_dump_printf(*fpp, _("# *警告!!* 以降の行は自動生成されたものです。\n",
250 "# *Warning!* The lines below are an automatic dump.\n"));
251 auto_dump_printf(*fpp, _("# *警告!!* 後で自動的に削除されるので編集しないでください。\n",
252 "# Don't edit them; changes will be deleted and replaced automatically.\n"));
257 * @brief prfファイルをファイルクローズする /
258 * Append foot part and close auto dump.
261 void close_auto_dump(FILE **fpp, concptr auto_dump_mark)
263 char footer_mark_str[80];
264 sprintf(footer_mark_str, auto_dump_footer, auto_dump_mark);
265 auto_dump_printf(*fpp, _("# *警告!!* 以降の行は自動生成されたものです。\n",
266 "# *Warning!* The lines below are an automatic dump.\n"));
267 auto_dump_printf(*fpp, _("# *警告!!* 後で自動的に削除されるので編集しないでください。\n",
268 "# Don't edit them; changes will be deleted and replaced automatically.\n"));
269 fprintf(*fpp, "%s (%d)\n", footer_mark_str, auto_dump_line_num);
270 angband_fclose(*fpp);
274 * @brief 全ユーザプロファイルをロードする / Load some "user pref files"
275 * @paaram player_ptr プレーヤーへの参照ポインタ
278 * Modified by Arcum Dagsson to support
279 * separate macro files for different realms.
281 void load_all_pref_files(player_type* player_ptr)
284 sprintf(buf, "user.prf");
285 process_pref_file(player_ptr, buf, process_autopick_file_command);
286 sprintf(buf, "user-%s.prf", ANGBAND_SYS);
287 process_pref_file(player_ptr, buf, process_autopick_file_command);
288 sprintf(buf, "%s.prf", rp_ptr->title);
289 process_pref_file(player_ptr, buf, process_autopick_file_command);
290 sprintf(buf, "%s.prf", cp_ptr->title);
291 process_pref_file(player_ptr, buf, process_autopick_file_command);
292 sprintf(buf, "%s.prf", player_ptr->base_name);
293 process_pref_file(player_ptr, buf, process_autopick_file_command);
294 if (player_ptr->realm1 != REALM_NONE) {
295 sprintf(buf, "%s.prf", realm_names[player_ptr->realm1]);
296 process_pref_file(player_ptr, buf, process_autopick_file_command);
299 if (player_ptr->realm2 != REALM_NONE) {
300 sprintf(buf, "%s.prf", realm_names[player_ptr->realm2]);
301 process_pref_file(player_ptr, buf, process_autopick_file_command);
304 autopick_load_pref(player_ptr, FALSE);
308 * @brief 生い立ちメッセージをファイルからロードする。
311 bool read_histpref(player_type *creature_ptr, void (*process_autopick_file_command)(char *))
318 char histbuf[HISTPREF_LIMIT];
320 if (!get_check(_("生い立ち設定ファイルをロードしますか? ", "Load background history preference file? ")))
324 histpref_buf = histbuf;
326 sprintf(buf, _("histedit-%s.prf", "histpref-%s.prf"), creature_ptr->base_name);
327 err = process_histpref_file(creature_ptr, buf, process_autopick_file_command);
330 strcpy(buf, _("histedit.prf", "histpref.prf"));
331 err = process_histpref_file(creature_ptr, buf, process_autopick_file_command);
335 msg_print(_("生い立ち設定ファイルの読み込みに失敗しました。", "Failed to load background history preference."));
339 } else if (!histpref_buf[0]) {
340 msg_print(_("有効な生い立ち設定はこのファイルにありません。", "There does not exist valid background history preference."));
346 for (i = 0; i < 4; i++)
347 creature_ptr->history[i][0] = '\0';
350 for (s = histpref_buf; *s == ' '; s++)
354 while ((n > 0) && (s[n - 1] == ' '))
357 roff_to_buf(s, 60, temp, sizeof(temp));
359 for (i = 0; i < 4; i++) {
363 strcpy(creature_ptr->history[i], t);
368 for (i = 0; i < 4; i++) {
370 for (j = 0; creature_ptr->history[i][j]; j++)
374 creature_ptr->history[i][j] = ' ';
375 creature_ptr->history[i][59] = '\0';