OSDN Git Service

[Implement] #41338 長いマクロを使えるようにする
authordis- <dis.rogue@gmail.com>
Thu, 28 Jan 2021 08:36:26 +0000 (17:36 +0900)
committerdis- <dis.rogue@gmail.com>
Thu, 28 Jan 2021 08:36:26 +0000 (17:36 +0900)
ファイルから文字列を取得するバッファサイズを拡張し、長文マクロに対応した。

src/io/read-pref-file.c
src/main-win.c
src/main/angband-initializer.c
src/main/game-data-initializer.c
src/util/angband-files.c
src/util/angband-files.h

index 2adcb1a..77ea628 100644 (file)
@@ -58,30 +58,31 @@ static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int p
        fp = angband_fopen(name, "r");
        if (!fp) return -1;
 
-       char buf[1024];
-       char old[1024];
        int line = -1;
        errr err = 0;
        bool bypass = FALSE;
-       while (angband_fgets(fp, buf, sizeof(buf)) == 0)
+       while (angband_fgets(fp, file_read__buf, FILE_READ_BUFF_SIZE) == 0)
        {
                line++;
-               if (!buf[0]) continue;
+        if (!file_read__buf[0])
+            continue;
 
 #ifdef JP
-               if (!iskanji(buf[0]))
+        if (!iskanji(file_read__buf[0]))
 #endif
-                       if (iswspace(buf[0])) continue;
+            if (iswspace(file_read__buf[0]))
+                continue;
 
-               if (buf[0] == '#') continue;
-               strcpy(old, buf);
+               if (file_read__buf[0] == '#')
+            continue;
+        strcpy(file_read__swp, file_read__buf);
 
                /* Process "?:<expr>" */
-               if ((buf[0] == '?') && (buf[1] == ':'))
+        if ((file_read__buf[0] == '?') && (file_read__buf[1] == ':'))
                {
                        char f;
                        char *s;
-                       s = buf + 2;
+            s = file_read__buf + 2;
                        concptr v = process_pref_file_expr(creature_ptr, &s, &f);
                        bypass = streq(v, "0");
                        continue;
@@ -90,7 +91,7 @@ static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int p
                if (bypass) continue;
 
                /* Process "%:<file>" */
-               if (buf[0] == '%')
+        if (file_read__buf[0] == '%')
                {
                        static int depth_count = 0;
                        if (depth_count > 20) continue;
@@ -99,13 +100,13 @@ static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int p
                        switch (preftype)
                        {
                        case PREF_TYPE_AUTOPICK:
-                               (void)process_autopick_file(creature_ptr, buf + 2, process_autopick_file_command);
+                (void)process_autopick_file(creature_ptr, file_read__buf + 2, process_autopick_file_command);
                                break;
                        case PREF_TYPE_HISTPREF:
-                               (void)process_histpref_file(creature_ptr, buf + 2, process_autopick_file_command);
+                (void)process_histpref_file(creature_ptr, file_read__buf + 2, process_autopick_file_command);
                                break;
                        default:
-                               (void)process_pref_file(creature_ptr, buf + 2, process_autopick_file_command);
+                (void)process_pref_file(creature_ptr, file_read__buf + 2, process_autopick_file_command);
                                break;
                        }
 
@@ -113,13 +114,13 @@ static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int p
                        continue;
                }
 
-               err = interpret_pref_file(creature_ptr, buf);
+               err = interpret_pref_file(creature_ptr, file_read__buf);
                if (err != 0)
                {
                        if (preftype != PREF_TYPE_AUTOPICK)
                                break;
                        
-                       (*process_autopick_file_command)(buf);
+                       (*process_autopick_file_command)(file_read__buf);
                        err = 0;
                }
        }
@@ -130,7 +131,7 @@ static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int p
                /* ToDo: Add better error messages */
                msg_format(_("ファイル'%s'の%d行でエラー番号%dのエラー。", "Error %d in line %d of file '%s'."),
                        _(name, err), line, _(err, name));
-               msg_format(_("('%s'を解析中)", "Parsing '%s'"), old);
+               msg_format(_("('%s'を解析中)", "Parsing '%s'"), file_read__swp);
                msg_print(NULL);
        }
 
