From 4dc034ecc39c49df4376b73678e6b047a6240689 Mon Sep 17 00:00:00 2001 From: Matt Mascarenhas Date: Wed, 6 Oct 2021 15:45:19 +0100 Subject: [PATCH] cinera.c: Use html_title in Welcome / End markers --- cinera/cinera.c | 57 +++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/cinera/cinera.c b/cinera/cinera.c index 81f03d6..31a2cbd 100644 --- a/cinera/cinera.c +++ b/cinera/cinera.c @@ -23,7 +23,7 @@ typedef struct version CINERA_APP_VERSION = { .Major = 0, .Minor = 10, - .Patch = 1 + .Patch = 2 }; #include // NOTE(matt): varargs @@ -9960,6 +9960,26 @@ GetNumberFromHMMLBaseFilename(string ProjectID, string HMMLBaseFilename) return Result; } +string +BestTitleForHTML(project *Project) +{ + return Project->HTMLTitle.Length ? Project->HTMLTitle : Project->Title; +} + +void +CopyProjectWelcomeStringToBuffer(buffer *B, string ProjectTitle) +{ + CopyStringToBuffer(B, + "
Welcome to %.*s
\n", (int)ProjectTitle.Length, ProjectTitle.Base); +} + +void +CopyProjectEndStringToBuffer(buffer *B, string ProjectTitle) +{ + CopyStringToBuffer(B, + "
You have arrived at the (current) end of %.*s
\n", (int)ProjectTitle.Length, ProjectTitle.Base); +} + rc HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseFilename, neighbourhood *N) { @@ -10127,15 +10147,7 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF Result = RC_ERROR_HMML; } - string ProjectTitle; - if(CurrentProject->HTMLTitle.Length) - { - ProjectTitle = CurrentProject->HTMLTitle; - } - else - { - ProjectTitle = CurrentProject->Title; - } + string ProjectTitle = BestTitleForHTML(CurrentProject); // TODO(matt): Handle the art and art_variants once .hmml supports them @@ -10295,8 +10307,7 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF } else { - CopyStringToBuffer(&PlayerBuffers.Main, - "
Welcome to %.*s
\n", (int)ProjectTitle.Length, ProjectTitle.Base); + CopyProjectWelcomeStringToBuffer(&PlayerBuffers.Main, ProjectTitle); } } N->WorkingThis.LinkOffsets.PrevEnd = (PlayerBuffers.Main.Ptr - PlayerBuffers.Main.Location - N->WorkingThis.LinkOffsets.PrevStart); @@ -10701,8 +10712,7 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF } else { - CopyStringToBuffer(&PlayerBuffers.Main, - "
You have arrived at the (current) end of %.*s
\n", (int)ProjectTitle.Length, ProjectTitle.Base); + CopyProjectEndStringToBuffer(&PlayerBuffers.Main, ProjectTitle); } } N->WorkingThis.LinkOffsets.NextEnd = (PlayerBuffers.Main.Ptr - PlayerBuffers.Main.Location - (N->WorkingThis.LinkOffsets.PrevStart + N->WorkingThis.LinkOffsets.PrevEnd + N->WorkingThis.LinkOffsets.NextStart)); @@ -12761,6 +12771,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li ConstructPlayerURL(&ToPlayerURL, P, Wrap0i(To->OutputLocation, sizeof(To->OutputLocation))); } + string ProjectTitle = BestTitleForHTML(CurrentProject); int NewPrevEnd = 0; int NewNextEnd = 0; switch(LinkDirection) @@ -12778,8 +12789,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li else { // TODO(matt): Be careful of this! Is this CurrentProject->Title definitely set to the right thing? - CopyStringToBuffer(&Link, - "
Welcome to %.*s
\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base); + CopyProjectWelcomeStringToBuffer(&Link, ProjectTitle); } NewPrevEnd = Link.Ptr - Link.Location; fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle); @@ -12787,8 +12797,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li { fwrite(HTML.Buffer.Location + From->LinkOffsets.PrevStart + From->LinkOffsets.PrevEnd, From->LinkOffsets.NextStart, 1, HTML.Handle); RewindBuffer(&Link); - CopyStringToBuffer(&Link, - "
You have arrived at the (current) end of %.*s
\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base); + CopyProjectEndStringToBuffer(&Link, ProjectTitle); NewNextEnd = Link.Ptr - Link.Location; fwrite(Link.Location, NewNextEnd, 1, HTML.Handle); fwrite(HTML.Buffer.Location + From->LinkOffsets.PrevStart + From->LinkOffsets.PrevEnd + From->LinkOffsets.NextStart + From->LinkOffsets.NextEnd, @@ -12812,8 +12821,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li if(FromHasOneNeighbour) { fwrite(HTML.Buffer.Location, From->LinkOffsets.PrevStart, 1, HTML.Handle); - CopyStringToBuffer(&Link, - "
Welcome to %.*s
\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base); + CopyProjectWelcomeStringToBuffer(&Link, ProjectTitle); NewPrevEnd = Link.Ptr - Link.Location; fwrite(Link.Location, NewPrevEnd, 1, HTML.Handle); RewindBuffer(&Link); @@ -12834,8 +12842,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li } else { - CopyStringToBuffer(&Link, - "
You have arrived at the (current) end of %.*s
\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base); + CopyProjectEndStringToBuffer(&Link, ProjectTitle); } NewNextEnd = Link.Ptr - Link.Location; fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle); @@ -12974,8 +12981,7 @@ MarkNextAsFirst(neighbourhood *N) fwrite(HTML.Buffer.Location, N->Next->LinkOffsets.PrevStart, 1, HTML.Handle); - CopyStringToBuffer(&Link, - "
Welcome to %.*s
\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base); + CopyProjectWelcomeStringToBuffer(&Link, BestTitleForHTML(CurrentProject)); fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle); @@ -13013,8 +13019,7 @@ MarkPrevAsFinal(neighbourhood *N) fwrite(HTML.Buffer.Location, N->Prev->LinkOffsets.PrevStart + N->Prev->LinkOffsets.PrevEnd + N->Prev->LinkOffsets.NextStart, 1, HTML.Handle); - CopyStringToBuffer(&Link, - "
You have arrived at the (current) end of %.*s
\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base); + CopyProjectEndStringToBuffer(&Link, BestTitleForHTML(CurrentProject)); fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle);