*/
#include "angband.h"
+#include "io/dump-remover.h"
#include "io/read-pref-file.h"
#include "io/interpret-pref-file.h"
-#include "autopick/autopick.h"
+#include "autopick/autopick-pref-processor.h"
#include "files.h" // 暫定。コールバック化して後で消す.
#include "world.h"
* @param preftype prefファイルのタイプ
* @return エラーコード
*/
-static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int preftype)
+static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int preftype, void(*process_autopick_file_command)(char*))
{
FILE *fp;
fp = my_fopen(name, "r");
switch (preftype)
{
case PREF_TYPE_AUTOPICK:
- (void)process_autopick_file(creature_ptr, buf + 2);
+ (void)process_autopick_file(creature_ptr, buf + 2, process_autopick_file_command);
break;
case PREF_TYPE_HISTPREF:
- (void)process_histpref_file(creature_ptr, buf + 2);
+ (void)process_histpref_file(creature_ptr, buf + 2, process_autopick_file_command);
break;
default:
- (void)process_pref_file(creature_ptr, buf + 2);
+ (void)process_pref_file(creature_ptr, buf + 2, process_autopick_file_command);
break;
}
if (preftype != PREF_TYPE_AUTOPICK)
break;
- process_autopick_file_command(buf);
+ (*process_autopick_file_command)(buf);
err = 0;
}
}
* allow conditional evaluation and filename inclusion.
* </pre>
*/
-errr process_pref_file(player_type *creature_ptr, concptr name)
+errr process_pref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
{
char buf[1024];
path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
- errr err1 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL);
+ errr err1 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL, process_autopick_file_command);
if (err1 > 0) return err1;
path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
- errr err2 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL);
+ errr err2 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL, process_autopick_file_command);
if (err2 < 0 && !err1)
return -2;
* @param name ファイル名
* @details
*/
-errr process_autopick_file(player_type *creature_ptr, concptr name)
+errr process_autopick_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
{
char buf[1024];
path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
- errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_AUTOPICK);
+ errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_AUTOPICK, process_autopick_file_command);
return err;
}
* @return エラーコード
* @details
*/
-errr process_histpref_file(player_type *creature_ptr, concptr name)
+errr process_histpref_file(player_type *creature_ptr, concptr name, void(*process_autopick_file_command)(char*))
{
bool old_character_xtra = current_world_ptr->character_xtra;
char buf[1024];
/* Hack -- prevent modification birth options in this file */
current_world_ptr->character_xtra = TRUE;
- errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_HISTPREF);
+ errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_HISTPREF, process_autopick_file_command);
current_world_ptr->character_xtra = old_character_xtra;
return err;
}
/*!
- * @brief prf出力内容を消去する /
- * Remove old lines automatically generated before.
- * @param orig_file 消去を行うファイル名
- */
-static void remove_auto_dump(concptr orig_file, concptr auto_dump_mark)
-{
- char header_mark_str[80];
- char footer_mark_str[80];
- sprintf(header_mark_str, auto_dump_header, auto_dump_mark);
- sprintf(footer_mark_str, auto_dump_footer, auto_dump_mark);
- size_t mark_len = strlen(footer_mark_str);
- FILE *orig_fff;
- orig_fff = my_fopen(orig_file, "r");
- if (!orig_fff) return;
-
- char tmp_file[1024];
- FILE *tmp_fff;
- tmp_fff = my_fopen_temp(tmp_file, 1024);
- if (!tmp_fff)
- {
- msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), tmp_file);
- msg_print(NULL);
- return;
- }
-
- char buf[1024];
- bool between_mark = FALSE;
- bool changed = FALSE;
- int line_num = 0;
- long header_location = 0;
- while (TRUE)
- {
- if (my_fgets(orig_fff, buf, sizeof(buf)))
- {
- if (between_mark)
- {
- fseek(orig_fff, header_location, SEEK_SET);
- between_mark = FALSE;
- continue;
- }
- else
- {
- break;
- }
- }
-
- if (!between_mark)
- {
- if (!strcmp(buf, header_mark_str))
- {
- header_location = ftell(orig_fff);
- line_num = 0;
- between_mark = TRUE;
- changed = TRUE;
- }
- else
- {
- fprintf(tmp_fff, "%s\n", buf);
- }
-
- continue;
- }
-
- if (!strncmp(buf, footer_mark_str, mark_len))
- {
- int tmp;
- if (!sscanf(buf + mark_len, " (%d)", &tmp)
- || tmp != line_num)
- {
- fseek(orig_fff, header_location, SEEK_SET);
- }
-
- between_mark = FALSE;
- continue;
- }
-
- line_num++;
- }
-
- my_fclose(orig_fff);
- my_fclose(tmp_fff);
-
- if (changed)
- {
- tmp_fff = my_fopen(tmp_file, "r");
- orig_fff = my_fopen(orig_file, "w");
- while (!my_fgets(tmp_fff, buf, sizeof(buf)))
- fprintf(orig_fff, "%s\n", buf);
-
- my_fclose(orig_fff);
- my_fclose(tmp_fff);
- }
-
- fd_kill(tmp_file);
-}
-
-
-/*!
* @brief prfファイルのフォーマットに従った内容を出力する /
* Dump a formatted line, using "vstrnfmt()".
* @param fmt 出力内容