Commit 2eddd7a7 authored by Matt Mascarenhas's avatar Matt Mascarenhas

cinera.c: Support limitless templates

Previously we had a template tag limit of 16. This commit lifts that
limit to support "unlimited" tags per template.

Skip already offset landmarks most efficiently when adding a new asset.

New template tags:
    __CINERA_SEARCH_URL__
    __CINERA_VOD_PLATFORM__
parent 3da53413
......@@ -85,6 +85,7 @@ directory. Typical operation will involve setting these flags:
*Optional tags available for use in your Player Template*
- `<!-- __CINERA_TITLE__ -->`
- `<!-- __CINERA_VIDEO_ID__ -->`
- `<!-- __CINERA_VOD_PLATFORM__ -->`
*Other tags available for use in either template*
- Asset tags:
......@@ -114,6 +115,7 @@ trigger a rehash and edit of all HTML pages citing this asset.
- `<!-- __CINERA_PROJECT__ -->`
- `<!-- __CINERA_PROJECT_ID__ -->`
- `<!-- __CINERA_SEARCH_URL__ -->`
- `<!-- __CINERA_THEME__ -->`
- `<!-- __CINERA_URL__ -->` _Only really usable if BaseURL is set (-B)_
- `<!-- __CINERA_CUSTOM0__ -->`
......
......@@ -17,7 +17,7 @@ typedef struct
version CINERA_APP_VERSION = {
.Major = 0,
.Minor = 6,
.Patch = 0
.Patch = 1
};
#include <stdarg.h> // NOTE(matt): varargs
......@@ -424,7 +424,6 @@ typedef struct
// NOTE(matt): Globals
arena MemoryArena;
arena TemplateArena;
config Config;
assets Assets;
int inotifyInstance;
......@@ -473,6 +472,7 @@ typedef struct
char URLSearch[MAX_BASE_URL_LENGTH + 1 + MAX_RELATIVE_PAGE_LOCATION_LENGTH + 1];
char URLPlayer[MAX_BASE_URL_LENGTH + 1 + MAX_RELATIVE_PAGE_LOCATION_LENGTH + 1 + MAX_PLAYER_URL_PREFIX_LENGTH + MAX_BASE_FILENAME_LENGTH + 1];
char VideoID[16];
char VODPlatform[16];
} buffers;
enum
......@@ -509,6 +509,7 @@ enum
TAG_TITLE,
TAG_VIDEO_ID,
TAG_VOD_PLATFORM,
// Anywhere Optional
TAG_ASSET,
......@@ -517,6 +518,7 @@ enum
TAG_JS,
TAG_PROJECT,
TAG_PROJECT_ID,
TAG_SEARCH_URL,
TAG_THEME,
TAG_URL,
TEMPLATE_TAG_COUNT,
......@@ -551,6 +553,7 @@ char *TemplateTags[] = {
"__CINERA_TITLE__",
"__CINERA_VIDEO_ID__",
"__CINERA_VOD_PLATFORM__",
"__CINERA_ASSET__",
"__CINERA_CSS__",
......@@ -558,6 +561,7 @@ char *TemplateTags[] = {
"__CINERA_JS__",
"__CINERA_PROJECT__",
"__CINERA_PROJECT_ID__",
"__CINERA_SEARCH_URL__",
"__CINERA_THEME__",
"__CINERA_URL__",
};
......@@ -566,21 +570,21 @@ typedef struct
{
int Offset;
uint32_t AssetIndex;
enum8(template_tags) TagCode;
enum8(template_tag_codes) TagCode;
} tag_offset;
typedef struct
{
int Validity; // NOTE(matt): Bitmask describing which page the template is valid for, i.e. contents and / or player page
int TagCapacity;
int TagCount;
char Filename[256];
tag_offset Tag[16];
tag_offset *Tags;
} template_metadata;
typedef struct
{
file_buffer File;
template_metadata Metadata;
buffer Buffer;
} template;
// TODO(matt): Consider putting the ref_info and quote_info into linked lists on the heap, just to avoid all the hardcoded sizes
......@@ -597,15 +601,14 @@ typedef struct
int Identifier;
} identifier;
#define REF_MAX_IDENTIFIER 64
#define MAX_REF_IDENTIFIER_COUNT 64
typedef struct
{
char RefTitle[620];
char ID[512];
char URL[512];
char Source[256];
identifier Identifier[REF_MAX_IDENTIFIER];
identifier Identifier[MAX_REF_IDENTIFIER_COUNT];
int IdentifierCount;
} ref_info;
......@@ -1348,17 +1351,48 @@ LogError(int LogLevel, char *Format, ...)
}
}
int
ReadFileIntoBuffer(file_buffer *File, int BufferPadding)
{
if(!(File->Handle = fopen(File->Path, "r"))) // TODO(matt): Fuller error handling
{
return RC_ERROR_FILE;
}
fseek(File->Handle, 0, SEEK_END);
File->FileSize = ftell(File->Handle);
File->Buffer.Size = File->FileSize + 1 + BufferPadding; // NOTE(matt): +1 to accommodate a NULL terminator
fseek(File->Handle, 0, SEEK_SET);
// TODO(matt): Consider using the MemoryArena? Maybe have separate ReadFileIntoMemory() and ReadFileIntoArena()
if(!(File->Buffer.Location = malloc(File->Buffer.Size)))
{
fclose(File->Handle);
return RC_ERROR_MEMORY;
}
File->Buffer.Ptr = File->Buffer.Location;
fread(File->Buffer.Location, File->FileSize, 1, File->Handle);
File->Buffer.Location[File->FileSize] = '\0';
fclose(File->Handle);
File->Buffer.ID = File->Path;
return RC_SUCCESS;
}
void
FreeBuffer(buffer *Buffer)
{
free(Buffer->Location);
Buffer->Location = 0;
Buffer->Ptr = 0;
Buffer->Size = 0;
#if DEBUG_MEM
FILE *MemLog = fopen("/home/matt/cinera_mem", "a+");
fprintf(MemLog, " Freed %s\n", Buffer->ID);
fclose(MemLog);
printf(" Freed %s\n", Buffer->ID);
#endif
Buffer->ID = 0;
}
int
......@@ -1439,7 +1473,7 @@ enum
TEMPLATE_SEARCH,
TEMPLATE_PLAYER,
TEMPLATE_BESPOKE
} templates;
} template_types;
char *
GetDirectoryPath(char *Filepath)
......@@ -1477,19 +1511,19 @@ GetBaseFilename(char *Filepath,
}
void
ConstructTemplatePath(template *Template, int TemplateType)
ConstructTemplatePath(template *Template, enum8(template_types) Type)
{
// NOTE(matt): Bespoke template paths are set relative to:
// in Project Edition: ProjectDir
// in Single Edition: Parent directory of .hmml file
if(Template->Metadata.Filename[0] != '/')
if(Template->File.Path[0] != '/')
{
char Temp[256];
CopyString(Temp, sizeof(Temp), "%s", Template->Metadata.Filename);
char *Ptr = Template->Metadata.Filename;
char *End = Template->Metadata.Filename + sizeof(Template->Metadata.Filename);
if(TemplateType == TEMPLATE_BESPOKE)
CopyString(Temp, sizeof(Temp), "%s", Template->File.Path);
char *Ptr = Template->File.Path;
char *End = Template->File.Path + sizeof(Template->File.Path);
if(Type == TEMPLATE_BESPOKE)
{
if(Config.Edition == EDITION_SINGLE)
{
......@@ -1508,87 +1542,61 @@ ConstructTemplatePath(template *Template, int TemplateType)
}
}
int
InitTemplate(template **Template)
void
FitTemplateTag(template *Template)
{
if(TemplateArena.Ptr - TemplateArena.Location + sizeof(template) > TemplateArena.Size)
{
return RC_ARENA_FULL;
}
*Template = (template *)TemplateArena.Ptr;
Clear((*Template)->Metadata.Filename, 256); // NOTE(matt): template_metadata specifies Filename[256]
(*Template)->Metadata.Validity = 0;
(*Template)->Metadata.TagCount = 0;
for(int i = 0; i < 16; ++i) // NOTE(matt): template_metadata specifies Tag[16]
int BlockSize = 16;
if(Template->Metadata.TagCount == Template->Metadata.TagCapacity)
{
(*Template)->Metadata.Tag[i].Offset = 0;
(*Template)->Metadata.Tag[i].TagCode = 0;
Template->Metadata.TagCapacity += BlockSize;
if(Template->Metadata.Tags)
{
Template->Metadata.Tags = realloc(Template->Metadata.Tags, Template->Metadata.TagCapacity * sizeof(*Template->Metadata.Tags));
}
else
{
Template->Metadata.Tags = calloc(Template->Metadata.TagCapacity, sizeof(*Template->Metadata.Tags));
}
}
TemplateArena.Ptr += sizeof(template);
return RC_SUCCESS;
}
int
ClaimTemplate(template **Template, char *Location, int TemplateType)
void
PushTemplateTag(template *Template, int Offset, enum8(template_tag_types) TagType, int AssetIndex)
{
CopyString((*Template)->Metadata.Filename, sizeof((*Template)->Metadata.Filename), "%s", Location);
ConstructTemplatePath((*Template), TemplateType);
fprintf(stderr, "%sPacking%s template: %s\n", ColourStrings[CS_ONGOING], ColourStrings[CS_END], (*Template)->Metadata.Filename);
FILE *File;
if(!(File = fopen((*Template)->Metadata.Filename, "r")))
{
LogError(LOG_ERROR, "Unable to open template %s: %s", (*Template)->Metadata.Filename, strerror(errno));
fprintf(stderr, "Unable to open template %s: %s\n", (*Template)->Metadata.Filename, strerror(errno));
Clear((*Template)->Metadata.Filename, 256); // NOTE(matt): template_metadata specifies Filename[256]
return RC_ERROR_FILE;
}
fseek(File, 0, SEEK_END);
(*Template)->Buffer.Size = ftell(File);
if(TemplateArena.Ptr - TemplateArena.Location + (*Template)->Buffer.Size > TemplateArena.Size)
{
Clear((*Template)->Metadata.Filename, 256); // NOTE(matt): template_metadata specifies Filename[256]
return RC_ARENA_FULL;
}
(*Template)->Buffer.Location = TemplateArena.Ptr;
(*Template)->Buffer.Ptr = (*Template)->Buffer.Location;
(*Template)->Buffer.ID = (*Template)->Metadata.Filename;
fseek(File, 0, SEEK_SET);
fread((*Template)->Buffer.Location, (*Template)->Buffer.Size, 1, File);
fclose(File);
FitTemplateTag(Template);
Template->Metadata.Tags[Template->Metadata.TagCount].Offset = Offset;
Template->Metadata.Tags[Template->Metadata.TagCount].TagCode = TagType;
Template->Metadata.Tags[Template->Metadata.TagCount].AssetIndex = AssetIndex;
++Template->Metadata.TagCount;
}
TemplateArena.Ptr += (*Template)->Buffer.Size;
void
ClearTemplateMetadata(template *Template)
{
Template->Metadata.TagCapacity = 0;
Template->Metadata.TagCount = 0;
Template->Metadata.Validity = 0;
}
#if DEBUG
printf(" ClaimTemplate(%s): %d\n"
" Total ClaimedMemory: %ld\n\n", (*Template)->Metadata.Filename, (*Template)->Buffer.Size, TemplateArena.Ptr - TemplateArena.Location);
#endif
return RC_SUCCESS;
void
InitTemplate(template *Template, char *Location, enum8(template_types) Type)
{
CopyStringNoFormat(Template->File.Path, sizeof(Template->File.Path), Location);
ConstructTemplatePath(Template, Type);
ReadFileIntoBuffer(&Template->File, 0);
ClearTemplateMetadata(Template);
}
int
DeclaimTemplate(template *Template)
void
FreeTemplate(template *Template)
{
Clear(Template->Metadata.Filename, 256);
Template->Metadata.Validity = 0;
for(int i = 0; i < Template->Metadata.TagCount; ++i)
{
Template->Metadata.Tag[i].Offset = 0;
Template->Metadata.Tag[i].TagCode = 0;
}
Template->Metadata.TagCount = 0;
TemplateArena.Ptr -= (*Template).Buffer.Size;
FreeBuffer(&Template->File.Buffer);
Clear(Template->File.Path, sizeof(Template->File.Path));
Template->File.FileSize = 0;
#if DEBUG
printf("DeclaimTemplate(%s)\n"
" Total ClaimedMemory: %ld\n\n",
(*Template).Metadata.Filename,
TemplateArena.Ptr - TemplateArena.Location);
#endif
return RC_SUCCESS;
free(Template->Metadata.Tags);
Template->Metadata.Tags = 0;
ClearTemplateMetadata(Template);
}
int
......@@ -1771,34 +1779,6 @@ enum
CreditsError_NoCredentials
} credits_errors;
int
ReadFileIntoBuffer(file_buffer *File, int BufferPadding)
{
if(!(File->Handle = fopen(File->Path, "r"))) // TODO(matt): Fuller error handling
{
return RC_ERROR_FILE;
}
fseek(File->Handle, 0, SEEK_END);
File->FileSize = ftell(File->Handle);
File->Buffer.Size = File->FileSize + 1 + BufferPadding; // NOTE(matt): +1 to accommodate a NULL terminator
fseek(File->Handle, 0, SEEK_SET);
// TODO(matt): Consider using the MemoryArena? Maybe have separate ReadFileIntoMemory() and ReadFileIntoArena()
if(!(File->Buffer.Location = malloc(File->Buffer.Size)))
{
fclose(File->Handle);
return RC_ERROR_MEMORY;
}
File->Buffer.Ptr = File->Buffer.Location;
fread(File->Buffer.Location, File->FileSize, 1, File->Handle);
File->Buffer.Location[File->FileSize] = '\0';
fclose(File->Handle);
File->Buffer.ID = File->Path;
return RC_SUCCESS;
}
size_t
StringToFletcher32(const char *Data, size_t Length)
{// https://en.wikipedia.org/wiki/Fletcher%27s_checksum
......@@ -3556,6 +3536,7 @@ PrintUsage(char *BinaryLocation, config *DefaultConfig)
" Optional tags available for use in your Player Template:\n"
" <!-- __CINERA_TITLE__ -->\n"
" <!-- __CINERA_VIDEO_ID__ -->\n"
" <!-- __CINERA_VOD_PLATFORM__ -->\n"
"\n"
" Other tags available for use in either template:\n"
" Asset tags:\n"
......@@ -3585,6 +3566,7 @@ PrintUsage(char *BinaryLocation, config *DefaultConfig)
"\n"
" <!-- __CINERA_PROJECT__ -->\n"
" <!-- __CINERA_PROJECT_ID__ -->\n"
" <!-- __CINERA_SEARCH_URL__ -->\n"
" <!-- __CINERA_THEME__ -->\n"
" <!-- __CINERA_URL__ -->\n"
" Only really usable if BaseURL is set %s(-B)%s\n"
......@@ -3791,13 +3773,13 @@ StripPWDIndicators(char *Path)
}
int
ParseAssetString(template **Template, enum8(template_tag_codes) TagIndex, uint32_t *AssetIndexPtr)
ParseAssetString(template *Template, enum8(template_tag_codes) TagIndex, uint32_t *AssetIndexPtr)
{
char *Ptr = (*Template)->Buffer.Ptr + StringLength(TemplateTags[TagIndex]);
ConsumeWhitespace(&(*Template)->Buffer, &Ptr);
char *Ptr = Template->File.Buffer.Ptr + StringLength(TemplateTags[TagIndex]);
ConsumeWhitespace(&Template->File.Buffer, &Ptr);
buffer AssetString;
ClaimBuffer(&AssetString, "AssetString", MAX_ASSET_FILENAME_LENGTH);
if(ParseQuotedString(&AssetString, &(*Template)->Buffer, &Ptr, TagIndex) == RC_ERROR_PARSING)
if(ParseQuotedString(&AssetString, &Template->File.Buffer, &Ptr, TagIndex) == RC_ERROR_PARSING)
{
DeclaimBuffer(&AssetString);
return RC_ERROR_PARSING;
......@@ -3820,27 +3802,18 @@ ParseAssetString(template **Template, enum8(template_tag_codes) TagIndex, uint32
}
int
ValidateTemplate(template **Template, char *Location, enum8(templates) TemplateType)
PackTemplate(template *Template, char *Location, enum8(template_types) Type)
{
// TODO(matt): Record line numbers and contextual information:
// <? ?>
// <!-- -->
// < >
// <script </script>
#if 1
int Return = ClaimTemplate(Template, Location, TemplateType);
switch(Return)
{
case RC_ARENA_FULL:
case RC_ERROR_FILE:
return Return;
case RC_SUCCESS:
break;
}
#endif
InitTemplate(Template, Location, Type);
buffer Errors;
if(ClaimBuffer(&Errors, "Errors", Kilobytes(1)) == RC_ARENA_FULL) { DeclaimTemplate(*Template); return RC_ARENA_FULL; };
if(ClaimBuffer(&Errors, "Errors", Kilobytes(1)) == RC_ARENA_FULL) { FreeTemplate(Template); return RC_ARENA_FULL; };
bool HaveErrors = FALSE;
bool HaveAssetParsingErrors = FALSE;
......@@ -3851,19 +3824,20 @@ ValidateTemplate(template **Template, char *Location, enum8(templates) TemplateT
bool FoundScript = FALSE;
bool FoundSearch = FALSE;
char *Previous = (*Template)->Buffer.Location;
char *Previous = Template->File.Buffer.Location;
while((*Template)->Buffer.Ptr - (*Template)->Buffer.Location < (*Template)->Buffer.Size)
while(Template->File.Buffer.Ptr - Template->File.Buffer.Location < Template->File.Buffer.Size)
{
NextTagSearch:
if(*(*Template)->Buffer.Ptr == '!' && ((*Template)->Buffer.Ptr > (*Template)->Buffer.Location && !StringsDifferT("<!--", &(*Template)->Buffer.Ptr[-1], 0)))
if(*Template->File.Buffer.Ptr == '!' && (Template->File.Buffer.Ptr > Template->File.Buffer.Location && !StringsDifferT("<!--", &Template->File.Buffer.Ptr[-1], 0)))
{
char *CommentStart = &(*Template)->Buffer.Ptr[-1];
while((*Template)->Buffer.Ptr - (*Template)->Buffer.Location < (*Template)->Buffer.Size && StringsDifferT("-->", (*Template)->Buffer.Ptr, 0))
char *CommentStart = &Template->File.Buffer.Ptr[-1];
Template->File.Buffer.Ptr += StringLength("!--");
while(Template->File.Buffer.Ptr - Template->File.Buffer.Location < Template->File.Buffer.Size && StringsDifferT("-->", Template->File.Buffer.Ptr, 0))
{
for(int TagIndex = 0; TagIndex < TEMPLATE_TAG_COUNT; ++TagIndex)
{
if(!(StringsDifferT(TemplateTags[TagIndex], (*Template)->Buffer.Ptr, 0)))
if(!(StringsDifferT(TemplateTags[TagIndex], Template->File.Buffer.Ptr, 0)))
{
// TODO(matt): Pack up this data for BuffersToHTML() to use
/*
......@@ -3877,6 +3851,8 @@ NextTagSearch:
*
*/
uint32_t AssetIndex = 0;
switch(TagIndex)
{
case TAG_SEARCH:
......@@ -3924,12 +3900,7 @@ NextTagSearch:
case TAG_IMAGE:
case TAG_JS:
{
uint32_t AI;
if(ParseAssetString(Template, TagIndex, &AI) == RC_SUCCESS)
{
(*Template)->Metadata.Tag[(*Template)->Metadata.TagCount].AssetIndex = AI;
}
else
if(ParseAssetString(Template, TagIndex, &AssetIndex) == RC_ERROR_PARSING)
{
HaveErrors = TRUE;
HaveAssetParsingErrors = TRUE;
......@@ -3937,60 +3908,61 @@ NextTagSearch:
} goto RecordTag;
default: // NOTE(matt): All freely usable tags should hit this case
RecordTag:
(*Template)->Metadata.Tag[(*Template)->Metadata.TagCount].Offset = CommentStart - Previous;
(*Template)->Metadata.Tag[(*Template)->Metadata.TagCount].TagCode = TagIndex;
(*Template)->Metadata.TagCount++;
DepartComment(&(*Template)->Buffer);
Previous = (*Template)->Buffer.Ptr;
goto NextTagSearch;
{
int Offset = CommentStart - Previous;
PushTemplateTag(Template, Offset, TagIndex, AssetIndex);
DepartComment(&Template->File.Buffer);
Previous = Template->File.Buffer.Ptr;
goto NextTagSearch;
}
};
}
}
++(*Template)->Buffer.Ptr;
++Template->File.Buffer.Ptr;
}
}
else
{
++(*Template)->Buffer.Ptr;
++Template->File.Buffer.Ptr;
}
}
if(HaveAssetParsingErrors)
{
DeclaimBuffer(&Errors);
DeclaimTemplate(*Template);
FreeTemplate(Template);
return RC_INVALID_TEMPLATE;
}
if(FoundSearch)
{
(*Template)->Metadata.Validity |= PAGE_SEARCH;
Template->Metadata.Validity |= PAGE_SEARCH;
}
if(!HaveErrors && FoundIncludes && FoundMenus && FoundPlayer && FoundScript)
{
(*Template)->Metadata.Validity |= PAGE_PLAYER;
Template->Metadata.Validity |= PAGE_PLAYER;
}
if(!(Config.Mode & MODE_FORCEINTEGRATION))
{
if(TemplateType == TEMPLATE_SEARCH && !((*Template)->Metadata.Validity & PAGE_SEARCH))
if(Type == TEMPLATE_SEARCH && !(Template->Metadata.Validity & PAGE_SEARCH))
{
CopyStringToBuffer(&Errors, "Search template %s must include one <!-- __CINERA_SEARCH__ --> tag\n", (*Template)->Metadata.Filename);
CopyStringToBuffer(&Errors, "Search template %s must include one <!-- __CINERA_SEARCH__ --> tag\n", Template->File.Path);
fprintf(stderr, "%s", Errors.Location);
DeclaimBuffer(&Errors);
DeclaimTemplate(*Template);
FreeTemplate(Template);
return RC_INVALID_TEMPLATE;
}
else if((TemplateType == TEMPLATE_PLAYER || TemplateType == TEMPLATE_BESPOKE) && !((*Template)->Metadata.Validity & PAGE_PLAYER))
else if((Type == TEMPLATE_PLAYER || Type == TEMPLATE_BESPOKE) && !(Template->Metadata.Validity & PAGE_PLAYER))
{
if(!FoundIncludes){ CopyStringToBuffer(&Errors, "Player template %s must include one <!-- __CINERA_INCLUDES__ --> tag\n", (*Template)->Metadata.Filename); };
if(!FoundMenus){ CopyStringToBuffer(&Errors, "Player template %s must include one <!-- __CINERA_MENUS__ --> tag\n", (*Template)->Metadata.Filename); };
if(!FoundPlayer){ CopyStringToBuffer(&Errors, "Player template %s must include one <!-- __CINERA_PLAYER__ --> tag\n", (*Template)->Metadata.Filename); };
if(!FoundScript){ CopyStringToBuffer(&Errors, "Player template %s must include one <!-- __CINERA_SCRIPT__ --> tag\n", (*Template)->Metadata.Filename); };
if(!FoundIncludes){ CopyStringToBuffer(&Errors, "Player template %s must include one <!-- __CINERA_INCLUDES__ --> tag\n", Template->File.Path); };
if(!FoundMenus){ CopyStringToBuffer(&Errors, "Player template %s must include one <!-- __CINERA_MENUS__ --> tag\n", Template->File.Path); };
if(!FoundPlayer){ CopyStringToBuffer(&Errors, "Player template %s must include one <!-- __CINERA_PLAYER__ --> tag\n", Template->File.Path); };
if(!FoundScript){ CopyStringToBuffer(&Errors, "Player template %s must include one <!-- __CINERA_SCRIPT__ --> tag\n", Template->File.Path); };
fprintf(stderr, "%s", Errors.Location);
DeclaimBuffer(&Errors);
DeclaimTemplate(*Template);
FreeTemplate(Template);
return RC_INVALID_TEMPLATE;
}
}
......@@ -4506,7 +4478,7 @@ OffsetLandmarksMenus(buffer *Src)
//
int
HMMLToBuffers(buffers *CollationBuffers, template **BespokeTemplate, char *Filename, neighbourhood *N)
HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, char *Filename, neighbourhood *N)
{
RewindBuffer(&CollationBuffers->IncludesPlayer);
RewindBuffer(&CollationBuffers->Menus);
......@@ -4530,6 +4502,9 @@ HMMLToBuffers(buffers *CollationBuffers, template **BespokeTemplate, char *Filen
*CollationBuffers->Custom14 = '\0';
*CollationBuffers->Custom15 = '\0';
*CollationBuffers->Title = '\0';
*CollationBuffers->URLPlayer = '\0';
*CollationBuffers->URLSearch = '\0';
*CollationBuffers->VODPlatform = '\0';
char Filepath[256];
if(Config.Edition == EDITION_PROJECT)
......@@ -4607,7 +4582,20 @@ HMMLToBuffers(buffers *CollationBuffers, template **BespokeTemplate, char *Filen
fprintf(stderr, "Please set the id attribute in the [video] node of your .hmml file\n");
HaveErrors = TRUE;
}
CopyString(CollationBuffers->VideoID, sizeof(CollationBuffers->VideoID), "%s", HMML.metadata.id);
else
{
CopyString(CollationBuffers->VideoID, sizeof(CollationBuffers->VideoID), "%s", HMML.metadata.id);
}
if(!HMML.metadata.vod_platform)
{
fprintf(stderr, "Please set the vod_platform attribute in the [video] node of your .hmml file\n");
HaveErrors = TRUE;
}
else
{
CopyString(CollationBuffers->VODPlatform, sizeof(CollationBuffers->VODPlatform), "%s", HMML.metadata.vod_platform);
}
buffer URLPlayer;
ClaimBuffer(&URLPlayer, "URLPlayer", MAX_BASE_URL_LENGTH + 1 + MAX_RELATIVE_PAGE_LOCATION_LENGTH + 1 + MAX_PLAYER_URL_PREFIX_LENGTH + MAX_BASE_FILENAME_LENGTH);
......@@ -4691,7 +4679,7 @@ HMMLToBuffers(buffers *CollationBuffers, template **BespokeTemplate, char *Filen
{
if(HMML.metadata.template)
{
switch(ValidateTemplate(BespokeTemplate, HMML.metadata.template, TEMPLATE_BESPOKE))
switch(PackTemplate(BespokeTemplate, HMML.metadata.template, TEMPLATE_BESPOKE))
{
case RC_ARENA_FULL:
case RC_INVALID_TEMPLATE: // Invalid template
......@@ -5033,9 +5021,9 @@ HMMLToBuffers(buffers *CollationBuffers, template **BespokeTemplate, char *Filen
{
for(int i = 0; i < UniqueRefs; ++i)
{
if(ReferencesArray[i].IdentifierCount == REF_MAX_IDENTIFIER)
if(ReferencesArray[i].IdentifierCount == MAX_REF_IDENTIFIER_COUNT)
{
LogError(LOG_EMERGENCY, "REF_MAX_IDENTIFIER (%d) reached. Contact [email protected]", REF_MAX_IDENTIFIER);
LogError(LOG_EMERGENCY, "REF_MAX_IDENTIFIER (%d) reached. Contact [email protected]", MAX_REF_IDENTIFIER_COUNT);
fprintf(stderr, "%s:%d: Too many timecodes associated with one reference (increase REF_MAX_IDENTIFIER)\n", Filename, Anno->line);
hmml_free(&HMML);
return RC_ERROR_MAX_REFS;
......@@ -5737,8 +5725,6 @@ AppendedIdentifier:
" </div>\n"
" </div>");
// TODO(matt): Maybe do something about indentation levels
buffer URLSearch;
ClaimBuffer(&URLSearch, "URLSearch", MAX_BASE_URL_LENGTH + 1 + MAX_RELATIVE_PAGE_LOCATION_LENGTH + 1);
ConstructSearchURL(&URLSearch);
......@@ -5869,13 +5855,12 @@ BuffersToHTML(buffers *CollationBuffers, template *Template, char *OutputPath, i
fclose(MemLog);
#endif
if(StringsDiffer(Template->Metadata.Filename, ""))
if(Template->File.Buffer.Location)
{
if((StringsDiffer(Template->Metadata.Filename, ""))
&& ((Template->Metadata.Validity & PageType) || Config.Mode & MODE_FORCEINTEGRATION))
if((Template->Metadata.Validity & PageType) || Config.Mode & MODE_FORCEINTEGRATION)
{
buffer Output;
Output.Size = Template->Buffer.Size + (Kilobytes(512));
Output.Size = Template->File.Buffer.Size + (Kilobytes(512));
Output.ID = "Output";
if(!(Output.Location = malloc(Output.Size)))
{
......@@ -5894,19 +5879,19 @@ BuffersToHTML(buffers *CollationBuffers, template *Template, char *OutputPath, i
Output.Ptr = Output.Location;
bool NeedPlayerOffset = PlayerOffset ? TRUE : FALSE;
Template->Buffer.Ptr = Template->Buffer.Location;
Template->File.Buffer.Ptr = Template->File.Buffer.Location;
for(int i = 0; i < Template->Metadata.TagCount; ++i)
{
int j = 0;
while(Template->Metadata.Tag[i].Offset > j)
while(Template->Metadata.Tags[i].Offset > j)
{
*Output.Ptr++ = *Template->Buffer.Ptr++;
*Output.Ptr++ = *Template->File.Buffer.Ptr++;
++j;
}
// TODO(matt): Make this whole template stuff context-aware, so it can determine whether or not to HTML-encode
// or sanitise punctuation for CSS-safety
switch(Template->Metadata.Tag[i].TagCode)
switch(Template->Metadata.Tags[i].TagCode)
{
case TAG_PROJECT_ID:
if(CollationBuffers->ProjectID[0] == '\0')
......@@ -5930,12 +5915,9 @@ BuffersToHTML(buffers *CollationBuffers, template *Template, char *OutputPath, i
CopyStringToBufferHTMLSafe(&Output, CollationBuffers->ProjectName);
}
break;
case TAG_THEME:
CopyStringToBufferNoFormat(&Output, CollationBuffers->Theme); // NOTE(matt): Not HTML-safe
break;
case TAG_TITLE:
CopyStringToBufferHTMLSafe(&Output, CollationBuffers->Title);
break;
case TAG_SEARCH_URL: CopyStringToBufferNoFormat(&Output, CollationBuffers->URLSearch); break; // NOTE(matt): Not HTML-safe
case TAG_THEME: CopyStringToBufferNoFormat(&Output, CollationBuffers->Theme); break; // NOTE(matt): Not HTML-safe
case TAG_TITLE: CopyStringToBufferHTMLSafe(&Output, CollationBuffers->Title); break;
case TAG_URL:
if(PageType == PAGE_PLAYER)
{
......@@ -5946,9 +5928,8 @@ BuffersToHTML(buffers *CollationBuffers, template *Template, char *OutputPath, i
CopyStringToBufferNoFormat(&Output, CollationBuffers->URLSearch);
}
break;
case TAG_VIDEO_ID:
CopyStringToBufferNoFormat(&Output, CollationBuffers->VideoID);
break;
case TAG_VIDEO_ID: CopyStringToBufferNoFormat(&Output, CollationBuffers->VideoID); break;
case TAG_VOD_PLATFORM: CopyStringToBufferNoFormat(&Output, CollationBuffers->VODPlatform); break;
case TAG_SEARCH:
if(Config.Edition == EDITION_SINGLE)
{
......@@ -5989,39 +5970,39 @@ BuffersToHTML(buffers *CollationBuffers, template *Template, char *OutputPath, i
case TAG_ASSET:
{
buffer URL;
ConstructResolvedAssetURL(&URL, Template->Metadata.Tag[i].AssetIndex, PageType);
ConstructResolvedAssetURL(&URL, Template->Metadata.Tags[i].AssetIndex, PageType);
CopyStringToBuffer(&Output, "%s", URL.Location);
DeclaimBuffer(&URL);
PushAssetLandmark(&Output, Template->Metadata.Tag[i].AssetIndex, PageType);
PushAssetLandmark(&Output, Template->Metadata.Tags[i].AssetIndex, PageType);
} break;
case TAG_CSS:
{
buffer URL;
ConstructResolvedAssetURL(&URL, Template->Metadata.Tag[i].AssetIndex, PageType);
ConstructResolvedAssetURL(&URL, Template->Metadata.Tags[i].AssetIndex, PageType);
CopyStringToBuffer(&Output,
"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s",
URL.Location);
DeclaimBuffer(&URL);
PushAssetLandmark(&Output, Template->Metadata.Tag[i].AssetIndex, PageType);
PushAssetLandmark(&Output, Template->Metadata.Tags[i].AssetIndex, PageType);