From 8e0069eb71a30b4f640aabfedbc7f0ee9eebdf26 Mon Sep 17 00:00:00 2001 From: David Kinder Date: Mon, 13 Feb 2023 19:53:51 +0000 Subject: [PATCH] Use per-platform CSS when generating RTP and failure HTML pages --- inrtps/Chapter 1/Main.w | 26 +++++++++++++++++++++++++- inrtps/Chapter 1/Making RTP Pages.w | 10 ++++++++-- inrtps/Manual/Using Inrtps.w | 4 +++- resources/Outcome Pages/failed.html | 9 ++++++++- resources/Outcome Pages/released.html | 9 ++++++++- resources/Outcome Pages/rtp.html | 22 +++++++++------------- 6 files changed, 61 insertions(+), 19 deletions(-) diff --git a/inrtps/Chapter 1/Main.w b/inrtps/Chapter 1/Main.w index e8fa20622..707ee7578 100644 --- a/inrtps/Chapter 1/Main.w +++ b/inrtps/Chapter 1/Main.w @@ -22,7 +22,9 @@ int main(int argc, char **argv) { text_stream *f = NULL; if (font_setting) f = I"face='lucida grande,geneva,arial,tahoma,verdana,helvetica,helv'"; - Translator::go(from_folder, to_folder, f); + TEMPORARY_TEXT(css) + @; + Translator::go(from_folder, to_folder, f, css); } Foundation::end(); return 0; @@ -54,3 +56,25 @@ void Main::bareword(int id, text_stream *arg, void *state) { else if (to_folder == NULL) to_folder = Pathnames::from_text(arg); else Errors::fatal("too many arguments given at command line"); } + +@ We also read the per-platform CSS file, if present: + +@ = + filename *css_filename = NULL; + pathname *css_path = Pathnames::from_text(I"inform7/Internal/HTML"); + TEMPORARY_TEXT(platform_variation) + WRITE_TO(platform_variation, "%s-platform.css", PLATFORM_STRING); + css_filename = Filenames::in(css_path, platform_variation); + if (TextFiles::exists(css_filename) == FALSE) { + css_filename = Filenames::in(css_path, I"platform.css"); + } + if (TextFiles::exists(css_filename)) { + TextFiles::read(css_filename, FALSE, "can't open css file", + TRUE, Main::read_css_line, NULL, css); + } + +@ = +void Main::read_css_line(text_stream *line, text_file_position *tfp, void *X) { + text_stream *str = (text_stream *) X; + WRITE_TO(str, "%S\n", line); +} diff --git a/inrtps/Chapter 1/Making RTP Pages.w b/inrtps/Chapter 1/Making RTP Pages.w index 440392d9b..9d061b86e 100644 --- a/inrtps/Chapter 1/Making RTP Pages.w +++ b/inrtps/Chapter 1/Making RTP Pages.w @@ -11,13 +11,14 @@ typedef struct translator_state { struct text_stream *current_title; struct text_stream *current_pcode; struct text_stream *font; + struct text_stream *css; struct filename *model_to_follow; struct pathname *destination_folder; struct text_stream *write_to; int counter; } translator_state; -void Translator::go(pathname *from_folder, pathname *to_folder, text_stream *font_setting) { +void Translator::go(pathname *from_folder, pathname *to_folder, text_stream *font_setting, text_stream *css) { filename *texts = Filenames::in(from_folder, I"texts.txt"); translator_state ts; ts.current_text = Str::new(); @@ -27,6 +28,7 @@ void Translator::go(pathname *from_folder, pathname *to_folder, text_stream *fon ts.destination_folder = to_folder; ts.model_to_follow = NULL; ts.font = font_setting; + ts.css = css; ts.counter = 0; TextFiles::read(texts, FALSE, "unable to read file of source text", TRUE, &Translator::go_helper, NULL, &ts); @@ -85,7 +87,7 @@ void Translator::flush(translator_state *ts) { match_results mr = Regexp::create_mr(); while (Regexp::match(&mr, ts->current_text, L"(%c*?)\"(%c*?)\"(%c*)")) { Str::clear(ts->current_text); - WRITE_TO(ts->current_text, "%S%S%S", + WRITE_TO(ts->current_text, "%S%S%S", mr.exp[0], mr.exp[1], mr.exp[2]); } while (Regexp::match(&mr, ts->current_text, L"(%c*?)_QUOTE_(%c*)")) { @@ -129,4 +131,8 @@ void Translator::flush_helper(text_stream *text, text_file_position *tfp, void * Str::clear(text); WRITE_TO(text, "%S%S%S", mr.exp[0], ts->font, mr.exp[1]); } + while (Regexp::match(&mr, text, L"(%c*?)%*5(%c*)")) { + Str::clear(text); + WRITE_TO(text, "%S%S%S", mr.exp[0], ts->css, mr.exp[1]); + } Regexp::dispose_of(&mr); diff --git a/inrtps/Manual/Using Inrtps.w b/inrtps/Manual/Using Inrtps.w index 14a6adf3c..6a80caf06 100644 --- a/inrtps/Manual/Using Inrtps.w +++ b/inrtps/Manual/Using Inrtps.w @@ -53,7 +53,7 @@ from the next. For instance: A number cannot be divided by 0: similarly, we cannot take the remainder after dividing something by 0. = -The model file is a standard HTML file, except that it can contain four +The model file is a standard HTML file, except that it can contain five escape codes, which Inrtps expands. Thus: (a) |*1| expands to the code number of the message. @@ -61,3 +61,5 @@ escape codes, which Inrtps expands. Thus: (c) |*3| expands to a short title for the message. (d) |*4| expands to font settings inside a || tag. (This will be blank if |nofont| is set, or will choose a Helvetica-like font if |font| is set.) +(e) |*5| expands to the contents of the appropriate per-platform CSS file, which +is read from the Internal/HTML/ directory of the Inform installation. diff --git a/resources/Outcome Pages/failed.html b/resources/Outcome Pages/failed.html index 63d7c7383..070e91640 100644 --- a/resources/Outcome Pages/failed.html +++ b/resources/Outcome Pages/failed.html @@ -1,5 +1,12 @@ - + + + + Translating the Source - *3

*2 diff --git a/resources/Outcome Pages/released.html b/resources/Outcome Pages/released.html index 71582c0e6..e30a596b7 100644 --- a/resources/Outcome Pages/released.html +++ b/resources/Outcome Pages/released.html @@ -1,5 +1,12 @@ - + + + + Packaging up for Release - *3

*2 diff --git a/resources/Outcome Pages/rtp.html b/resources/Outcome Pages/rtp.html index 7a12d680f..ddc0ad33f 100644 --- a/resources/Outcome Pages/rtp.html +++ b/resources/Outcome Pages/rtp.html @@ -2,33 +2,29 @@ + @@ -36,9 +32,9 @@
-
-
Run-Time Problem
-
*3 (*1)
+
+
Run-Time Problem
+
*3 (*1)