hmml_to_html.c: Beginning Integration [#25]
This commit is contained in:
parent
280102869b
commit
0ad47c6c48
|
@ -305,7 +305,8 @@ StringsDifferL(char *A, char *B, int LengthofA)
|
|||
{
|
||||
++i;
|
||||
}
|
||||
if(!A[i] && LengthofA == i && (B[i] == ' ' || B[i] == '\"'))
|
||||
// TODO(matt): Uncomment
|
||||
if(!A[i] && LengthofA == i)// && (B[i] == ' ' || B[i] == '\"'))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -1186,6 +1187,7 @@ main(int ArgC, char **Args)
|
|||
|
||||
// NOTE(matt): Tree structure of buffer dependencies
|
||||
// Master
|
||||
// Header
|
||||
// Title
|
||||
// QuoteMenu
|
||||
// ReferenceMenu
|
||||
|
@ -1204,6 +1206,7 @@ main(int ArgC, char **Args)
|
|||
// FilterState
|
||||
|
||||
buffer Master;
|
||||
buffer Header;
|
||||
|
||||
buffer Title;
|
||||
buffer QuoteMenu;
|
||||
|
@ -1248,6 +1251,7 @@ main(int ArgC, char **Args)
|
|||
{
|
||||
// NOTE(matt): Tree structure of "global" buffer dependencies
|
||||
// Master
|
||||
// Header
|
||||
// Title
|
||||
// QuoteMenu
|
||||
// ReferenceMenu
|
||||
|
@ -1262,6 +1266,7 @@ main(int ArgC, char **Args)
|
|||
// FilterState
|
||||
|
||||
ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, "Master", Kilobytes(512));
|
||||
ClaimBuffer(MemoryArena, &ClaimedMemory, &Header, "Header", Kilobytes(1));
|
||||
|
||||
ClaimBuffer(MemoryArena, &ClaimedMemory, &Title, "Title", Kilobytes(16));
|
||||
ClaimBuffer(MemoryArena, &ClaimedMemory, &QuoteMenu, "QuoteMenu", Kilobytes(16));
|
||||
|
@ -2161,18 +2166,12 @@ CategoryMedium[j][2]
|
|||
" </div>\n"
|
||||
" </div>\n");
|
||||
|
||||
//NOTE(matt): Collate the buffers!
|
||||
#if DEBUG
|
||||
printf("Buffer Collation\n\n");
|
||||
#endif
|
||||
|
||||
CopyStringToBuffer(&Master,
|
||||
"<html>\n"
|
||||
" <head>\n"
|
||||
" <meta charset=\"UTF-8\">\n"
|
||||
// TODO(matt): Maybe do something about indentation levels
|
||||
CopyStringToBuffer(&Header,
|
||||
"<meta charset=\"UTF-8\">\n"
|
||||
" <title>");
|
||||
CopyStringToBufferHTMLSafe(&Master, HMML.metadata.title);
|
||||
CopyStringToBuffer(&Master, "</title>\n" // TODO(matt): Add the full name of the project, parsed from a config
|
||||
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=\"player.js\"></script>\n"
|
||||
|
@ -2371,12 +2370,176 @@ HMML.metadata.project);
|
|||
" setDotLightness(topicDots[i]);\n"
|
||||
"}\n"
|
||||
" </script>\n");
|
||||
|
||||
//NOTE(matt): Here is where we do all our CopyBuffer() calls
|
||||
CopyBuffer(&Master, &Title);
|
||||
CopyBuffer(&Master, &Player);
|
||||
CopyBuffer(&Master, &Script);
|
||||
//
|
||||
//NOTE(matt): Collate the buffers!
|
||||
#if DEBUG
|
||||
printf("Buffer Collation\n\n");
|
||||
#endif
|
||||
|
||||
char *CINERA_MODE = getenv("CINERA_MODE");
|
||||
if(CINERA_MODE && !StringsDiffer(CINERA_MODE, "INTEGRATE"))
|
||||
{
|
||||
FILE *TemplateFile;
|
||||
if(!(TemplateFile = fopen("template.html", "r")))
|
||||
{
|
||||
perror(Args[0]);
|
||||
hmml_free(&HMML);
|
||||
free(MemoryArena);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek(TemplateFile, 0, SEEK_END);
|
||||
int TemplateSize = ftell(TemplateFile);
|
||||
fseek(TemplateFile, 0, SEEK_SET);
|
||||
char *TemplateBuffer;
|
||||
if(!(TemplateBuffer = malloc(TemplateSize)))
|
||||
{
|
||||
perror(Args[0]);
|
||||
hmml_free(&HMML);
|
||||
free(MemoryArena);
|
||||
return 1;
|
||||
}
|
||||
fread(TemplateBuffer, TemplateSize, 1, TemplateFile);
|
||||
fclose(TemplateFile);
|
||||
|
||||
char *OutputBuffer;
|
||||
if(!(OutputBuffer = malloc(TemplateSize + Master.Size)))
|
||||
{
|
||||
perror(Args[0]);
|
||||
hmml_free(&HMML);
|
||||
free(MemoryArena);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *TemplatePtr = TemplateBuffer;
|
||||
char *OutputPtr = OutputBuffer;
|
||||
|
||||
char *HeaderTag = "<!-- __CINERA_HEADER__ -->";
|
||||
char *TitleTag = "<!-- __CINERA_TITLE__ -->";
|
||||
char *PlayerTag = "<!-- __CINERA_PLAYER__ -->";
|
||||
char *ScriptTag = "<!-- __CINERA_SCRIPT__ -->";
|
||||
|
||||
bool FoundHeader = FALSE;
|
||||
bool FoundTitle = FALSE;
|
||||
bool FoundPlayer = FALSE;
|
||||
bool FoundScript = FALSE;
|
||||
|
||||
while(TemplatePtr - TemplateBuffer < TemplateSize)
|
||||
{
|
||||
if(*TemplatePtr == '!')
|
||||
{
|
||||
if(OutputPtr > OutputBuffer)
|
||||
{
|
||||
--OutputPtr;
|
||||
}
|
||||
if(TemplatePtr > TemplateBuffer)
|
||||
{
|
||||
--TemplatePtr;
|
||||
}
|
||||
|
||||
if(!(StringsDifferL(HeaderTag, TemplatePtr, StringLength(HeaderTag))))
|
||||
{
|
||||
FoundHeader = TRUE;
|
||||
CopyStringNoFormat(OutputPtr, Header.Location);
|
||||
OutputPtr += Header.Ptr - Header.Location;
|
||||
}
|
||||
else if(!(StringsDifferL(TitleTag, TemplatePtr, StringLength(TitleTag))))
|
||||
{
|
||||
FoundTitle = TRUE;
|
||||
CopyStringNoFormat(OutputPtr, Title.Location);
|
||||
OutputPtr += Title.Ptr - Title.Location;
|
||||
}
|
||||
else if(!(StringsDifferL(PlayerTag, TemplatePtr, StringLength(PlayerTag))))
|
||||
{
|
||||
FoundPlayer = TRUE;
|
||||
CopyStringNoFormat(OutputPtr, Player.Location);
|
||||
OutputPtr += Player.Ptr - Player.Location;
|
||||
}
|
||||
else if(!(StringsDifferL(ScriptTag, TemplatePtr, StringLength(ScriptTag))))
|
||||
{
|
||||
FoundScript = TRUE;
|
||||
CopyStringNoFormat(OutputPtr, Script.Location);
|
||||
OutputPtr += Script.Ptr - Script.Location;
|
||||
}
|
||||
else
|
||||
{
|
||||
++OutputPtr;
|
||||
*OutputPtr++ = '!';
|
||||
}
|
||||
|
||||
while(TemplatePtr - TemplateBuffer < TemplateSize && *TemplatePtr != '>')
|
||||
{
|
||||
++TemplatePtr;
|
||||
}
|
||||
if(TemplatePtr - TemplateBuffer < TemplateSize)
|
||||
{
|
||||
++TemplatePtr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*OutputPtr++ = *TemplatePtr++;
|
||||
}
|
||||
}
|
||||
|
||||
if(FoundHeader && FoundTitle && FoundPlayer && FoundScript)
|
||||
{
|
||||
FILE *OutFile;
|
||||
if(!(OutFile = fopen("out_integrated.html", "w")))
|
||||
{
|
||||
perror(Args[0]);
|
||||
hmml_free(&HMML);
|
||||
free(MemoryArena);
|
||||
return 1;
|
||||
}
|
||||
fwrite(OutputBuffer, OutputPtr - OutputBuffer, 1, OutFile);
|
||||
fclose(OutFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Template is missing necessary tags\n");
|
||||
free(TemplateBuffer);
|
||||
free(OutputBuffer);
|
||||
hmml_free(&HMML);
|
||||
free(MemoryArena);
|
||||
return 1;
|
||||
}
|
||||
|
||||
free(TemplateBuffer);
|
||||
free(OutputBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// NOTE(matt): Perform the normal collation into Master, and write-out to out.html
|
||||
CopyStringToBuffer(&Master,
|
||||
"<html>\n"
|
||||
" <head>\n");
|
||||
|
||||
//NOTE(matt): Here is where we do all our CopyBuffer() calls
|
||||
CopyBuffer(&Master, &Header);
|
||||
CopyBuffer(&Master, &Title);
|
||||
CopyBuffer(&Master, &Player);
|
||||
CopyBuffer(&Master, &Script);
|
||||
//
|
||||
|
||||
CopyStringToBuffer(&Master,
|
||||
" </body>\n"
|
||||
"</html>\n");
|
||||
|
||||
FILE *OutFile;
|
||||
if(!(OutFile = fopen("out.html", "w")))
|
||||
{
|
||||
perror(Args[0]);
|
||||
hmml_free(&HMML);
|
||||
free(MemoryArena);
|
||||
return 1;
|
||||
}
|
||||
fwrite(Master.Location, Master.Ptr - Master.Location, 1, OutFile);
|
||||
fclose(OutFile);
|
||||
}
|
||||
|
||||
DeclaimBuffer(&Master, &ClaimedMemory);
|
||||
|
||||
|
||||
// NOTE(matt): Tree structure of "global" buffer dependencies
|
||||
// FilterState
|
||||
|
@ -2393,6 +2556,7 @@ HMML.metadata.project);
|
|||
// ReferenceMenu
|
||||
// QuoteMenu
|
||||
// Title
|
||||
// Header
|
||||
|
||||
DeclaimBuffer(&FilterState, &ClaimedMemory);
|
||||
DeclaimBuffer(&Script, &ClaimedMemory);
|
||||
|
@ -2410,22 +2574,7 @@ HMML.metadata.project);
|
|||
DeclaimBuffer(&QuoteMenu, &ClaimedMemory);
|
||||
DeclaimBuffer(&Title, &ClaimedMemory);
|
||||
|
||||
CopyStringToBuffer(&Master,
|
||||
" </body>\n"
|
||||
"</html>\n");
|
||||
|
||||
FILE *OutFile;
|
||||
if(!(OutFile = fopen("out.html", "w")))
|
||||
{
|
||||
perror(Args[0]);
|
||||
hmml_free(&HMML);
|
||||
free(MemoryArena);
|
||||
return 1;
|
||||
}
|
||||
fwrite(Master.Location, Master.Ptr - Master.Location, 1, OutFile);
|
||||
fclose(OutFile);
|
||||
|
||||
DeclaimBuffer(&Master, &ClaimedMemory);
|
||||
DeclaimBuffer(&Header, &ClaimedMemory);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue