hmml_to_html.c: Clean up buffer claiming

This commit is contained in:
Matt Mascarenhas 2017-05-22 16:33:53 +01:00
parent 3c32b5904b
commit 4ec635831a
1 changed files with 84 additions and 33 deletions

View File

@ -158,7 +158,6 @@ CopyStringToBuffer(buffer *Dest, char *Format, ...)
{
printf("Too big! Too big!\n");
__asm__("int3");
}
}
va_list Args;
@ -171,7 +170,6 @@ CopyStringToBuffer(buffer *Dest, char *Format, ...)
{
printf("Too big! Too big!\n");
__asm__("int3");
}
}
Dest->Ptr += Length;
@ -549,6 +547,7 @@ GenerateTopicColours(buffer *Colour, char *Topic)
int TopicsLength = ftell(TopicsFile);
fseek(TopicsFile, 0, SEEK_SET);
// TODO(matt): May this not just ClaimBuffer?
if(!(TopicsBuffer = malloc(TopicsLength)))
{
perror("GenerateTopicColours");
@ -880,6 +879,26 @@ main(int ArgC, char **Args)
buffer Config;
#endif
// NOTE(matt): Tree structure of buffer dependencies
// Master
// Title
// QuoteMenu
// ReferenceMenu
// FilterMenu
// FilterTopics
// FilterMedia
// Player
// Colour
// Annotation
// AnnotationHeader
// AnnotationClass
// AnnotationData
// Text
// Category
// FilterState
buffer Master;
buffer Title;
buffer QuoteMenu;
buffer ReferenceMenu;
@ -888,23 +907,18 @@ main(int ArgC, char **Args)
buffer FilterMedia;
buffer Player;
buffer Colour;
buffer Annotation;
buffer AnnotationHeader;
buffer AnnotationClass;
buffer AnnotationData;
buffer Text;
buffer Category;
buffer Colour;
buffer FilterState;
buffer Master;
for(int FileIndex = 1; FileIndex < ArgC; ++FileIndex)
{
// TODO(matt): Maybe look into this further. It works, but there may be
// bugs lurking
ClaimedMemory = 0;
FILE *InFile;
if(!(InFile = fopen(Args[FileIndex], "r")))
{
@ -922,16 +936,33 @@ main(int ArgC, char **Args)
if(HMML.well_formed)
{
// NOTE(matt): Tree structure of "global" buffer dependencies
// Master
// Title
// QuoteMenu
// ReferenceMenu
// FilterMenu
// FilterTopics
// FilterMedia
// Player
// Colour
// Annotation
// FilterState
ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, "Master", 1024 * 512);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Player, "Player", 1024 * 256);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Title, "Title", 1024 * 16);
ClaimBuffer(MemoryArena, &ClaimedMemory, &QuoteMenu, "QuoteMenu", 1024 * 16);
ClaimBuffer(MemoryArena, &ClaimedMemory, &ReferenceMenu, "ReferenceMenu", 1024 * 16);
ClaimBuffer(MemoryArena, &ClaimedMemory, &FilterMenu, "FilterMenu", 1024 * 16);
ClaimBuffer(MemoryArena, &ClaimedMemory, &FilterTopics, "FilterTopics", 1024 * 8);
ClaimBuffer(MemoryArena, &ClaimedMemory, &FilterMedia, "FilterMedia", 1024 * 8);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Player, "Player", 1024 * 256);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Colour, "Colour", 32);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Annotation, "Annotation", 1024 * 8);
ClaimBuffer(MemoryArena, &ClaimedMemory, &FilterState, "FilterState", 1024 * 4);
ClaimBuffer(MemoryArena, &ClaimedMemory, &ReferenceMenu, "ReferenceMenu", 1024 * 16);
ClaimBuffer(MemoryArena, &ClaimedMemory, &QuoteMenu, "QuoteMenu", 1024 * 16);
ref_info ReferencesArray[200] = { 0 };
category_info CategoriesArray[64] = { 0 };
@ -954,6 +985,10 @@ main(int ArgC, char **Args)
" <div class=\"video_container\" data-videoId=\"%s\"></div>\n"
" <div class=\"markers_container %s\">\n", HMML.metadata.id, HMML.metadata.project);
#if DEBUG
printf(" --- Entering Annotations Loop ---\n");
#endif
for(int AnnotationIndex = 0; AnnotationIndex < HMML.annotation_count; ++AnnotationIndex)
{
#if DEBUG
@ -966,10 +1001,18 @@ main(int ArgC, char **Args)
quote_info QuoteInfo = { 0 };
// NOTE(matt): Tree structure of "annotation local" buffer dependencies
// AnnotationHeader
// AnnotationClass
// AnnotationData
// Text
// Category
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationHeader, "AnnotationHeader", 512);
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, "AnnotationClass", 256);
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, "AnnotationData", 128);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, "Text", 1024 * 4);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Colour, "Colour", 32);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, "Category", 256);
CopyStringToBuffer(&AnnotationHeader,
" <div data-timestamp=\"%d\"",
@ -1036,10 +1079,6 @@ Readable);
HasFilterMenu = TRUE;
}
BuildFilter(CategoriesArray, &UniqueCategories, Anno->markers[MarkerIndex].marker);
if(!HasCategory)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, "Category", 256);
}
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, Anno->markers[MarkerIndex].marker);
}
}
@ -1114,7 +1153,6 @@ Readable);
AppendedIdentifier:
if(!HasReference)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, "AnnotationData", 128);
if(CurrentRef->isbn)
{
CopyStringToBuffer(&AnnotationData, " data-ref=\"%s", CurrentRef->isbn);
@ -1179,7 +1217,6 @@ AppendedIdentifier:
if(!HasReference)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, "AnnotationData", 128);
CopyStringToBuffer(&AnnotationData, " data-ref=\"&#%d;", QuoteIdentifier);
}
else
@ -1241,10 +1278,6 @@ Anno->time);
{
BuildFilter(CategoriesArray, &UniqueCategories, Anno->markers[MarkerIndex].marker);
}
if(!HasCategory)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, "Category", 256);
}
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, Anno->markers[MarkerIndex].marker);
}
@ -1255,12 +1288,9 @@ Anno->time);
{
CopyStringToBuffer(&AnnotationData, "\"");
CopyBuffer(&AnnotationHeader, &AnnotationData);
DeclaimBuffer(&AnnotationData, &ClaimedMemory);
}
CopyStringToBuffer(&AnnotationHeader, ">\n");
ClaimBuffer(MemoryArena, &ClaimedMemory, &Annotation, "Annotation", 1024 * 8);
CopyBuffer(&Annotation, &AnnotationHeader);
CopyStringToBuffer(&Annotation,
" <div class=\"content\"><span class=\"timecode\">%s</span>",
@ -1270,7 +1300,6 @@ Anno->time);
// TODO(matt): Handle special-cases, i.e. default media, and possibly other things
if(!HasCategory)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, "Category", 256);
BuildFilter(CategoriesArray, &UniqueCategories, "default");
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, "default");
}
@ -1280,7 +1309,6 @@ Anno->time);
{
CopyStringToBuffer(&Category, "</span>");
CopyBuffer(&Text, &Category);
DeclaimBuffer(&Category, &ClaimedMemory);
}
*Text.Ptr = '\0';
@ -1308,15 +1336,23 @@ Anno->time);
CopyBuffer(&Player, &Annotation);
DeclaimBuffer(&Annotation, &ClaimedMemory);
DeclaimBuffer(&Colour, &ClaimedMemory);
// NOTE(matt): Tree structure of "annotation local" buffer dependencies
// Category
// Text
// AnnotationData
// AnnotationClass
// AnnotationHeader
DeclaimBuffer(&Category, &ClaimedMemory);
DeclaimBuffer(&Text, &ClaimedMemory);
DeclaimBuffer(&AnnotationData, &ClaimedMemory);
DeclaimBuffer(&AnnotationClass, &ClaimedMemory);
DeclaimBuffer(&AnnotationHeader, &ClaimedMemory);
Annotation.Ptr = Annotation.Location;
}
#if DEBUG
printf("EOA\n\n");
printf(" --- End of Annotations Loop ---\n\n");
#endif
if(HasQuoteMenu)
{
@ -1558,14 +1594,29 @@ HMML.metadata.annotator);
CopyBuffer(&Master, &FilterState);
}
DeclaimBuffer(&QuoteMenu, &ClaimedMemory);
DeclaimBuffer(&ReferenceMenu, &ClaimedMemory);
// NOTE(matt): Tree structure of "global" buffer dependencies
// FilterState
// Annotation
// Colour
// Player
// FilterMedia
// FilterTopics
// FilterMenu
// ReferenceMenu
// QuoteMenu
// Title
DeclaimBuffer(&FilterState, &ClaimedMemory);
DeclaimBuffer(&Annotation, &ClaimedMemory);
DeclaimBuffer(&Colour, &ClaimedMemory);
DeclaimBuffer(&Player, &ClaimedMemory);
DeclaimBuffer(&FilterMedia, &ClaimedMemory);
DeclaimBuffer(&FilterTopics, &ClaimedMemory);
DeclaimBuffer(&FilterMenu, &ClaimedMemory);
DeclaimBuffer(&ReferenceMenu, &ClaimedMemory);
DeclaimBuffer(&QuoteMenu, &ClaimedMemory);
DeclaimBuffer(&Title, &ClaimedMemory);
DeclaimBuffer(&Player, &ClaimedMemory);
CopyStringToBuffer(&Master,
"// Filter Mode Toggle\n"