1 #include "core/show-file.h"
2 #include "core/asking-player.h"
3 #include "io/files-util.h"
4 #include "io/input-key-acceptor.h"
5 #include "main/sound-of-music.h"
6 #include "system/angband-version.h"
7 #include "term/gameterm.h"
8 #include "term/screen-processor.h"
9 #include "term/term-color-types.h"
10 #include "util/angband-files.h"
11 #include "util/int-char-converter.h"
12 #include "util/string-processor.h"
13 #include "view/display-messages.h"
17 * @brief ファイル内容の一行をコンソールに出力する
18 * Display single line of on-line help file
25 * You can insert some special color tag to change text color.
27 * WHITETEXT [[[[y|SOME TEXT WHICH IS DISPLAYED IN YELLOW| WHITETEXT
28 * A colored segment is between "[[[[y|" and the last "|".
29 * You can use any single character in place of the "|".
32 static void show_file_aux_line(concptr str, int cy, concptr shower)
44 static const char tag_str[] = "[[[[";
45 byte color = TERM_WHITE;
47 for (int i = 0; str[i];)
49 int len = strlen(&str[i]);
50 int showercol = len + 1;
51 int bracketcol = len + 1;
56 ptr = angband_strstr(&lcstr[i], shower);
57 if (ptr) showercol = ptr - &lcstr[i];
60 ptr = in_tag ? angband_strchr(&str[i], in_tag) : angband_strstr(&str[i], tag_str);
61 if (ptr) bracketcol = ptr - &str[i];
62 if (bracketcol < endcol) endcol = bracketcol;
63 if (showercol < endcol) endcol = showercol;
65 term_addstr(endcol, color, &str[i]);
69 if (shower && endcol == showercol)
71 int showerlen = strlen(shower);
72 term_addstr(showerlen, TERM_YELLOW, &str[i]);
78 if (endcol != bracketcol) continue;
88 i += sizeof(tag_str) - 1;
89 color = color_char_to_attr(str[i]);
90 if (color == 255 || str[i + 1] == '\0')
93 term_addstr(-1, TERM_WHITE, tag_str);
94 cx += sizeof(tag_str) - 1;
103 term_erase(cx, cy, 255);
109 * @brief ファイル内容をコンソールに出力する
110 * Recursive file perusal.
111 * @param creature_ptr プレーヤーへの参照ポインタ
112 * @param show_version TRUEならばコンソール上にゲームのバージョンを表示する
113 * @param name ファイル名の文字列
114 * @param what 内容キャプションの文字列
120 * Process various special text in the input file, including
121 * the "menu" structures used by the "help file" system.
122 * Return FALSE on 'q' to exit from a deep, otherwise TRUE.
125 bool show_file(player_type *creature_ptr, bool show_version, concptr name, concptr what, int line, BIT_FLAGS mode)
128 term_get_size(&wid, &hgt);
131 strcpy(finder_str, "");
134 strcpy(shower_str, "");
140 for (int i = 0; i < 68; i++)
146 strcpy(filename, name);
147 int n = strlen(filename);
150 for (int i = 0; i < n; i++)
152 if (filename[i] == '#')
155 tag = filename + i + 1;
165 strcpy(caption, what);
167 fff = angband_fopen(path, "r");
172 sprintf(caption, _("ヘルプ・ファイル'%s'", "Help file '%s'"), name);
173 path_build(path, sizeof(path), ANGBAND_DIR_HELP, name);
174 fff = angband_fopen(path, "r");
179 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
180 path_build(path, sizeof(path), ANGBAND_DIR_INFO, name);
181 fff = angband_fopen(path, "r");
186 path_build(path, sizeof(path), ANGBAND_DIR, name);
188 for (int i = 0; path[i]; i++)
190 path[i] = PATH_SEP[0];
192 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
193 fff = angband_fopen(path, "r");
198 msg_format(_("'%s'をオープンできません。", "Cannot open '%s'."), name);
210 bool reverse = (line < 0);
214 if (angband_fgets(fff, buf, sizeof(buf))) break;
215 if (!prefix(str, "***** "))
221 if ((str[6] == '[') && isalpha(str[7]))
223 int k = str[7] - 'A';
225 if ((str[8] == ']') && (str[9] == ' '))
227 strncpy(hook[k], str + 10, 31);
234 if (str[6] != '<') continue;
236 size_t len = strlen(str);
237 if (str[len - 1] == '>')
240 if (tag && streq(str + 7, tag)) line = next;
247 line = ((size - 1) / rows)*rows;
254 if (line >= size - rows)
256 if (line < 0) line = 0;
261 fff = angband_fopen(path, "r");
262 if (!fff) return FALSE;
269 if (angband_fgets(fff, buf, sizeof(buf))) break;
270 if (prefix(buf, "***** ")) continue;
275 concptr shower = NULL;
276 for (int i = 0; i < rows; i++)
280 if (angband_fgets(fff, buf, sizeof(buf))) break;
281 if (prefix(buf, "***** ")) continue;
288 if (!angband_strstr(lc_buf, find)) continue;
292 show_file_aux_line(str, i + 2, shower);
296 while (row_count < rows)
298 term_erase(0, row_count + 2, 255);
312 prt(format(_("[変愚蛮怒 %d.%d.%d, %s, %d/%d]", "[Hengband %d.%d.%d, %s, Line %d/%d]"),
313 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH,
314 caption, line, size), 0, 0);
318 prt(format(_("[%s, %d/%d]", "[%s, Line %d/%d]"),
319 caption, line, size), 0, 0);
324 prt(_("[キー:(?)ヘルプ (ESC)終了]", "[Press ESC to exit.]"), hgt - 1, 0);
330 prt("[キー:(RET/スペース)↑ (-)↓ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
332 prt("[キー:(RET/スペース)↓ (-)↑ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
334 prt("[Press Return, Space, -, =, /, |, or ESC to exit.]", hgt - 1, 0);
338 skey = inkey_special(TRUE);
342 if (strcmp(name, _("jhelpinfo.txt", "helpinfo.txt")) != 0)
343 show_file(creature_ptr, TRUE, _("jhelpinfo.txt", "helpinfo.txt"), NULL, 0, mode);
346 prt(_("強調: ", "Show: "), hgt - 1, 0);
349 strcpy(back_str, shower_str);
350 if (askfor(shower_str, 80))
354 str_tolower(shower_str);
359 else strcpy(shower_str, back_str);
364 prt(_("検索: ", "Find: "), hgt - 1, 0);
365 strcpy(back_str, finder_str);
366 if (askfor(finder_str, 80))
373 str_tolower(finder_str);
378 else strcpy(finder_str, back_str);
384 prt(_("行: ", "Goto Line: "), hgt - 1, 0);
387 if (askfor(tmp, 80)) line = atoi(tmp);
396 line = ((size - 1) / rows) * rows;
402 prt(_("ファイル・ネーム: ", "Goto File: "), hgt - 1, 0);
403 strcpy(tmp, _("jhelp.hlp", "help.hlp"));
407 if (!show_file(creature_ptr, TRUE, tmp, NULL, 0, mode)) skey = 'q';
414 line = line + (reverse ? rows : -rows);
415 if (line < 0) line = 0;
420 if (line < 0) line = 0;
425 line = line + (reverse ? -1 : 1);
426 if (line < 0) line = 0;
432 if (line < 0) line = 0;
441 line = line + (reverse ? -rows : rows);
442 if (line < 0) line = 0;
453 if (!(skey & SKEY_MASK) && isalpha(skey))
456 if ((key > -1) && hook[key][0])
458 /* Recurse on that file */
459 if (!show_file(creature_ptr, TRUE, hook[key], NULL, 0, mode))
472 if (!get_string(_("ファイル名: ", "File name: "), xtmp, 80)) continue;
474 path_build(buff, sizeof(buff), ANGBAND_DIR_USER, xtmp);
476 /* Hack -- Re-Open the file */
477 fff = angband_fopen(path, "r");
479 ffp = angband_fopen(buff, "w");
483 msg_print(_("ファイルを開けません。", "Failed to open file."));
488 sprintf(xtmp, "%s: %s", creature_ptr->name, what ? what : caption);
489 angband_fputs(ffp, xtmp, 80);
490 angband_fputs(ffp, "\n", 80);
492 while (!angband_fgets(fff, buff, sizeof(buff)))
493 angband_fputs(ffp, buff, 80);
496 fff = angband_fopen(path, "r");
499 if ((skey == ESCAPE) || (skey == '<')) break;
501 if (skey == KTRL('q')) skey = 'q';
503 if (skey == 'q') break;
507 return (skey != 'q');
511 * Convert string to lower case
513 void str_tolower(char *str)
515 for (; *str; str++) {
522 *str = (char)tolower(*str);