3 * @brief プレイヤーのインターフェイスに関するコマンドの実装 / Interface commands
5 * @author Mogami & Hourier
7 * remove_auto_dump(orig_file, mark)
8 * Remove the old automatic dump of type "mark".
9 * auto_dump_printf(fmt, ...)
10 * Dump a formatted string using fprintf().
11 * open_auto_dump(buf, mark)
12 * Open a file, remove old dump, and add new header.
13 * close_auto_dump(void)
14 * Add a footer, and close the file.
17 #include "system/angband.h"
18 #include "io-dump/dump-remover.h"
19 #include "io/read-pref-file.h"
20 #include "io/interpret-pref-file.h"
21 #include "autopick/autopick-pref-processor.h"
22 #include "io/files-util.h"
23 #include "io/pref-file-expressor.h"
24 #include "world/world.h"
25 #include "system/system-variables.h"
26 #include "autopick/autopick-reader-writer.h"
28 // todo コールバック関数に変更するので、いずれ消す.
29 #define PREF_TYPE_NORMAL 0
30 #define PREF_TYPE_AUTOPICK 1
31 #define PREF_TYPE_HISTPREF 2
33 char auto_dump_header[] = "# vvvvvvv== %s ==vvvvvvv";
34 char auto_dump_footer[] = "# ^^^^^^^== %s ==^^^^^^^";
36 // Mark strings for auto dump
38 // Variables for auto dump
39 static int auto_dump_line_num;
43 * @brief process_pref_fileのサブルーチン /
44 * Open the "user pref file" and parse it.
45 * @param creature_ptr プレーヤーへの参照ポインタ
46 * @param name 読み込むファイル名
47 * @param preftype prefファイルのタイプ
50 static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int preftype, void(*process_autopick_file_command)(char*))
53 fp = my_fopen(name, "r");
61 while (my_fgets(fp, buf, sizeof(buf)) == 0)
64 if (!buf[0]) continue;
69 if (iswspace(buf[0])) continue;
71 if (buf[0] == '#') continue;
74 /* Process "?:<expr>" */
75 if ((buf[0] == '?') && (buf[1] == ':'))
80 concptr v = process_pref_file_expr(creature_ptr, &s, &f);
81 bypass = streq(v, "0");
87 /* Process "%:<file>" */
90 static int depth_count = 0;
91 if (depth_count > 20) continue;
96 case PREF_TYPE_AUTOPICK:
97 (void)process_autopick_file(creature_ptr, buf + 2, process_autopick_file_command);
99 case PREF_TYPE_HISTPREF:
100 (void)process_histpref_file(creature_ptr, buf + 2, process_autopick_file_command);
103 (void)process_pref_file(creature_ptr, buf + 2, process_autopick_file_command);
111 err = interpret_pref_file(creature_ptr, buf);
114 if (preftype != PREF_TYPE_AUTOPICK)
117 (*process_autopick_file_command)(buf);
124 /* Print error message */
125 /* ToDo: Add better error messages */
126 msg_format(_("ファイル'%s'の%d行でエラー番号%dのエラー。", "Error %d in line %d of file '%s'."),
127 _(name, err), line, _(err, name));
128 msg_format(_("('%s'を解析中)", "Parsing '%s'"), old);
138 * @brief pref設定ファイルを読み込み設定を反映させる /
139 * Process the "user pref file" with the given name
140 * @param creature_ptr プレーヤーへの参照ポインタ
141 * @param name 読み込むファイル名
145 * See the functions above for a list of legal "commands".
146 * We also accept the special "?" and "%" directives, which
147 * allow conditional evaluation and filename inclusion.
150 errr process_pref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
153 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
155 errr err1 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL, process_autopick_file_command);
156 if (err1 > 0) return err1;
158 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
159 errr err2 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL, process_autopick_file_command);
160 if (err2 < 0 && !err1)
168 * @brief 自動拾いファイルを読み込む /
169 * @param creature_ptr プレーヤーへの参照ポインタ
173 errr process_autopick_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
176 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
177 errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_AUTOPICK, process_autopick_file_command);
183 * @brief プレイヤーの生い立ちファイルを読み込む /
184 * Process file for player's history editor.
185 * @param creature_ptr プレーヤーへの参照ポインタ
190 errr process_histpref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
192 bool old_character_xtra = current_world_ptr->character_xtra;
194 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
196 /* Hack -- prevent modification birth options in this file */
197 current_world_ptr->character_xtra = TRUE;
198 errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_HISTPREF, process_autopick_file_command);
199 current_world_ptr->character_xtra = old_character_xtra;
205 * @brief prfファイルのフォーマットに従った内容を出力する /
206 * Dump a formatted line, using "vstrnfmt()".
209 void auto_dump_printf(FILE *auto_dump_stream, concptr fmt, ...)
214 (void)vstrnfmt(buf, sizeof(buf), fmt, vp);
216 for (concptr p = buf; *p; p++)
218 if (*p == '\n') auto_dump_line_num++;
221 fprintf(auto_dump_stream, "%s", buf);
226 * @brief prfファイルをファイルオープンする /
227 * Open file to append auto dump.
229 * @param mark 出力するヘッダマーク
230 * @return ファイルポインタを取得できたらTRUEを返す
232 bool open_auto_dump(FILE **fpp, concptr buf, concptr mark)
234 char header_mark_str[80];
235 concptr auto_dump_mark = mark;
236 sprintf(header_mark_str, auto_dump_header, auto_dump_mark);
237 remove_auto_dump(buf, mark);
238 *fpp = my_fopen(buf, "a");
241 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), buf);
246 fprintf(*fpp, "%s\n", header_mark_str);
247 auto_dump_line_num = 0;
248 auto_dump_printf(*fpp, _("# *警告!!* 以降の行は自動生成されたものです。\n",
249 "# *Warning!* The lines below are an automatic dump.\n"));
250 auto_dump_printf(*fpp, _("# *警告!!* 後で自動的に削除されるので編集しないでください。\n",
251 "# Don't edit them; changes will be deleted and replaced automatically.\n"));
256 * @brief prfファイルをファイルクローズする /
257 * Append foot part and close auto dump.
260 void close_auto_dump(FILE **fpp, concptr auto_dump_mark)
262 char footer_mark_str[80];
263 sprintf(footer_mark_str, auto_dump_footer, auto_dump_mark);
264 auto_dump_printf(*fpp, _("# *警告!!* 以降の行は自動生成されたものです。\n",
265 "# *Warning!* The lines below are an automatic dump.\n"));
266 auto_dump_printf(*fpp, _("# *警告!!* 後で自動的に削除されるので編集しないでください。\n",
267 "# Don't edit them; changes will be deleted and replaced automatically.\n"));
268 fprintf(*fpp, "%s (%d)\n", footer_mark_str, auto_dump_line_num);
273 * @brief 全ユーザプロファイルをロードする / Load some "user pref files"
274 * @paaram player_ptr プレーヤーへの参照ポインタ
277 * Modified by Arcum Dagsson to support
278 * separate macro files for different realms.
280 void load_all_pref_files(player_type* player_ptr)
283 sprintf(buf, "user.prf");
284 process_pref_file(player_ptr, buf, process_autopick_file_command);
285 sprintf(buf, "user-%s.prf", ANGBAND_SYS);
286 process_pref_file(player_ptr, buf, process_autopick_file_command);
287 sprintf(buf, "%s.prf", rp_ptr->title);
288 process_pref_file(player_ptr, buf, process_autopick_file_command);
289 sprintf(buf, "%s.prf", cp_ptr->title);
290 process_pref_file(player_ptr, buf, process_autopick_file_command);
291 sprintf(buf, "%s.prf", player_ptr->base_name);
292 process_pref_file(player_ptr, buf, process_autopick_file_command);
293 if (player_ptr->realm1 != REALM_NONE) {
294 sprintf(buf, "%s.prf", realm_names[player_ptr->realm1]);
295 process_pref_file(player_ptr, buf, process_autopick_file_command);
298 if (player_ptr->realm2 != REALM_NONE) {
299 sprintf(buf, "%s.prf", realm_names[player_ptr->realm2]);
300 process_pref_file(player_ptr, buf, process_autopick_file_command);
303 autopick_load_pref(player_ptr, FALSE);
307 * @brief 生い立ちメッセージをファイルからロードする。
310 bool read_histpref(player_type *creature_ptr, void (*process_autopick_file_command)(char *))
317 char histbuf[HISTPREF_LIMIT];
319 if (!get_check(_("生い立ち設定ファイルをロードしますか? ", "Load background history preference file? ")))
323 histpref_buf = histbuf;
325 sprintf(buf, _("histedit-%s.prf", "histpref-%s.prf"), creature_ptr->base_name);
326 err = process_histpref_file(creature_ptr, buf, process_autopick_file_command);
329 strcpy(buf, _("histedit.prf", "histpref.prf"));
330 err = process_histpref_file(creature_ptr, buf, process_autopick_file_command);
334 msg_print(_("生い立ち設定ファイルの読み込みに失敗しました。", "Failed to load background history preference."));
338 } else if (!histpref_buf[0]) {
339 msg_print(_("有効な生い立ち設定はこのファイルにありません。", "There does not exist valid background history preference."));
345 for (i = 0; i < 4; i++)
346 creature_ptr->history[i][0] = '\0';
349 for (s = histpref_buf; *s == ' '; s++)
353 while ((n > 0) && (s[n - 1] == ' '))
356 roff_to_buf(s, 60, temp, sizeof(temp));
358 for (i = 0; i < 4; i++) {
362 strcpy(creature_ptr->history[i], t);
367 for (i = 0; i < 4; i++) {
369 for (j = 0; creature_ptr->history[i][j]; j++)
373 creature_ptr->history[i][j] = ' ';
374 creature_ptr->history[i][59] = '\0';