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.
18 #include "io/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 "files.h" // 暫定。コールバック化して後で消す.
23 #include "world/world.h"
25 #include "autopick/autopick-reader-writer.h"
27 // todo コールバック関数に変更するので、いずれ消す.
28 #define PREF_TYPE_NORMAL 0
29 #define PREF_TYPE_AUTOPICK 1
30 #define PREF_TYPE_HISTPREF 2
32 char auto_dump_header[] = "# vvvvvvv== %s ==vvvvvvv";
33 char auto_dump_footer[] = "# ^^^^^^^== %s ==^^^^^^^";
35 // Mark strings for auto dump
37 // Variables for auto dump
38 static int auto_dump_line_num;
42 * @brief process_pref_fileのサブルーチン /
43 * Open the "user pref file" and parse it.
44 * @param creature_ptr プレーヤーへの参照ポインタ
45 * @param name 読み込むファイル名
46 * @param preftype prefファイルのタイプ
49 static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int preftype, void(*process_autopick_file_command)(char*))
52 fp = my_fopen(name, "r");
60 while (my_fgets(fp, buf, sizeof(buf)) == 0)
63 if (!buf[0]) continue;
68 if (iswspace(buf[0])) continue;
70 if (buf[0] == '#') continue;
73 /* Process "?:<expr>" */
74 if ((buf[0] == '?') && (buf[1] == ':'))
79 concptr v = process_pref_file_expr(creature_ptr, &s, &f);
80 bypass = streq(v, "0");
86 /* Process "%:<file>" */
89 static int depth_count = 0;
90 if (depth_count > 20) continue;
95 case PREF_TYPE_AUTOPICK:
96 (void)process_autopick_file(creature_ptr, buf + 2, process_autopick_file_command);
98 case PREF_TYPE_HISTPREF:
99 (void)process_histpref_file(creature_ptr, buf + 2, process_autopick_file_command);
102 (void)process_pref_file(creature_ptr, buf + 2, process_autopick_file_command);
110 err = interpret_pref_file(creature_ptr, buf);
113 if (preftype != PREF_TYPE_AUTOPICK)
116 (*process_autopick_file_command)(buf);
123 /* Print error message */
124 /* ToDo: Add better error messages */
125 msg_format(_("ファイル'%s'の%d行でエラー番号%dのエラー。", "Error %d in line %d of file '%s'."),
126 _(name, err), line, _(err, name));
127 msg_format(_("('%s'を解析中)", "Parsing '%s'"), old);
137 * @brief pref設定ファイルを読み込み設定を反映させる /
138 * Process the "user pref file" with the given name
139 * @param creature_ptr プレーヤーへの参照ポインタ
140 * @param name 読み込むファイル名
144 * See the functions above for a list of legal "commands".
145 * We also accept the special "?" and "%" directives, which
146 * allow conditional evaluation and filename inclusion.
149 errr process_pref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
152 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
154 errr err1 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL, process_autopick_file_command);
155 if (err1 > 0) return err1;
157 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
158 errr err2 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL, process_autopick_file_command);
159 if (err2 < 0 && !err1)
167 * @brief 自動拾いファイルを読み込む /
168 * @param creature_ptr プレーヤーへの参照ポインタ
172 errr process_autopick_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
175 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
176 errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_AUTOPICK, process_autopick_file_command);
182 * @brief プレイヤーの生い立ちファイルを読み込む /
183 * Process file for player's history editor.
184 * @param creature_ptr プレーヤーへの参照ポインタ
189 errr process_histpref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
191 bool old_character_xtra = current_world_ptr->character_xtra;
193 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
195 /* Hack -- prevent modification birth options in this file */
196 current_world_ptr->character_xtra = TRUE;
197 errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_HISTPREF, process_autopick_file_command);
198 current_world_ptr->character_xtra = old_character_xtra;
204 * @brief prfファイルのフォーマットに従った内容を出力する /
205 * Dump a formatted line, using "vstrnfmt()".
208 void auto_dump_printf(FILE *auto_dump_stream, concptr fmt, ...)
213 (void)vstrnfmt(buf, sizeof(buf), fmt, vp);
215 for (concptr p = buf; *p; p++)
217 if (*p == '\n') auto_dump_line_num++;
220 fprintf(auto_dump_stream, "%s", buf);
225 * @brief prfファイルをファイルオープンする /
226 * Open file to append auto dump.
228 * @param mark 出力するヘッダマーク
229 * @return ファイルポインタを取得できたらTRUEを返す
231 bool open_auto_dump(FILE **fpp, concptr buf, concptr mark)
233 char header_mark_str[80];
234 concptr auto_dump_mark = mark;
235 sprintf(header_mark_str, auto_dump_header, auto_dump_mark);
236 remove_auto_dump(buf, mark);
237 *fpp = my_fopen(buf, "a");
240 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), buf);
245 fprintf(*fpp, "%s\n", header_mark_str);
246 auto_dump_line_num = 0;
247 auto_dump_printf(*fpp, _("# *警告!!* 以降の行は自動生成されたものです。\n",
248 "# *Warning!* The lines below are an automatic dump.\n"));
249 auto_dump_printf(*fpp, _("# *警告!!* 後で自動的に削除されるので編集しないでください。\n",
250 "# Don't edit them; changes will be deleted and replaced automatically.\n"));
255 * @brief prfファイルをファイルクローズする /
256 * Append foot part and close auto dump.
259 void close_auto_dump(FILE **fpp, concptr auto_dump_mark)
261 char footer_mark_str[80];
262 sprintf(footer_mark_str, auto_dump_footer, auto_dump_mark);
263 auto_dump_printf(*fpp, _("# *警告!!* 以降の行は自動生成されたものです。\n",
264 "# *Warning!* The lines below are an automatic dump.\n"));
265 auto_dump_printf(*fpp, _("# *警告!!* 後で自動的に削除されるので編集しないでください。\n",
266 "# Don't edit them; changes will be deleted and replaced automatically.\n"));
267 fprintf(*fpp, "%s (%d)\n", footer_mark_str, auto_dump_line_num);
272 * @brief 全ユーザプロファイルをロードする / Load some "user pref files"
273 * @paaram player_ptr プレーヤーへの参照ポインタ
276 * Modified by Arcum Dagsson to support
277 * separate macro files for different realms.
279 void load_all_pref_files(player_type* player_ptr)
282 sprintf(buf, "user.prf");
283 process_pref_file(player_ptr, buf, process_autopick_file_command);
284 sprintf(buf, "user-%s.prf", ANGBAND_SYS);
285 process_pref_file(player_ptr, buf, process_autopick_file_command);
286 sprintf(buf, "%s.prf", rp_ptr->title);
287 process_pref_file(player_ptr, buf, process_autopick_file_command);
288 sprintf(buf, "%s.prf", cp_ptr->title);
289 process_pref_file(player_ptr, buf, process_autopick_file_command);
290 sprintf(buf, "%s.prf", player_ptr->base_name);
291 process_pref_file(player_ptr, buf, process_autopick_file_command);
292 if (player_ptr->realm1 != REALM_NONE) {
293 sprintf(buf, "%s.prf", realm_names[player_ptr->realm1]);
294 process_pref_file(player_ptr, buf, process_autopick_file_command);
297 if (player_ptr->realm2 != REALM_NONE) {
298 sprintf(buf, "%s.prf", realm_names[player_ptr->realm2]);
299 process_pref_file(player_ptr, buf, process_autopick_file_command);
302 autopick_load_pref(player_ptr, FALSE);