1 #include "core/show-file.h"
2 #include "io/files-util.h"
3 #include "system/angband-version.h"
4 #include "term/gameterm.h"
5 #include "term/term-color-types.h"
9 * @brief ファイル内容の一行をコンソールに出力する
10 * Display single line of on-line help file
17 * You can insert some special color tag to change text color.
19 * WHITETEXT [[[[y|SOME TEXT WHICH IS DISPLAYED IN YELLOW| WHITETEXT
20 * A colored segment is between "[[[[y|" and the last "|".
21 * You can use any single character in place of the "|".
24 static void show_file_aux_line(concptr str, int cy, concptr shower)
36 static const char tag_str[] = "[[[[";
37 byte color = TERM_WHITE;
39 for (int i = 0; str[i];)
41 int len = strlen(&str[i]);
42 int showercol = len + 1;
43 int bracketcol = len + 1;
48 ptr = angband_strstr(&lcstr[i], shower);
49 if (ptr) showercol = ptr - &lcstr[i];
52 ptr = in_tag ? angband_strchr(&str[i], in_tag) : angband_strstr(&str[i], tag_str);
53 if (ptr) bracketcol = ptr - &str[i];
54 if (bracketcol < endcol) endcol = bracketcol;
55 if (showercol < endcol) endcol = showercol;
57 Term_addstr(endcol, color, &str[i]);
61 if (shower && endcol == showercol)
63 int showerlen = strlen(shower);
64 Term_addstr(showerlen, TERM_YELLOW, &str[i]);
70 if (endcol != bracketcol) continue;
80 i += sizeof(tag_str) - 1;
81 color = color_char_to_attr(str[i]);
82 if (color == 255 || str[i + 1] == '\0')
85 Term_addstr(-1, TERM_WHITE, tag_str);
86 cx += sizeof(tag_str) - 1;
95 Term_erase(cx, cy, 255);
101 * @brief ファイル内容をコンソールに出力する
102 * Recursive file perusal.
103 * @param creature_ptr プレーヤーへの参照ポインタ
104 * @param show_version TRUEならばコンソール上にゲームのバージョンを表示する
105 * @param name ファイル名の文字列
106 * @param what 内容キャプションの文字列
112 * Process various special text in the input file, including
113 * the "menu" structures used by the "help file" system.
114 * Return FALSE on 'q' to exit from a deep, otherwise TRUE.
117 bool show_file(player_type *creature_ptr, bool show_version, concptr name, concptr what, int line, BIT_FLAGS mode)
120 Term_get_size(&wid, &hgt);
123 strcpy(finder_str, "");
126 strcpy(shower_str, "");
132 for (int i = 0; i < 68; i++)
138 strcpy(filename, name);
139 int n = strlen(filename);
142 for (int i = 0; i < n; i++)
144 if (filename[i] == '#')
147 tag = filename + i + 1;
157 strcpy(caption, what);
159 fff = angband_fopen(path, "r");
164 sprintf(caption, _("ヘルプ・ファイル'%s'", "Help file '%s'"), name);
165 path_build(path, sizeof(path), ANGBAND_DIR_HELP, name);
166 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");
178 path_build(path, sizeof(path), ANGBAND_DIR, name);
180 for (int i = 0; path[i]; i++)
182 path[i] = PATH_SEP[0];
184 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
185 fff = angband_fopen(path, "r");
190 msg_format(_("'%s'をオープンできません。", "Cannot open '%s'."), name);
202 bool reverse = (line < 0);
206 if (angband_fgets(fff, buf, sizeof(buf))) break;
207 if (!prefix(str, "***** "))
213 if ((str[6] == '[') && isalpha(str[7]))
215 int k = str[7] - 'A';
217 if ((str[8] == ']') && (str[9] == ' '))
219 strncpy(hook[k], str + 10, 31);
226 if (str[6] != '<') continue;
228 size_t len = strlen(str);
229 if (str[len - 1] == '>')
232 if (tag && streq(str + 7, tag)) line = next;
239 line = ((size - 1) / rows)*rows;
246 if (line >= size - rows)
248 if (line < 0) line = 0;
253 fff = angband_fopen(path, "r");
254 if (!fff) return FALSE;
261 if (angband_fgets(fff, buf, sizeof(buf))) break;
262 if (prefix(buf, "***** ")) continue;
267 concptr shower = NULL;
268 for (int i = 0; i < rows; i++)
272 if (angband_fgets(fff, buf, sizeof(buf))) break;
273 if (prefix(buf, "***** ")) continue;
280 if (!angband_strstr(lc_buf, find)) continue;
284 show_file_aux_line(str, i + 2, shower);
288 while (row_count < rows)
290 Term_erase(0, row_count + 2, 255);
304 prt(format(_("[変愚蛮怒 %d.%d.%d, %s, %d/%d]", "[Hengband %d.%d.%d, %s, Line %d/%d]"),
305 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH,
306 caption, line, size), 0, 0);
310 prt(format(_("[%s, %d/%d]", "[%s, Line %d/%d]"),
311 caption, line, size), 0, 0);
316 prt(_("[キー:(?)ヘルプ (ESC)終了]", "[Press ESC to exit.]"), hgt - 1, 0);
322 prt("[キー:(RET/スペース)↑ (-)↓ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
324 prt("[キー:(RET/スペース)↓ (-)↑ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
326 prt("[Press Return, Space, -, =, /, |, or ESC to exit.]", hgt - 1, 0);
330 skey = inkey_special(TRUE);
334 if (strcmp(name, _("jhelpinfo.txt", "helpinfo.txt")) != 0)
335 show_file(creature_ptr, TRUE, _("jhelpinfo.txt", "helpinfo.txt"), NULL, 0, mode);
338 prt(_("強調: ", "Show: "), hgt - 1, 0);
341 strcpy(back_str, shower_str);
342 if (askfor(shower_str, 80))
346 str_tolower(shower_str);
351 else strcpy(shower_str, back_str);
356 prt(_("検索: ", "Find: "), hgt - 1, 0);
357 strcpy(back_str, finder_str);
358 if (askfor(finder_str, 80))
365 str_tolower(finder_str);
370 else strcpy(finder_str, back_str);
376 prt(_("行: ", "Goto Line: "), hgt - 1, 0);
379 if (askfor(tmp, 80)) line = atoi(tmp);
388 line = ((size - 1) / rows) * rows;
394 prt(_("ファイル・ネーム: ", "Goto File: "), hgt - 1, 0);
395 strcpy(tmp, _("jhelp.hlp", "help.hlp"));
399 if (!show_file(creature_ptr, TRUE, tmp, NULL, 0, mode)) skey = 'q';
406 line = line + (reverse ? rows : -rows);
407 if (line < 0) line = 0;
412 if (line < 0) line = 0;
417 line = line + (reverse ? -1 : 1);
418 if (line < 0) line = 0;
424 if (line < 0) line = 0;
433 line = line + (reverse ? -rows : rows);
434 if (line < 0) line = 0;
445 if (!(skey & SKEY_MASK) && isalpha(skey))
448 if ((key > -1) && hook[key][0])
450 /* Recurse on that file */
451 if (!show_file(creature_ptr, TRUE, hook[key], NULL, 0, mode))
464 if (!get_string(_("ファイル名: ", "File name: "), xtmp, 80)) continue;
466 path_build(buff, sizeof(buff), ANGBAND_DIR_USER, xtmp);
468 /* Hack -- Re-Open the file */
469 fff = angband_fopen(path, "r");
471 ffp = angband_fopen(buff, "w");
475 msg_print(_("ファイルを開けません。", "Failed to open file."));
480 sprintf(xtmp, "%s: %s", creature_ptr->name, what ? what : caption);
481 angband_fputs(ffp, xtmp, 80);
482 angband_fputs(ffp, "\n", 80);
484 while (!angband_fgets(fff, buff, sizeof(buff)))
485 angband_fputs(ffp, buff, 80);
488 fff = angband_fopen(path, "r");
491 if ((skey == ESCAPE) || (skey == '<')) break;
493 if (skey == KTRL('q')) skey = 'q';
495 if (skey == 'q') break;
499 return (skey != 'q');