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)
43 static const char tag_str[] = "[[[[";
44 byte color = TERM_WHITE;
46 for (int i = 0; str[i];) {
47 int len = strlen(&str[i]);
48 int showercol = len + 1;
49 int bracketcol = len + 1;
53 ptr = angband_strstr(&lcstr[i], shower);
55 showercol = ptr - &lcstr[i];
58 ptr = in_tag ? angband_strchr(&str[i], in_tag) : angband_strstr(&str[i], tag_str);
60 bracketcol = ptr - &str[i];
61 if (bracketcol < endcol)
63 if (showercol < endcol)
66 term_addstr(endcol, color, &str[i]);
70 if (shower && endcol == showercol) {
71 int showerlen = strlen(shower);
72 term_addstr(showerlen, TERM_YELLOW, &str[i]);
78 if (endcol != bracketcol)
88 i += sizeof(tag_str) - 1;
89 color = color_char_to_attr(str[i]);
90 if (color == 255 || str[i + 1] == '\0') {
92 term_addstr(-1, TERM_WHITE, tag_str);
93 cx += sizeof(tag_str) - 1;
102 term_erase(cx, cy, 255);
107 * @brief ファイル内容をコンソールに出力する
108 * Recursive file perusal.
109 * @param creature_ptr プレーヤーへの参照ポインタ
110 * @param show_version TRUEならばコンソール上にゲームのバージョンを表示する
111 * @param name ファイル名の文字列
112 * @param what 内容キャプションの文字列
118 * Process various special text in the input file, including
119 * the "menu" structures used by the "help file" system.
120 * Return FALSE on 'q' to exit from a deep, otherwise TRUE.
123 bool show_file(player_type *creature_ptr, bool show_version, concptr name, concptr what, int line, BIT_FLAGS mode)
126 term_get_size(&wid, &hgt);
129 strcpy(finder_str, "");
132 strcpy(shower_str, "");
138 for (int i = 0; i < 68; i++) {
143 strcpy(filename, name);
144 int n = strlen(filename);
147 for (int i = 0; i < n; i++) {
148 if (filename[i] == '#') {
150 tag = filename + i + 1;
159 strcpy(caption, what);
161 fff = angband_fopen(path, "r");
165 sprintf(caption, _("ヘルプ・ファイル'%s'", "Help file '%s'"), name);
166 path_build(path, sizeof(path), ANGBAND_DIR_HELP, name);
167 fff = angband_fopen(path, "r");
171 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
172 path_build(path, sizeof(path), ANGBAND_DIR_INFO, name);
173 fff = angband_fopen(path, "r");
177 path_build(path, sizeof(path), ANGBAND_DIR, name);
179 for (int i = 0; path[i]; i++)
181 path[i] = PATH_SEP[0];
183 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
184 fff = angband_fopen(path, "r");
188 msg_format(_("'%s'をオープンできません。", "Cannot open '%s'."), name);
200 bool reverse = (line < 0);
203 if (angband_fgets(fff, buf, sizeof(buf)))
205 if (!prefix(str, "***** ")) {
210 if ((str[6] == '[') && isalpha(str[7])) {
211 int k = str[7] - 'A';
213 if ((str[8] == ']') && (str[9] == ' ')) {
214 strncpy(hook[k], str + 10, 31);
224 size_t len = strlen(str);
225 if (str[len - 1] == '>') {
227 if (tag && streq(str + 7, tag))
235 line = ((size - 1) / rows) * rows;
240 concptr shower = NULL;
242 if (line >= size - rows)
249 fff = angband_fopen(path, "r");
256 while (next < line) {
257 if (angband_fgets(fff, buf, sizeof(buf)))
259 if (prefix(buf, "***** "))
265 for (row_count = 0; row_count < rows;) {
269 if (angband_fgets(fff, buf, sizeof(buf)))
271 if (prefix(buf, "***** "))
274 if (find && !row_count) {
278 if (!angband_strstr(lc_buf, find))
283 show_file_aux_line(str, row_count + 2, shower);
287 while (row_count < rows) {
288 term_erase(0, row_count + 2, 255);
299 prt(format(_("[変愚蛮怒 %d.%d.%d, %s, %d/%d]", "[Hengband %d.%d.%d, %s, Line %d/%d]"), FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH, caption,
306 prt(format("[%s]", title), 0, 0);
308 prt(format(_("[%s, %d/%d]", "[%s, Line %d/%d]"), caption, line, size), 0, 0);
312 prt(_("[キー:(?)ヘルプ (ESC)終了]", "[Press ESC to exit.]"), hgt - 1, 0);
316 prt("[キー:(RET/スペース)↑ (-)↓ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
318 prt("[キー:(RET/スペース)↓ (-)↑ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
320 prt("[Press Return, Space, -, =, /, |, or ESC to exit.]", hgt - 1, 0);
324 skey = inkey_special(TRUE);
327 if (strcmp(name, _("jhelpinfo.txt", "helpinfo.txt")) != 0)
328 show_file(creature_ptr, TRUE, _("jhelpinfo.txt", "helpinfo.txt"), NULL, 0, mode);
331 prt(_("強調: ", "Show: "), hgt - 1, 0);
334 strcpy(back_str, shower_str);
335 if (askfor(shower_str, 80)) {
337 str_tolower(shower_str);
342 strcpy(shower_str, back_str);
347 prt(_("検索: ", "Find: "), hgt - 1, 0);
348 strcpy(back_str, finder_str);
349 if (askfor(finder_str, 80)) {
354 str_tolower(finder_str);
359 strcpy(finder_str, back_str);
364 prt(_("行: ", "Goto Line: "), hgt - 1, 0);
377 line = ((size - 1) / rows) * rows;
382 prt(_("ファイル・ネーム: ", "Goto File: "), hgt - 1, 0);
383 strcpy(tmp, _("jhelp.hlp", "help.hlp"));
385 if (askfor(tmp, 80)) {
386 if (!show_file(creature_ptr, TRUE, tmp, NULL, 0, mode))
394 line = line + (reverse ? rows : -rows);
407 line = line + (reverse ? -1 : 1);
425 line = line + (reverse ? -rows : rows);
437 if (!(skey & SKEY_MASK) && isalpha(skey))
440 if ((key > -1) && hook[key][0]) {
441 /* Recurse on that file */
442 if (!show_file(creature_ptr, TRUE, hook[key], NULL, 0, mode))
454 if (!get_string(_("ファイル名: ", "File name: "), xtmp, 80))
457 path_build(buff, sizeof(buff), ANGBAND_DIR_USER, xtmp);
459 /* Hack -- Re-Open the file */
460 fff = angband_fopen(path, "r");
462 ffp = angband_fopen(buff, "w");
465 msg_print(_("ファイルを開けません。", "Failed to open file."));
470 sprintf(xtmp, "%s: %s", creature_ptr->name, what ? what : caption);
471 angband_fputs(ffp, xtmp, 80);
472 angband_fputs(ffp, "\n", 80);
474 while (!angband_fgets(fff, buff, sizeof(buff)))
475 angband_fputs(ffp, buff, 80);
478 fff = angband_fopen(path, "r");
481 if ((skey == ESCAPE) || (skey == '<'))
484 if (skey == KTRL('q'))
492 return (skey != 'q');
496 * Convert string to lower case
498 void str_tolower(char *str)
500 for (; *str; str++) {
507 *str = (char)tolower(*str);