2017-03-10 14:19:25 +00:00
|
|
|
#if 0
|
|
|
|
ctime -begin ${0%.*}.ctm
|
2017-03-25 02:07:55 +00:00
|
|
|
gcc -g -Wall -fsanitize=address -std=c99 $0 -o ${0%.*} hmml.a
|
2017-03-10 14:19:25 +00:00
|
|
|
ctime -end ${0%.*}.ctm
|
|
|
|
exit
|
|
|
|
#endif
|
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
typedef unsigned int bool;
|
2017-03-10 14:19:25 +00:00
|
|
|
|
|
|
|
#define TRUE 1
|
|
|
|
#define FALSE 0
|
|
|
|
|
2017-04-13 00:21:04 +00:00
|
|
|
#include <stdarg.h> // NOTE(matt): varargs
|
|
|
|
#include <stdio.h> // NOTE(matt): printf, sprintf, vsprintf, fprintf, perror
|
|
|
|
#include <stdlib.h> // NOTE(matt): calloc, malloc, free
|
|
|
|
#include <string.h> // NOTE(matt): strncmp, memset
|
2017-03-23 00:34:59 +00:00
|
|
|
#include "hmmlib.h"
|
|
|
|
|
2017-03-10 14:19:25 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *Location;
|
|
|
|
char *Ptr;
|
|
|
|
int Size;
|
|
|
|
} buffer;
|
|
|
|
|
2017-03-19 01:23:44 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2017-03-30 02:57:04 +00:00
|
|
|
char Timecode[8];
|
|
|
|
int Identifier;
|
|
|
|
} identifier;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2017-04-13 00:21:04 +00:00
|
|
|
char RefTitle[620];
|
|
|
|
char ID[512];
|
|
|
|
char URL[512];
|
|
|
|
char Source[256];
|
2017-03-30 02:57:04 +00:00
|
|
|
identifier Identifier[12];
|
|
|
|
int IdentifierCount;
|
2017-03-19 01:23:44 +00:00
|
|
|
} ref_info;
|
|
|
|
|
2017-03-25 02:07:55 +00:00
|
|
|
#define ArrayCount(A) sizeof(A)/sizeof(*(A))
|
|
|
|
|
2017-03-16 00:56:58 +00:00
|
|
|
void
|
|
|
|
ClaimBuffer(char *MemoryArena, int *ClaimedMemory, buffer *Buffer, int Size)
|
|
|
|
{
|
|
|
|
Buffer->Location = MemoryArena + *ClaimedMemory;
|
|
|
|
Buffer->Size = Size;
|
|
|
|
*ClaimedMemory += Buffer->Size;
|
|
|
|
Buffer->Ptr = Buffer->Location;
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:19:25 +00:00
|
|
|
int
|
|
|
|
TimecodeToSeconds(char *Timecode)
|
|
|
|
{
|
|
|
|
int HMS[3] = { 0, 0, 0 }; // 0 == Seconds; 1 == Minutes; 2 == Hours
|
|
|
|
int Colons = 0;
|
|
|
|
while(*Timecode)
|
|
|
|
{
|
2017-04-13 00:21:04 +00:00
|
|
|
//if((*Timecode < '0' || *Timecode > '9') && *Timecode != ':') { return FALSE; }
|
2017-03-10 14:19:25 +00:00
|
|
|
|
|
|
|
if(*Timecode == ':')
|
|
|
|
{
|
|
|
|
++Colons;
|
2017-04-13 00:21:04 +00:00
|
|
|
//if(Colons > 2) { return FALSE; }
|
2017-03-10 14:19:25 +00:00
|
|
|
for(int i = 0; i < Colons; ++i)
|
|
|
|
{
|
|
|
|
HMS[Colons - i] = HMS[Colons - (i + 1)];
|
|
|
|
}
|
|
|
|
HMS[0] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HMS[0] = HMS[0] * 10 + *Timecode - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
++Timecode;
|
|
|
|
}
|
|
|
|
|
2017-04-13 00:21:04 +00:00
|
|
|
//if(HMS[0] > 59 || HMS[1] > 59 || Timecode[-1] == ':') { return FALSE; }
|
2017-03-10 14:19:25 +00:00
|
|
|
|
|
|
|
return HMS[2] * 60 * 60 + HMS[1] * 60 + HMS[0];
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:56:58 +00:00
|
|
|
void
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(buffer *Dest, buffer *Src)
|
2017-03-16 00:56:58 +00:00
|
|
|
{
|
|
|
|
Src->Ptr = Src->Location;
|
|
|
|
while(*Src->Ptr)
|
|
|
|
{
|
|
|
|
*Dest->Ptr++ = *Src->Ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 01:10:45 +00:00
|
|
|
__attribute__ ((format (printf, 2, 3)))
|
2017-03-30 02:57:04 +00:00
|
|
|
void
|
2017-04-19 01:10:45 +00:00
|
|
|
CopyString(char Dest[], char *Format, ...)
|
2017-03-30 02:57:04 +00:00
|
|
|
{
|
2017-04-19 01:10:45 +00:00
|
|
|
va_list Args;
|
|
|
|
va_start(Args, Format);
|
|
|
|
vsprintf(Dest, Format, Args);
|
|
|
|
va_end(Args);
|
2017-03-30 02:57:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
__attribute__ ((format (printf, 2, 3)))
|
2017-03-16 00:56:58 +00:00
|
|
|
void
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(buffer *Dest, char *Format, ...)
|
2017-03-16 00:56:58 +00:00
|
|
|
{
|
2017-03-23 00:34:59 +00:00
|
|
|
va_list Args;
|
|
|
|
va_start(Args, Format);
|
|
|
|
int Length = vsprintf(Dest->Ptr, Format, Args);
|
|
|
|
va_end(Args);
|
|
|
|
Dest->Ptr += Length;
|
2017-03-16 00:56:58 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 01:45:16 +00:00
|
|
|
int
|
|
|
|
StringsDiffer(char *A, char *B)
|
|
|
|
{
|
2017-03-21 02:38:18 +00:00
|
|
|
while(*A && *B && *A == *B)
|
2017-03-17 01:45:16 +00:00
|
|
|
{
|
|
|
|
++A, ++B;
|
|
|
|
}
|
|
|
|
return *A - *B;
|
|
|
|
}
|
|
|
|
|
2017-04-13 23:46:21 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2017-04-21 01:25:40 +00:00
|
|
|
unsigned int Hue:16;
|
|
|
|
unsigned int Saturation:8;
|
|
|
|
unsigned int Lightness:8;
|
2017-04-13 23:46:21 +00:00
|
|
|
} hsl_colour;
|
|
|
|
|
|
|
|
hsl_colour
|
2017-03-18 02:04:13 +00:00
|
|
|
CharToColour(char Char)
|
|
|
|
{
|
2017-04-13 23:46:21 +00:00
|
|
|
hsl_colour Colour;
|
|
|
|
|
2017-03-18 02:04:13 +00:00
|
|
|
if(Char >= 'a' && Char <= 'z')
|
|
|
|
{
|
2017-04-19 01:10:45 +00:00
|
|
|
Colour.Hue = (((float)Char - 'a') / ('z' - 'a') * 360);
|
|
|
|
Colour.Saturation = (((float)Char - 'a') / ('z' - 'a') * 26 + 74);
|
2017-03-18 02:04:13 +00:00
|
|
|
}
|
|
|
|
else if(Char >= 'A' && Char <= 'Z')
|
|
|
|
{
|
2017-04-19 01:10:45 +00:00
|
|
|
Colour.Hue = (((float)Char - 'A') / ('Z' - 'A') * 360);
|
|
|
|
Colour.Saturation = (((float)Char - 'A') / ('Z' - 'A') * 26 + 74);
|
2017-03-18 02:04:13 +00:00
|
|
|
}
|
|
|
|
else if(Char >= '0' && Char <= '9')
|
|
|
|
{
|
2017-04-19 01:10:45 +00:00
|
|
|
Colour.Hue = (((float)Char - '0') / ('9' - '0') * 360);
|
|
|
|
Colour.Saturation = (((float)Char - '0') / ('9' - '0') * 26 + 74);
|
2017-03-18 02:04:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-13 23:46:21 +00:00
|
|
|
Colour.Hue = 180;
|
|
|
|
Colour.Saturation = 50;
|
2017-03-18 02:04:13 +00:00
|
|
|
}
|
2017-04-13 23:46:21 +00:00
|
|
|
|
|
|
|
return Colour;
|
2017-03-18 02:04:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 23:46:21 +00:00
|
|
|
char *
|
|
|
|
StringToColourHash(buffer *Buffer, char *String)
|
2017-03-18 02:04:13 +00:00
|
|
|
{
|
2017-04-13 23:46:21 +00:00
|
|
|
hsl_colour Colour = {0, 0, 26};
|
2017-03-18 02:04:13 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 0; String[i]; ++i)
|
|
|
|
{
|
2017-04-13 23:46:21 +00:00
|
|
|
Colour.Hue += CharToColour(String[i]).Hue;
|
|
|
|
Colour.Saturation += CharToColour(String[i]).Saturation;
|
2017-03-18 02:04:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 23:46:21 +00:00
|
|
|
Colour.Hue = Colour.Hue % 360;
|
2017-04-19 01:10:45 +00:00
|
|
|
Colour.Saturation = Colour.Saturation % 26 + 74;
|
2017-04-13 23:46:21 +00:00
|
|
|
Buffer->Ptr = Buffer->Location;
|
|
|
|
CopyStringToBuffer(Buffer, "hsl(%d, %d%%, %d%%)", Colour.Hue, Colour.Saturation, Colour.Lightness);
|
|
|
|
return(Buffer->Location);
|
2017-03-18 02:04:13 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 02:07:55 +00:00
|
|
|
int
|
|
|
|
StringLength(char *String)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
while(String[i])
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
SanitisePunctuation(char *String)
|
|
|
|
{
|
|
|
|
char *Ptr = String;
|
|
|
|
while(*Ptr)
|
|
|
|
{
|
|
|
|
if(*Ptr == ' ')
|
|
|
|
{
|
|
|
|
*Ptr = '_';
|
|
|
|
}
|
|
|
|
if((*Ptr < '0' || *Ptr > '9') &&
|
|
|
|
(*Ptr < 'a' || *Ptr > 'z') &&
|
|
|
|
(*Ptr < 'A' || *Ptr > 'Z'))
|
|
|
|
{
|
|
|
|
*Ptr = '-';
|
|
|
|
}
|
|
|
|
++Ptr;
|
|
|
|
}
|
|
|
|
return String;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *CategoryMedium[] =
|
|
|
|
{
|
|
|
|
"blackboard",
|
2017-03-31 00:56:50 +00:00
|
|
|
"owl",
|
|
|
|
"rant",
|
2017-03-25 02:07:55 +00:00
|
|
|
"research",
|
|
|
|
"run",
|
|
|
|
};
|
|
|
|
|
2017-04-21 01:25:40 +00:00
|
|
|
int
|
2017-04-19 01:10:45 +00:00
|
|
|
BuildReference(ref_info *ReferencesArray, int RefIdentifier, int UniqueRefs, HMML_Reference Ref, HMML_Annotation Anno)
|
|
|
|
{
|
2017-04-21 01:25:40 +00:00
|
|
|
if(Ref.page && Ref.url && Ref.title)
|
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, Ref.title);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.page);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
|
|
|
else if(Ref.url && Ref.title)
|
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.title);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
|
|
|
else if(Ref.site && Ref.page && Ref.url)
|
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, Ref.site);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.page);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
|
|
|
else if(Ref.site && Ref.url)
|
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.site);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
|
|
|
else if(Ref.site && Ref.url && Ref.title)
|
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, Ref.site);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.title);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
|
|
|
else if(Ref.url && Ref.title && Ref.author && Ref.publisher && Ref.isbn)
|
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.isbn);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, "%s (%s)", Ref.author, Ref.publisher);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.title);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
|
|
|
else if(Ref.title && Ref.author && Ref.isbn)
|
2017-04-19 01:10:45 +00:00
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.isbn);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, Ref.author);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.title);
|
2017-04-21 01:25:40 +00:00
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, "http://www.isbnsearch.org/isbn/%s", Ref.isbn);
|
2017-04-19 01:10:45 +00:00
|
|
|
}
|
2017-04-21 01:25:40 +00:00
|
|
|
else if(Ref.url && Ref.article && Ref.author)
|
2017-04-19 01:10:45 +00:00
|
|
|
{
|
2017-04-21 01:25:40 +00:00
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, Ref.author);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.article);
|
2017-04-19 01:10:45 +00:00
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
2017-04-21 01:25:40 +00:00
|
|
|
else if(Ref.url && Ref.title && Ref.author)
|
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, Ref.author);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.title);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2017-04-19 01:10:45 +00:00
|
|
|
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].Identifier[ReferencesArray[UniqueRefs].IdentifierCount].Timecode, Anno.time);
|
|
|
|
ReferencesArray[UniqueRefs].Identifier[ReferencesArray[UniqueRefs].IdentifierCount].Identifier = RefIdentifier;
|
2017-04-21 01:25:40 +00:00
|
|
|
return 0;
|
2017-04-19 01:10:45 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 03:10:15 +00:00
|
|
|
void
|
|
|
|
BuildCategories(buffer *AnnotationClass, buffer *Category, int *MarkerIndex, bool *HasCategory, char *Marker)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
|
|
|
|
{
|
|
|
|
if(!StringsDiffer(CategoryMedium[i], Marker))
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(AnnotationClass, " %s", SanitisePunctuation(Marker));
|
|
|
|
++*MarkerIndex;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(*HasCategory == FALSE)
|
|
|
|
{
|
2017-03-29 03:38:12 +00:00
|
|
|
CopyStringToBuffer(Category, "<span class=\"categories\">");
|
2017-03-25 03:10:15 +00:00
|
|
|
*HasCategory = TRUE;
|
|
|
|
}
|
2017-03-29 03:38:12 +00:00
|
|
|
|
|
|
|
CopyStringToBuffer(Category, "<div class=\"category %s\"></div>",
|
|
|
|
SanitisePunctuation(Marker));
|
|
|
|
|
2017-03-25 03:10:15 +00:00
|
|
|
CopyStringToBuffer(AnnotationClass, " cat_%s",
|
|
|
|
SanitisePunctuation(Marker));
|
|
|
|
++*MarkerIndex;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-31 00:56:50 +00:00
|
|
|
void
|
2017-04-13 23:46:21 +00:00
|
|
|
GenerateTopicColours(buffer *Colour, char *Topic)
|
2017-03-31 00:56:50 +00:00
|
|
|
{
|
|
|
|
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
|
|
|
|
{
|
|
|
|
if(!StringsDiffer(Topic, CategoryMedium[i]))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *TopicsFile;
|
|
|
|
char *TopicsBuffer;
|
2017-04-13 00:21:04 +00:00
|
|
|
if((TopicsFile = fopen("topics.css", "a+")))
|
2017-03-31 00:56:50 +00:00
|
|
|
{
|
|
|
|
fseek(TopicsFile, 0, SEEK_END);
|
|
|
|
int TopicsLength = ftell(TopicsFile);
|
|
|
|
fseek(TopicsFile, 0, SEEK_SET);
|
|
|
|
|
2017-04-13 00:21:04 +00:00
|
|
|
if(!(TopicsBuffer = malloc(TopicsLength)))
|
2017-03-31 00:56:50 +00:00
|
|
|
{
|
|
|
|
perror("hmml_to_html");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fread(TopicsBuffer, TopicsLength, 1, TopicsFile);
|
|
|
|
|
2017-04-13 00:21:04 +00:00
|
|
|
char *TopicsPtr = TopicsBuffer;
|
2017-03-31 00:56:50 +00:00
|
|
|
|
|
|
|
while(TopicsPtr - TopicsBuffer < TopicsLength)
|
|
|
|
{
|
|
|
|
TopicsPtr += 39;
|
|
|
|
if(!strncmp(SanitisePunctuation(Topic), TopicsPtr, StringLength(Topic)))
|
|
|
|
{
|
|
|
|
free(TopicsBuffer);
|
2017-04-21 01:25:40 +00:00
|
|
|
fclose(TopicsFile);
|
2017-03-31 00:56:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while(TopicsPtr - TopicsBuffer < TopicsLength && *TopicsPtr != '\n')
|
|
|
|
{
|
|
|
|
++TopicsPtr;
|
|
|
|
}
|
|
|
|
++TopicsPtr;
|
|
|
|
}
|
2017-04-13 00:21:04 +00:00
|
|
|
|
2017-04-13 23:46:21 +00:00
|
|
|
fprintf(TopicsFile, ".marker .content .categories .category.%s { border-color: %s; background: %s; }\n",
|
|
|
|
SanitisePunctuation(Topic), StringToColourHash(Colour, Topic), StringToColourHash(Colour, Topic));
|
2017-04-13 00:21:04 +00:00
|
|
|
|
|
|
|
fclose(TopicsFile);
|
|
|
|
free(TopicsBuffer);
|
2017-03-31 00:56:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-13 00:21:04 +00:00
|
|
|
perror("hmml_to_html");
|
|
|
|
return;
|
2017-03-31 00:56:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:19:25 +00:00
|
|
|
int
|
|
|
|
main(int ArgC, char **Args)
|
|
|
|
{
|
|
|
|
if(ArgC < 2)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s filename(s)\n", Args[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(matt): Init MemoryArena
|
|
|
|
char *MemoryArena;
|
2017-03-16 00:56:58 +00:00
|
|
|
int ArenaSize = 1024 * 1024;
|
2017-03-10 14:19:25 +00:00
|
|
|
if(!(MemoryArena = calloc(ArenaSize, 1)))
|
|
|
|
{
|
|
|
|
perror(Args[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int ClaimedMemory = 0;
|
|
|
|
|
|
|
|
// NOTE(matt): Setup buffers and ptrs
|
2017-03-22 02:18:31 +00:00
|
|
|
char *InPtr;
|
|
|
|
|
|
|
|
buffer Title;
|
|
|
|
buffer QuoteMenu;
|
|
|
|
buffer ReferenceMenu;
|
|
|
|
|
|
|
|
buffer Player;
|
|
|
|
buffer Annotation;
|
|
|
|
buffer AnnotationHeader;
|
|
|
|
buffer AnnotationClass;
|
|
|
|
buffer AnnotationData;
|
|
|
|
buffer Text;
|
|
|
|
buffer Category;
|
2017-04-13 23:46:21 +00:00
|
|
|
buffer Colour;
|
2017-03-22 02:18:31 +00:00
|
|
|
|
|
|
|
buffer Master;
|
|
|
|
|
|
|
|
for(int FileIndex = 1; FileIndex < ArgC; ++FileIndex)
|
|
|
|
{
|
2017-04-21 01:25:40 +00:00
|
|
|
// TODO(matt): Maybe look into this further. It works, but there may be
|
|
|
|
// bugs lurking
|
|
|
|
ClaimedMemory = 0;
|
2017-03-22 02:18:31 +00:00
|
|
|
FILE *InFile;
|
|
|
|
if(!(InFile = fopen(Args[FileIndex], "r")))
|
|
|
|
{
|
|
|
|
perror(Args[0]);
|
|
|
|
free(MemoryArena);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
HMML_Output HMML = hmml_parse_file(InFile);
|
|
|
|
fclose(InFile);
|
|
|
|
|
|
|
|
if(HMML.well_formed)
|
|
|
|
{
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Title, 1024 * 16);
|
2017-03-30 02:57:04 +00:00
|
|
|
ref_info ReferencesArray[200];
|
|
|
|
memset(ReferencesArray, 0, sizeof(ReferencesArray));
|
2017-03-22 02:18:31 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Player, 1024 * 256);
|
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
bool HasQuoteMenu = FALSE;
|
|
|
|
bool HasReferenceMenu = FALSE;
|
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
int QuoteIdentifier = 0x3b1;
|
2017-03-29 03:38:12 +00:00
|
|
|
int RefIdentifier = 1;
|
2017-03-30 02:57:04 +00:00
|
|
|
int UniqueRefs = 0;
|
2017-03-29 03:38:12 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Title,
|
2017-04-13 00:21:04 +00:00
|
|
|
" <div class=\"title %s\">\n"
|
|
|
|
" <span class=\"episode_name\">%s</span>\n", HMML.metadata.project, HMML.metadata.title);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Player,
|
2017-03-22 02:18:31 +00:00
|
|
|
" <div class=\"player_container\">\n"
|
|
|
|
" <div class=\"video_container\" data-videoId=\"%s\"></div>\n"
|
2017-04-13 00:21:04 +00:00
|
|
|
" <div class=\"markers_container %s\">\n", HMML.metadata.id, HMML.metadata.project);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
|
|
|
for(int AnnotationIndex = 0; AnnotationIndex < HMML.annotation_count; ++AnnotationIndex)
|
|
|
|
{
|
2017-03-29 03:38:12 +00:00
|
|
|
HMML_Annotation *Anno = HMML.annotations + AnnotationIndex;
|
2017-03-25 02:07:55 +00:00
|
|
|
bool HasCategory = FALSE;
|
2017-03-29 03:38:12 +00:00
|
|
|
bool HasQuote = FALSE;
|
|
|
|
bool HasReference = FALSE;
|
|
|
|
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationHeader, 512);
|
2017-03-25 03:10:15 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, 256);
|
2017-03-29 03:38:12 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, 256);
|
2017-03-22 02:18:31 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, 1024 * 4);
|
2017-04-13 23:46:21 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Colour, 32);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&AnnotationHeader,
|
2017-03-22 02:18:31 +00:00
|
|
|
" <div data-timestamp=\"%d\"",
|
2017-03-29 03:38:12 +00:00
|
|
|
TimecodeToSeconds(Anno->time));
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&AnnotationClass,
|
2017-03-22 02:18:31 +00:00
|
|
|
" class=\"marker");
|
2017-03-23 00:34:59 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
if(Anno->author)
|
2017-03-23 00:34:59 +00:00
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationClass, " authored");
|
|
|
|
CopyStringToBuffer(&Text,
|
2017-04-13 23:46:21 +00:00
|
|
|
"<span class=\"author\" style=\"color: %s;\">%s</span> ",
|
|
|
|
StringToColourHash(&Colour, Anno->author),
|
2017-03-29 03:38:12 +00:00
|
|
|
Anno->author);
|
2017-03-23 00:34:59 +00:00
|
|
|
}
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
InPtr = Anno->text;
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-25 02:07:55 +00:00
|
|
|
int MarkerIndex = 0, RefIndex = 0;
|
2017-03-29 03:38:12 +00:00
|
|
|
while(*InPtr || RefIndex < Anno->reference_count)
|
2017-03-25 02:07:55 +00:00
|
|
|
{
|
2017-03-29 03:38:12 +00:00
|
|
|
if(MarkerIndex < Anno->marker_count &&
|
|
|
|
InPtr - Anno->text == Anno->markers[MarkerIndex].offset)
|
2017-03-25 02:07:55 +00:00
|
|
|
{
|
2017-03-29 03:38:12 +00:00
|
|
|
char *Readable = Anno->markers[MarkerIndex].parameter
|
|
|
|
? Anno->markers[MarkerIndex].parameter
|
|
|
|
: Anno->markers[MarkerIndex].marker;
|
|
|
|
if(Anno->markers[MarkerIndex].type == HMML_MEMBER)
|
2017-03-25 02:07:55 +00:00
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Text,
|
2017-04-13 23:46:21 +00:00
|
|
|
// TODO(matt): Hoverbox
|
|
|
|
"<a href=\"https://handmade.network/m/%s\" target=\"blank\" style=\"color: %s; text-decoration: none\">%.*s</a>",
|
2017-03-29 03:38:12 +00:00
|
|
|
Anno->markers[MarkerIndex].marker,
|
2017-04-13 23:46:21 +00:00
|
|
|
StringToColourHash(&Colour, Anno->markers[MarkerIndex].marker),
|
2017-03-25 03:10:15 +00:00
|
|
|
StringLength(Readable), InPtr);
|
|
|
|
InPtr += StringLength(Readable);
|
|
|
|
++MarkerIndex;
|
2017-03-25 02:07:55 +00:00
|
|
|
}
|
2017-03-29 03:38:12 +00:00
|
|
|
else if(Anno->markers[MarkerIndex].type == HMML_PROJECT)
|
2017-03-25 02:07:55 +00:00
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Text,
|
2017-04-13 23:46:21 +00:00
|
|
|
// TODO(matt): Hoverbox
|
|
|
|
"<a href=\"https://%s.handmade.network/\" target=\"blank\" style=\"color: %s; text-decoration: none\">%s</a>",
|
2017-03-29 03:38:12 +00:00
|
|
|
Anno->markers[MarkerIndex].marker,
|
2017-04-13 23:46:21 +00:00
|
|
|
StringToColourHash(&Colour, Anno->markers[MarkerIndex].marker),
|
2017-03-25 02:07:55 +00:00
|
|
|
Readable);
|
2017-03-25 03:10:15 +00:00
|
|
|
InPtr += StringLength(Readable);
|
|
|
|
++MarkerIndex;
|
2017-03-25 02:07:55 +00:00
|
|
|
}
|
2017-03-29 03:38:12 +00:00
|
|
|
else if(Anno->markers[MarkerIndex].type == HMML_CATEGORY)
|
2017-03-25 02:07:55 +00:00
|
|
|
{
|
2017-04-13 23:46:21 +00:00
|
|
|
GenerateTopicColours(&Colour, Anno->markers[MarkerIndex].marker);
|
2017-03-29 03:38:12 +00:00
|
|
|
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, Anno->markers[MarkerIndex].marker);
|
2017-03-25 02:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
if(RefIndex < Anno->reference_count &&
|
|
|
|
InPtr - Anno->text == Anno->references[RefIndex].offset)
|
2017-03-25 02:07:55 +00:00
|
|
|
{
|
2017-03-29 03:38:12 +00:00
|
|
|
HMML_Reference *CurrentRef = Anno->references + RefIndex;
|
|
|
|
if(!HasReferenceMenu)
|
|
|
|
{
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &ReferenceMenu, 1024 * 16);
|
|
|
|
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
|
|
|
" <div class=\"refs_container\">\n"
|
|
|
|
" <span>References ▼</span>\n"
|
|
|
|
" <div class=\"mouse_catcher\"></div>\n"
|
|
|
|
" <div class=\"refs\">\n");
|
|
|
|
|
2017-04-21 01:25:40 +00:00
|
|
|
if(BuildReference(ReferencesArray, RefIdentifier, UniqueRefs, *CurrentRef, *Anno) == 1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d: Cannot process new combination of reference info\n", Args[FileIndex], Anno->line);
|
|
|
|
hmml_free(&HMML);
|
|
|
|
free(MemoryArena);
|
|
|
|
return 1;
|
|
|
|
}
|
2017-03-30 02:57:04 +00:00
|
|
|
++ReferencesArray[RefIdentifier - 1].IdentifierCount;
|
|
|
|
++UniqueRefs;
|
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
HasReferenceMenu = TRUE;
|
|
|
|
}
|
2017-03-30 02:57:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int i = 0; i < UniqueRefs; ++i)
|
|
|
|
{
|
2017-04-19 01:10:45 +00:00
|
|
|
if(CurrentRef->isbn)
|
|
|
|
{
|
|
|
|
if(!StringsDiffer(CurrentRef->isbn, ReferencesArray[i].ID))
|
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[i].Identifier[ReferencesArray[i].IdentifierCount].Timecode, Anno->time);
|
|
|
|
ReferencesArray[i].Identifier[ReferencesArray[i].IdentifierCount].Identifier = RefIdentifier;
|
|
|
|
++ReferencesArray[i].IdentifierCount;
|
|
|
|
goto AppendedIdentifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(CurrentRef->url)
|
|
|
|
{
|
|
|
|
if(!StringsDiffer(CurrentRef->url, ReferencesArray[i].ID))
|
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[i].Identifier[ReferencesArray[i].IdentifierCount].Timecode, Anno->time);
|
|
|
|
ReferencesArray[i].Identifier[ReferencesArray[i].IdentifierCount].Identifier = RefIdentifier;
|
|
|
|
++ReferencesArray[i].IdentifierCount;
|
|
|
|
goto AppendedIdentifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-03-30 02:57:04 +00:00
|
|
|
{
|
2017-04-19 01:10:45 +00:00
|
|
|
fprintf(stderr, "%s:%d: Reference must have an ISBN or URL\n", Args[FileIndex], Anno->line);
|
|
|
|
return 1;
|
2017-03-30 02:57:04 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-29 03:38:12 +00:00
|
|
|
|
2017-04-21 01:25:40 +00:00
|
|
|
if(BuildReference(ReferencesArray, RefIdentifier, UniqueRefs, *CurrentRef, *Anno) == 1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d: Cannot process new combination of reference info\n", Args[FileIndex], Anno->line);
|
|
|
|
hmml_free(&HMML);
|
|
|
|
free(MemoryArena);
|
|
|
|
return 1;
|
|
|
|
}
|
2017-03-30 02:57:04 +00:00
|
|
|
++ReferencesArray[UniqueRefs].IdentifierCount;
|
|
|
|
++UniqueRefs;
|
|
|
|
}
|
|
|
|
AppendedIdentifier:
|
2017-03-29 03:38:12 +00:00
|
|
|
if(!HasReference)
|
|
|
|
{
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, 128);
|
2017-04-19 01:10:45 +00:00
|
|
|
if(CurrentRef->isbn)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, " data-ref=\"%s", CurrentRef->isbn);
|
|
|
|
}
|
|
|
|
else if(CurrentRef->url)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, " data-ref=\"%s", CurrentRef->url);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d: Reference must have an ISBN or URL\n", Args[FileIndex], Anno->line);
|
|
|
|
free(MemoryArena);
|
|
|
|
hmml_free(&HMML);
|
|
|
|
return 1;
|
|
|
|
}
|
2017-03-29 03:38:12 +00:00
|
|
|
|
|
|
|
HasReference = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-19 01:10:45 +00:00
|
|
|
if(CurrentRef->isbn)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, ",%s", CurrentRef->isbn);
|
|
|
|
}
|
|
|
|
else if(CurrentRef->url)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, ",%s", CurrentRef->url);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-21 01:25:40 +00:00
|
|
|
fprintf(stderr, "%s:%d: Reference must have an ISBN or URL", Args[FileIndex], Anno->line);
|
2017-04-19 01:10:45 +00:00
|
|
|
free(MemoryArena);
|
|
|
|
hmml_free(&HMML);
|
|
|
|
return 1;
|
|
|
|
}
|
2017-03-29 03:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CopyStringToBuffer(&Text, "<sup>%d</sup>", RefIdentifier);
|
|
|
|
|
2017-03-25 02:07:55 +00:00
|
|
|
++RefIndex;
|
2017-03-29 03:38:12 +00:00
|
|
|
++RefIdentifier;
|
2017-03-25 02:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(*InPtr)
|
|
|
|
{
|
|
|
|
*Text.Ptr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
if(Anno->is_quote)
|
|
|
|
{
|
|
|
|
if(!HasQuoteMenu)
|
|
|
|
{
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &QuoteMenu, 1024 * 16);
|
|
|
|
CopyStringToBuffer(&QuoteMenu,
|
|
|
|
" <div class=\"refs_container\">\n"
|
|
|
|
" <span>Quotes ▼</span>\n"
|
|
|
|
" <div class=\"mouse_catcher\"></div>\n"
|
|
|
|
" <div class=\"refs\">\n");
|
|
|
|
|
|
|
|
HasQuoteMenu = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!HasReference)
|
|
|
|
{
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, 128);
|
2017-03-29 03:38:12 +00:00
|
|
|
CopyStringToBuffer(&AnnotationData, " data-ref=\"&#%d;", QuoteIdentifier);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, ",&#%d;", QuoteIdentifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
HasQuote = TRUE;
|
|
|
|
|
|
|
|
CopyStringToBuffer(&QuoteMenu,
|
|
|
|
" <span data-id=\"&#%d;\" class=\"ref\">\n"
|
|
|
|
" <span class=\"ref_content\">\n"
|
|
|
|
" <div class=\"source\">#%d • %s</div>\n"
|
|
|
|
" <div class=\"ref_title\">%s</div>\n"
|
|
|
|
" </span>\n"
|
|
|
|
" <div class=\"ref_indices\">\n"
|
|
|
|
" <span data-timestamp=\"%d\" class=\"timecode\"><span class=\"ref_index\">[&#%d;]</span><span class=\"time\">%s</span></span>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" </span>\n",
|
|
|
|
QuoteIdentifier,
|
|
|
|
Anno->quote.id,
|
|
|
|
"Quote date",
|
|
|
|
"Quote text",
|
|
|
|
TimecodeToSeconds(Anno->time),
|
|
|
|
QuoteIdentifier,
|
|
|
|
Anno->time);
|
|
|
|
if(!Anno->text[0])
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Text, "“Quote text”");
|
|
|
|
}
|
|
|
|
CopyStringToBuffer(&Text, "<sup>&#%d;</sup>", QuoteIdentifier);
|
|
|
|
++QuoteIdentifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(MarkerIndex < Anno->marker_count)
|
2017-03-25 02:07:55 +00:00
|
|
|
{
|
2017-04-13 23:46:21 +00:00
|
|
|
GenerateTopicColours(&Colour, Anno->markers[MarkerIndex].marker);
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimedMemory -= Colour.Size;
|
2017-03-29 03:38:12 +00:00
|
|
|
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, Anno->markers[MarkerIndex].marker);
|
2017-03-25 02:07:55 +00:00
|
|
|
}
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&AnnotationClass, "\"");
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&AnnotationHeader, &AnnotationClass);
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimedMemory -= AnnotationClass.Size;
|
2017-03-29 03:38:12 +00:00
|
|
|
|
|
|
|
if(HasQuote || HasReference)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, "\"");
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&AnnotationHeader, &AnnotationData);
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimedMemory -= AnnotationData.Size;
|
2017-03-29 03:38:12 +00:00
|
|
|
}
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&AnnotationHeader, ">\n");
|
2017-03-22 02:18:31 +00:00
|
|
|
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Annotation, 1024 * 4);
|
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Annotation, &AnnotationHeader);
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimedMemory -= AnnotationHeader.Size;
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Annotation,
|
2017-03-22 02:18:31 +00:00
|
|
|
" <div class=\"content\"><span class=\"timecode\">%s</span>",
|
2017-03-29 03:38:12 +00:00
|
|
|
Anno->time);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-25 02:07:55 +00:00
|
|
|
if(HasCategory)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Category, "</span>");
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Text, &Category);
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimedMemory -= Category.Size;
|
2017-03-25 02:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*Text.Ptr = '\0';
|
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Annotation, &Text);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Annotation, "</div>\n"
|
2017-03-22 02:18:31 +00:00
|
|
|
" <div class=\"progress faded\">\n"
|
|
|
|
" <div class=\"content\"><span class=\"timecode\">%s</span>",
|
2017-03-29 03:38:12 +00:00
|
|
|
Anno->time);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Annotation, &Text);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Annotation, "</div>\n"
|
2017-03-22 02:18:31 +00:00
|
|
|
" </div>\n"
|
|
|
|
" <div class=\"progress main\">\n"
|
|
|
|
" <div class=\"content\"><span class=\"timecode\">%s</span>",
|
2017-03-29 03:38:12 +00:00
|
|
|
Anno->time);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Annotation, &Text);
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimedMemory -= Text.Size;
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Annotation, "</div>\n"
|
2017-03-22 02:18:31 +00:00
|
|
|
" </div>\n"
|
2017-03-23 00:34:59 +00:00
|
|
|
" </div>\n");
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Player, &Annotation);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
|
|
|
ClaimedMemory -= Annotation.Size;
|
|
|
|
}
|
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
if(HasQuoteMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&QuoteMenu,
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n");
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Title, &QuoteMenu);
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimedMemory -= QuoteMenu.Size;
|
2017-03-29 03:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(HasReferenceMenu)
|
|
|
|
{
|
2017-03-30 02:57:04 +00:00
|
|
|
for(int i = 0; i < UniqueRefs; ++i)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
|
|
|
" <a data-id=\"%s\" href=\"%s\" target=\"_blank\" class=\"ref\">\n"
|
2017-04-19 01:10:45 +00:00
|
|
|
" <span class=\"ref_content\">\n",
|
|
|
|
ReferencesArray[i].ID,
|
|
|
|
ReferencesArray[i].URL);
|
|
|
|
|
2017-04-21 01:25:40 +00:00
|
|
|
if(*ReferencesArray[i].Source)
|
2017-04-19 01:10:45 +00:00
|
|
|
{
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
2017-03-30 02:57:04 +00:00
|
|
|
" <div class=\"source\">%s</div>\n"
|
2017-04-19 01:10:45 +00:00
|
|
|
" <div class=\"ref_title\">%s</div>\n",
|
|
|
|
ReferencesArray[i].Source,
|
|
|
|
ReferencesArray[i].RefTitle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
|
|
|
" <div class=\"ref_title\">%s</div>\n",
|
2017-04-21 01:25:40 +00:00
|
|
|
ReferencesArray[i].RefTitle);
|
2017-04-19 01:10:45 +00:00
|
|
|
}
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
|
|
|
" </span>\n");
|
|
|
|
|
2017-04-21 01:25:40 +00:00
|
|
|
for(int j = 0; j < ReferencesArray[i].IdentifierCount;)
|
2017-03-30 02:57:04 +00:00
|
|
|
{
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
2017-04-21 01:25:40 +00:00
|
|
|
" <div class=\"ref_indices\">\n ");
|
|
|
|
for(int k = 0; k < 3 && j < ReferencesArray[i].IdentifierCount; ++k, ++j)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
2017-03-31 00:56:50 +00:00
|
|
|
"<span data-timestamp=\"%d\" class=\"timecode\"><span class=\"ref_index\">[%d]</span><span class=\"time\">%s</span></span>",
|
2017-03-30 02:57:04 +00:00
|
|
|
TimecodeToSeconds(ReferencesArray[i].Identifier[j].Timecode),
|
|
|
|
ReferencesArray[i].Identifier[j].Identifier,
|
|
|
|
ReferencesArray[i].Identifier[j].Timecode);
|
2017-04-21 01:25:40 +00:00
|
|
|
}
|
2017-04-13 00:21:04 +00:00
|
|
|
CopyStringToBuffer(&ReferenceMenu, "\n"
|
2017-04-21 01:25:40 +00:00
|
|
|
" </div>\n");
|
|
|
|
}
|
2017-04-13 00:21:04 +00:00
|
|
|
|
2017-04-21 01:25:40 +00:00
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
2017-03-30 02:57:04 +00:00
|
|
|
" </a>\n");
|
|
|
|
}
|
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n");
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Title, &ReferenceMenu);
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimedMemory -= ReferenceMenu.Size;
|
2017-03-29 03:38:12 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Title,
|
2017-03-22 02:18:31 +00:00
|
|
|
" <span class=\"annotator_container\">Annotator: <span class=\"annotator\">%s</span></span>\n"
|
2017-04-21 01:25:40 +00:00
|
|
|
" </div>\n",
|
|
|
|
HMML.metadata.annotator);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Player,
|
2017-03-22 02:18:31 +00:00
|
|
|
" </div>\n"
|
|
|
|
" </div>\n");
|
|
|
|
|
|
|
|
//NOTE(matt): Collate the buffers!
|
|
|
|
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, 1024 * 512);
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Master,
|
2017-03-25 02:07:55 +00:00
|
|
|
"<html>\n"
|
2017-03-22 02:18:31 +00:00
|
|
|
" <head>\n"
|
|
|
|
" <meta charset=\"UTF-8\">\n"
|
|
|
|
"\n"
|
|
|
|
" <!-- Load the player -->\n"
|
|
|
|
" <script type=\"text/javascript\" src=\"player.js\"></script>\n"
|
|
|
|
" <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n"
|
2017-04-13 00:21:04 +00:00
|
|
|
" <link rel=\"stylesheet\" type=\"text/css\" href=\"%s.css\">\n"
|
2017-03-31 00:56:50 +00:00
|
|
|
" <link rel=\"stylesheet\" type=\"text/css\" href=\"topics.css\">\n"
|
2017-03-22 02:18:31 +00:00
|
|
|
" </head>\n"
|
2017-04-13 00:21:04 +00:00
|
|
|
" <body>\n", HMML.metadata.project);
|
2017-03-22 02:18:31 +00:00
|
|
|
|
|
|
|
//NOTE(matt): Here is where we do all our CopyBuffer() calls
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Master, &Title);
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimedMemory -= Title.Size;
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Master, &Player);
|
2017-04-21 01:25:40 +00:00
|
|
|
ClaimedMemory -= Player.Size;
|
2017-03-22 02:18:31 +00:00
|
|
|
//
|
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Master,
|
2017-03-22 02:18:31 +00:00
|
|
|
" <script>\n"
|
|
|
|
" var player = new Player(document.querySelector(\".player_container\"), onRefChanged);\n"
|
|
|
|
" window.addEventListener(\"resize\", function() { player.updateSize(); });\n"
|
|
|
|
" document.addEventListener(\"keypress\", function(ev) {\n"
|
|
|
|
" switch (ev.key) {\n"
|
|
|
|
" case 'n':\n"
|
|
|
|
" case 'd':\n"
|
|
|
|
" case 's': {\n"
|
|
|
|
" player.jumpToNextMarker();\n"
|
|
|
|
" } break;\n"
|
|
|
|
"\n"
|
|
|
|
" case 'p':\n"
|
|
|
|
" case 'a':\n"
|
|
|
|
" case 'w': {\n"
|
|
|
|
" player.jumpToPrevMarker();\n"
|
|
|
|
" } break;\n"
|
|
|
|
" }\n"
|
|
|
|
"});\n"
|
|
|
|
"\n"
|
|
|
|
"var refTimecodes = document.querySelectorAll(\".refs .ref .timecode\");\n"
|
|
|
|
"for (var i = 0; i < refTimecodes.length; ++i) {\n"
|
|
|
|
" refTimecodes[i].addEventListener(\"click\", function(ev) {\n"
|
|
|
|
" if (player) {\n"
|
|
|
|
" var time = ev.currentTarget.getAttribute(\"data-timestamp\");\n"
|
|
|
|
" player.setTime(parseInt(time, 10));\n"
|
|
|
|
" player.play();\n"
|
|
|
|
" ev.preventDefault();\n"
|
|
|
|
" ev.stopPropagation();\n"
|
|
|
|
" return false;\n"
|
|
|
|
" }\n"
|
|
|
|
" });\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"var refSources = document.querySelectorAll(\".refs .ref\");\n"
|
|
|
|
"for (var i = 0; i < refSources.length; ++i) {\n"
|
|
|
|
" refSources[i].addEventListener(\"click\", function(ev) {\n"
|
|
|
|
" if (player) {\n"
|
|
|
|
" player.pause();\n"
|
|
|
|
" }\n"
|
|
|
|
" });\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"function onRefChanged(ref) {\n"
|
|
|
|
" var sourceMenus = document.querySelectorAll(\".refs_container\");\n"
|
|
|
|
" for (var MenuIndex = 0; MenuIndex < sourceMenus.length; ++MenuIndex)\n"
|
|
|
|
" {\n"
|
|
|
|
" var SetMenu = 0;\n"
|
|
|
|
" if (ref !== undefined && ref !== null) {\n"
|
|
|
|
" var refElements = sourceMenus[MenuIndex].querySelectorAll(\".refs .ref\");\n"
|
|
|
|
" var refs = ref.split(\",\");\n"
|
|
|
|
"\n"
|
|
|
|
" for (var i = 0; i < refElements.length; ++i) {\n"
|
|
|
|
" if (refs.includes(refElements[i].getAttribute(\"data-id\"))) {\n"
|
|
|
|
" refElements[i].classList.add(\"current\");\n"
|
|
|
|
" SetMenu = 1;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" refElements[i].classList.remove(\"current\");\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" if(SetMenu) {\n"
|
|
|
|
" sourceMenus[MenuIndex].classList.add(\"current\");\n"
|
|
|
|
" } else {\n"
|
|
|
|
" sourceMenus[MenuIndex].classList.remove(\"current\");\n"
|
|
|
|
" }\n"
|
|
|
|
"\n"
|
|
|
|
" } else {\n"
|
|
|
|
" sourceMenus[MenuIndex].classList.remove(\"current\");\n"
|
|
|
|
" var refs = sourceMenus[MenuIndex].querySelectorAll(\".refs .ref\");\n"
|
|
|
|
" for (var i = 0; i < refs.length; ++i) {\n"
|
|
|
|
" refs[i].classList.remove(\"current\");\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n"
|
|
|
|
" </script>\n"
|
|
|
|
" </body>\n"
|
|
|
|
"</html>\n");
|
|
|
|
|
|
|
|
FILE *OutFile;
|
|
|
|
if(!(OutFile = fopen("out.html", "w")))
|
|
|
|
{
|
|
|
|
perror(Args[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
fwrite(Master.Location, Master.Ptr - Master.Location, 1, OutFile);
|
|
|
|
fclose(OutFile);
|
|
|
|
|
|
|
|
ClaimedMemory -= Master.Size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d: %s\n", Args[FileIndex], HMML.error.line, HMML.error.message);
|
|
|
|
}
|
|
|
|
hmml_free(&HMML);
|
|
|
|
}
|
2017-03-10 14:19:25 +00:00
|
|
|
free(MemoryArena);
|
|
|
|
}
|