index 51d20c6..a0bb8cb 100644 (file)
@@ -1972,7 +1972,7 @@ static void windows_map(player_type *player_ptr)
 static void term_data_link(term_data *td)
 {
     term_type *t = &td->t;
-    term_init(t, td->cols, td->rows, td->keys);
+    term_init(t, td->cols, td->rows, FILE_READ_BUFF_SIZE);
     t->soft_cursor = TRUE;
     t->higher_pict = TRUE;
     t->attr_blank = TERM_WHITE;
index 61b5cd6..cd7f19a 100644 (file)
 #include "util/angband-files.h"
 #include "world/world.h"
 
+char *file_read__buf;
+char *file_read__swp;
+char *file_read__tmp;
+
 /*!
  * @brief 各データファイルを読み取るためのパスを取得する
  * Find the default paths to all of our important sub-directories.
@@ -147,6 +151,9 @@ static void put_title(void)
  */
 void init_angband(player_type *player_ptr, process_autopick_file_command_pf process_autopick_file_command)
 {
+    C_MAKE(file_read__buf, FILE_READ_BUFF_SIZE, char);
+    C_MAKE(file_read__swp, FILE_READ_BUFF_SIZE, char);
+    C_MAKE(file_read__tmp, FILE_READ_BUFF_SIZE, char);
     char buf[1024];
     path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
     int fd = fd_open(buf, O_RDONLY);
index d29b1a3..774a772 100644 (file)
@@ -12,6 +12,7 @@
 #include "system/floor-type-definition.h"
 #include "system/object-type-definition.h"
 #include "term/gameterm.h"
+#include "util/angband-files.h"
 #include "util/quarks.h"
 #include "util/tag-sorter.h"
 #include "view/display-messages.h"
@@ -58,7 +59,7 @@ errr init_other(player_type *player_ptr)
     C_MAKE(macro__pat, MACRO_MAX, concptr);
     C_MAKE(macro__act, MACRO_MAX, concptr);
     C_MAKE(macro__cmd, MACRO_MAX, bool);
-    C_MAKE(macro__buf, 1024, char);
+    C_MAKE(macro__buf, FILE_READ_BUFF_SIZE, char);
     quark_init();
 
     C_MAKE(message__ptr, MESSAGE_MAX, u32b);
index 180f66e..fe05c38 100644 (file)
@@ -242,13 +242,12 @@ errr angband_fgets(FILE *fff, char *buf, huge n)
 {
     huge i = 0;
     char *s;
-    char tmp[1024];
 
-    if (fgets(tmp, 1024, fff)) {
+    if (fgets(file_read__tmp, FILE_READ_BUFF_SIZE, fff)) {
 #ifdef JP
-        guess_convert_to_system_encoding(tmp, sizeof(tmp));
+        guess_convert_to_system_encoding(file_read__tmp, FILE_READ_BUFF_SIZE);
 #endif
-        for (s = tmp; *s; s++) {
+        for (s = file_read__tmp; *s; s++) {
             if (*s == '\n') {
                 buf[i] = '\0';
                 return 0;
index 7a58544..4f5ac40 100644 (file)
@@ -31,6 +31,11 @@ extern int usleep(huge usecs);
 #endif
 #endif
 
+#define FILE_READ_BUFF_SIZE 65535
+extern char *file_read__buf;
+extern char *file_read__swp;
+extern char *file_read__tmp;
+
 errr path_parse(char *buf, int max, concptr file);
 errr path_build(char *buf, int max, concptr path, concptr file);
 FILE *angband_fopen(concptr file, concptr mode);