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" // 暫定。コールバック化して後で消す.
25 // todo コールバック関数に変更するので、いずれ消す.
26 #define PREF_TYPE_NORMAL 0
27 #define PREF_TYPE_AUTOPICK 1
28 #define PREF_TYPE_HISTPREF 2
30 char auto_dump_header[] = "# vvvvvvv== %s ==vvvvvvv";
31 char auto_dump_footer[] = "# ^^^^^^^== %s ==^^^^^^^";
33 // Mark strings for auto dump
35 // Variables for auto dump
36 static int auto_dump_line_num;
40 * @brief process_pref_fileのサブルーチン /
41 * Open the "user pref file" and parse it.
42 * @param creature_ptr プレーヤーへの参照ポインタ
43 * @param name 読み込むファイル名
44 * @param preftype prefファイルのタイプ
47 static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int preftype, void(*process_autopick_file_command)(char*))
50 fp = my_fopen(name, "r");
58 while (my_fgets(fp, buf, sizeof(buf)) == 0)
61 if (!buf[0]) continue;
66 if (iswspace(buf[0])) continue;
68 if (buf[0] == '#') continue;
71 /* Process "?:<expr>" */
72 if ((buf[0] == '?') && (buf[1] == ':'))
77 concptr v = process_pref_file_expr(creature_ptr, &s, &f);
78 bypass = streq(v, "0");
84 /* Process "%:<file>" */
87 static int depth_count = 0;
88 if (depth_count > 20) continue;
93 case PREF_TYPE_AUTOPICK:
94 (void)process_autopick_file(creature_ptr, buf + 2, process_autopick_file_command);
96 case PREF_TYPE_HISTPREF:
97 (void)process_histpref_file(creature_ptr, buf + 2, process_autopick_file_command);
100 (void)process_pref_file(creature_ptr, buf + 2, process_autopick_file_command);
108 err = interpret_pref_file(creature_ptr, buf);
111 if (preftype != PREF_TYPE_AUTOPICK)
114 (*process_autopick_file_command)(buf);
121 /* Print error message */
122 /* ToDo: Add better error messages */
123 msg_format(_("ファイル'%s'の%d行でエラー番号%dのエラー。", "Error %d in line %d of file '%s'."),
124 _(name, err), line, _(err, name));
125 msg_format(_("('%s'を解析中)", "Parsing '%s'"), old);
135 * @brief pref設定ファイルを読み込み設定を反映させる /
136 * Process the "user pref file" with the given name
137 * @param creature_ptr プレーヤーへの参照ポインタ
138 * @param name 読み込むファイル名
142 * See the functions above for a list of legal "commands".
143 * We also accept the special "?" and "%" directives, which
144 * allow conditional evaluation and filename inclusion.
147 errr process_pref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
150 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
152 errr err1 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL, process_autopick_file_command);
153 if (err1 > 0) return err1;
155 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
156 errr err2 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL, process_autopick_file_command);
157 if (err2 < 0 && !err1)
165 * @brief 自動拾いファイルを読み込む /
166 * @param creature_ptr プレーヤーへの参照ポインタ
170 errr process_autopick_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
173 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
174 errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_AUTOPICK, process_autopick_file_command);
180 * @brief プレイヤーの生い立ちファイルを読み込む /
181 * Process file for player's history editor.
182 * @param creature_ptr プレーヤーへの参照ポインタ
187 errr process_histpref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
189 bool old_character_xtra = current_world_ptr->character_xtra;
191 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
193 /* Hack -- prevent modification birth options in this file */
194 current_world_ptr->character_xtra = TRUE;
195 errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_HISTPREF, process_autopick_file_command);
196 current_world_ptr->character_xtra = old_character_xtra;
202 * @brief prfファイルのフォーマットに従った内容を出力する /
203 * Dump a formatted line, using "vstrnfmt()".
206 void auto_dump_printf(FILE *auto_dump_stream, concptr fmt, ...)
211 (void)vstrnfmt(buf, sizeof(buf), fmt, vp);
213 for (concptr p = buf; *p; p++)
215 if (*p == '\n') auto_dump_line_num++;
218 fprintf(auto_dump_stream, "%s", buf);
223 * @brief prfファイルをファイルオープンする /
224 * Open file to append auto dump.
226 * @param mark 出力するヘッダマーク
227 * @return ファイルポインタを取得できたらTRUEを返す
229 bool open_auto_dump(FILE **fpp, concptr buf, concptr mark)
231 char header_mark_str[80];
232 concptr auto_dump_mark = mark;
233 sprintf(header_mark_str, auto_dump_header, auto_dump_mark);
234 remove_auto_dump(buf, mark);
235 *fpp = my_fopen(buf, "a");
238 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), buf);
243 fprintf(*fpp, "%s\n", header_mark_str);
244 auto_dump_line_num = 0;
245 auto_dump_printf(*fpp, _("# *警告!!* 以降の行は自動生成されたものです。\n",
246 "# *Warning!* The lines below are an automatic dump.\n"));
247 auto_dump_printf(*fpp, _("# *警告!!* 後で自動的に削除されるので編集しないでください。\n",
248 "# Don't edit them; changes will be deleted and replaced automatically.\n"));
253 * @brief prfファイルをファイルクローズする /
254 * Append foot part and close auto dump.
257 void close_auto_dump(FILE **fpp, concptr auto_dump_mark)
259 char footer_mark_str[80];
260 sprintf(footer_mark_str, auto_dump_footer, auto_dump_mark);
261 auto_dump_printf(*fpp, _("# *警告!!* 以降の行は自動生成されたものです。\n",
262 "# *Warning!* The lines below are an automatic dump.\n"));
263 auto_dump_printf(*fpp, _("# *警告!!* 後で自動的に削除されるので編集しないでください。\n",
264 "# Don't edit them; changes will be deleted and replaced automatically.\n"));
265 fprintf(*fpp, "%s (%d)\n", footer_mark_str, auto_dump_line_num);