hmml_to_html.c: Enable custom title [#25]

Also track an example template.html
This commit is contained in:
Matt Mascarenhas 2017-06-21 21:30:05 +01:00
parent 3ff29b39bf
commit c8c9a19554
4 changed files with 112 additions and 80 deletions

View File

@ -20,3 +20,6 @@
.category.inventory { border: 1px solid hsl(111, 79%, 26%); background: hsl(111, 79%, 26%); }
.category.hardware { border: 1px solid hsl(284, 94%, 26%); background: hsl(284, 94%, 26%); }
.category.math { border: 1px solid hsl(185, 74%, 26%); background: hsl(185, 74%, 26%); }
.category.platform-layer { border: 1px solid hsl(160, 81%, 26%); background: hsl(160, 81%, 26%); }
.category.font { border: 1px solid hsl(13, 87%, 26%); background: hsl(13, 87%, 26%); }
.category.input-handling { border: 1px solid hsl(335, 94%, 26%); background: hsl(335, 94%, 26%); }

View File

@ -1196,8 +1196,8 @@ main(int ArgC, char **Args)
// NOTE(matt): Tree structure of buffer dependencies
// Master
// Header
// Title
// Includes
// Menus
// QuoteMenu
// ReferenceMenu
// FilterMenu
@ -1215,9 +1215,9 @@ main(int ArgC, char **Args)
// FilterState
buffer Master;
buffer Header;
buffer Includes;
buffer Title;
buffer Menus;
buffer QuoteMenu;
buffer ReferenceMenu;
buffer FilterMenu;
@ -1260,8 +1260,8 @@ main(int ArgC, char **Args)
{
// NOTE(matt): Tree structure of "global" buffer dependencies
// Master
// Header
// Title
// Includes
// Menus
// QuoteMenu
// ReferenceMenu
// FilterMenu
@ -1275,9 +1275,9 @@ main(int ArgC, char **Args)
// FilterState
ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, "Master", Kilobytes(512));
ClaimBuffer(MemoryArena, &ClaimedMemory, &Header, "Header", Kilobytes(1));
ClaimBuffer(MemoryArena, &ClaimedMemory, &Includes, "Includes", Kilobytes(1));
ClaimBuffer(MemoryArena, &ClaimedMemory, &Title, "Title", Kilobytes(16));
ClaimBuffer(MemoryArena, &ClaimedMemory, &Menus, "Menus", Kilobytes(16));
ClaimBuffer(MemoryArena, &ClaimedMemory, &QuoteMenu, "QuoteMenu", Kilobytes(16));
ClaimBuffer(MemoryArena, &ClaimedMemory, &ReferenceMenu, "ReferenceMenu", Kilobytes(16));
ClaimBuffer(MemoryArena, &ClaimedMemory, &FilterMenu, "FilterMenu", Kilobytes(16));
@ -1309,11 +1309,11 @@ main(int ArgC, char **Args)
int UniqueTopics = 0;
int UniqueMedia = 0;
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <div class=\"title %s\">\n"
" <span class=\"episode_name\">", HMML.metadata.project);
CopyStringToBufferHTMLSafe(&Title, HMML.metadata.title);
CopyStringToBuffer(&Title, "</span>\n"
CopyStringToBufferHTMLSafe(&Menus, HMML.metadata.title);
CopyStringToBuffer(&Menus, "</span>\n"
" <span id=\"focus-warn\">⚠ Click here to regain focus ⚠</span>\n");
CopyStringToBuffer(&Player,
@ -1785,7 +1785,7 @@ Anno->time);
CopyStringToBuffer(&QuoteMenu,
" </div>\n"
" </div>\n");
CopyBuffer(&Title, &QuoteMenu);
CopyBuffer(&Menus, &QuoteMenu);
}
if(HasReferenceMenu)
@ -1841,7 +1841,7 @@ ReferencesArray[i].Identifier[j].Timecode);
CopyStringToBuffer(&ReferenceMenu,
" </div>\n"
" </div>\n");
CopyBuffer(&Title, &ReferenceMenu);
CopyBuffer(&Menus, &ReferenceMenu);
}
if(HasFilterMenu)
@ -1942,18 +1942,18 @@ CategoryMedium[j][2]
" </div>\n");
}
CopyBuffer(&Title, &FilterMenu);
CopyBuffer(&Menus, &FilterMenu);
if(HasCreditsMenu)
{
CopyBuffer(&Title, &CreditsMenu);
CopyBuffer(&Menus, &CreditsMenu);
}
#if CONFIG
// TODO(matt): Here is where I test ParseConfig
ParseConfig(&Config, HMML.metadata.annotator);
#endif
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <div class=\"help\">\n"
" <span>?</span>\n"
" <div class=\"help_container\">\n"
@ -1964,64 +1964,64 @@ CategoryMedium[j][2]
if(HasFilterMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key\">z</span> <span class=\"help_text\">Toggle filter mode</span> <span class=\"help_key\">V</span> <span class=\"help_text\">Revert filter to original state</span>\n");
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key unavailable\">z</span> <span class=\"help_text unavailable\">Toggle filter mode</span> <span class=\"help_key unavailable\">V</span> <span class=\"help_text unavailable\">Revert filter to original state</span>\n");
}
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
"\n"
" <h2>Menu toggling</h2>\n");
if(HasQuoteMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key\">q</span> <span class=\"help_text\">Quotes</span>\n");
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key unavailable\">q</span> <span class=\"help_text unavailable\">Quotes</span>\n");
}
if(HasReferenceMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key\">r</span> <span class=\"help_text\">References</span>\n");
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key unavailable\">r</span> <span class=\"help_text unavailable\">References</span>\n");
}
if(HasFilterMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key\">f</span> <span class=\"help_text\">Filter</span>\n");
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key unavailable\">f</span> <span class=\"help_text unavailable\">Filter</span>\n");
}
if(HasCreditsMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key\">c</span> <span class=\"help_text\">Credits</span>\n");
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key unavailable\">c</span> <span class=\"help_text unavailable\">Credits</span>\n");
}
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
"\n"
" <h2>Movement</h2>\n"
" <div class=\"help_paragraph\">\n"
@ -2060,86 +2060,86 @@ CategoryMedium[j][2]
if(HasQuoteMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <h2>Quotes ");
if(HasReferenceMenu)
{
CopyStringToBuffer(&Title, "and References Menus</h2>\n");
CopyStringToBuffer(&Menus, "and References Menus</h2>\n");
}
else
{
CopyStringToBuffer(&Title, "<span class=\"unavailable\">and References</span> Menus</h2>\n");
CopyStringToBuffer(&Menus, "<span class=\"unavailable\">and References</span> Menus</h2>\n");
}
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <h2><span class=\"unavailable\">Quotes");
if(HasReferenceMenu)
{
CopyStringToBuffer(&Title, " and</span> References Menus</h2>\n");
CopyStringToBuffer(&Menus, " and</span> References Menus</h2>\n");
}
else
{
CopyStringToBuffer(&Title, " and References Menus</span></h2>\n");
CopyStringToBuffer(&Menus, " and References Menus</span></h2>\n");
}
}
if(HasQuoteMenu || HasReferenceMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span style=\"width: auto\" class=\"help_key\">Enter</span> <span class=\"help_text\">Jump to timecode</span><br>\n");
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span style=\"width: auto\" class=\"help_key unavailable\">Enter</span> <span class=\"help_text unavailable\">Jump to timecode</span><br>\n");
}
if(HasReferenceMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <h2>References ");
if(HasCreditsMenu)
{
CopyStringToBuffer(&Title, "and Credits Menus</h2>\n");
CopyStringToBuffer(&Menus, "and Credits Menus</h2>\n");
}
else
{
CopyStringToBuffer(&Title, "<span class=\"unavailable\">and Credits</span> Menus</h2>\n");
CopyStringToBuffer(&Menus, "<span class=\"unavailable\">and Credits</span> Menus</h2>\n");
}
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <h2><span class=\"unavailable\">References");
if(HasCreditsMenu)
{
CopyStringToBuffer(&Title, " and</span> Credits Menus</h2>\n");
CopyStringToBuffer(&Menus, " and</span> Credits Menus</h2>\n");
}
else
{
CopyStringToBuffer(&Title, " and Credits Menus</span></h2>\n");
CopyStringToBuffer(&Menus, " and Credits Menus</span></h2>\n");
}
}
if(HasReferenceMenu || HasCreditsMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key\">o</span> <span class=\"help_text\">Open URL (in new tab)</span>\n");
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <span class=\"help_key unavailable\">o</span> <span class=\"help_text unavailable\">Open URL (in new tab)</span>\n");
}
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
"\n");
if(HasFilterMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <h2>Filter Menu</h2>\n"
" <span class=\"help_key\">x</span>, <span style=\"width: auto\" class=\"help_key\">Space</span> <span class=\"help_text\">Toggle category and focus next</span><br>\n"
" <span class=\"help_key\">X</span>, <span style=\"width: auto; margin-right: 0px\" class=\"help_key\">Shift</span><span style=\"width: auto\" class=\"help_key\">Space</span> <span class=\"help_text\">Toggle category and focus previous</span><br>\n"
@ -2147,7 +2147,7 @@ CategoryMedium[j][2]
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <h2><span class=\"unavailable\">Filter Menu</span></h2>\n"
" <span class=\"help_key unavailable\">x</span>, <span style=\"width: auto\" class=\"help_key unavailable\">Space</span> <span class=\"help_text unavailable\">Toggle category and focus next</span><br>\n"
" <span class=\"help_key unavailable\">X</span>, <span style=\"width: auto; margin-right: 0px\" class=\"help_key unavailable\">Shift</span><span style=\"width: auto\" class=\"help_key unavailable\">Space</span> <span class=\"help_text unavailable\">Toggle category and focus previous</span><br>\n"
@ -2156,18 +2156,18 @@ CategoryMedium[j][2]
if(HasCreditsMenu)
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <h2>Credits Menu</h2>\n"
" <span style=\"width: auto\" class=\"help_key\">Enter</span> <span class=\"help_text\">Open URL (in new tab)</span><br>\n");
}
else
{
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" <h2><span class=\"unavailable\">Credits Menu</span></h2>\n"
" <span style=\"width: auto\" class=\"help_key unavailable\">Enter</span> <span class=\"help_text unavailable\">Open URL (in new tab)</span><br>\n");
}
CopyStringToBuffer(&Title,
CopyStringToBuffer(&Menus,
" </div>\n"
" </div>\n"
@ -2178,11 +2178,8 @@ CategoryMedium[j][2]
" </div>");
// TODO(matt): Maybe do something about indentation levels
CopyStringToBuffer(&Header,
CopyStringToBuffer(&Includes,
"<meta charset=\"UTF-8\">\n"
" <title>");
CopyStringToBufferHTMLSafe(&Header, HMML.metadata.title);
CopyStringToBuffer(&Header, "</title>\n" // TODO(matt): Add the full name of the project, parsed from a config
"\n"
" <!-- Load the player -->\n"
" <script type=\"text/javascript\" src=\"cinera.js\"></script>\n"
@ -2402,23 +2399,28 @@ HMML.metadata.project);
{
perror(Args[0]); hmml_free(&HMML); free(MemoryArena); return 1;
}
Template.Ptr = Template.Location;
fread(Template.Location, Template.Size, 1, TemplateFile);
fclose(TemplateFile);
buffer Output;
Output.Size = Template.Size + Master.Size;
Output.ID = "Output";
if(!(Output.Location = malloc(Template.Size + Master.Size)))
if(!(Output.Location = malloc(Output.Size)))
{
perror(Args[0]); free(Template.Location); hmml_free(&HMML); free(MemoryArena); return 1;
}
Output.Ptr = Output.Location;
char *HeaderTag = "__CINERA_HEADER__";
char *TitleTag = "__CINERA_TITLE__";
char *IncludesTag = "__CINERA_INCLUDES__";
char *TitleTag = "__CINERA_TITLE__";
char *MenusTag = "__CINERA_MENUS__";
char *PlayerTag = "__CINERA_PLAYER__";
char *ScriptTag = "__CINERA_SCRIPT__";
bool FoundHeader = FALSE;
bool FoundTitle = FALSE;
bool FoundIncludes = FALSE;
bool FoundTitle = FALSE;
bool FoundMenus = FALSE;
bool FoundPlayer = FALSE;
bool FoundScript = FALSE;
@ -2429,16 +2431,16 @@ HMML.metadata.project);
char *CommentStart = &Output.Ptr[-1];
while(Template.Ptr - Template.Location < Template.Size)
{
if(!(StringsDifferT(HeaderTag, Template.Ptr, 0)))
if(!(StringsDifferT(IncludesTag, Template.Ptr, 0)))
{
if(FoundHeader == TRUE)
if(FoundIncludes == TRUE)
{
fprintf(stderr, "Template contains more than one <!-- __CINERA_HEADER__ --> tag\n");
fprintf(stderr, "Template contains more than one <!-- __CINERA_INCLUDES__ --> tag\n");
free(Template.Location); free(Output.Location); hmml_free(&HMML); free(MemoryArena); return 1;
}
FoundHeader = TRUE;
FoundIncludes = TRUE;
Output.Ptr = CommentStart;
CopyBuffer(&Output, &Header);
CopyBuffer(&Output, &Includes);
while(Template.Ptr - Template.Location < Template.Size)
{
if(!StringsDifferT("-->", Template.Ptr, 0))
@ -2450,6 +2452,7 @@ HMML.metadata.project);
}
break;
}
else if(!(StringsDifferT(TitleTag, Template.Ptr, 0)))
{
if(FoundTitle == TRUE)
@ -2457,20 +2460,35 @@ HMML.metadata.project);
fprintf(stderr, "Template contains more than one <!-- __CINERA_TITLE__ --> tag\n");
free(Template.Location); free(Output.Location); hmml_free(&HMML); free(MemoryArena); return 1;
}
/* TODO(matt): Allow setting a Title format, e.g.
<-- __CINERA_TITLE__ "%s - HandmadeDev" -->
Where %s is replaced with the HMML.metadata.title
Perhaps it would be saner to do this in the config file
*/
FoundTitle = TRUE;
Output.Ptr = CommentStart;
CopyBuffer(&Output, &Title);
CopyStringToBuffer(&Output, HMML.metadata.title);
while(Template.Ptr - Template.Location < Template.Size)
{
if(!StringsDifferT("-->", Template.Ptr, 0))
{
Template.Ptr += StringLength("-->");
break;
}
++Template.Ptr;
}
break;
}
else if(!(StringsDifferT(MenusTag, Template.Ptr, 0)))
{
if(FoundMenus == TRUE)
{
fprintf(stderr, "Template contains more than one <!-- __CINERA_MENUS__ --> tag\n");
free(Template.Location); free(Output.Location); hmml_free(&HMML); free(MemoryArena); return 1;
}
FoundMenus = TRUE;
Output.Ptr = CommentStart;
CopyBuffer(&Output, &Menus);
while(Template.Ptr - Template.Location < Template.Size)
{
if(!StringsDifferT("-->", Template.Ptr, 0))
{
Template.Ptr += StringLength("-->");
printf("%c%c%c\n", Template.Ptr[-1], Template.Ptr[0], Template.Ptr[1]);
break;
}
++Template.Ptr;
@ -2532,7 +2550,7 @@ HMML.metadata.project);
}
}
if(FoundHeader && FoundTitle && FoundPlayer && FoundScript)
if(FoundIncludes && FoundMenus && FoundPlayer && FoundScript)
{
FILE *OutFile;
if(!(OutFile = fopen("out_integrated.html", "w")))
@ -2545,8 +2563,8 @@ HMML.metadata.project);
else
{
fprintf(stderr, "Template is missing necessary tags:\n");
if(!FoundHeader) { fprintf(stderr, " <!-- __CINERA_HEADER__ -->\n"); }
if(!FoundTitle) { fprintf(stderr, " <!-- __CINERA_TITLE__ -->\n"); }
if(!FoundIncludes) { fprintf(stderr, " <!-- __CINERA_INCLUDES__ -->\n"); }
if(!FoundMenus) { fprintf(stderr, " <!-- __CINERA_MENUS__ -->\n"); }
if(!FoundPlayer) { fprintf(stderr, " <!-- __CINERA_PLAYER__ -->\n"); }
if(!FoundScript) { fprintf(stderr, " <!-- __CINERA_SCRIPT__ -->\n"); }
free(Template.Location); free(Output.Location); hmml_free(&HMML); free(MemoryArena); return 1;
@ -2563,12 +2581,12 @@ HMML.metadata.project);
" <head>\n");
//NOTE(matt): Here is where we do all our CopyBuffer() calls
CopyBuffer(&Master, &Header);
CopyBuffer(&Master, &Includes);
CopyStringToBuffer(&Master,
"\n"
" </head>\n"
" <body>\n");
CopyBuffer(&Master, &Title);
CopyBuffer(&Master, &Menus);
CopyStringToBuffer(&Master, "\n");
CopyBuffer(&Master, &Player);
CopyStringToBuffer(&Master, "\n");
@ -2603,8 +2621,8 @@ HMML.metadata.project);
// FilterMenu
// ReferenceMenu
// QuoteMenu
// Title
// Header
// Menus
// Includes
// Master
DeclaimBuffer(&FilterState, &ClaimedMemory);
@ -2621,9 +2639,9 @@ HMML.metadata.project);
DeclaimBuffer(&FilterMenu, &ClaimedMemory);
DeclaimBuffer(&ReferenceMenu, &ClaimedMemory);
DeclaimBuffer(&QuoteMenu, &ClaimedMemory);
DeclaimBuffer(&Title, &ClaimedMemory);
DeclaimBuffer(&Menus, &ClaimedMemory);
DeclaimBuffer(&Header, &ClaimedMemory);
DeclaimBuffer(&Includes, &ClaimedMemory);
DeclaimBuffer(&Master, &ClaimedMemory);
}
else

View File

@ -0,0 +1,11 @@
<html>
<head>
<title>Preceding Text - <!-- __CINERA_TITLE__ --> - Following Text</title>
<!-- __CINERA_INCLUDES__ -->
</head>
<body>
<!-- __CINERA_MENUS__ -->
<!-- __CINERA_PLAYER__ -->
<!-- __CINERA_SCRIPT__ -->
</body>
</html>