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-05-22 21:37:00 +00:00
|
|
|
#define DEBUG 0
|
2017-05-21 06:35:16 +00:00
|
|
|
|
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
|
2017-03-23 00:34:59 +00:00
|
|
|
#include "hmmlib.h"
|
2017-05-25 20:28:52 +00:00
|
|
|
//#include "config.h" // TODO(matt): Implement config.h
|
2017-03-23 00:34:59 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
#define Kilobytes(Bytes) Bytes << 10
|
|
|
|
#define Megabytes(Bytes) Bytes << 20
|
|
|
|
|
2017-03-10 14:19:25 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *Location;
|
|
|
|
char *Ptr;
|
2017-05-21 06:35:16 +00:00
|
|
|
char *ID;
|
2017-03-10 14:19:25 +00:00
|
|
|
int Size;
|
|
|
|
} buffer;
|
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
// TODO(matt): Consider putting the ref_info and quote_info into linked lists on the heap, just to avoid all the hardcoded sizes
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char Date[32];
|
|
|
|
char Text[512];
|
|
|
|
} quote_info;
|
|
|
|
|
2017-03-19 01:23:44 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2017-03-30 02:57:04 +00:00
|
|
|
char Timecode[8];
|
|
|
|
int Identifier;
|
|
|
|
} identifier;
|
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
#define REF_MAX_IDENTIFIER 32
|
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2017-04-13 00:21:04 +00:00
|
|
|
char RefTitle[620];
|
|
|
|
char ID[512];
|
|
|
|
char URL[512];
|
|
|
|
char Source[256];
|
2017-05-13 15:38:10 +00:00
|
|
|
identifier Identifier[REF_MAX_IDENTIFIER];
|
2017-03-30 02:57:04 +00:00
|
|
|
int IdentifierCount;
|
2017-03-19 01:23:44 +00:00
|
|
|
} ref_info;
|
|
|
|
|
2017-04-23 02:47:42 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
char Marker[32];
|
|
|
|
char WrittenText[32];
|
2017-05-21 06:35:16 +00:00
|
|
|
} category_info;
|
2017-04-23 02:47:42 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
// TODO(matt): Parse this stuff out of a config file
|
|
|
|
char *Credentials[ ][5] =
|
|
|
|
{
|
|
|
|
{ "Miblo", "Matt Mascarenhas", "http://miblodelcarpio.co.uk", "patreon_logo.png", "http://patreon.com/miblo"},
|
|
|
|
{ "miotatsu", "Mio Iwakura", "http://riscy.tv/", "patreon_logo.png", "http://patreon.com/miotatsu"},
|
|
|
|
{ "nothings", "Sean Barrett", "https://nothings.org/", "", ""},
|
|
|
|
{ "cmuratori", "Casey Muratori", "https://handmadehero.org", "patreon_logo.png", "http://patreon.com/cmuratori"},
|
|
|
|
{ "fierydrake", "Mike Tunnicliffe", "", "", ""},
|
|
|
|
};
|
|
|
|
|
2017-03-25 02:07:55 +00:00
|
|
|
#define ArrayCount(A) sizeof(A)/sizeof(*(A))
|
|
|
|
|
2017-03-16 00:56:58 +00:00
|
|
|
void
|
2017-05-21 06:35:16 +00:00
|
|
|
ClaimBuffer(char *MemoryArena, int *ClaimedMemory, buffer *Buffer, char *ID, int Size)
|
2017-03-16 00:56:58 +00:00
|
|
|
{
|
|
|
|
Buffer->Location = MemoryArena + *ClaimedMemory;
|
|
|
|
Buffer->Size = Size;
|
2017-05-21 06:35:16 +00:00
|
|
|
Buffer->ID = ID;
|
2017-03-16 00:56:58 +00:00
|
|
|
*ClaimedMemory += Buffer->Size;
|
2017-05-21 06:35:16 +00:00
|
|
|
*Buffer->Location = '\0';
|
2017-03-16 00:56:58 +00:00
|
|
|
Buffer->Ptr = Buffer->Location;
|
2017-05-21 06:35:16 +00:00
|
|
|
#if DEBUG
|
|
|
|
printf(" Claimed: %s: %d\n"
|
|
|
|
" Total ClaimedMemory: %d\n\n", Buffer->ID, Buffer->Size, *ClaimedMemory);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeclaimBuffer(buffer *Buffer, int *ClaimedMemory)
|
|
|
|
{
|
|
|
|
*Buffer->Location = '\0';
|
|
|
|
*ClaimedMemory -= Buffer->Size;
|
|
|
|
#if DEBUG
|
|
|
|
printf("Declaimed: %s\n"
|
|
|
|
" Total ClaimedMemory: %d\n\n", Buffer->ID, *ClaimedMemory);
|
|
|
|
#endif
|
2017-03-16 00:56:58 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2017-05-21 06:35:16 +00:00
|
|
|
// TODO(matt)
|
|
|
|
{
|
|
|
|
if(Dest->Ptr - Dest->Location >= Dest->Size)
|
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
fprintf(stderr, "CopyBuffer: %s cannot accommodate %s\n", Dest->ID, Src->ID);
|
2017-05-21 06:35:16 +00:00
|
|
|
__asm__("int3");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2017-03-16 00:56:58 +00:00
|
|
|
*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);
|
2017-05-21 06:35:16 +00:00
|
|
|
// TODO(matt):
|
|
|
|
{
|
|
|
|
if(Length + (Dest->Ptr - Dest->Location) >= Dest->Size)
|
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
fprintf(stderr, "CopyStringToBuffer: %s cannot accommodate %d-character string\n", Dest->ID, Length);
|
2017-05-21 06:35:16 +00:00
|
|
|
__asm__("int3");
|
|
|
|
}
|
|
|
|
}
|
2017-03-23 00:34:59 +00:00
|
|
|
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-23 00:30:37 +00:00
|
|
|
bool
|
|
|
|
StringsDifferL(char *A, char *B, int LengthofA)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
while(i < LengthofA && A[i] && A[i] == B[i])
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if(!A[i] && LengthofA == i)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
int
|
|
|
|
BuildCredits(buffer *CreditsMenu, buffer *HostInfo, buffer *AnnotatorInfo, bool *HasCreditsMenu, char *Host, char *Annotator)
|
|
|
|
{
|
|
|
|
bool FoundHost = FALSE;
|
|
|
|
bool FoundAnnotator = FALSE;
|
|
|
|
|
|
|
|
for(int CredentialIndex = 0; CredentialIndex < ArrayCount(Credentials); ++CredentialIndex)
|
|
|
|
{
|
|
|
|
if(!StringsDiffer(Host, Credentials[CredentialIndex][0]))
|
|
|
|
{
|
|
|
|
FoundHost = TRUE; // TODO(matt): Check if this is actually necessary...
|
|
|
|
CopyStringToBuffer(HostInfo,
|
|
|
|
" <span class=\"credit\">\n");
|
|
|
|
if(*Credentials[CredentialIndex][2])
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(HostInfo,
|
|
|
|
" <a href=\"%s\" target=\"_blank\" class=\"person\">\n"
|
|
|
|
" <div class=\"role\">Host</div>\n"
|
|
|
|
" <div class=\"name\">%s</div>\n"
|
|
|
|
" </a>\n",
|
|
|
|
Credentials[CredentialIndex][2],
|
|
|
|
Credentials[CredentialIndex][1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(HostInfo,
|
|
|
|
" <div class=\"person\">\n"
|
|
|
|
" <div class=\"role\">Host</div>\n"
|
|
|
|
" <div class=\"name\">%s</div>\n"
|
|
|
|
" </div>\n",
|
|
|
|
Credentials[CredentialIndex][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*Credentials[CredentialIndex][4] && *Credentials[CredentialIndex][3])
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(HostInfo,
|
|
|
|
" <a class=\"support\" href=\"%s\"><img src=\"%s\"></a>\n",
|
|
|
|
Credentials[CredentialIndex][4],
|
|
|
|
Credentials[CredentialIndex][3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyStringToBuffer(HostInfo,
|
|
|
|
" </span>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!StringsDiffer(Annotator, Credentials[CredentialIndex][0]))
|
|
|
|
{
|
|
|
|
FoundAnnotator = TRUE; // TODO(matt): Check if this is actually necessary...
|
|
|
|
CopyStringToBuffer(AnnotatorInfo,
|
|
|
|
" <span class=\"credit\">\n");
|
|
|
|
if(*Credentials[CredentialIndex][2])
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(AnnotatorInfo,
|
|
|
|
" <a href=\"%s\" target=\"_blank\" class=\"person\">\n"
|
|
|
|
" <div class=\"role\">Annotator</div>\n"
|
|
|
|
" <div class=\"name\">%s</div>\n"
|
|
|
|
" </a>\n",
|
|
|
|
Credentials[CredentialIndex][2],
|
|
|
|
Credentials[CredentialIndex][1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(AnnotatorInfo,
|
|
|
|
" <div class=\"person\">\n"
|
|
|
|
" <div class=\"role\">Annotator</div>\n"
|
|
|
|
" <div class=\"name\">%s</div>\n"
|
|
|
|
" </div>\n",
|
|
|
|
Credentials[CredentialIndex][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*Credentials[CredentialIndex][4] && *Credentials[CredentialIndex][3])
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(AnnotatorInfo,
|
|
|
|
" <a class=\"support\" href=\"%s\"><img src=\"%s\"></a>\n",
|
|
|
|
Credentials[CredentialIndex][4],
|
|
|
|
Credentials[CredentialIndex][3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyStringToBuffer(AnnotatorInfo,
|
|
|
|
" </span>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FoundHost || FoundAnnotator)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(CreditsMenu,
|
|
|
|
" <div class=\"menu\">\n"
|
|
|
|
" <div class=\"mouse_catcher\"></div>\n"
|
|
|
|
" <span>Credits</span>\n"
|
|
|
|
" <div class=\"credits_container\">\n");
|
|
|
|
|
|
|
|
if(FoundHost)
|
|
|
|
{
|
|
|
|
CopyBuffer(CreditsMenu, HostInfo);
|
|
|
|
}
|
|
|
|
if(FoundAnnotator)
|
|
|
|
{
|
|
|
|
CopyBuffer(CreditsMenu, AnnotatorInfo);
|
|
|
|
}
|
|
|
|
CopyStringToBuffer(CreditsMenu,
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*HasCreditsMenu = TRUE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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-23 00:30:37 +00:00
|
|
|
if(Ref.url && Ref.title && Ref.author && Ref.publisher && Ref.isbn)
|
2017-04-21 01:25:40 +00:00
|
|
|
{
|
2017-04-23 00:30:37 +00:00
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.isbn);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, "%s (%s)", Ref.author, Ref.publisher);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.title);
|
2017-04-21 01:25:40 +00:00
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
2017-04-23 00:30:37 +00:00
|
|
|
else if(Ref.page && Ref.url && Ref.title)
|
2017-04-21 01:25:40 +00:00
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.url);
|
2017-04-23 00:30:37 +00:00
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, Ref.title);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.page);
|
2017-04-21 01:25:40 +00:00
|
|
|
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 && 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.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-05-21 06:35:16 +00:00
|
|
|
//TODO(matt): Look into finding the best ISBN searcher the web has to offer
|
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);
|
|
|
|
}
|
2017-04-23 00:30:37 +00:00
|
|
|
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.url)
|
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, Ref.site);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
2017-04-21 01:25:40 +00:00
|
|
|
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-05-21 06:35:16 +00:00
|
|
|
char *CategoryMedium[][3] =
|
|
|
|
{
|
2017-05-22 21:37:00 +00:00
|
|
|
// medium icon written name
|
|
|
|
{ "authored", "🗪", "Chat Comment"}, // TODO(matt): Conditionally handle Chat vs Guest Comments
|
|
|
|
{ "blackboard", "🖌", "Blackboard"},
|
|
|
|
{ "default", "🖮", "Programming"}, // TODO(matt): Potentially make this configurable per project
|
|
|
|
{ "experience", "🍷", "Experience"},
|
|
|
|
{ "owl", "🦉", "Owl of Shame"},
|
|
|
|
{ "rant", "💢", "Rant"},
|
|
|
|
{ "research", "📖", "Research"},
|
|
|
|
{ "run", "🏃", "In-Game"}, // TODO(matt): Potentially make this configurable per project
|
|
|
|
{ "trivia", "🎲", "Trivia"},
|
2017-05-21 06:35:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2017-05-24 21:56:36 +00:00
|
|
|
BuildFilter(category_info *TopicsArray, int *UniqueTopics, category_info *MediaArray, int *UniqueMedia, char *Marker)
|
2017-05-21 06:35:16 +00:00
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
bool IsMedium = FALSE;
|
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
int i = 0;
|
2017-05-24 21:56:36 +00:00
|
|
|
for(i = 0; i < ArrayCount(CategoryMedium); ++i)
|
2017-05-21 06:35:16 +00:00
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
if(!StringsDiffer(CategoryMedium[i][0], Marker))
|
2017-05-21 06:35:16 +00:00
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
IsMedium = TRUE;
|
|
|
|
break;
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
2017-05-24 21:56:36 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
int Offset;
|
2017-05-24 21:56:36 +00:00
|
|
|
if(IsMedium)
|
|
|
|
{
|
|
|
|
int j = 0;
|
|
|
|
for(j = 0; j < *UniqueMedia; ++j)
|
2017-05-22 21:37:00 +00:00
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
if(!StringsDiffer(CategoryMedium[i][0], MediaArray[j].Marker))
|
2017-05-22 21:37:00 +00:00
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
return;
|
2017-05-22 21:37:00 +00:00
|
|
|
}
|
2017-05-24 21:56:36 +00:00
|
|
|
if((Offset = StringsDiffer(CategoryMedium[i][2], MediaArray[j].WrittenText)) < 0)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
for(k = *UniqueMedia; k > j; --k)
|
|
|
|
{
|
|
|
|
CopyString(MediaArray[k].Marker, MediaArray[k-1].Marker);
|
|
|
|
CopyString(MediaArray[k].WrittenText, MediaArray[k-1].WrittenText);
|
|
|
|
}
|
2017-05-22 21:37:00 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
CopyString(MediaArray[k].Marker, CategoryMedium[i][0]);
|
|
|
|
CopyString(MediaArray[k].WrittenText, CategoryMedium[i][2]);
|
|
|
|
break;
|
|
|
|
}
|
2017-05-22 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
if(j == *UniqueMedia)
|
|
|
|
{
|
|
|
|
CopyString(MediaArray[j].Marker, CategoryMedium[i][0]);
|
|
|
|
CopyString(MediaArray[j].WrittenText, CategoryMedium[i][2]);
|
|
|
|
}
|
2017-05-22 21:37:00 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
++*UniqueMedia;
|
|
|
|
return;
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
2017-05-24 21:56:36 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
for(i = 0; i < *UniqueTopics; ++i)
|
|
|
|
{
|
|
|
|
if(!StringsDiffer(Marker, TopicsArray[i].Marker))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if((Offset = StringsDiffer(Marker, TopicsArray[i].Marker)) < 0)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
for(j = *UniqueTopics; j > i; --j)
|
|
|
|
{
|
|
|
|
CopyString(TopicsArray[j].Marker, TopicsArray[j-1].Marker);
|
|
|
|
}
|
2017-05-21 06:35:16 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
CopyString(TopicsArray[j].Marker, Marker);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-05-22 21:37:00 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
if(i == *UniqueTopics)
|
2017-05-21 06:35:16 +00:00
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
CopyString(TopicsArray[i].Marker, Marker);
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
2017-05-24 21:56:36 +00:00
|
|
|
|
|
|
|
++*UniqueTopics;
|
2017-05-25 20:28:52 +00:00
|
|
|
return;
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-25 03:10:15 +00:00
|
|
|
void
|
2017-05-22 21:37:00 +00:00
|
|
|
BuildCategories(buffer *AnnotationClass, buffer *Category, int *MarkerIndex, bool *HasCategory, bool *HasMedium, char *Marker)
|
2017-03-25 03:10:15 +00:00
|
|
|
{
|
2017-05-22 21:37:00 +00:00
|
|
|
// NOTE(matt): This guy could also sort, so that the dots appear in a consistent order in the annotations
|
|
|
|
// If so, the Category buffer would have to only contain the category names and no more until collation time
|
|
|
|
// BuildCategories() would have to parse the Category.Location out to an array, sort that array and write it back in
|
|
|
|
// The code in the "annotation loop" would then have to write both the head and tail of the category stuff
|
2017-03-25 03:10:15 +00:00
|
|
|
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
|
|
|
|
{
|
2017-05-21 06:35:16 +00:00
|
|
|
if(!StringsDiffer(CategoryMedium[i][0], Marker))
|
2017-03-25 03:10:15 +00:00
|
|
|
{
|
|
|
|
CopyStringToBuffer(AnnotationClass, " %s", SanitisePunctuation(Marker));
|
2017-05-22 21:37:00 +00:00
|
|
|
*HasMedium = TRUE;
|
2017-03-25 03:10:15 +00:00
|
|
|
++*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-04-23 02:47:42 +00:00
|
|
|
int
|
|
|
|
StringToInt(char *String)
|
|
|
|
{
|
|
|
|
int Result = 0;
|
|
|
|
while(*String)
|
|
|
|
{
|
|
|
|
Result = Result * 10 + (*String - '0');
|
|
|
|
++String;
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
BuildQuote(quote_info *Info, char *Speaker, int ID)
|
|
|
|
{
|
2017-05-21 06:35:16 +00:00
|
|
|
// TODO(matt): Pull these paths from the config
|
|
|
|
// Also notable that there are different paths for different projects
|
|
|
|
//
|
|
|
|
// TODO(matt): Handle csv's double quote escaping stuff
|
|
|
|
|
2017-04-30 03:20:31 +00:00
|
|
|
char *QuoteDir = "/home/matt/git/GitHub/insofaras/25fc16d58a297a486334";
|
2017-04-30 02:15:10 +00:00
|
|
|
if(!StringsDiffer(Speaker, "handmade_hero"))
|
|
|
|
{
|
|
|
|
QuoteDir = "/home/matt/git/GitHub/Chronister/01e754a09fd84c839ad7";
|
|
|
|
}
|
|
|
|
|
2017-04-23 02:47:42 +00:00
|
|
|
char Path[255] = {0};
|
2017-04-30 02:15:10 +00:00
|
|
|
sprintf(Path, "%s/#%s", QuoteDir, Speaker);
|
2017-04-23 02:47:42 +00:00
|
|
|
FILE *File;
|
|
|
|
if(!(File = fopen(Path, "r")))
|
|
|
|
{
|
|
|
|
perror("hmml_to_html");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fseek(File, 0, SEEK_END);
|
|
|
|
int Length = ftell(File);
|
|
|
|
fseek(File, 0, SEEK_SET);
|
|
|
|
char *Buffer;
|
|
|
|
if(!(Buffer = malloc(Length)))
|
|
|
|
{
|
|
|
|
perror("hmml_to_html");
|
|
|
|
}
|
|
|
|
fread(Buffer, Length, 1, File);
|
|
|
|
fclose(File);
|
2017-05-21 06:35:16 +00:00
|
|
|
|
|
|
|
// TODO(matt): Search the quote store in reverse
|
2017-04-23 02:47:42 +00:00
|
|
|
char *InPtr = Buffer;
|
|
|
|
|
|
|
|
while(InPtr - Buffer < Length)
|
|
|
|
{
|
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
char InID[4] = { 0 };
|
2017-04-23 02:47:42 +00:00
|
|
|
char *OutPtr = InID;
|
|
|
|
while(*InPtr != ',')
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
*OutPtr = '\0';
|
|
|
|
|
|
|
|
if(StringToInt(InID) == ID)
|
|
|
|
{
|
|
|
|
InPtr += 2;
|
|
|
|
OutPtr = Info->Date;
|
|
|
|
while(*InPtr != '"')
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
*OutPtr = '\0';
|
|
|
|
|
|
|
|
InPtr += 3;
|
|
|
|
OutPtr = Info->Text;
|
|
|
|
while(*InPtr != '\n')
|
|
|
|
{
|
|
|
|
if(*InPtr == '\\')
|
|
|
|
{
|
|
|
|
++InPtr;
|
|
|
|
}
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
*--OutPtr = '\0';
|
|
|
|
|
|
|
|
free(Buffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(*InPtr != '\n')
|
|
|
|
{
|
|
|
|
++InPtr;
|
|
|
|
}
|
|
|
|
++InPtr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(Buffer);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2017-05-21 06:35:16 +00:00
|
|
|
if(!StringsDiffer(Topic, CategoryMedium[i][0]))
|
2017-03-31 00:56:50 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *TopicsFile;
|
|
|
|
char *TopicsBuffer;
|
2017-05-21 06:35:16 +00:00
|
|
|
// TODO(matt): Consider (optionally) pulling this path from the config
|
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-05-25 20:28:52 +00:00
|
|
|
// TODO(matt): May this not just ClaimBuffer (if I can figure out how)?
|
2017-04-13 00:21:04 +00:00
|
|
|
if(!(TopicsBuffer = malloc(TopicsLength)))
|
2017-03-31 00:56:50 +00:00
|
|
|
{
|
2017-05-13 15:38:10 +00:00
|
|
|
perror("GenerateTopicColours");
|
2017-03-31 00:56:50 +00:00
|
|
|
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)
|
|
|
|
{
|
2017-05-15 01:11:11 +00:00
|
|
|
TopicsPtr += StringLength(".category.");
|
2017-04-23 00:30:37 +00:00
|
|
|
if(!StringsDifferL(SanitisePunctuation(Topic), TopicsPtr, StringLength(Topic)))
|
2017-03-31 00:56:50 +00:00
|
|
|
{
|
|
|
|
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-05-15 01:11:11 +00:00
|
|
|
fprintf(TopicsFile, ".category.%s { border: 1px solid %s; background: %s; }\n",
|
2017-04-13 23:46:21 +00:00
|
|
|
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-05-13 15:38:10 +00:00
|
|
|
perror("GenerateTopicColours");
|
2017-04-13 00:21:04 +00:00
|
|
|
return;
|
2017-03-31 00:56:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
#define CONFIG 0
|
|
|
|
|
|
|
|
#if CONFIG
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *Username;
|
|
|
|
char *Display_Name;
|
|
|
|
char *Homepage;
|
|
|
|
char *Funding_Platform;
|
|
|
|
char *Funding_Username;
|
|
|
|
unsigned int Index;
|
|
|
|
} credentials;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
credentials Credentials;
|
|
|
|
} config;
|
|
|
|
|
|
|
|
int
|
|
|
|
ParseConfig(buffer *Buffer, char *Username)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Essentially, I want to pass a Username to this, and have it write the credentials into the Config buffer
|
|
|
|
Let's start by just grabbing the stuff and printing it out
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TODO(matt): Actually figure out the "standard" config location
|
|
|
|
char Config_Location[255];
|
|
|
|
if(getenv("XDG_CONFIG_HOME"))
|
|
|
|
{
|
|
|
|
sprintf(Config_Location, "%s/hmml.conf", getenv("XDG_CONFIG_HOME"));
|
|
|
|
}
|
|
|
|
else if(getenv("HOME"))
|
|
|
|
{
|
|
|
|
sprintf(Config_Location, "%s/.config/hmml.conf", getenv("HOME"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Config file location not set");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *InFile;
|
|
|
|
if(!(InFile = fopen(Config_Location, "r")))
|
|
|
|
{
|
|
|
|
perror(Config_Location);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Reading: %s\n", Config_Location);
|
|
|
|
|
|
|
|
fseek(InFile, 0, SEEK_END);
|
|
|
|
int InSize = ftell(InFile);
|
|
|
|
fseek(InFile, 0, SEEK_SET);
|
|
|
|
|
|
|
|
char *InBuffer;
|
|
|
|
//config Config = { 0 };
|
|
|
|
|
|
|
|
if(!(InBuffer = malloc(InSize)))
|
|
|
|
{
|
|
|
|
perror("ParseConfig");
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
fread(InBuffer, InSize, 1, InFile);
|
|
|
|
fclose(InFile);
|
|
|
|
|
|
|
|
char *InPtr = InBuffer;
|
|
|
|
char OutBuffer[256];
|
|
|
|
//char *OutPtr = Config.Credentials.Display_Name;
|
|
|
|
char *OutPtr = OutBuffer;
|
|
|
|
bool Quoted = FALSE;
|
|
|
|
bool FoundCredentials, ParsingUsername = FALSE;
|
|
|
|
unsigned int ScopeDepth = 0;
|
|
|
|
|
|
|
|
while(InPtr - InBuffer < InSize)
|
|
|
|
{
|
|
|
|
switch(*InPtr)
|
|
|
|
{
|
|
|
|
case '#':
|
|
|
|
{
|
|
|
|
if(!Quoted)
|
|
|
|
{
|
|
|
|
printf(" We are commenting\n");
|
|
|
|
while(InPtr - InBuffer < InSize && *InPtr != '\n')
|
|
|
|
{
|
|
|
|
++InPtr;
|
|
|
|
}
|
|
|
|
++InPtr;
|
|
|
|
while(InPtr - InBuffer < InSize && (*InPtr == ' ' || *InPtr == '\n'))
|
|
|
|
{
|
|
|
|
++InPtr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '{':
|
|
|
|
{
|
|
|
|
if(!Quoted)
|
|
|
|
{
|
|
|
|
++ScopeDepth;
|
|
|
|
++InPtr;
|
|
|
|
while(*InPtr == '\n' || *InPtr == ' ')
|
|
|
|
{
|
|
|
|
++InPtr;
|
|
|
|
}
|
|
|
|
printf(" We have entered a scope\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '}':
|
|
|
|
{
|
|
|
|
if(!Quoted)
|
|
|
|
{
|
|
|
|
--ScopeDepth;
|
|
|
|
++InPtr;
|
|
|
|
printf(" We have left a scope\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#if 1
|
|
|
|
case ' ':
|
|
|
|
{
|
|
|
|
if(!Quoted)
|
|
|
|
{
|
|
|
|
++InPtr;
|
|
|
|
*OutPtr = '\0';
|
|
|
|
OutPtr = OutBuffer;
|
|
|
|
printf("%s\n", OutBuffer);
|
|
|
|
|
|
|
|
// TODO(matt): Switch on the OutBuffer? I have a feeling that isn't actually possible, though
|
|
|
|
if(!StringsDiffer("credentials", OutBuffer))
|
|
|
|
{
|
|
|
|
FoundCredentials = TRUE;
|
|
|
|
printf(" We have found the credentials block\n");
|
|
|
|
}
|
|
|
|
if(ParsingUsername)
|
|
|
|
{
|
|
|
|
printf(" The username is %s\n", OutBuffer);
|
|
|
|
ParsingUsername = FALSE;
|
|
|
|
}
|
|
|
|
if(FoundCredentials && (!StringsDiffer("username", OutBuffer)))
|
|
|
|
{
|
|
|
|
ParsingUsername = TRUE;
|
|
|
|
printf(" We have found the username\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case '"':
|
|
|
|
{
|
|
|
|
if(!Quoted)
|
|
|
|
{
|
|
|
|
Quoted = TRUE;
|
|
|
|
printf(" We are quoting!\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Quoted = FALSE;
|
|
|
|
printf(" We are no longer quoting!\n");
|
|
|
|
}
|
|
|
|
++InPtr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ';':
|
|
|
|
{
|
|
|
|
if(!Quoted)
|
|
|
|
{
|
|
|
|
printf(" We have reached the end of a setting\n");
|
|
|
|
++InPtr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case '\n':
|
|
|
|
{
|
|
|
|
if(!Quoted)
|
|
|
|
{
|
|
|
|
if(InPtr - InBuffer < InSize)
|
|
|
|
{
|
|
|
|
*OutPtr = '\0';
|
|
|
|
OutPtr = OutBuffer;
|
|
|
|
// TODO(matt)
|
|
|
|
if(!StringsDiffer("credentials", OutBuffer))
|
|
|
|
{
|
|
|
|
FoundCredentials = TRUE;
|
|
|
|
printf(" We have found the credentials block\n");
|
|
|
|
}
|
|
|
|
if(ParsingUsername)
|
|
|
|
{
|
|
|
|
printf(" The username is %s\n", OutBuffer);
|
|
|
|
ParsingUsername = FALSE;
|
|
|
|
}
|
|
|
|
if(FoundCredentials && (!StringsDiffer("username", OutBuffer)))
|
|
|
|
{
|
|
|
|
ParsingUsername = TRUE;
|
|
|
|
printf(" We have found the username\n");
|
|
|
|
}
|
|
|
|
printf("%s\n", OutBuffer);
|
|
|
|
++InPtr;
|
|
|
|
while(InPtr - InBuffer < InSize && *InPtr == ' ') // NOTE(matt): Skip indentation whitespace
|
|
|
|
{
|
|
|
|
++InPtr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(InPtr - InBuffer == InSize)
|
|
|
|
{
|
|
|
|
printf(" We have reached the EOF\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
while(InPtr - InBuffer < InSize)
|
|
|
|
{
|
|
|
|
while(*InPtr != '\n')
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
*OutPtr = '\0';
|
|
|
|
printf("%s\n", Config.Credentials.Display_Name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
free(InBuffer);
|
|
|
|
|
|
|
|
// Reading from the config file, parsing it inline (on the stack) and writing into the buffer *Config
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
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-05-24 21:56:36 +00:00
|
|
|
int ArenaSize = Megabytes(4);
|
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;
|
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
#if CONFIG
|
|
|
|
buffer Config;
|
|
|
|
#endif
|
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
// 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;
|
|
|
|
|
2017-03-22 02:18:31 +00:00
|
|
|
buffer Title;
|
|
|
|
buffer QuoteMenu;
|
|
|
|
buffer ReferenceMenu;
|
2017-05-21 06:35:16 +00:00
|
|
|
buffer FilterMenu;
|
|
|
|
buffer FilterTopics;
|
|
|
|
buffer FilterMedia;
|
2017-05-25 20:28:52 +00:00
|
|
|
buffer CreditsMenu;
|
|
|
|
buffer HostInfo;
|
|
|
|
buffer AnnotatorInfo;
|
2017-03-22 02:18:31 +00:00
|
|
|
|
|
|
|
buffer Player;
|
2017-05-22 15:33:53 +00:00
|
|
|
buffer Colour;
|
2017-03-22 02:18:31 +00:00
|
|
|
buffer Annotation;
|
|
|
|
buffer AnnotationHeader;
|
|
|
|
buffer AnnotationClass;
|
|
|
|
buffer AnnotationData;
|
|
|
|
buffer Text;
|
|
|
|
buffer Category;
|
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
buffer FilterState;
|
|
|
|
|
2017-03-22 02:18:31 +00:00
|
|
|
for(int FileIndex = 1; FileIndex < ArgC; ++FileIndex)
|
|
|
|
{
|
|
|
|
FILE *InFile;
|
|
|
|
if(!(InFile = fopen(Args[FileIndex], "r")))
|
|
|
|
{
|
|
|
|
perror(Args[0]);
|
|
|
|
free(MemoryArena);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
#if CONFIG
|
2017-05-24 21:56:36 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Config, "Config", Kilobytes(1));
|
2017-05-13 15:38:10 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-22 02:18:31 +00:00
|
|
|
HMML_Output HMML = hmml_parse_file(InFile);
|
|
|
|
fclose(InFile);
|
|
|
|
|
|
|
|
if(HMML.well_formed)
|
|
|
|
{
|
2017-05-22 15:33:53 +00:00
|
|
|
// NOTE(matt): Tree structure of "global" buffer dependencies
|
|
|
|
// Master
|
|
|
|
// Title
|
|
|
|
// QuoteMenu
|
|
|
|
// ReferenceMenu
|
|
|
|
// FilterMenu
|
|
|
|
// FilterTopics
|
|
|
|
// FilterMedia
|
2017-05-25 20:28:52 +00:00
|
|
|
// CreditsMenu
|
2017-05-22 15:33:53 +00:00
|
|
|
// Player
|
|
|
|
// Colour
|
|
|
|
// Annotation
|
|
|
|
// FilterState
|
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, "Master", Kilobytes(512));
|
2017-05-21 06:35:16 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Title, "Title", Kilobytes(16));
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &QuoteMenu, "QuoteMenu", Kilobytes(16));
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &ReferenceMenu, "ReferenceMenu", Kilobytes(16));
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &FilterMenu, "FilterMenu", Kilobytes(16));
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &FilterTopics, "FilterTopics", Kilobytes(8));
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &FilterMedia, "FilterMedia", Kilobytes(8));
|
2017-05-25 20:28:52 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &CreditsMenu, "CreditsMenu", Kilobytes(8));
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &HostInfo, "HostInfo", Kilobytes(1));
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotatorInfo, "AnnotatorInfo", Kilobytes(1));
|
2017-05-22 15:33:53 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Player, "Player", Kilobytes(256));
|
2017-05-22 15:33:53 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Colour, "Colour", 32);
|
2017-05-24 21:56:36 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Annotation, "Annotation", Kilobytes(8));
|
2017-05-22 15:33:53 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &FilterState, "FilterState", Kilobytes(4));
|
2017-05-21 06:35:16 +00:00
|
|
|
|
2017-04-23 00:30:37 +00:00
|
|
|
ref_info ReferencesArray[200] = { 0 };
|
2017-05-24 21:56:36 +00:00
|
|
|
category_info TopicsArray[56] = { 0 };
|
|
|
|
category_info MediaArray[8] = { 0 };
|
2017-03-22 02:18:31 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
bool HasQuoteMenu = FALSE;
|
|
|
|
bool HasReferenceMenu = FALSE;
|
2017-05-21 06:35:16 +00:00
|
|
|
bool HasFilterMenu = FALSE;
|
2017-05-25 20:28:52 +00:00
|
|
|
bool HasCreditsMenu = FALSE;
|
2017-03-29 03:38:12 +00:00
|
|
|
|
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-05-24 21:56:36 +00:00
|
|
|
int UniqueTopics = 0;
|
|
|
|
int UniqueMedia = 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
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
BuildCredits(&CreditsMenu, &HostInfo, &AnnotatorInfo, &HasCreditsMenu, HMML.metadata.member, HMML.metadata.annotator);
|
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
#if DEBUG
|
|
|
|
printf(" --- Entering Annotations Loop ---\n");
|
|
|
|
#endif
|
|
|
|
|
2017-03-22 02:18:31 +00:00
|
|
|
for(int AnnotationIndex = 0; AnnotationIndex < HMML.annotation_count; ++AnnotationIndex)
|
|
|
|
{
|
2017-05-21 06:35:16 +00:00
|
|
|
#if DEBUG
|
|
|
|
printf("%d\n", AnnotationIndex);
|
|
|
|
#endif
|
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-05-22 21:37:00 +00:00
|
|
|
bool HasMedium = FALSE;
|
2017-03-29 03:38:12 +00:00
|
|
|
bool HasQuote = FALSE;
|
|
|
|
bool HasReference = FALSE;
|
|
|
|
|
2017-04-23 02:47:42 +00:00
|
|
|
quote_info QuoteInfo = { 0 };
|
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
// NOTE(matt): Tree structure of "annotation local" buffer dependencies
|
|
|
|
// AnnotationHeader
|
|
|
|
// AnnotationClass
|
|
|
|
// AnnotationData
|
|
|
|
// Text
|
|
|
|
// Category
|
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationHeader, "AnnotationHeader", 512);
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, "AnnotationClass", 256);
|
2017-05-24 21:56:36 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, "AnnotationData", 256);
|
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, "Text", Kilobytes(4));
|
2017-05-22 15:33:53 +00:00
|
|
|
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, "Category", 256);
|
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
|
|
|
{
|
2017-05-21 06:35:16 +00:00
|
|
|
if(!HasFilterMenu)
|
|
|
|
{
|
|
|
|
HasFilterMenu = TRUE;
|
|
|
|
}
|
2017-05-24 21:56:36 +00:00
|
|
|
BuildFilter(TopicsArray, &UniqueTopics, MediaArray, &UniqueMedia, "authored");
|
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
|
2017-05-21 06:35:16 +00:00
|
|
|
// We should get instructions on how to get this info in the config
|
2017-04-13 23:46:21 +00:00
|
|
|
"<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
|
2017-05-21 06:35:16 +00:00
|
|
|
// We should get instructions on how to get this info in the config
|
2017-04-13 23:46:21 +00:00
|
|
|
"<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-05-21 06:35:16 +00:00
|
|
|
// TODO(matt): Maybe stuff this into BuildCategories
|
|
|
|
if(!HasFilterMenu)
|
|
|
|
{
|
|
|
|
HasFilterMenu = TRUE;
|
|
|
|
}
|
2017-05-24 21:56:36 +00:00
|
|
|
BuildFilter(TopicsArray, &UniqueTopics, MediaArray, &UniqueMedia, Anno->markers[MarkerIndex].marker);
|
2017-05-22 21:37:00 +00:00
|
|
|
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, 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)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
2017-05-13 15:38:10 +00:00
|
|
|
" <div class=\"menu\">\n"
|
2017-03-29 03:38:12 +00:00
|
|
|
" <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);
|
2017-04-23 00:30:37 +00:00
|
|
|
hmml_free(&HMML);
|
|
|
|
free(MemoryArena);
|
2017-04-19 01:10:45 +00:00
|
|
|
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)
|
|
|
|
{
|
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);
|
|
|
|
hmml_free(&HMML);
|
2017-04-23 00:30:37 +00:00
|
|
|
free(MemoryArena);
|
2017-04-19 01:10:45 +00:00
|
|
|
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
|
|
|
hmml_free(&HMML);
|
2017-04-23 00:30:37 +00:00
|
|
|
free(MemoryArena);
|
2017-04-19 01:10:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2017-03-29 03:38:12 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
if(RefIndex > 1 && Anno->references[RefIndex].offset == Anno->references[RefIndex-1].offset)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Text, "<sup>,%d</sup>", RefIdentifier);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Text, "<sup>%d</sup>", RefIdentifier);
|
|
|
|
}
|
2017-03-29 03:38:12 +00:00
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&QuoteMenu,
|
2017-05-13 15:38:10 +00:00
|
|
|
" <div class=\"menu\">\n"
|
2017-03-29 03:38:12 +00:00
|
|
|
" <span>Quotes ▼</span>\n"
|
|
|
|
" <div class=\"mouse_catcher\"></div>\n"
|
|
|
|
" <div class=\"refs\">\n");
|
|
|
|
|
|
|
|
HasQuoteMenu = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!HasReference)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, " data-ref=\"&#%d;", QuoteIdentifier);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, ",&#%d;", QuoteIdentifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
HasQuote = TRUE;
|
|
|
|
|
2017-04-23 02:47:42 +00:00
|
|
|
|
|
|
|
if(BuildQuote(&QuoteInfo, HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member, Anno->quote.id) == 1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d: Quote #%s %d not found! Consider pulling the latest quotes\n",
|
|
|
|
Args[FileIndex],
|
|
|
|
Anno->line,
|
|
|
|
HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member,
|
|
|
|
Anno->quote.id);
|
|
|
|
hmml_free(&HMML);
|
|
|
|
free(MemoryArena);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
CopyStringToBuffer(&QuoteMenu,
|
|
|
|
" <span data-id=\"&#%d;\" class=\"ref\">\n"
|
|
|
|
" <span class=\"ref_content\">\n"
|
2017-04-23 02:47:42 +00:00
|
|
|
" <div class=\"source\">Quote %d</div>\n"
|
2017-03-29 03:38:12 +00:00
|
|
|
" <div class=\"ref_title\">%s</div>\n"
|
2017-04-23 02:47:42 +00:00
|
|
|
" <div class=\"quote_byline\">—%s, %s</div>\n"
|
2017-03-29 03:38:12 +00:00
|
|
|
" </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,
|
2017-04-23 02:47:42 +00:00
|
|
|
QuoteInfo.Text,
|
|
|
|
HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member,
|
|
|
|
QuoteInfo.Date,
|
2017-03-29 03:38:12 +00:00
|
|
|
TimecodeToSeconds(Anno->time),
|
|
|
|
QuoteIdentifier,
|
|
|
|
Anno->time);
|
|
|
|
if(!Anno->text[0])
|
|
|
|
{
|
2017-04-23 02:47:42 +00:00
|
|
|
CopyStringToBuffer(&Text, "“%s”", QuoteInfo.Text);
|
2017-03-29 03:38:12 +00:00
|
|
|
}
|
|
|
|
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-05-21 06:35:16 +00:00
|
|
|
// TODO(matt): Maybe stuff this into BuildCategories
|
|
|
|
if(!HasFilterMenu)
|
|
|
|
{
|
|
|
|
HasFilterMenu = TRUE;
|
|
|
|
}
|
|
|
|
if(Anno->markers[MarkerIndex].marker)
|
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
BuildFilter(TopicsArray, &UniqueTopics, MediaArray, &UniqueMedia, Anno->markers[MarkerIndex].marker);
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
2017-05-22 21:37:00 +00:00
|
|
|
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, Anno->markers[MarkerIndex].marker);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!HasMedium)
|
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
BuildFilter(TopicsArray, &UniqueTopics, MediaArray, &UniqueMedia, "default");
|
2017-05-22 21:37:00 +00:00
|
|
|
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, "default");
|
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-03-29 03:38:12 +00:00
|
|
|
|
|
|
|
if(HasQuote || HasReference)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, "\"");
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&AnnotationHeader, &AnnotationData);
|
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
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Annotation, &AnnotationHeader);
|
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-05-21 06:35:16 +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-03-25 02:07:55 +00:00
|
|
|
}
|
2017-05-22 21:37:00 +00:00
|
|
|
// NOTE(matt): This feels a bit janky...
|
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-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
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
// NOTE(matt): Tree structure of "annotation local" buffer dependencies
|
|
|
|
// Category
|
|
|
|
// Text
|
|
|
|
// AnnotationData
|
|
|
|
// AnnotationClass
|
|
|
|
// AnnotationHeader
|
|
|
|
|
|
|
|
DeclaimBuffer(&Category, &ClaimedMemory);
|
2017-05-21 06:35:16 +00:00
|
|
|
DeclaimBuffer(&Text, &ClaimedMemory);
|
2017-05-22 15:33:53 +00:00
|
|
|
DeclaimBuffer(&AnnotationData, &ClaimedMemory);
|
2017-05-21 06:35:16 +00:00
|
|
|
DeclaimBuffer(&AnnotationClass, &ClaimedMemory);
|
|
|
|
DeclaimBuffer(&AnnotationHeader, &ClaimedMemory);
|
2017-05-22 15:33:53 +00:00
|
|
|
Annotation.Ptr = Annotation.Location;
|
2017-03-22 02:18:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
#if DEBUG
|
2017-05-22 15:33:53 +00:00
|
|
|
printf(" --- End of Annotations Loop ---\n\n");
|
2017-05-21 06:35:16 +00:00
|
|
|
#endif
|
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-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-03-29 03:38:12 +00:00
|
|
|
}
|
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
if(HasFilterMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&FilterState, "var filterState = {\n");
|
2017-05-24 21:56:36 +00:00
|
|
|
for(int i = 0; i < UniqueTopics; ++i)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&FilterState, "\"%s\":\t{ \"type\": \"%s\",\t\"off\": false },\n",
|
|
|
|
TopicsArray[i].Marker, "topic");
|
|
|
|
}
|
|
|
|
for(int i = 0; i < UniqueMedia; ++i)
|
2017-05-21 06:35:16 +00:00
|
|
|
{
|
|
|
|
CopyStringToBuffer(&FilterState, "\"%s\":\t{ \"type\": \"%s\",\t\"off\": false },\n",
|
2017-05-24 21:56:36 +00:00
|
|
|
MediaArray[i].Marker, "medium");
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
|
|
|
CopyStringToBuffer(&FilterState, "};\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
CopyStringToBuffer(&FilterMenu,
|
|
|
|
" <div class=\"menu filter\">\n"
|
|
|
|
" <span><img src=\"hues_HCL.png\"></span>\n"
|
|
|
|
" <div class=\"filter_container\">\n"
|
|
|
|
" <div class=\"filter_mode inclusive\">Filter mode: </div>\n"
|
|
|
|
" <div class=\"filters\">\n");
|
|
|
|
|
|
|
|
{
|
|
|
|
bool HasTopic = FALSE;
|
|
|
|
bool HasMedium = FALSE;
|
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
for(int i = 0; i < UniqueTopics; ++i)
|
2017-05-21 06:35:16 +00:00
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
if(!HasTopic)
|
2017-05-21 06:35:16 +00:00
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
CopyStringToBuffer(&FilterMenu,
|
|
|
|
" <div class=\"filter_topics\">\n"
|
|
|
|
" <div class=\"filter_title\">Topics</div>\n");
|
|
|
|
|
|
|
|
HasTopic = TRUE;
|
|
|
|
}
|
|
|
|
CopyStringToBuffer(&FilterTopics,
|
|
|
|
" <div class=\"filter_content %s\">\n"
|
|
|
|
" <span class=\"icon category %s\"></span><span class=\"text\">%s</span>\n"
|
|
|
|
" </div>\n",
|
|
|
|
TopicsArray[i].Marker,
|
|
|
|
TopicsArray[i].Marker,
|
|
|
|
TopicsArray[i].Marker);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < UniqueMedia; ++i)
|
|
|
|
{
|
|
|
|
if(!HasMedium)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&FilterMedia,
|
2017-05-21 06:35:16 +00:00
|
|
|
" <div class=\"filter_media\">\n"
|
|
|
|
" <div class=\"filter_title\">Media</div>\n");
|
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
HasMedium = TRUE;
|
|
|
|
}
|
2017-05-21 06:35:16 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
int j;
|
|
|
|
for(j = 0; j < ArrayCount(CategoryMedium); ++j)
|
|
|
|
{
|
|
|
|
if(!StringsDiffer(MediaArray[i].Marker, CategoryMedium[j][0]))
|
2017-05-21 06:35:16 +00:00
|
|
|
{
|
2017-05-24 21:56:36 +00:00
|
|
|
break;
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
2017-05-24 21:56:36 +00:00
|
|
|
}
|
2017-05-21 06:35:16 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
CopyStringToBuffer(&FilterMedia,
|
2017-05-21 06:35:16 +00:00
|
|
|
" <div class=\"filter_content %s\">\n"
|
|
|
|
" <span class=\"icon\">%s</span><span class=\"text\">%s</span>\n"
|
|
|
|
" </div>\n",
|
2017-05-24 21:56:36 +00:00
|
|
|
MediaArray[i].Marker,
|
2017-05-21 06:35:16 +00:00
|
|
|
CategoryMedium[j][1],
|
|
|
|
CategoryMedium[j][2]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(HasTopic)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&FilterTopics,
|
|
|
|
" </div>\n");
|
|
|
|
CopyBuffer(&FilterMenu, &FilterTopics);
|
|
|
|
}
|
|
|
|
if(HasMedium)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&FilterMedia,
|
|
|
|
" </div>\n");
|
|
|
|
CopyBuffer(&FilterMenu, &FilterMedia);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CopyStringToBuffer(&FilterMenu,
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyBuffer(&Title, &FilterMenu);
|
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
if(HasCreditsMenu)
|
|
|
|
{
|
|
|
|
CopyBuffer(&Title, &CreditsMenu);
|
|
|
|
}
|
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
#if CONFIG
|
|
|
|
// TODO(matt): Here is where I test ParseConfig
|
|
|
|
ParseConfig(&Config, HMML.metadata.annotator);
|
|
|
|
#endif
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Title,
|
2017-05-25 20:28:52 +00:00
|
|
|
" </div>\n");
|
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!
|
2017-05-21 06:35:16 +00:00
|
|
|
#if DEBUG
|
|
|
|
printf("Buffer Collation\n\n");
|
|
|
|
#endif
|
2017-03-22 02:18:31 +00:00
|
|
|
|
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"
|
2017-05-25 20:28:52 +00:00
|
|
|
" <title>%s</title>\n" // TODO(matt): Add the full name of the project, parsed from a config
|
2017-03-22 02:18:31 +00:00
|
|
|
"\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-05-24 21:56:36 +00:00
|
|
|
" <body>\n",
|
|
|
|
HMML.metadata.title,
|
|
|
|
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);
|
|
|
|
CopyBuffer(&Master, &Player);
|
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"
|
2017-05-21 06:35:16 +00:00
|
|
|
"var filter = document.querySelector(\".filter\");\n"
|
|
|
|
"var filterModeElement = filter.querySelector(\".filter_mode\");\n"
|
|
|
|
"var filterMode = filterModeElement.classList[1];\n");
|
|
|
|
|
|
|
|
if(HasFilterMenu)
|
|
|
|
{
|
|
|
|
CopyBuffer(&Master, &FilterState);
|
|
|
|
}
|
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
// NOTE(matt): Tree structure of "global" buffer dependencies
|
|
|
|
// FilterState
|
|
|
|
// Annotation
|
|
|
|
// Colour
|
|
|
|
// Player
|
2017-05-25 20:28:52 +00:00
|
|
|
// AnnotatorInfo
|
|
|
|
// HostInfo
|
|
|
|
// CreditsMenu
|
2017-05-22 15:33:53 +00:00
|
|
|
// FilterMedia
|
|
|
|
// FilterTopics
|
|
|
|
// FilterMenu
|
|
|
|
// ReferenceMenu
|
|
|
|
// QuoteMenu
|
|
|
|
// Title
|
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
DeclaimBuffer(&FilterState, &ClaimedMemory);
|
2017-05-22 15:33:53 +00:00
|
|
|
DeclaimBuffer(&Annotation, &ClaimedMemory);
|
|
|
|
DeclaimBuffer(&Colour, &ClaimedMemory);
|
|
|
|
DeclaimBuffer(&Player, &ClaimedMemory);
|
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
DeclaimBuffer(&AnnotatorInfo, &ClaimedMemory);
|
|
|
|
DeclaimBuffer(&HostInfo, &ClaimedMemory);
|
|
|
|
DeclaimBuffer(&CreditsMenu, &ClaimedMemory);
|
2017-05-21 06:35:16 +00:00
|
|
|
DeclaimBuffer(&FilterMedia, &ClaimedMemory);
|
|
|
|
DeclaimBuffer(&FilterTopics, &ClaimedMemory);
|
|
|
|
DeclaimBuffer(&FilterMenu, &ClaimedMemory);
|
2017-05-22 15:33:53 +00:00
|
|
|
DeclaimBuffer(&ReferenceMenu, &ClaimedMemory);
|
|
|
|
DeclaimBuffer(&QuoteMenu, &ClaimedMemory);
|
2017-05-21 06:35:16 +00:00
|
|
|
DeclaimBuffer(&Title, &ClaimedMemory);
|
|
|
|
|
|
|
|
CopyStringToBuffer(&Master,
|
|
|
|
"// Filter Mode Toggle\n"
|
|
|
|
"var testMarkers = document.querySelectorAll(\".marker\");\n"
|
|
|
|
"filterModeElement.addEventListener(\"click\", function(ev) {\n"
|
|
|
|
" if(filterMode == \"inclusive\")\n"
|
|
|
|
" {\n"
|
|
|
|
" filterModeElement.classList.remove(\"inclusive\");\n"
|
|
|
|
" filterModeElement.classList.add(\"exclusive\");\n"
|
|
|
|
" filterMode = \"exclusive\";\n"
|
|
|
|
"\n"
|
|
|
|
" for(var i = 0; i < testMarkers.length; ++i)\n"
|
|
|
|
" {\n"
|
|
|
|
" var testCategories = testMarkers[i].classList;\n"
|
|
|
|
" for(var j = 0; j < testCategories.length; ++j)\n"
|
|
|
|
" {\n"
|
|
|
|
" if((testCategories[j].startsWith(\"off_\")) && !testMarkers[i].classList.contains(\"skip\"))\n"
|
|
|
|
" {\n"
|
|
|
|
" testMarkers[i].classList.add(\"skip\");\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" else\n"
|
|
|
|
" {\n"
|
|
|
|
" filterModeElement.classList.remove(\"exclusive\");\n"
|
|
|
|
" filterModeElement.classList.add(\"inclusive\");\n"
|
|
|
|
" filterMode = \"inclusive\";\n"
|
|
|
|
"\n"
|
|
|
|
" for(var i = 0; i < testMarkers.length; ++i)\n"
|
|
|
|
" {\n"
|
|
|
|
" var testCategories = testMarkers[i].classList;\n"
|
|
|
|
" for(var j = 0; j < testCategories.length; ++j)\n"
|
|
|
|
" {\n"
|
|
|
|
" if((testCategories[j] in filterState || testCategories[j].startsWith(\"cat_\")) && testMarkers[i].classList.contains(\"skip\"))\n"
|
|
|
|
" {\n"
|
|
|
|
" testMarkers[i].classList.remove(\"skip\");\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
"});\n"
|
|
|
|
"\n"
|
|
|
|
"// Filter Toggle\n"
|
|
|
|
"var filterCategories = filter.querySelectorAll(\".filter_topics .filter_content,.filter_media .filter_content\");\n"
|
|
|
|
"for(var i = 0; i < filterCategories.length; ++i)\n"
|
|
|
|
"{\n"
|
|
|
|
" filterCategories[i].addEventListener(\"click\", function(ev) {\n"
|
|
|
|
" var selectedCategory = this.classList[1];\n"
|
|
|
|
" filterState[selectedCategory].off = !filterState[selectedCategory].off;\n"
|
|
|
|
"\n"
|
|
|
|
" if(filterState[selectedCategory].off)\n"
|
|
|
|
" {\n"
|
|
|
|
" this.classList.add(\"off\");\n"
|
|
|
|
" var testMarkers = document.querySelectorAll(\".marker.\" + selectedCategory + \", .marker.cat_\" + selectedCategory);\n"
|
|
|
|
" for(var j = 0; j < testMarkers.length; ++j)\n"
|
|
|
|
" {\n"
|
|
|
|
" if(filterState[selectedCategory].type == \"topic\")\n"
|
|
|
|
" {\n"
|
|
|
|
" testMarkers[j].classList.remove(\"cat_\" + selectedCategory);\n"
|
|
|
|
" testMarkers[j].classList.add(\"off_\" + selectedCategory);\n"
|
|
|
|
" var markerCategories = testMarkers[j].querySelectorAll(\".category.\" + selectedCategory);\n"
|
|
|
|
" for(var k = 0; k < markerCategories.length; ++k)\n"
|
|
|
|
" {\n"
|
|
|
|
" if(markerCategories[k].classList.contains(selectedCategory))\n"
|
|
|
|
" {\n"
|
|
|
|
" markerCategories[k].classList.add(\"off\");\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" else\n"
|
|
|
|
" {\n"
|
|
|
|
" testMarkers[j].classList.remove(selectedCategory);\n"
|
|
|
|
" testMarkers[j].classList.add(\"off_\" + selectedCategory);\n"
|
|
|
|
" }\n"
|
|
|
|
"\n"
|
|
|
|
" Skipping = 1;\n"
|
|
|
|
" if(filterMode == \"exclusive\")\n"
|
|
|
|
" {\n"
|
|
|
|
" testMarkers[j].classList.add(\"skip\");\n"
|
|
|
|
" }\n"
|
|
|
|
" else\n"
|
|
|
|
" {\n"
|
|
|
|
" var markerClasses = testMarkers[j].classList;\n"
|
|
|
|
" for(var k = 0; k < markerClasses.length; ++k)\n"
|
|
|
|
" {\n"
|
|
|
|
" if(markerClasses[k] in filterState || markerClasses[k].replace(/^cat_/, \"\") in filterState)\n"
|
|
|
|
" {\n"
|
|
|
|
" Skipping = 0;\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" if(Skipping)\n"
|
|
|
|
" {\n"
|
|
|
|
" testMarkers[j].classList.add(\"skip\");\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
"\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" else\n"
|
|
|
|
" {\n"
|
|
|
|
" this.classList.remove(\"off\");\n"
|
|
|
|
" var testMarkers = document.querySelectorAll(\".marker.off_\" + selectedCategory);\n"
|
|
|
|
" for(var j = 0; j < testMarkers.length; ++j)\n"
|
|
|
|
" {\n"
|
|
|
|
" if(filterState[selectedCategory].type == \"topic\")\n"
|
|
|
|
" {\n"
|
|
|
|
" testMarkers[j].classList.remove(\"off_\" + selectedCategory);\n"
|
|
|
|
" testMarkers[j].classList.add(\"cat_\" + selectedCategory);\n"
|
|
|
|
" var markerCategories = testMarkers[j].querySelectorAll(\".category.\" + selectedCategory);\n"
|
|
|
|
" for(var k = 0; k < markerCategories.length; ++k)\n"
|
|
|
|
" {\n"
|
|
|
|
" if(markerCategories[k].classList.contains(selectedCategory))\n"
|
|
|
|
" {\n"
|
|
|
|
" markerCategories[k].classList.remove(\"off\");\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" else\n"
|
|
|
|
" {\n"
|
|
|
|
" testMarkers[j].classList.remove(\"off_\" + selectedCategory);\n"
|
|
|
|
" testMarkers[j].classList.add(selectedCategory);\n"
|
|
|
|
" }\n"
|
|
|
|
"\n"
|
|
|
|
" Skipping = 0;\n"
|
|
|
|
" if(filterMode == \"inclusive\")\n"
|
|
|
|
" {\n"
|
|
|
|
" testMarkers[j].classList.remove(\"skip\");\n"
|
|
|
|
" }\n"
|
|
|
|
" else\n"
|
|
|
|
" {\n"
|
|
|
|
" var markerClasses = testMarkers[j].classList;\n"
|
|
|
|
" for(var k = 0; k < markerClasses.length; ++k)\n"
|
|
|
|
" {\n"
|
|
|
|
" if(markerClasses[k].startsWith(\"off_\"))\n"
|
|
|
|
" {\n"
|
|
|
|
" Skipping = 1;\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" if(!Skipping)\n"
|
|
|
|
" {\n"
|
|
|
|
" testMarkers[j].classList.remove(\"skip\");\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" }\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 resetFade()\n"
|
|
|
|
"{\n"
|
|
|
|
" filter.classList.remove(\"responsible\");\n"
|
|
|
|
" filter.querySelector(\".filter_mode\").classList.remove(\"responsible\");\n"
|
|
|
|
" var responsibleCategories = filter.querySelectorAll(\".filter_content.responsible\");\n"
|
|
|
|
" for(var i = 0; i < responsibleCategories.length; ++i)\n"
|
|
|
|
" {\n"
|
|
|
|
" responsibleCategories[i].classList.remove(\"responsible\");\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"var sourceMenus = document.querySelectorAll(\".menu\");\n"
|
|
|
|
"function onRefChanged(ref, element) {\n"
|
|
|
|
" if(element.classList.contains(\"skip\"))\n"
|
|
|
|
" {\n"
|
|
|
|
" if(!filter.classList.contains(\"responsible\"))\n"
|
|
|
|
" {\n"
|
|
|
|
" filter.classList.add(\"responsible\");\n"
|
|
|
|
" }\n"
|
|
|
|
"\n"
|
|
|
|
" for(var selector = 0; selector < element.classList.length; ++selector)\n"
|
|
|
|
" {\n"
|
|
|
|
" if(element.classList[selector].startsWith(\"off_\"))\n"
|
|
|
|
" {\n"
|
|
|
|
" if(!filter.querySelector(\".filter_content.\" + element.classList[selector].replace(/^off_/, \"\")).classList.contains(\"responsible\"))\n"
|
|
|
|
" {\n"
|
|
|
|
" filter.querySelector(\".filter_content.\" + element.classList[selector].replace(/^off_/, \"\")).classList.add(\"responsible\");\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" if((element.classList[selector].startsWith(\"cat_\") || element.classList[selector] in filterState))\n"
|
|
|
|
" {\n"
|
|
|
|
" if(!filter.querySelector(\".filter_mode\").classList.add(\"responsible\"))\n"
|
|
|
|
" {\n"
|
|
|
|
" filter.querySelector(\".filter_mode\").classList.add(\"responsible\");\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" setTimeout(resetFade, 8000);\n"
|
|
|
|
" }\n"
|
|
|
|
" player.jumpToNextMarker();\n"
|
|
|
|
" return;\n"
|
|
|
|
" }\n"
|
|
|
|
"\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");
|
|
|
|
|
2017-03-22 02:18:31 +00:00
|
|
|
FILE *OutFile;
|
|
|
|
if(!(OutFile = fopen("out.html", "w")))
|
|
|
|
{
|
|
|
|
perror(Args[0]);
|
2017-04-23 00:30:37 +00:00
|
|
|
hmml_free(&HMML);
|
|
|
|
free(MemoryArena);
|
2017-03-22 02:18:31 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
fwrite(Master.Location, Master.Ptr - Master.Location, 1, OutFile);
|
|
|
|
fclose(OutFile);
|
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
DeclaimBuffer(&Master, &ClaimedMemory);
|
2017-03-22 02:18:31 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|