2017-03-10 14:19:25 +00:00
|
|
|
#if 0
|
|
|
|
ctime -begin ${0%.*}.ctm
|
2017-08-09 00:57:09 +00:00
|
|
|
gcc -g -no-pie -fsanitize=address -Wall -std=c99 -pipe $0 -o ${0%.*} hmml.a -lcurl
|
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-06-25 18:05:58 +00:00
|
|
|
#include <getopt.h> // NOTE(matt): getopts
|
2017-05-25 20:28:52 +00:00
|
|
|
//#include "config.h" // TODO(matt): Implement config.h
|
2017-08-09 00:57:09 +00:00
|
|
|
#include <curl/curl.h>
|
2017-08-10 01:05:41 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <sys/stat.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-06-10 16:47:47 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
EDITION_SINGLE = 0,
|
|
|
|
EDITION_PROJECT = 1,
|
|
|
|
EDITION_NETWORK = 2
|
|
|
|
} EDITION;
|
|
|
|
|
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-07-29 23:01:39 +00:00
|
|
|
#define REF_MAX_IDENTIFIER 64
|
2017-05-13 15:38:10 +00:00
|
|
|
|
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] =
|
|
|
|
{
|
2017-06-21 19:38:57 +00:00
|
|
|
{ "Miblo", "Matt Mascarenhas", "http://miblodelcarpio.co.uk", "cinera_icon_patreon.png", "https://patreon.com/miblo"},
|
|
|
|
{ "miotatsu", "Mio Iwakura", "http://riscy.tv/", "cinera_icon_patreon.png", "https://patreon.com/miotatsu"},
|
2017-05-25 20:28:52 +00:00
|
|
|
{ "nothings", "Sean Barrett", "https://nothings.org/", "", ""},
|
2017-06-21 19:38:57 +00:00
|
|
|
{ "cmuratori", "Casey Muratori", "https://handmadehero.org", "cinera_icon_patreon.png", "https://patreon.com/cmuratori"},
|
2017-05-25 20:28:52 +00:00
|
|
|
{ "fierydrake", "Mike Tunnicliffe", "", "", ""},
|
2017-06-21 19:38:57 +00:00
|
|
|
{ "abnercoimbre", "Abner Coimbre", "https://handmade.network/m/abnercoimbre", "cinera_icon_patreon.png", "https://patreon.com/handmade_dev"},
|
2017-05-25 20:28:52 +00:00
|
|
|
};
|
|
|
|
|
2017-06-10 16:47:47 +00:00
|
|
|
#define EDITION EDITION_SINGLE
|
|
|
|
|
2017-03-25 02:07:55 +00:00
|
|
|
#define ArrayCount(A) sizeof(A)/sizeof(*(A))
|
|
|
|
|
2017-07-29 00:36:14 +00:00
|
|
|
#define ClaimBuffer(MemoryArena, ClaimedMemory, Buffer, ID, Size) if(__ClaimBuffer(MemoryArena, ClaimedMemory, Buffer, ID, Size))\
|
|
|
|
{\
|
|
|
|
fprintf(stderr, "%s:%d: MemoryArena cannot contain %s of size %d\n", __FILE__, __LINE__, ID, Size);\
|
|
|
|
hmml_free(&HMML);\
|
|
|
|
FreeBuffer(MemoryArena);\
|
|
|
|
return 1;\
|
|
|
|
};
|
|
|
|
|
2017-03-16 00:56:58 +00:00
|
|
|
void
|
2017-07-29 00:36:14 +00:00
|
|
|
FreeBuffer(buffer *Buffer)
|
|
|
|
{
|
|
|
|
free(Buffer->Location);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
__ClaimBuffer(buffer *MemoryArena, int *ClaimedMemory, buffer *Buffer, char *ID, int Size)
|
2017-03-16 00:56:58 +00:00
|
|
|
{
|
2017-07-29 00:36:14 +00:00
|
|
|
if(*ClaimedMemory + Size > MemoryArena->Size)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
Buffer->Location = MemoryArena->Location + *ClaimedMemory;
|
2017-03-16 00:56:58 +00:00
|
|
|
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"
|
2017-06-25 18:05:58 +00:00
|
|
|
" Total ClaimedMemory: %d\n\n", Buffer->ID, Buffer->Size, *ClaimedMemory);
|
2017-05-21 06:35:16 +00:00
|
|
|
#endif
|
2017-07-29 00:36:14 +00:00
|
|
|
return 0;
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeclaimBuffer(buffer *Buffer, int *ClaimedMemory)
|
|
|
|
{
|
|
|
|
*Buffer->Location = '\0';
|
|
|
|
*ClaimedMemory -= Buffer->Size;
|
|
|
|
#if DEBUG
|
|
|
|
printf("Declaimed: %s\n"
|
2017-06-25 18:05:58 +00:00
|
|
|
" Total ClaimedMemory: %d\n\n", Buffer->ID, *ClaimedMemory);
|
2017-05-21 06:35:16 +00:00
|
|
|
#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-06-25 18:22:54 +00:00
|
|
|
|
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';
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-10 14:19:25 +00:00
|
|
|
++Timecode;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-04-13 00:21:04 +00:00
|
|
|
//if(HMS[0] > 59 || HMS[1] > 59 || Timecode[-1] == ':') { return FALSE; }
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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-06-13 22:13:03 +00:00
|
|
|
int
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(char *Dest, char *String)
|
|
|
|
{
|
2017-06-13 22:13:03 +00:00
|
|
|
int Length = 0;
|
2017-06-07 23:47:47 +00:00
|
|
|
while(*String)
|
|
|
|
{
|
|
|
|
*Dest++ = *String++;
|
2017-06-13 22:13:03 +00:00
|
|
|
++Length;
|
2017-06-07 23:47:47 +00:00
|
|
|
}
|
2017-06-15 22:10:36 +00:00
|
|
|
*Dest = '\0';
|
2017-06-13 22:13:03 +00:00
|
|
|
return Length;
|
2017-06-07 23:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
StringLength(char *String)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
while(String[i])
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
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);
|
2017-06-03 01:32:18 +00:00
|
|
|
int Length = vsnprintf(Dest->Ptr, Dest->Size - (Dest->Ptr - Dest->Location), Format, Args);
|
2017-03-23 00:34:59 +00:00
|
|
|
va_end(Args);
|
2017-05-21 06:35:16 +00:00
|
|
|
// TODO(matt):
|
|
|
|
{
|
|
|
|
if(Length + (Dest->Ptr - Dest->Location) >= Dest->Size)
|
|
|
|
{
|
2017-06-21 23:16:09 +00:00
|
|
|
fprintf(stderr, "CopyStringToBuffer: %s cannot accommodate %d-character string:\n"
|
|
|
|
"\n"
|
2017-06-23 14:47:48 +00:00
|
|
|
"%s\n", Dest->ID, Length, Format);
|
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-06-07 23:47:47 +00:00
|
|
|
void
|
|
|
|
CopyStringToBufferHTMLSafe(buffer *Dest, char *String)
|
|
|
|
{
|
|
|
|
while(*String)
|
|
|
|
{
|
|
|
|
if(Dest->Ptr - Dest->Location >= Dest->Size)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "CopyStringToBufferHTMLSafe: %s cannot accommodate %d-character string\n", Dest->ID, StringLength(String));
|
|
|
|
__asm__("int3");
|
|
|
|
}
|
|
|
|
switch(*String)
|
|
|
|
{
|
|
|
|
case '<':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(Dest, "<");
|
|
|
|
String++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
case '>':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(Dest, ">");
|
|
|
|
String++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
case '&':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(Dest, "&");
|
|
|
|
String++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
case '\"':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(Dest, """);
|
|
|
|
String++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
case '\'':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(Dest, "'");
|
|
|
|
String++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
default:
|
2017-06-25 18:05:58 +00:00
|
|
|
*Dest->Ptr++ = *String++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-10 16:47:47 +00:00
|
|
|
void
|
|
|
|
CopyStringToBufferCSVSafe(buffer *Dest, char *String)
|
|
|
|
{
|
|
|
|
while(*String)
|
|
|
|
{
|
|
|
|
if(Dest->Ptr - Dest->Location >= Dest->Size)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "CopyStringToBufferHTMLSafe: %s cannot accommodate %d-character string\n", Dest->ID, StringLength(String));
|
|
|
|
__asm__("int3");
|
|
|
|
}
|
|
|
|
switch(*String)
|
|
|
|
{
|
|
|
|
case '<':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(Dest, "<");
|
|
|
|
String++;
|
|
|
|
break;
|
2017-06-10 16:47:47 +00:00
|
|
|
case '>':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(Dest, ">");
|
|
|
|
String++;
|
|
|
|
break;
|
2017-06-10 16:47:47 +00:00
|
|
|
case '&':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(Dest, "&");
|
|
|
|
String++;
|
|
|
|
break;
|
2017-06-10 16:47:47 +00:00
|
|
|
case '\"':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(Dest, """);
|
|
|
|
String += 2;
|
|
|
|
break;
|
2017-06-10 16:47:47 +00:00
|
|
|
case '\'':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(Dest, "'");
|
|
|
|
String++;
|
|
|
|
break;
|
2017-06-10 16:47:47 +00:00
|
|
|
default:
|
2017-06-25 18:05:58 +00:00
|
|
|
*Dest->Ptr++ = *String++;
|
|
|
|
break;
|
2017-06-10 16:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 01:45:16 +00:00
|
|
|
int
|
2017-06-13 22:13:03 +00:00
|
|
|
StringsDiffer(char *A, char *B) // NOTE(matt): Two null-terminated strings
|
2017-03-17 01:45:16 +00:00
|
|
|
{
|
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
|
2017-06-13 22:13:03 +00:00
|
|
|
StringsDifferT(char *A, // NOTE(matt): Null-terminated string
|
|
|
|
char *B, // NOTE(matt): Not null-terminated string (e.g. one mid-buffer)
|
2017-06-16 07:55:59 +00:00
|
|
|
char Terminator // NOTE(matt): Caller definable terminator. Pass 0 to only match on the extent of A
|
2017-06-13 22:13:03 +00:00
|
|
|
)
|
2017-04-23 00:30:37 +00:00
|
|
|
{
|
2017-06-13 22:13:03 +00:00
|
|
|
int ALength = StringLength(A);
|
2017-04-23 00:30:37 +00:00
|
|
|
int i = 0;
|
2017-06-13 22:13:03 +00:00
|
|
|
while(i < ALength && A[i] && A[i] == B[i])
|
2017-04-23 00:30:37 +00:00
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
2017-06-13 22:13:03 +00:00
|
|
|
if((!Terminator && !A[i] && ALength == i) ||
|
2017-06-25 18:05:58 +00:00
|
|
|
(!A[i] && ALength == i && (B[i] == Terminator)))
|
2017-04-23 00:30:37 +00:00
|
|
|
{
|
|
|
|
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-06-25 18:22:54 +00:00
|
|
|
|
2017-04-13 23:46:21 +00:00
|
|
|
return Colour;
|
2017-03-18 02:04:13 +00:00
|
|
|
}
|
|
|
|
|
2017-06-09 22:04:07 +00:00
|
|
|
hsl_colour *
|
|
|
|
StringToColourHash(hsl_colour *Colour, char *String)
|
2017-03-18 02:04:13 +00:00
|
|
|
{
|
2017-06-09 22:04:07 +00:00
|
|
|
Colour->Hue = 0;
|
|
|
|
Colour->Saturation = 0;
|
|
|
|
Colour->Lightness = 26;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-18 02:04:13 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; String[i]; ++i)
|
|
|
|
{
|
2017-06-09 22:04:07 +00:00
|
|
|
Colour->Hue += CharToColour(String[i]).Hue;
|
|
|
|
Colour->Saturation += CharToColour(String[i]).Saturation;
|
2017-03-18 02:04:13 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-09 22:04:07 +00:00
|
|
|
Colour->Hue = Colour->Hue % 360;
|
|
|
|
Colour->Saturation = Colour->Saturation % 26 + 74;
|
|
|
|
return(Colour);
|
2017-03-18 02:04:13 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 02:07:55 +00:00
|
|
|
char *
|
|
|
|
SanitisePunctuation(char *String)
|
|
|
|
{
|
|
|
|
char *Ptr = String;
|
|
|
|
while(*Ptr)
|
|
|
|
{
|
|
|
|
if(*Ptr == ' ')
|
|
|
|
{
|
|
|
|
*Ptr = '_';
|
|
|
|
}
|
|
|
|
if((*Ptr < '0' || *Ptr > '9') &&
|
2017-06-25 18:05:58 +00:00
|
|
|
(*Ptr < 'a' || *Ptr > 'z') &&
|
|
|
|
(*Ptr < 'A' || *Ptr > 'Z'))
|
2017-03-25 02:07:55 +00:00
|
|
|
{
|
|
|
|
*Ptr = '-';
|
|
|
|
}
|
|
|
|
++Ptr;
|
|
|
|
}
|
|
|
|
return String;
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
int
|
2017-06-25 18:05:58 +00:00
|
|
|
BuildCredits(buffer *CreditsMenu, buffer *HostInfo, buffer *AnnotatorInfo, bool *HasCreditsMenu, char *ImagesDir, char *Host, char *Annotator)
|
2017-05-25 20:28:52 +00:00
|
|
|
{
|
2017-06-21 15:12:40 +00:00
|
|
|
// TODO(matt): Handle co-hosts and guests
|
2017-05-25 20:28:52 +00:00
|
|
|
bool FoundHost = FALSE;
|
|
|
|
bool FoundAnnotator = FALSE;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
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,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"credit\">\n");
|
2017-05-25 20:28:52 +00:00
|
|
|
if(*Credentials[CredentialIndex][2])
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(HostInfo,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <a class=\"person\" href=\"%s\" target=\"_blank\">\n"
|
|
|
|
" <div class=\"role\">Host</div>\n"
|
|
|
|
" <div class=\"name\">%s</div>\n"
|
|
|
|
" </a>\n",
|
|
|
|
Credentials[CredentialIndex][2],
|
|
|
|
Credentials[CredentialIndex][1]);
|
2017-05-25 20:28:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(HostInfo,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"person\">\n"
|
|
|
|
" <div class=\"role\">Host</div>\n"
|
|
|
|
" <div class=\"name\">%s</div>\n"
|
|
|
|
" </div>\n",
|
|
|
|
Credentials[CredentialIndex][1]);
|
2017-05-25 20:28:52 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
if(*Credentials[CredentialIndex][4] && *Credentials[CredentialIndex][3])
|
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(HostInfo,
|
|
|
|
" <a class=\"support\" href=\"%s\" target=\"_blank\"><img src=\"%s/%s\"></a>\n",
|
|
|
|
Credentials[CredentialIndex][4],
|
|
|
|
ImagesDir,
|
|
|
|
Credentials[CredentialIndex][3]);
|
2017-05-25 20:28:52 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
CopyStringToBuffer(HostInfo,
|
2017-06-25 18:05:58 +00:00
|
|
|
" </span>\n");
|
2017-05-25 20:28:52 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
if(!StringsDiffer(Annotator, Credentials[CredentialIndex][0]))
|
|
|
|
{
|
|
|
|
FoundAnnotator = TRUE; // TODO(matt): Check if this is actually necessary...
|
|
|
|
CopyStringToBuffer(AnnotatorInfo,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"credit\">\n");
|
2017-05-25 20:28:52 +00:00
|
|
|
if(*Credentials[CredentialIndex][2])
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(AnnotatorInfo,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <a class=\"person\" href=\"%s\" target=\"_blank\">\n"
|
|
|
|
" <div class=\"role\">Annotator</div>\n"
|
|
|
|
" <div class=\"name\">%s</div>\n"
|
|
|
|
" </a>\n",
|
|
|
|
Credentials[CredentialIndex][2],
|
|
|
|
Credentials[CredentialIndex][1]);
|
2017-05-25 20:28:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(AnnotatorInfo,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"person\">\n"
|
|
|
|
" <div class=\"role\">Annotator</div>\n"
|
|
|
|
" <div class=\"name\">%s</div>\n"
|
|
|
|
" </div>\n",
|
|
|
|
Credentials[CredentialIndex][1]);
|
2017-05-25 20:28:52 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
if(*Credentials[CredentialIndex][4] && *Credentials[CredentialIndex][3])
|
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(AnnotatorInfo,
|
|
|
|
" <a class=\"support\" href=\"%s\" target=\"_blank\"><img src=\"%s/%s\"></a>\n",
|
|
|
|
Credentials[CredentialIndex][4],
|
|
|
|
ImagesDir,
|
|
|
|
Credentials[CredentialIndex][3]);
|
2017-05-25 20:28:52 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
CopyStringToBuffer(AnnotatorInfo,
|
2017-06-25 18:05:58 +00:00
|
|
|
" </span>\n");
|
2017-05-25 20:28:52 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
if(FoundHost || FoundAnnotator)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(CreditsMenu,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"menu credits\">\n"
|
|
|
|
" <div class=\"mouse_catcher\"></div>\n"
|
|
|
|
" <span>Credits</span>\n"
|
|
|
|
" <div class=\"credits_container\">\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
if(FoundHost)
|
|
|
|
{
|
|
|
|
CopyBuffer(CreditsMenu, HostInfo);
|
|
|
|
}
|
|
|
|
if(FoundAnnotator)
|
|
|
|
{
|
|
|
|
CopyBuffer(CreditsMenu, AnnotatorInfo);
|
|
|
|
}
|
|
|
|
CopyStringToBuffer(CreditsMenu,
|
2017-06-25 18:05:58 +00:00
|
|
|
" </div>\n"
|
|
|
|
" </div>\n");
|
2017-05-25 20:28:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
*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-07-29 23:01:39 +00:00
|
|
|
|
|
|
|
#define REF_SITE (1 << 0)
|
|
|
|
#define REF_PAGE (1 << 1)
|
|
|
|
#define REF_URL (1 << 2)
|
|
|
|
#define REF_TITLE (1 << 3)
|
|
|
|
#define REF_ARTICLE (1 << 4)
|
|
|
|
#define REF_AUTHOR (1 << 5)
|
|
|
|
#define REF_EDITOR (1 << 6)
|
|
|
|
#define REF_PUBLISHER (1 << 7)
|
|
|
|
#define REF_ISBN (1 << 8)
|
|
|
|
|
|
|
|
int Mask = 0;
|
|
|
|
|
|
|
|
if(Ref.site) { Mask |= REF_SITE; }
|
|
|
|
if(Ref.page) { Mask |= REF_PAGE; }
|
|
|
|
if(Ref.url) { Mask |= REF_URL; }
|
|
|
|
if(Ref.title) { Mask |= REF_TITLE; }
|
|
|
|
if(Ref.article) { Mask |= REF_ARTICLE; }
|
|
|
|
if(Ref.author) { Mask |= REF_AUTHOR; }
|
|
|
|
if(Ref.editor) { Mask |= REF_EDITOR; }
|
|
|
|
if(Ref.publisher) { Mask |= REF_PUBLISHER; }
|
|
|
|
if(Ref.isbn) { Mask |= REF_ISBN; }
|
|
|
|
|
|
|
|
if((REF_URL | REF_TITLE | REF_AUTHOR | REF_PUBLISHER | REF_ISBN) == Mask)
|
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);
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].RefTitle, Ref.title);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].URL, Ref.url);
|
2017-04-21 01:25:40 +00:00
|
|
|
}
|
2017-07-29 23:01:39 +00:00
|
|
|
else if((REF_AUTHOR | REF_SITE | REF_PAGE | REF_URL) == Mask)
|
|
|
|
{
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].Source, Ref.site);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].RefTitle, "%s: \"%s\"", Ref.author, Ref.page);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].URL, Ref.url);
|
|
|
|
}
|
|
|
|
else if((REF_PAGE | REF_URL | REF_TITLE) == Mask)
|
2017-04-21 01:25:40 +00:00
|
|
|
{
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].Source, Ref.title);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].RefTitle, Ref.page);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].URL, Ref.url);
|
2017-04-21 01:25:40 +00:00
|
|
|
}
|
2017-07-29 23:01:39 +00:00
|
|
|
else if((REF_SITE | REF_PAGE | REF_URL) == Mask)
|
2017-04-21 01:25:40 +00:00
|
|
|
{
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].Source, Ref.site);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].RefTitle, Ref.page);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].URL, Ref.url);
|
2017-04-21 01:25:40 +00:00
|
|
|
}
|
2017-07-29 23:01:39 +00:00
|
|
|
else if((REF_SITE | REF_URL | REF_TITLE) == Mask)
|
2017-04-21 01:25:40 +00:00
|
|
|
{
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].Source, Ref.site);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].RefTitle, Ref.title);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].URL, Ref.url);
|
2017-04-21 01:25:40 +00:00
|
|
|
}
|
2017-07-29 23:01:39 +00:00
|
|
|
else if((REF_TITLE | REF_AUTHOR | REF_ISBN) == Mask)
|
2017-04-19 01:10:45 +00:00
|
|
|
{
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].ID, Ref.isbn);
|
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, Ref.author);
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(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-06-03 01:32:18 +00:00
|
|
|
CopyString(ReferencesArray[UniqueRefs].URL, "http://www.openisbn.com/isbn/%s", Ref.isbn);
|
2017-04-19 01:10:45 +00:00
|
|
|
}
|
2017-07-29 23:01:39 +00:00
|
|
|
else if((REF_URL | REF_ARTICLE | REF_AUTHOR) == Mask)
|
2017-04-19 01:10:45 +00:00
|
|
|
{
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].ID, Ref.url);
|
2017-04-21 01:25:40 +00:00
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, Ref.author);
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].RefTitle, Ref.article);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].URL, Ref.url);
|
2017-04-19 01:10:45 +00:00
|
|
|
}
|
2017-07-29 23:01:39 +00:00
|
|
|
else if((REF_URL | REF_TITLE | REF_AUTHOR) == Mask)
|
2017-04-21 01:25:40 +00:00
|
|
|
{
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].ID, Ref.url);
|
2017-04-21 01:25:40 +00:00
|
|
|
CopyString(ReferencesArray[UniqueRefs].Source, Ref.author);
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].RefTitle, Ref.title);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].URL, Ref.url);
|
2017-04-21 01:25:40 +00:00
|
|
|
}
|
2017-07-29 23:01:39 +00:00
|
|
|
else if((REF_URL | REF_TITLE) == Mask)
|
2017-04-23 00:30:37 +00:00
|
|
|
{
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].RefTitle, Ref.title);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].URL, Ref.url);
|
2017-04-23 00:30:37 +00:00
|
|
|
}
|
2017-07-29 23:01:39 +00:00
|
|
|
else if((REF_SITE | REF_URL) == Mask)
|
2017-04-23 00:30:37 +00:00
|
|
|
{
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].ID, Ref.url);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].RefTitle, Ref.site);
|
|
|
|
CopyStringNoFormat(ReferencesArray[UniqueRefs].URL, Ref.url);
|
2017-04-23 00:30:37 +00:00
|
|
|
}
|
2017-04-21 01:25:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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
|
2017-08-05 18:13:02 +00:00
|
|
|
{ "afk", "…" , "Away from Keyboard"}, // TODO(matt): Filter this out by default
|
|
|
|
{ "authored", "🗪", "Chat Comment"}, // TODO(matt): Conditionally handle Chat vs Guest Comments
|
|
|
|
{ "blackboard", "🖌", "Blackboard"},
|
|
|
|
{ "experience", "🍷", "Experience"},
|
|
|
|
{ "owl", "🦉", "Owl of Shame"},
|
|
|
|
{ "programming", "🖮", "Programming"}, // TODO(matt): Potentially make this configurable per project
|
|
|
|
{ "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-06-25 18:22:54 +00:00
|
|
|
|
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-06-25 18:22:54 +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-06-25 18:22:54 +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-06-25 18:22:54 +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-06-25 18:22:54 +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-06-25 18:22:54 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
CopyString(TopicsArray[j].Marker, Marker);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:22:54 +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-06-25 18:22:54 +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-06-25 18:22:54 +00:00
|
|
|
|
2017-06-11 22:49:04 +00:00
|
|
|
// NOTE(matt): Iterate through the Category->Location looking for "Marker", and bail if we find it
|
|
|
|
char *Ptr = Category->Location;
|
|
|
|
bool Found = FALSE;
|
|
|
|
while(*Ptr)
|
|
|
|
{
|
|
|
|
if(*Ptr == '\"')
|
|
|
|
{
|
|
|
|
++Ptr;
|
2017-06-13 22:13:03 +00:00
|
|
|
if(!StringsDifferT(SanitisePunctuation(Marker), Ptr, ' '))
|
2017-06-11 22:49:04 +00:00
|
|
|
{
|
|
|
|
Found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(*Ptr != '\"')
|
|
|
|
{
|
|
|
|
++Ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++Ptr;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-11 22:49:04 +00:00
|
|
|
if(Found == FALSE)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(Category, "<div title=\"%s\" class=\"category %s\"></div>",
|
2017-06-25 18:05:58 +00:00
|
|
|
SanitisePunctuation(Marker),
|
|
|
|
SanitisePunctuation(Marker));
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-11 22:49:04 +00:00
|
|
|
CopyStringToBuffer(AnnotationClass, " cat_%s",
|
2017-06-25 18:05:58 +00:00
|
|
|
SanitisePunctuation(Marker));
|
2017-06-11 22:49:04 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-25 03:10:15 +00:00
|
|
|
++*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;
|
|
|
|
}
|
|
|
|
|
2017-08-09 00:57:09 +00:00
|
|
|
size_t
|
|
|
|
CurlIntoBuffer(char *InPtr, size_t CharLength, size_t Chars, char **OutputPtr)
|
2017-04-23 02:47:42 +00:00
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
int Length = CharLength * Chars;
|
|
|
|
int i;
|
|
|
|
for(i = 0; InPtr[i] && i < Length; ++i)
|
2017-04-23 02:47:42 +00:00
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
*((*OutputPtr)++) = InPtr[i];
|
2017-04-23 02:47:42 +00:00
|
|
|
}
|
2017-08-09 00:57:09 +00:00
|
|
|
**OutputPtr = '\0';
|
|
|
|
return Length;
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2017-08-10 01:05:41 +00:00
|
|
|
SearchQuotes(buffer QuoteStaging, int CacheSize, quote_info *Info, int ID)
|
2017-08-09 00:57:09 +00:00
|
|
|
{
|
|
|
|
QuoteStaging.Ptr = QuoteStaging.Location;
|
2017-08-10 01:05:41 +00:00
|
|
|
while(QuoteStaging.Ptr - QuoteStaging.Location < CacheSize)
|
2017-04-23 02:47:42 +00:00
|
|
|
{
|
2017-05-21 06:35:16 +00:00
|
|
|
char InID[4] = { 0 };
|
2017-08-09 00:57:09 +00:00
|
|
|
char InTime[16] = { 0 };
|
2017-04-23 02:47:42 +00:00
|
|
|
char *OutPtr = InID;
|
2017-08-09 00:57:09 +00:00
|
|
|
while(*QuoteStaging.Ptr != ',')
|
2017-04-23 02:47:42 +00:00
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
*OutPtr++ = *QuoteStaging.Ptr++;
|
2017-04-23 02:47:42 +00:00
|
|
|
}
|
|
|
|
*OutPtr = '\0';
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-04-23 02:47:42 +00:00
|
|
|
if(StringToInt(InID) == ID)
|
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
QuoteStaging.Ptr += 1;
|
|
|
|
OutPtr = InTime;
|
|
|
|
while(*QuoteStaging.Ptr != ',')
|
2017-04-23 02:47:42 +00:00
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
*OutPtr++ = *QuoteStaging.Ptr++;
|
2017-04-23 02:47:42 +00:00
|
|
|
}
|
|
|
|
*OutPtr = '\0';
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-08-09 00:57:09 +00:00
|
|
|
long int Time = StringToInt(InTime);
|
|
|
|
strftime(Info->Date, 32, "%d %B, %Y", gmtime(&Time));
|
|
|
|
|
|
|
|
QuoteStaging.Ptr += 1;
|
2017-04-23 02:47:42 +00:00
|
|
|
OutPtr = Info->Text;
|
2017-08-09 00:57:09 +00:00
|
|
|
while(*QuoteStaging.Ptr != '\n')
|
2017-04-23 02:47:42 +00:00
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
*OutPtr++ = *QuoteStaging.Ptr++;
|
2017-04-23 02:47:42 +00:00
|
|
|
}
|
2017-08-11 22:41:52 +00:00
|
|
|
*OutPtr = '\0';
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-08-09 00:57:09 +00:00
|
|
|
FreeBuffer(&QuoteStaging);
|
2017-04-23 02:47:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
while(*QuoteStaging.Ptr != '\n')
|
2017-04-23 02:47:42 +00:00
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
++QuoteStaging.Ptr;
|
2017-04-23 02:47:42 +00:00
|
|
|
}
|
2017-08-09 00:57:09 +00:00
|
|
|
++QuoteStaging.Ptr;
|
2017-04-23 02:47:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-08-11 22:41:52 +00:00
|
|
|
int
|
|
|
|
MakeDir(char *Path)
|
|
|
|
{
|
|
|
|
int i = StringLength(Path);
|
|
|
|
int Ancestors = 0;
|
|
|
|
while(mkdir(Path, 00755) == -1)
|
|
|
|
{
|
|
|
|
while(Path[i] != '/' && i > 0)
|
|
|
|
{
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
++Ancestors;
|
|
|
|
Path[i] = '\0';
|
|
|
|
if(i == 0) { return 1; }
|
|
|
|
}
|
|
|
|
while(Ancestors > 0)
|
|
|
|
{
|
|
|
|
while(Path[i] != '\0')
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
Path[i] = '/';
|
|
|
|
--Ancestors;
|
|
|
|
if((mkdir(Path, 00755)) == -1)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CurlQuotes(buffer *QuoteStaging, char *QuotesURL)
|
|
|
|
{
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
if(curl) {
|
|
|
|
CURLcode res;
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &QuoteStaging->Ptr);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlIntoBuffer);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, QuotesURL);
|
|
|
|
if((res = curl_easy_perform(curl)))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", curl_easy_strerror(res));
|
|
|
|
}
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-10 01:05:41 +00:00
|
|
|
int
|
|
|
|
BuildQuote(quote_info *Info, char *Speaker, int ID, char *CacheDir)
|
|
|
|
{
|
|
|
|
// TODO(matt): Rebuild cache option
|
|
|
|
|
|
|
|
char QuoteCacheDir[255];
|
|
|
|
CopyString(QuoteCacheDir, "%s/quotes", CacheDir);
|
|
|
|
char QuoteCachePath[255];
|
|
|
|
CopyString(QuoteCachePath, "%s/%s", QuoteCacheDir, Speaker);
|
|
|
|
FILE *QuoteCache;
|
2017-08-11 22:41:52 +00:00
|
|
|
char QuotesURL[256];
|
|
|
|
CopyString(QuotesURL, "https://dev.abaines.me.uk/quotes/%s.raw", Speaker);
|
|
|
|
bool CacheAvailable = FALSE;
|
2017-08-10 01:05:41 +00:00
|
|
|
|
2017-08-11 22:41:52 +00:00
|
|
|
if(!(QuoteCache = fopen(QuoteCachePath, "a+")))
|
2017-08-10 01:05:41 +00:00
|
|
|
{
|
2017-08-11 22:41:52 +00:00
|
|
|
if(MakeDir(QuoteCacheDir) == 0)
|
2017-08-10 01:05:41 +00:00
|
|
|
{
|
2017-08-11 22:41:52 +00:00
|
|
|
CacheAvailable = TRUE;
|
|
|
|
};
|
|
|
|
if(!(QuoteCache = fopen(QuoteCachePath, "a+")))
|
|
|
|
{
|
|
|
|
perror(QuoteCachePath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CacheAvailable = TRUE;
|
2017-08-10 01:05:41 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-11 22:41:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CacheAvailable = TRUE;
|
|
|
|
}
|
2017-08-10 01:05:41 +00:00
|
|
|
|
|
|
|
buffer QuoteStaging;
|
|
|
|
QuoteStaging.ID = "QuoteStaging";
|
|
|
|
QuoteStaging.Size = Kilobytes(256);
|
|
|
|
if(!(QuoteStaging.Location = malloc(QuoteStaging.Size)))
|
|
|
|
{
|
|
|
|
perror("malloc");
|
|
|
|
}
|
|
|
|
QuoteStaging.Ptr = QuoteStaging.Location;
|
|
|
|
|
2017-08-11 22:41:52 +00:00
|
|
|
if(CacheAvailable)
|
2017-08-10 01:05:41 +00:00
|
|
|
{
|
2017-08-11 22:41:52 +00:00
|
|
|
fseek(QuoteCache, 0, SEEK_END);
|
|
|
|
int FileSize = ftell(QuoteCache);
|
|
|
|
fseek(QuoteCache, 0, SEEK_SET);
|
|
|
|
|
|
|
|
fread(QuoteStaging.Location, FileSize, 1, QuoteCache);
|
|
|
|
fclose(QuoteCache);
|
2017-08-10 01:05:41 +00:00
|
|
|
|
2017-08-11 22:41:52 +00:00
|
|
|
if(SearchQuotes(QuoteStaging, FileSize, Info, ID) == 1)
|
|
|
|
{
|
|
|
|
CurlQuotes(&QuoteStaging, QuotesURL);
|
|
|
|
|
|
|
|
if(!(QuoteCache = fopen(QuoteCachePath, "w")))
|
2017-08-10 01:05:41 +00:00
|
|
|
{
|
2017-08-11 22:41:52 +00:00
|
|
|
perror(QuoteCachePath);
|
2017-08-10 01:05:41 +00:00
|
|
|
}
|
2017-08-11 22:41:52 +00:00
|
|
|
fwrite(QuoteStaging.Location, QuoteStaging.Ptr - QuoteStaging.Location, 1, QuoteCache);
|
|
|
|
fclose(QuoteCache);
|
2017-08-10 01:05:41 +00:00
|
|
|
|
2017-08-11 22:41:52 +00:00
|
|
|
int CacheSize = QuoteStaging.Ptr - QuoteStaging.Location;
|
|
|
|
QuoteStaging.Ptr = QuoteStaging.Location;
|
|
|
|
if(SearchQuotes(QuoteStaging, CacheSize, Info, ID) == 1)
|
|
|
|
{
|
|
|
|
FreeBuffer(&QuoteStaging);
|
|
|
|
return 1;
|
|
|
|
}
|
2017-08-10 01:05:41 +00:00
|
|
|
}
|
2017-08-11 22:41:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurlQuotes(&QuoteStaging, QuotesURL);
|
2017-08-10 01:05:41 +00:00
|
|
|
int CacheSize = QuoteStaging.Ptr - QuoteStaging.Location;
|
|
|
|
QuoteStaging.Ptr = QuoteStaging.Location;
|
|
|
|
if(SearchQuotes(QuoteStaging, CacheSize, Info, ID) == 1)
|
|
|
|
{
|
|
|
|
FreeBuffer(&QuoteStaging);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2017-08-11 22:41:52 +00:00
|
|
|
|
2017-08-10 01:05:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-31 00:56:50 +00:00
|
|
|
void
|
2017-06-25 18:05:58 +00:00
|
|
|
GenerateTopicColours(buffer *Colour, char *Topic, char *TopicsDir)
|
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;
|
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-31 00:56:50 +00:00
|
|
|
FILE *TopicsFile;
|
|
|
|
char *TopicsBuffer;
|
2017-05-21 06:35:16 +00:00
|
|
|
// TODO(matt): Consider (optionally) pulling this path from the config
|
2017-06-25 18:05:58 +00:00
|
|
|
char TopicsPath[255];
|
|
|
|
CopyString(TopicsPath, "%s/cinera_topcs.css", TopicsDir);
|
2017-06-21 19:38:57 +00:00
|
|
|
if((TopicsFile = fopen("cinera_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-06-25 18:22:54 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-31 00:56:50 +00:00
|
|
|
fread(TopicsBuffer, TopicsLength, 1, TopicsFile);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-04-13 00:21:04 +00:00
|
|
|
char *TopicsPtr = TopicsBuffer;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-31 00:56:50 +00:00
|
|
|
while(TopicsPtr - TopicsBuffer < TopicsLength)
|
|
|
|
{
|
2017-05-15 01:11:11 +00:00
|
|
|
TopicsPtr += StringLength(".category.");
|
2017-06-13 22:13:03 +00:00
|
|
|
if(!StringsDifferT(SanitisePunctuation(Topic), TopicsPtr, ' '))
|
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-06-25 18:22:54 +00:00
|
|
|
|
2017-06-09 22:04:07 +00:00
|
|
|
hsl_colour Colour;
|
|
|
|
StringToColourHash(&Colour, Topic);
|
|
|
|
fprintf(TopicsFile, ".category.%s { border: 1px solid hsl(%d, %d%%, %d%%); background: hsl(%d, %d%%, %d%%); }\n",
|
2017-06-25 18:05:58 +00:00
|
|
|
SanitisePunctuation(Topic), Colour.Hue, Colour.Saturation, Colour.Lightness, Colour.Hue, Colour.Saturation, Colour.Lightness);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
FILE *InFile;
|
|
|
|
if(!(InFile = fopen(Config_Location, "r")))
|
|
|
|
{
|
|
|
|
perror(Config_Location);
|
|
|
|
return 2;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
printf("Reading: %s\n", Config_Location);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
fseek(InFile, 0, SEEK_END);
|
|
|
|
int InSize = ftell(InFile);
|
|
|
|
fseek(InFile, 0, SEEK_SET);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
char *InBuffer;
|
|
|
|
//config Config = { 0 };
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
if(!(InBuffer = malloc(InSize)))
|
|
|
|
{
|
|
|
|
perror("ParseConfig");
|
|
|
|
return 3;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
fread(InBuffer, InSize, 1, InFile);
|
|
|
|
fclose(InFile);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
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;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
while(InPtr - InBuffer < InSize)
|
|
|
|
{
|
|
|
|
switch(*InPtr)
|
|
|
|
{
|
|
|
|
case '#':
|
2017-06-25 18:05:58 +00:00
|
|
|
{
|
|
|
|
if(!Quoted)
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
printf(" We are commenting\n");
|
|
|
|
while(InPtr - InBuffer < InSize && *InPtr != '\n')
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
|
|
|
++InPtr;
|
|
|
|
}
|
2017-06-25 18:05:58 +00:00
|
|
|
++InPtr;
|
|
|
|
while(InPtr - InBuffer < InSize && (*InPtr == ' ' || *InPtr == '\n'))
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
++InPtr;
|
2017-05-13 15:38:10 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:05:58 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-05-13 15:38:10 +00:00
|
|
|
case '{':
|
2017-06-25 18:05:58 +00:00
|
|
|
{
|
|
|
|
if(!Quoted)
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
++ScopeDepth;
|
|
|
|
++InPtr;
|
|
|
|
while(*InPtr == '\n' || *InPtr == ' ')
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
|
|
|
++InPtr;
|
|
|
|
}
|
2017-06-25 18:05:58 +00:00
|
|
|
printf(" We have entered a scope\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
2017-05-13 15:38:10 +00:00
|
|
|
}
|
2017-06-25 18:05:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-05-13 15:38:10 +00:00
|
|
|
case '}':
|
2017-06-25 18:05:58 +00:00
|
|
|
{
|
|
|
|
if(!Quoted)
|
|
|
|
{
|
|
|
|
--ScopeDepth;
|
|
|
|
++InPtr;
|
|
|
|
printf(" We have left a scope\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#if 1
|
|
|
|
case ' ':
|
|
|
|
{
|
|
|
|
if(!Quoted)
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
++InPtr;
|
|
|
|
*OutPtr = '\0';
|
|
|
|
OutPtr = OutBuffer;
|
|
|
|
printf("%s\n", OutBuffer);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
// TODO(matt): Switch on the OutBuffer? I have a feeling that isn't actually possible, though
|
|
|
|
if(!StringsDiffer("credentials", OutBuffer))
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
FoundCredentials = TRUE;
|
|
|
|
printf(" We have found the credentials block\n");
|
2017-05-13 15:38:10 +00:00
|
|
|
}
|
2017-06-25 18:05:58 +00:00
|
|
|
if(ParsingUsername)
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
printf(" The username is %s\n", OutBuffer);
|
|
|
|
ParsingUsername = FALSE;
|
|
|
|
}
|
|
|
|
if(FoundCredentials && (!StringsDiffer("username", OutBuffer)))
|
|
|
|
{
|
|
|
|
ParsingUsername = TRUE;
|
|
|
|
printf(" We have found the username\n");
|
2017-05-13 15:38:10 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:05:58 +00:00
|
|
|
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)
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
if(InPtr - InBuffer < InSize)
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
|
|
|
*OutPtr = '\0';
|
|
|
|
OutPtr = OutBuffer;
|
2017-06-25 18:05:58 +00:00
|
|
|
// TODO(matt)
|
2017-05-13 15:38:10 +00:00
|
|
|
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");
|
|
|
|
}
|
2017-06-25 18:05:58 +00:00
|
|
|
printf("%s\n", OutBuffer);
|
2017-05-13 15:38:10 +00:00
|
|
|
++InPtr;
|
2017-06-25 18:05:58 +00:00
|
|
|
while(InPtr - InBuffer < InSize && *InPtr == ' ') // NOTE(matt): Skip indentation whitespace
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
|
|
|
++InPtr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:05:58 +00:00
|
|
|
else
|
2017-05-13 15:38:10 +00:00
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
if(InPtr - InBuffer == InSize)
|
|
|
|
{
|
|
|
|
printf(" We have reached the EOF\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
break;
|
|
|
|
}
|
2017-05-13 15:38:10 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
#if 0
|
|
|
|
while(InPtr - InBuffer < InSize)
|
|
|
|
{
|
|
|
|
while(*InPtr != '\n')
|
|
|
|
{
|
|
|
|
*OutPtr++ = *InPtr++;
|
|
|
|
}
|
|
|
|
*OutPtr = '\0';
|
|
|
|
printf("%s\n", Config.Credentials.Display_Name);
|
|
|
|
}
|
|
|
|
#endif
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
free(InBuffer);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
// Reading from the config file, parsing it inline (on the stack) and writing into the buffer *Config
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
void
|
2017-08-09 00:57:09 +00:00
|
|
|
PrintUsage(char *BinaryLocation, char *DefaultCSSDir, char *DefaultImagesDir, char *DefaultJSDir, char *DefaultDefaultMedium, char *DefaultOutLocation, char *DefaultTemplateLocation)
|
2017-06-25 18:05:58 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s [option(s)] filename(s)\n"
|
|
|
|
"\n"
|
|
|
|
"Options:\n"
|
|
|
|
" -c <CSS directory path>\n"
|
|
|
|
" Override default CSS directory (\"%s\")\n"
|
2017-08-08 18:19:11 +00:00
|
|
|
" -f\n"
|
|
|
|
" Force integration with an incomplete template\n"
|
2017-06-25 18:05:58 +00:00
|
|
|
" -i <images directory path>\n"
|
|
|
|
" Override default images directory (\"%s\")\n"
|
|
|
|
" -j <JS directory path>\n"
|
|
|
|
" Override default JS directory (\"%s\")\n"
|
2017-08-05 18:13:02 +00:00
|
|
|
" -m <default medium>\n"
|
|
|
|
" Override default default medium (\"%s\")\n"
|
2017-06-25 18:05:58 +00:00
|
|
|
" -o <output location>\n"
|
|
|
|
" Override default output location (\"%s\")\n"
|
|
|
|
" -t <template location>\n"
|
|
|
|
" Override default template location (\"%s\")\n"
|
|
|
|
" and automatically enable integration\n"
|
|
|
|
//" -c config location\n"
|
|
|
|
" -h\n"
|
|
|
|
" display this help\n"
|
|
|
|
"\n"
|
|
|
|
"Environment Variables:\n"
|
|
|
|
" CINERA_MODE\n"
|
|
|
|
" =INTEGRATE\n"
|
2017-08-08 18:19:11 +00:00
|
|
|
" Enable integration\n"
|
|
|
|
"\n"
|
|
|
|
"Template:\n"
|
|
|
|
" A complete template shall contain exactly one each of the following tags:\n"
|
|
|
|
" <!-- __CINERA_INCLUDES__ -->\n"
|
|
|
|
" <!-- __CINERA_MENUS__ -->\n"
|
|
|
|
" <!-- __CINERA_PLAYER__ -->\n"
|
|
|
|
" <!-- __CINERA_SCRIPT__ --> (must come after <!-- __CINERA_PLAYER__ -->)\n"
|
|
|
|
" Other available tags include:\n"
|
|
|
|
" <!-- __CINERA_TITLE__ -->\n",
|
2017-08-09 00:57:09 +00:00
|
|
|
BinaryLocation, DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultOutLocation, DefaultTemplateLocation);
|
2017-06-25 18:05:58 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 14:19:25 +00:00
|
|
|
int
|
|
|
|
main(int ArgC, char **Args)
|
|
|
|
{
|
2017-08-08 19:26:54 +00:00
|
|
|
// TODO(matt): Read all defaults from the config
|
2017-06-25 18:05:58 +00:00
|
|
|
char *DefaultCSSDir = ".";
|
|
|
|
char *CSSDir = DefaultCSSDir;
|
|
|
|
|
|
|
|
char *DefaultImagesDir = ".";
|
|
|
|
char *ImagesDir = DefaultImagesDir;
|
|
|
|
|
|
|
|
char *DefaultJSDir = ".";
|
|
|
|
char *JSDir = DefaultJSDir;
|
|
|
|
|
2017-08-05 18:13:02 +00:00
|
|
|
char *DefaultDefaultMedium = "programming";
|
|
|
|
char *DefaultMedium = DefaultDefaultMedium;
|
|
|
|
|
2017-08-08 19:26:54 +00:00
|
|
|
bool HasTemplate = FALSE;
|
2017-06-25 18:05:58 +00:00
|
|
|
char *DefaultTemplateLocation = "template.html";
|
|
|
|
char *TemplateLocation = DefaultTemplateLocation;
|
2017-08-08 19:26:54 +00:00
|
|
|
HasTemplate = TRUE;
|
2017-06-25 18:05:58 +00:00
|
|
|
|
|
|
|
char *DefaultOutLocation = "out.html";
|
|
|
|
char *OutLocation = DefaultOutLocation;
|
|
|
|
|
|
|
|
char *DefaultOutIntegratedLocation = "out_integrated.html";
|
|
|
|
char *OutIntegratedLocation = DefaultOutIntegratedLocation;
|
|
|
|
|
|
|
|
char *CINERA_MODE = getenv("CINERA_MODE");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-08-08 18:19:11 +00:00
|
|
|
bool DefaultForceIntegration = FALSE;
|
|
|
|
bool ForceIntegration = DefaultForceIntegration;
|
|
|
|
|
2017-08-10 01:05:41 +00:00
|
|
|
char CacheDir[255] = { 0 };
|
|
|
|
if(getenv("XDG_CACHE_HOME"))
|
|
|
|
{
|
|
|
|
CopyString(CacheDir, "%s/cinera", getenv("XDG_CACHE_HOME"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyString(CacheDir, "%s/.cache/cinera", getenv("HOME"));
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:19:25 +00:00
|
|
|
if(ArgC < 2)
|
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultOutLocation, DefaultTemplateLocation);
|
2017-03-10 14:19:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2017-06-25 18:05:58 +00:00
|
|
|
|
|
|
|
char CommandLineArg;
|
2017-08-08 18:19:11 +00:00
|
|
|
while((CommandLineArg = getopt(ArgC, Args, "c:fi:j:m:o:q:t:h")) != -1)
|
2017-06-25 18:05:58 +00:00
|
|
|
{
|
|
|
|
switch(CommandLineArg)
|
|
|
|
{
|
|
|
|
case 'c':
|
|
|
|
CSSDir = optarg;
|
|
|
|
break;
|
2017-08-08 18:19:11 +00:00
|
|
|
case 'f':
|
|
|
|
ForceIntegration = TRUE;
|
|
|
|
break;
|
2017-06-25 18:05:58 +00:00
|
|
|
case 'i':
|
|
|
|
ImagesDir = optarg;
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
JSDir = optarg;
|
|
|
|
break;
|
2017-08-05 18:13:02 +00:00
|
|
|
case 'm':
|
|
|
|
DefaultMedium = optarg;
|
|
|
|
break;
|
2017-06-25 18:05:58 +00:00
|
|
|
case 'o':
|
|
|
|
OutLocation = optarg;
|
|
|
|
OutIntegratedLocation = optarg;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
TemplateLocation = optarg;
|
|
|
|
CINERA_MODE="INTEGRATE";
|
|
|
|
break;
|
|
|
|
//case 'c':
|
|
|
|
// Override config path, once we even have a default!
|
|
|
|
case 'h':
|
|
|
|
default:
|
2017-08-09 00:57:09 +00:00
|
|
|
PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultOutLocation, DefaultTemplateLocation);
|
2017-06-25 18:05:58 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(optind == ArgC)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: requires at least one input .hmml file\n", Args[0]);
|
2017-08-09 00:57:09 +00:00
|
|
|
PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultOutLocation, DefaultTemplateLocation);
|
2017-06-25 18:05:58 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(CSSDir[StringLength(CSSDir) - 1] == '/')
|
|
|
|
{
|
|
|
|
CSSDir[StringLength(CSSDir) - 1] = '\0';
|
|
|
|
}
|
2017-08-05 18:13:02 +00:00
|
|
|
|
|
|
|
bool ValidDefaultMedium = FALSE;
|
|
|
|
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
|
|
|
|
{
|
|
|
|
if(!StringsDiffer(DefaultMedium, CategoryMedium[i][0]))
|
|
|
|
{
|
|
|
|
ValidDefaultMedium = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!ValidDefaultMedium)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Specified default medium \"%s\" not available. Valid media are:\n", DefaultMedium);
|
|
|
|
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
|
|
|
|
{
|
|
|
|
fprintf(stderr, " %s\n", CategoryMedium[i][0]);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "To have \"%s\" added to the list, contact matt@handmadedev.org\n", DefaultMedium);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
if(ImagesDir[StringLength(ImagesDir) - 1] == '/')
|
|
|
|
{
|
|
|
|
ImagesDir[StringLength(ImagesDir) - 1] = '\0';
|
|
|
|
}
|
|
|
|
if(JSDir[StringLength(JSDir) - 1] == '/')
|
|
|
|
{
|
|
|
|
JSDir[StringLength(JSDir) - 1] = '\0';
|
|
|
|
}
|
2017-08-08 19:26:54 +00:00
|
|
|
|
|
|
|
buffer Template;
|
|
|
|
Template.ID = "Template";
|
|
|
|
if(HasTemplate)
|
|
|
|
{
|
|
|
|
if(CINERA_MODE && !StringsDiffer(CINERA_MODE, "INTEGRATE"))
|
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
// TODO(matt): Put the Errors in the MemoryArena
|
|
|
|
buffer Errors;
|
|
|
|
Errors.ID = "Errors";
|
|
|
|
Errors.Size = Kilobytes(1);
|
|
|
|
if(!(Errors.Location = malloc(Errors.Size)))
|
|
|
|
{
|
|
|
|
perror(Args[0]); return 1;
|
|
|
|
}
|
|
|
|
Errors.Ptr = Errors.Location;
|
|
|
|
bool HaveErrors = FALSE;
|
|
|
|
|
2017-08-08 19:26:54 +00:00
|
|
|
FILE *TemplateFile;
|
|
|
|
if(!(TemplateFile = fopen(TemplateLocation, "r")))
|
|
|
|
{
|
|
|
|
perror(Args[0]); return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fseek(TemplateFile, 0, SEEK_END);
|
|
|
|
Template.Size = ftell(TemplateFile);
|
|
|
|
fseek(TemplateFile, 0, SEEK_SET);
|
|
|
|
if(!(Template.Location = malloc(Template.Size)))
|
|
|
|
{
|
|
|
|
perror(Args[0]); return 1;
|
|
|
|
}
|
|
|
|
Template.Ptr = Template.Location;
|
|
|
|
fread(Template.Location, Template.Size, 1, TemplateFile);
|
|
|
|
fclose(TemplateFile);
|
|
|
|
|
|
|
|
char *IncludesTag = "__CINERA_INCLUDES__";
|
|
|
|
char *TitleTag = "__CINERA_TITLE__";
|
|
|
|
char *MenusTag = "__CINERA_MENUS__";
|
|
|
|
char *PlayerTag = "__CINERA_PLAYER__";
|
|
|
|
char *ScriptTag = "__CINERA_SCRIPT__";
|
|
|
|
|
|
|
|
bool FoundIncludes = FALSE;
|
|
|
|
bool FoundMenus = FALSE;
|
|
|
|
bool FoundPlayer = FALSE;
|
|
|
|
bool FoundScript = FALSE;
|
|
|
|
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(*Template.Ptr == '!' && (Template.Ptr > Template.Location && !StringsDifferT("<!--", &Template.Ptr[-1], 0)))
|
|
|
|
{
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(!(StringsDifferT(IncludesTag, Template.Ptr, 0)))
|
|
|
|
{
|
|
|
|
if(!ForceIntegration && FoundIncludes == TRUE)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Errors, "Template contains more than one <!-- __CINERA_INCLUDES__ --> tag\n");
|
|
|
|
HaveErrors = TRUE;
|
|
|
|
}
|
|
|
|
FoundIncludes = TRUE;
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(!StringsDifferT("-->", Template.Ptr, 0))
|
|
|
|
{
|
|
|
|
Template.Ptr += StringLength("-->");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++Template.Ptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(!(StringsDifferT(TitleTag, Template.Ptr, 0)))
|
|
|
|
{
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(!StringsDifferT("-->", Template.Ptr, 0))
|
|
|
|
{
|
|
|
|
Template.Ptr += StringLength("-->");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++Template.Ptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(!(StringsDifferT(MenusTag, Template.Ptr, 0)))
|
|
|
|
{
|
|
|
|
if(!ForceIntegration && FoundMenus == TRUE)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Errors, "Template contains more than one <!-- __CINERA_MENUS__ --> tag\n");
|
|
|
|
HaveErrors = TRUE;
|
|
|
|
}
|
|
|
|
FoundMenus = TRUE;
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(!StringsDifferT("-->", Template.Ptr, 0))
|
|
|
|
{
|
|
|
|
Template.Ptr += StringLength("-->");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++Template.Ptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(!(StringsDifferT(PlayerTag, Template.Ptr, 0)))
|
|
|
|
{
|
|
|
|
if(!ForceIntegration && FoundPlayer == TRUE)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Errors, "Template contains more than one <!-- __CINERA_PLAYER__ --> tag\n");
|
|
|
|
HaveErrors = TRUE;
|
|
|
|
}
|
|
|
|
FoundPlayer = TRUE;
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(!StringsDifferT("-->", Template.Ptr, 0))
|
|
|
|
{
|
|
|
|
Template.Ptr += StringLength("-->");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++Template.Ptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(!(StringsDifferT(ScriptTag, Template.Ptr, 0)))
|
|
|
|
{
|
|
|
|
if(!ForceIntegration && FoundPlayer == FALSE)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Errors, "<!-- __CINERA_SCRIPT__ --> must come after <!-- __CINERA_PLAYER__ -->\n");
|
|
|
|
HaveErrors = TRUE;
|
|
|
|
}
|
|
|
|
if(!ForceIntegration && FoundScript == TRUE)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Errors, "Template contains more than one <!-- __CINERA_SCRIPT__ --> tag\n");
|
|
|
|
HaveErrors = TRUE;
|
|
|
|
}
|
|
|
|
FoundScript = TRUE;
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(!StringsDifferT("-->", Template.Ptr, 0))
|
|
|
|
{
|
|
|
|
Template.Ptr += StringLength("-->");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++Template.Ptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(!StringsDifferT("-->", Template.Ptr, 0))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Template.Ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Template.Ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!HaveErrors && FoundIncludes && FoundMenus && FoundPlayer && FoundScript)
|
|
|
|
{
|
|
|
|
Template.Ptr = Template.Location;
|
|
|
|
free(Errors.Location);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
if(!ForceIntegration)
|
|
|
|
{
|
|
|
|
if(!FoundIncludes){ CopyStringToBuffer(&Errors, "Template must include one <!-- __CINERA_INCLUDES__ --> tag\n"); };
|
|
|
|
if(!FoundMenus){ CopyStringToBuffer(&Errors, "Template must include one <!-- __CINERA_MENUS__ --> tag\n"); };
|
|
|
|
if(!FoundPlayer){ CopyStringToBuffer(&Errors, "Template must include one <!-- __CINERA_PLAYER__ --> tag\n"); };
|
|
|
|
if(!FoundScript){ CopyStringToBuffer(&Errors, "Template must include one <!-- __CINERA_SCRIPT__ --> tag\n"); };
|
|
|
|
fprintf(stderr, "%s", Errors.Location);
|
|
|
|
free(Template.Location); free(Errors.Location); return 1;
|
|
|
|
}
|
2017-08-08 19:26:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-08 18:19:11 +00:00
|
|
|
|
2017-03-10 14:19:25 +00:00
|
|
|
// NOTE(matt): Init MemoryArena
|
2017-07-29 00:36:14 +00:00
|
|
|
buffer MemoryArena;
|
|
|
|
MemoryArena.Size = Megabytes(4);
|
|
|
|
if(!(MemoryArena.Location = calloc(MemoryArena.Size, 1)))
|
2017-03-10 14:19:25 +00:00
|
|
|
{
|
|
|
|
perror(Args[0]);
|
2017-08-09 00:57:09 +00:00
|
|
|
free(Template.Location);
|
2017-03-10 14:19:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int ClaimedMemory = 0;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-10 14:19:25 +00:00
|
|
|
// NOTE(matt): Setup buffers and ptrs
|
2017-03-22 02:18:31 +00:00
|
|
|
char *InPtr;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-13 15:38:10 +00:00
|
|
|
#if CONFIG
|
|
|
|
buffer Config;
|
|
|
|
#endif
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
// NOTE(matt): Tree structure of buffer dependencies
|
|
|
|
// Master
|
2017-06-21 20:30:05 +00:00
|
|
|
// Includes
|
|
|
|
// Menus
|
2017-05-22 15:33:53 +00:00
|
|
|
// QuoteMenu
|
|
|
|
// ReferenceMenu
|
|
|
|
// FilterMenu
|
|
|
|
// FilterTopics
|
|
|
|
// FilterMedia
|
|
|
|
// Player
|
|
|
|
// Colour
|
|
|
|
// Annotation
|
|
|
|
// AnnotationHeader
|
|
|
|
// AnnotationClass
|
|
|
|
// AnnotationData
|
|
|
|
// Text
|
|
|
|
// Category
|
2017-06-03 01:32:18 +00:00
|
|
|
// Script
|
|
|
|
// FilterState
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
buffer Master;
|
2017-06-21 20:30:05 +00:00
|
|
|
buffer Includes;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-21 20:30:05 +00:00
|
|
|
buffer Menus;
|
2017-03-22 02:18:31 +00:00
|
|
|
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-06-25 18:22:54 +00:00
|
|
|
|
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-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
buffer Script;
|
2017-05-21 06:35:16 +00:00
|
|
|
buffer FilterState;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
for(int FileIndex = optind; FileIndex < ArgC; ++FileIndex)
|
2017-03-22 02:18:31 +00:00
|
|
|
{
|
|
|
|
FILE *InFile;
|
|
|
|
if(!(InFile = fopen(Args[FileIndex], "r")))
|
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
perror(Args[FileIndex]);
|
2017-07-29 00:36:14 +00:00
|
|
|
free(MemoryArena.Location);
|
2017-08-09 00:57:09 +00:00
|
|
|
free(Template.Location);
|
2017-03-22 02:18:31 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-07-29 00:36:14 +00:00
|
|
|
HMML_Output HMML = hmml_parse_file(InFile);
|
|
|
|
fclose(InFile);
|
|
|
|
|
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-06-25 18:22:54 +00:00
|
|
|
|
2017-03-22 02:18:31 +00:00
|
|
|
if(HMML.well_formed)
|
|
|
|
{
|
2017-06-21 23:16:09 +00:00
|
|
|
#if DEBUG
|
2017-06-25 18:05:58 +00:00
|
|
|
printf(
|
|
|
|
"================================================================================\n"
|
|
|
|
"%s\n"
|
|
|
|
"================================================================================\n",
|
|
|
|
Args[FileIndex]);
|
2017-06-21 23:16:09 +00:00
|
|
|
#endif
|
2017-05-22 15:33:53 +00:00
|
|
|
// NOTE(matt): Tree structure of "global" buffer dependencies
|
|
|
|
// Master
|
2017-06-21 20:30:05 +00:00
|
|
|
// Includes
|
|
|
|
// Menus
|
2017-05-22 15:33:53 +00:00
|
|
|
// 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
|
2017-06-03 01:32:18 +00:00
|
|
|
// Script
|
|
|
|
// FilterState
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-07-29 00:36:14 +00:00
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &Master, "Master", Kilobytes(512));
|
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &Includes, "Includes", Kilobytes(1));
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-07-29 00:36:14 +00:00
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &Menus, "Menus", Kilobytes(24));
|
|
|
|
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));
|
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &CreditsMenu, "CreditsMenu", Kilobytes(8));
|
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &HostInfo, "HostInfo", Kilobytes(1));
|
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &AnnotatorInfo, "AnnotatorInfo", Kilobytes(1));
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-07-29 00:36:14 +00:00
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &Player, "Player", Kilobytes(256));
|
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &Colour, "Colour", 32);
|
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &Annotation, "Annotation", Kilobytes(8));
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-07-29 00:36:14 +00:00
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &Script, "Script", Kilobytes(8));
|
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &FilterState, "FilterState", Kilobytes(4));
|
2017-06-25 18:22:54 +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-06-25 18:22:54 +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-06-25 18:22:54 +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-06-25 18:22:54 +00:00
|
|
|
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"title %s\">\n"
|
|
|
|
" <span class=\"episode_name\">", HMML.metadata.project);
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBufferHTMLSafe(&Menus, HMML.metadata.title);
|
|
|
|
CopyStringToBuffer(&Menus, "</span>\n"
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span id=\"focus-warn\">⚠ Click here to regain focus ⚠</span>\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Player,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"player_container\">\n"
|
|
|
|
" <div class=\"video_container\" data-videoId=\"%s\"></div>\n"
|
|
|
|
" <div class=\"markers_container %s\">\n", HMML.metadata.id, HMML.metadata.project);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-21 15:12:40 +00:00
|
|
|
// TODO(matt): Handle multiple annotators
|
2017-06-21 23:16:09 +00:00
|
|
|
if(HMML.metadata.annotator_count > 0)
|
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
BuildCredits(&CreditsMenu, &HostInfo, &AnnotatorInfo, &HasCreditsMenu, ImagesDir, HMML.metadata.member, HMML.metadata.annotators[0]);
|
2017-06-21 23:16:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: Missing annotator in [video] node\n", Args[FileIndex]);
|
|
|
|
hmml_free(&HMML);
|
2017-07-29 00:36:14 +00:00
|
|
|
free(MemoryArena.Location);
|
2017-08-09 00:57:09 +00:00
|
|
|
free(Template.Location);
|
2017-06-21 23:16:09 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
#if DEBUG
|
2017-06-25 18:05:58 +00:00
|
|
|
printf(" --- Entering Annotations Loop ---\n");
|
2017-05-22 15:33:53 +00:00
|
|
|
#endif
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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-06-25 18:22:54 +00:00
|
|
|
|
2017-04-23 02:47:42 +00:00
|
|
|
quote_info QuoteInfo = { 0 };
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
// NOTE(matt): Tree structure of "annotation local" buffer dependencies
|
|
|
|
// AnnotationHeader
|
|
|
|
// AnnotationClass
|
|
|
|
// AnnotationData
|
|
|
|
// Text
|
|
|
|
// Category
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-07-29 00:36:14 +00:00
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &AnnotationHeader, "AnnotationHeader", 512);
|
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &AnnotationClass, "AnnotationClass", 256);
|
2017-07-29 23:01:39 +00:00
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &AnnotationData, "AnnotationData", 512);
|
2017-07-29 00:36:14 +00:00
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &Text, "Text", Kilobytes(4));
|
|
|
|
ClaimBuffer(&MemoryArena, &ClaimedMemory, &Category, "Category", 512);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&AnnotationHeader,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div data-timestamp=\"%d\"",
|
|
|
|
TimecodeToSeconds(Anno->time));
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&AnnotationClass,
|
2017-06-25 18:05:58 +00:00
|
|
|
" class=\"marker");
|
2017-06-25 18:22:54 +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");
|
2017-06-09 22:04:07 +00:00
|
|
|
hsl_colour AuthorColour;
|
|
|
|
StringToColourHash(&AuthorColour, Anno->author);
|
2017-06-10 16:47:47 +00:00
|
|
|
if(EDITION == EDITION_NETWORK)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d - TODO(matt): Implement author hoverbox\n", __FILE__, __LINE__);
|
|
|
|
// NOTE(matt): We should get instructions on how to get this info in the config
|
|
|
|
CopyStringToBuffer(&Text,
|
2017-06-25 18:05:58 +00:00
|
|
|
"<a class=\"author\" href=\"https://handmade.network/m/%s\" target=\"blank\" style=\"color: hsl(%d, %d%%, %d%%); text-decoration: none\" data-hue=\"%d\" data-saturation=\"%d%%\">%s</a> ",
|
|
|
|
Anno->author,
|
|
|
|
AuthorColour.Hue, AuthorColour.Saturation, AuthorColour.Lightness,
|
|
|
|
AuthorColour.Hue, AuthorColour.Saturation,
|
|
|
|
Anno->author);
|
2017-06-10 16:47:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Text,
|
2017-06-25 18:05:58 +00:00
|
|
|
"<span class=\"author\" style=\"color: hsl(%d, %d%%, %d%%);\" data-hue=\"%d\" data-saturation=\"%d%%\">%s</span> ",
|
|
|
|
AuthorColour.Hue, AuthorColour.Saturation, AuthorColour.Lightness,
|
|
|
|
AuthorColour.Hue, AuthorColour.Saturation,
|
|
|
|
Anno->author);
|
2017-06-10 16:47:47 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 03:47:07 +00:00
|
|
|
if(!HasMedium)
|
|
|
|
{
|
|
|
|
HasMedium = TRUE;
|
|
|
|
}
|
2017-03-23 00:34:59 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
InPtr = Anno->text;
|
2017-06-25 18:22:54 +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 &&
|
2017-06-25 18:05:58 +00:00
|
|
|
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
|
|
|
{
|
2017-06-09 22:04:07 +00:00
|
|
|
hsl_colour MemberColour;
|
|
|
|
StringToColourHash(&MemberColour, Anno->markers[MarkerIndex].marker);
|
2017-06-10 16:47:47 +00:00
|
|
|
if(EDITION == EDITION_NETWORK)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d - TODO(matt): Implement member hoverbox\n", __FILE__, __LINE__);
|
|
|
|
// NOTE(matt): We should get instructions on how to get this info in the config
|
|
|
|
CopyStringToBuffer(&Text,
|
2017-06-25 18:05:58 +00:00
|
|
|
"<a class=\"member\" href=\"https://handmade.network/m/%s\" target=\"blank\" style=\"color: hsl(%d, %d%%, %d%%); text-decoration: none\" data-hue=\"%d\" data-saturation=\"%d%%\">%.*s</a>",
|
|
|
|
Anno->markers[MarkerIndex].marker,
|
|
|
|
MemberColour.Hue, MemberColour.Saturation, MemberColour.Lightness,
|
|
|
|
MemberColour.Hue, MemberColour.Saturation,
|
|
|
|
StringLength(Readable), InPtr);
|
2017-06-10 16:47:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Text,
|
2017-06-25 18:05:58 +00:00
|
|
|
"<span class=\"member\" style=\"color: hsl(%d, %d%%, %d%%);\" data-hue=\"%d\" data-saturation=\"%d%%\">%.*s</span>",
|
|
|
|
MemberColour.Hue, MemberColour.Saturation, MemberColour.Lightness,
|
|
|
|
MemberColour.Hue, MemberColour.Saturation,
|
|
|
|
StringLength(Readable), InPtr);
|
2017-06-10 16:47:47 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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_PROJECT)
|
2017-03-25 02:07:55 +00:00
|
|
|
{
|
2017-06-09 22:04:07 +00:00
|
|
|
hsl_colour ProjectColour;
|
|
|
|
StringToColourHash(&ProjectColour, Anno->markers[MarkerIndex].marker);
|
2017-06-10 16:47:47 +00:00
|
|
|
if(EDITION == EDITION_NETWORK)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d - TODO(matt): Implement project hoverbox\n", __FILE__, __LINE__);
|
|
|
|
// NOTE(matt): We should get instructions on how to get this info in the config
|
|
|
|
CopyStringToBuffer(&Text,
|
2017-06-25 18:05:58 +00:00
|
|
|
"<a class=\"project\" href=\"https://%s.handmade.network/\" target=\"blank\" style=\"color: hsl(%d, %d%%, %d%%); text-decoration: none\" data-hue=\"%d\" data-saturation=\"%d%%\">%s</a>",
|
|
|
|
Anno->markers[MarkerIndex].marker,
|
|
|
|
ProjectColour.Hue, ProjectColour.Saturation, ProjectColour.Lightness,
|
|
|
|
ProjectColour.Hue, ProjectColour.Saturation,
|
|
|
|
Readable);
|
2017-06-10 16:47:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Text,
|
2017-06-25 18:05:58 +00:00
|
|
|
"<span class=\"project\" style=\"color: hsl(%d, %d%%, %d%%);\" data-hue=\"%d\" data-saturation=\"%d%%\">%s</span>",
|
|
|
|
ProjectColour.Hue, ProjectColour.Saturation, ProjectColour.Lightness,
|
|
|
|
ProjectColour.Hue, ProjectColour.Saturation,
|
|
|
|
Readable);
|
2017-06-10 16:47:47 +00:00
|
|
|
}
|
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-06-25 18:05:58 +00:00
|
|
|
GenerateTopicColours(&Colour, Anno->markers[MarkerIndex].marker, CSSDir);
|
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-06-25 18:22:54 +00:00
|
|
|
|
2017-07-29 23:01:39 +00:00
|
|
|
while(RefIndex < Anno->reference_count &&
|
2017-06-25 18:05:58 +00:00
|
|
|
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-06-25 18:05:58 +00:00
|
|
|
" <div class=\"menu references\">\n"
|
|
|
|
" <span>References ▼</span>\n"
|
|
|
|
" <div class=\"mouse_catcher\"></div>\n"
|
|
|
|
" <div class=\"refs references_container\">\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-04-21 01:25:40 +00:00
|
|
|
if(BuildReference(ReferencesArray, RefIdentifier, UniqueRefs, *CurrentRef, *Anno) == 1)
|
|
|
|
{
|
2017-07-29 23:01:39 +00:00
|
|
|
fprintf(stderr, "%s:%d: Cannot process new combination of reference info\n"
|
|
|
|
"\n"
|
|
|
|
"Either tweak your annotation, or contact matt@handmadedev.org\n"
|
|
|
|
"mentioning the ref node you want to write and how you want it to\n"
|
|
|
|
"appear in the references menu\n", Args[FileIndex], Anno->line);
|
2017-04-21 01:25:40 +00:00
|
|
|
hmml_free(&HMML);
|
2017-07-29 00:36:14 +00:00
|
|
|
free(MemoryArena.Location);
|
2017-08-09 00:57:09 +00:00
|
|
|
free(Template.Location);
|
2017-04-21 01:25:40 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2017-03-30 02:57:04 +00:00
|
|
|
++ReferencesArray[RefIdentifier - 1].IdentifierCount;
|
|
|
|
++UniqueRefs;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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-07-29 00:36:14 +00:00
|
|
|
if(ReferencesArray[i].IdentifierCount == REF_MAX_IDENTIFIER)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d: Too many timecodes associated with one reference (increase REF_MAX_IDENTIFIER)\n", Args[FileIndex], Anno->line);
|
|
|
|
hmml_free(&HMML);
|
|
|
|
free(MemoryArena.Location);
|
2017-08-09 00:57:09 +00:00
|
|
|
free(Template.Location);
|
2017-07-29 00:36:14 +00:00
|
|
|
return 1;
|
|
|
|
}
|
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);
|
2017-07-29 00:36:14 +00:00
|
|
|
free(MemoryArena.Location);
|
2017-08-09 00:57:09 +00:00
|
|
|
free(Template.Location);
|
2017-04-19 01:10:45 +00:00
|
|
|
return 1;
|
2017-03-30 02:57:04 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-04-21 01:25:40 +00:00
|
|
|
if(BuildReference(ReferencesArray, RefIdentifier, UniqueRefs, *CurrentRef, *Anno) == 1)
|
|
|
|
{
|
2017-07-29 23:01:39 +00:00
|
|
|
fprintf(stderr, "%s:%d: Cannot process new combination of reference info\n"
|
|
|
|
"\n"
|
|
|
|
"Either tweak your annotation, or contact matt@handmadedev.org\n"
|
|
|
|
"mentioning the ref node you want to write and how you want it to\n"
|
|
|
|
"appear in the references menu\n", Args[FileIndex], Anno->line);
|
2017-04-21 01:25:40 +00:00
|
|
|
hmml_free(&HMML);
|
2017-07-29 00:36:14 +00:00
|
|
|
free(MemoryArena.Location);
|
2017-08-09 00:57:09 +00:00
|
|
|
free(Template.Location);
|
2017-04-21 01:25:40 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2017-03-30 02:57:04 +00:00
|
|
|
++ReferencesArray[UniqueRefs].IdentifierCount;
|
|
|
|
++UniqueRefs;
|
|
|
|
}
|
2017-06-25 18:05:58 +00:00
|
|
|
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-07-29 00:36:14 +00:00
|
|
|
free(MemoryArena.Location);
|
2017-08-09 00:57:09 +00:00
|
|
|
free(Template.Location);
|
2017-04-19 01:10:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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-07-29 00:36:14 +00:00
|
|
|
free(MemoryArena.Location);
|
2017-08-09 00:57:09 +00:00
|
|
|
free(Template.Location);
|
2017-04-19 01:10:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2017-03-29 03:38:12 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-07-29 23:01:39 +00:00
|
|
|
if(Anno->references[RefIndex].offset == Anno->references[RefIndex-1].offset)
|
2017-05-24 21:56:36 +00:00
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Text, "<sup>,%d</sup>", RefIdentifier);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Text, "<sup>%d</sup>", RefIdentifier);
|
|
|
|
}
|
2017-06-25 18:22:54 +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
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-25 02:07:55 +00:00
|
|
|
if(*InPtr)
|
|
|
|
{
|
2017-06-07 23:47:47 +00:00
|
|
|
switch(*InPtr)
|
|
|
|
{
|
|
|
|
case '<':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&Text, "<");
|
|
|
|
InPtr++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
case '>':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&Text, ">");
|
|
|
|
InPtr++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
case '&':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&Text, "&");
|
|
|
|
InPtr++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
case '\"':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&Text, """);
|
|
|
|
InPtr++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
case '\'':
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&Text, "'");
|
|
|
|
InPtr++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
default:
|
2017-06-25 18:05:58 +00:00
|
|
|
*Text.Ptr++ = *InPtr++;
|
|
|
|
break;
|
2017-06-07 23:47:47 +00:00
|
|
|
}
|
2017-03-25 02:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
if(Anno->is_quote)
|
|
|
|
{
|
|
|
|
if(!HasQuoteMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&QuoteMenu,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"menu quotes\">\n"
|
|
|
|
" <span>Quotes ▼</span>\n"
|
|
|
|
" <div class=\"mouse_catcher\"></div>\n"
|
|
|
|
" <div class=\"refs quotes_container\">\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
HasQuoteMenu = TRUE;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
if(!HasReference)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, " data-ref=\"&#%d;", QuoteIdentifier);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&AnnotationData, ",&#%d;", QuoteIdentifier);
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
HasQuote = TRUE;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-08-11 22:41:52 +00:00
|
|
|
char *Speaker = Anno->quote.author ? Anno->quote.author : HMML.metadata.stream_username ? HMML.metadata.stream_username : HMML.metadata.member;
|
2017-08-10 01:05:41 +00:00
|
|
|
if(BuildQuote(&QuoteInfo,
|
2017-08-11 22:41:52 +00:00
|
|
|
Speaker,
|
2017-08-10 01:05:41 +00:00
|
|
|
Anno->quote.id,
|
|
|
|
CacheDir) == 1)
|
2017-04-23 02:47:42 +00:00
|
|
|
{
|
2017-08-09 00:57:09 +00:00
|
|
|
fprintf(stderr, "%s:%d: Quote #%s %d not found. Unlucky!\n",
|
2017-04-23 02:47:42 +00:00
|
|
|
Args[FileIndex],
|
|
|
|
Anno->line,
|
2017-08-11 22:41:52 +00:00
|
|
|
Speaker,
|
2017-04-23 02:47:42 +00:00
|
|
|
Anno->quote.id);
|
|
|
|
hmml_free(&HMML);
|
2017-07-29 00:36:14 +00:00
|
|
|
free(MemoryArena.Location);
|
2017-08-09 00:57:09 +00:00
|
|
|
free(Template.Location);
|
2017-04-23 02:47:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2017-08-11 22:41:52 +00:00
|
|
|
if(BuildQuote(&QuoteInfo,
|
|
|
|
Speaker,
|
|
|
|
Anno->quote.id,
|
|
|
|
CacheDir) == 2)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d: Failed to create quote cache at %s/quotes/%s for Quote #%s %d.\n"
|
|
|
|
"Proceeding anyway, without a cache!\n",
|
|
|
|
Args[FileIndex],
|
|
|
|
Anno->line,
|
|
|
|
CacheDir,
|
|
|
|
Speaker,
|
|
|
|
Speaker,
|
|
|
|
Anno->quote.id);
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
CopyStringToBuffer(&QuoteMenu,
|
2017-08-10 01:05:41 +00:00
|
|
|
" <a target=\"_blank\" class=\"ref\" href=\"https://dev.abaines.me.uk/quotes/%s/%d\">\n"
|
|
|
|
" <span data-id=\"&#%d;\">\n"
|
|
|
|
" <span class=\"ref_content\">\n"
|
|
|
|
" <div class=\"source\">Quote %d</div>\n"
|
|
|
|
" <div class=\"ref_title\">",
|
2017-08-11 22:41:52 +00:00
|
|
|
Speaker,
|
2017-08-10 01:05:41 +00:00
|
|
|
Anno->quote.id,
|
2017-06-25 18:05:58 +00:00
|
|
|
QuoteIdentifier,
|
|
|
|
Anno->quote.id);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-10 16:47:47 +00:00
|
|
|
CopyStringToBufferCSVSafe(&QuoteMenu, QuoteInfo.Text);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-10 16:47:47 +00:00
|
|
|
CopyStringToBuffer(&QuoteMenu, "</div>\n"
|
2017-08-10 01:05:41 +00:00
|
|
|
" <div class=\"quote_byline\">—%s, %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"
|
2017-06-25 18:05:58 +00:00
|
|
|
" </span>\n"
|
2017-08-10 01:05:41 +00:00
|
|
|
" </a>\n",
|
2017-08-11 22:41:52 +00:00
|
|
|
Speaker,
|
2017-06-25 18:05:58 +00:00
|
|
|
QuoteInfo.Date,
|
|
|
|
TimecodeToSeconds(Anno->time),
|
|
|
|
QuoteIdentifier,
|
|
|
|
Anno->time);
|
2017-03-29 03:38:12 +00:00
|
|
|
if(!Anno->text[0])
|
|
|
|
{
|
2017-06-07 23:47:47 +00:00
|
|
|
CopyStringToBuffer(&Text, "“");
|
|
|
|
CopyStringToBufferHTMLSafe(&Text, QuoteInfo.Text);
|
|
|
|
CopyStringToBuffer(&Text, "”");
|
2017-03-29 03:38:12 +00:00
|
|
|
}
|
|
|
|
CopyStringToBuffer(&Text, "<sup>&#%d;</sup>", QuoteIdentifier);
|
|
|
|
++QuoteIdentifier;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
while(MarkerIndex < Anno->marker_count)
|
2017-03-25 02:07:55 +00:00
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
GenerateTopicColours(&Colour, Anno->markers[MarkerIndex].marker, CSSDir);
|
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);
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-22 21:37:00 +00:00
|
|
|
if(!HasMedium)
|
|
|
|
{
|
2017-08-05 18:13:02 +00:00
|
|
|
BuildFilter(TopicsArray, &UniqueTopics, MediaArray, &UniqueMedia, DefaultMedium);
|
|
|
|
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, DefaultMedium);
|
2017-03-25 02:07:55 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&AnnotationClass, "\"");
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&AnnotationHeader, &AnnotationClass);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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-06-25 18:22:54 +00:00
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Annotation, &AnnotationHeader);
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Annotation,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"content\"><span class=\"timecode\">%s</span>",
|
|
|
|
Anno->time);
|
2017-06-25 18:22:54 +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-06-25 18:22:54 +00:00
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Annotation, &Text);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Annotation, "</div>\n"
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"progress faded\">\n"
|
|
|
|
" <div class=\"content\"><span class=\"timecode\">%s</span>",
|
|
|
|
Anno->time);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Annotation, &Text);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Annotation, "</div>\n"
|
2017-06-25 18:05:58 +00:00
|
|
|
" </div>\n"
|
|
|
|
" <div class=\"progress main\">\n"
|
|
|
|
" <div class=\"content\"><span class=\"timecode\">%s</span>",
|
|
|
|
Anno->time);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Annotation, &Text);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Annotation, "</div>\n"
|
2017-06-25 18:05:58 +00:00
|
|
|
" </div>\n"
|
|
|
|
" </div>\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyBuffer(&Player, &Annotation);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
// NOTE(matt): Tree structure of "annotation local" buffer dependencies
|
|
|
|
// Category
|
|
|
|
// Text
|
|
|
|
// AnnotationData
|
|
|
|
// AnnotationClass
|
|
|
|
// AnnotationHeader
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
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-06-25 18:22:54 +00:00
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
#if DEBUG
|
2017-06-25 18:05:58 +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,
|
2017-06-25 18:05:58 +00:00
|
|
|
" </div>\n"
|
|
|
|
" </div>\n");
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyBuffer(&Menus, &QuoteMenu);
|
2017-03-29 03:38:12 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
|
|
|
" <a data-id=\"%s\" href=\"%s\" target=\"_blank\" class=\"ref\">\n"
|
|
|
|
" <span class=\"ref_content\">\n",
|
|
|
|
ReferencesArray[i].ID,
|
|
|
|
ReferencesArray[i].URL);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
if(*ReferencesArray[i].Source)
|
|
|
|
{
|
2017-03-30 02:57:04 +00:00
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"source\">");
|
|
|
|
CopyStringToBufferHTMLSafe(&ReferenceMenu, ReferencesArray[i].Source);
|
|
|
|
CopyStringToBuffer(&ReferenceMenu, "</div>\n"
|
|
|
|
" <div class=\"ref_title\">");
|
|
|
|
CopyStringToBufferHTMLSafe(&ReferenceMenu, ReferencesArray[i].RefTitle);
|
|
|
|
CopyStringToBuffer(&ReferenceMenu, "</div>\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
|
|
|
" <div class=\"ref_title\">");
|
|
|
|
CopyStringToBufferHTMLSafe(&ReferenceMenu, ReferencesArray[i].RefTitle);
|
|
|
|
CopyStringToBuffer(&ReferenceMenu, "</div>\n");
|
|
|
|
}
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
|
|
|
" </span>\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
for(int j = 0; j < ReferencesArray[i].IdentifierCount;)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
|
|
|
" <div class=\"ref_indices\">\n ");
|
|
|
|
for(int k = 0; k < 3 && j < ReferencesArray[i].IdentifierCount; ++k, ++j)
|
2017-04-19 01:10:45 +00:00
|
|
|
{
|
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
2017-06-25 18:05:58 +00:00
|
|
|
"<span data-timestamp=\"%d\" class=\"timecode\"><span class=\"ref_index\">[%d]</span><span class=\"time\">%s</span></span>",
|
|
|
|
TimecodeToSeconds(ReferencesArray[i].Identifier[j].Timecode),
|
|
|
|
ReferencesArray[i].Identifier[j].Identifier,
|
|
|
|
ReferencesArray[i].Identifier[j].Timecode);
|
2017-04-19 01:10:45 +00:00
|
|
|
}
|
2017-04-13 00:21:04 +00:00
|
|
|
CopyStringToBuffer(&ReferenceMenu, "\n"
|
2017-06-25 18:05:58 +00:00
|
|
|
" </div>\n");
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
|
|
|
" </a>\n");
|
2017-03-30 02:57:04 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-29 03:38:12 +00:00
|
|
|
CopyStringToBuffer(&ReferenceMenu,
|
2017-06-25 18:05:58 +00:00
|
|
|
" </div>\n"
|
|
|
|
" </div>\n");
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyBuffer(&Menus, &ReferenceMenu);
|
2017-03-29 03:38:12 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
if(HasFilterMenu)
|
|
|
|
{
|
2017-06-13 22:13:03 +00:00
|
|
|
CopyStringToBuffer(&FilterState,
|
2017-06-25 18:05:58 +00:00
|
|
|
" 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",
|
2017-06-25 18:05:58 +00:00
|
|
|
TopicsArray[i].Marker, "topic");
|
2017-05-24 21:56:36 +00:00
|
|
|
}
|
|
|
|
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-06-25 18:05:58 +00:00
|
|
|
MediaArray[i].Marker, "medium");
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
2017-06-13 22:13:03 +00:00
|
|
|
CopyStringToBuffer(&FilterState,
|
2017-06-25 18:05:58 +00:00
|
|
|
" };\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
CopyStringToBuffer(&FilterMenu,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"menu filter\">\n"
|
|
|
|
" <span><img src=\"%s/cinera_icon_filter.png\"></span>\n"
|
|
|
|
" <div class=\"filter_container\">\n"
|
|
|
|
" <div class=\"filter_mode inclusive\">Filter mode: </div>\n"
|
|
|
|
" <div class=\"filters\">\n", ImagesDir);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
{
|
|
|
|
bool HasTopic = FALSE;
|
|
|
|
bool HasMedium = FALSE;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"filter_topics\">\n"
|
|
|
|
" <div class=\"filter_title\">Topics</div>\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
HasTopic = TRUE;
|
|
|
|
}
|
|
|
|
CopyStringToBuffer(&FilterTopics,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <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);
|
2017-05-24 21:56:36 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
for(int i = 0; i < UniqueMedia; ++i)
|
|
|
|
{
|
|
|
|
if(!HasMedium)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&FilterMedia,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"filter_media\">\n"
|
|
|
|
" <div class=\"filter_title\">Media</div>\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
HasMedium = TRUE;
|
|
|
|
}
|
2017-06-25 18:22:54 +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-06-25 18:22:54 +00:00
|
|
|
|
2017-05-24 21:56:36 +00:00
|
|
|
CopyStringToBuffer(&FilterMedia,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"filter_content %s\">\n"
|
|
|
|
" <span class=\"icon\">%s</span><span class=\"text\">%s</span>\n"
|
|
|
|
" </div>\n",
|
|
|
|
MediaArray[i].Marker,
|
|
|
|
CategoryMedium[j][1],
|
|
|
|
CategoryMedium[j][2]
|
|
|
|
);
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
if(HasTopic)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&FilterTopics,
|
2017-06-25 18:05:58 +00:00
|
|
|
" </div>\n");
|
2017-05-21 06:35:16 +00:00
|
|
|
CopyBuffer(&FilterMenu, &FilterTopics);
|
|
|
|
}
|
|
|
|
if(HasMedium)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&FilterMedia,
|
2017-06-25 18:05:58 +00:00
|
|
|
" </div>\n");
|
2017-05-21 06:35:16 +00:00
|
|
|
CopyBuffer(&FilterMenu, &FilterMedia);
|
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&FilterMenu,
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n");
|
2017-05-21 06:35:16 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyBuffer(&Menus, &FilterMenu);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-25 20:28:52 +00:00
|
|
|
if(HasCreditsMenu)
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyBuffer(&Menus, &CreditsMenu);
|
2017-05-25 20:28:52 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <div class=\"help\">\n"
|
|
|
|
" <span>?</span>\n"
|
|
|
|
" <div class=\"help_container\">\n"
|
|
|
|
" <span class=\"help_key\">?</span><h1>Keyboard Navigation</h1>\n"
|
|
|
|
"\n"
|
|
|
|
" <h2>Global Keys</h2>\n"
|
|
|
|
" <span class=\"help_key\">W</span>, <span class=\"help_key\">A</span>, <span class=\"help_key\">P</span> / <span class=\"help_key\">S</span>, <span class=\"help_key\">D</span>, <span class=\"help_key\">N</span> <span class=\"help_text\">Jump to previous / next marker</span><br>\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasFilterMenu)
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key\">z</span> <span class=\"help_text\">Toggle filter mode</span> <span class=\"help_key\">V</span> <span class=\"help_text\">Revert filter to original state</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key unavailable\">z</span> <span class=\"help_text unavailable\">Toggle filter mode</span> <span class=\"help_key unavailable\">V</span> <span class=\"help_text unavailable\">Revert filter to original state</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
"\n"
|
|
|
|
" <h2>Menu toggling</h2>\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasQuoteMenu)
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key\">q</span> <span class=\"help_text\">Quotes</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key unavailable\">q</span> <span class=\"help_text unavailable\">Quotes</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasReferenceMenu)
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key\">r</span> <span class=\"help_text\">References</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key unavailable\">r</span> <span class=\"help_text unavailable\">References</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasFilterMenu)
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key\">f</span> <span class=\"help_text\">Filter</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key unavailable\">f</span> <span class=\"help_text unavailable\">Filter</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasCreditsMenu)
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key\">c</span> <span class=\"help_text\">Credits</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key unavailable\">c</span> <span class=\"help_text unavailable\">Credits</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
"\n"
|
|
|
|
" <h2>Movement</h2>\n"
|
|
|
|
" <div class=\"help_paragraph\">\n"
|
|
|
|
" <div class=\"key_block\">\n"
|
|
|
|
" <div class=\"key_column\" style=\"flex-grow: 1\">\n"
|
|
|
|
" <span class=\"help_key\">a</span>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" <div class=\"key_column\" style=\"flex-grow: 2\">\n"
|
|
|
|
" <span class=\"help_key\">w</span><br>\n"
|
|
|
|
" <span class=\"help_key\">s</span>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" <div class=\"key_column\" style=\"flex-grow: 1\">\n"
|
|
|
|
" <span class=\"help_key\">d</span>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" <div class=\"key_block\">\n"
|
|
|
|
" <span class=\"help_key\">h</span>\n"
|
|
|
|
" <span class=\"help_key\">j</span>\n"
|
|
|
|
" <span class=\"help_key\">k</span>\n"
|
|
|
|
" <span class=\"help_key\">l</span>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" <div class=\"key_block\">\n"
|
|
|
|
" <div style=\"flex-grow: 1\">\n"
|
|
|
|
" <span class=\"help_key\">←</span>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" <div style=\"flex-grow: 2\">\n"
|
|
|
|
" <span class=\"help_key\">↑</span><br>\n"
|
|
|
|
" <span class=\"help_key\">↓</span>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" <div style=\"flex-grow: 1\">\n"
|
|
|
|
" <span class=\"help_key\">→</span>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n"
|
|
|
|
" <br>\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasQuoteMenu)
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <h2>Quotes ");
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasReferenceMenu)
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus, "and References Menus</h2>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus, "<span class=\"unavailable\">and References</span> Menus</h2>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <h2><span class=\"unavailable\">Quotes");
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasReferenceMenu)
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus, " and</span> References Menus</h2>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus, " and References Menus</span></h2>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasQuoteMenu || HasReferenceMenu)
|
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
|
|
|
" <span style=\"width: auto\" class=\"help_key\">Enter</span> <span class=\"help_text\">Jump to timecode</span><br>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
|
|
|
" <span style=\"width: auto\" class=\"help_key unavailable\">Enter</span> <span class=\"help_text unavailable\">Jump to timecode</span><br>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-08-10 01:05:41 +00:00
|
|
|
if(HasQuoteMenu)
|
2017-06-03 01:32:18 +00:00
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-08-10 01:05:41 +00:00
|
|
|
" <h2>Quotes");
|
|
|
|
if(HasReferenceMenu)
|
2017-06-03 01:32:18 +00:00
|
|
|
{
|
2017-08-10 01:05:41 +00:00
|
|
|
CopyStringToBuffer(&Menus, ", References ");
|
|
|
|
if(HasCreditsMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus, "and Credits Menus</h2>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus, "<span class=\"unavailable\">and Credits</span> Menus</h2>");
|
|
|
|
}
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-10 01:05:41 +00:00
|
|
|
CopyStringToBuffer(&Menus, "<span class=\"unavailable\">, References ");
|
|
|
|
if(HasCreditsMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus, "</span>and Credits Menus</h2>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus, "and Credits</span> Menus</h2>");
|
|
|
|
}
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-08-10 01:05:41 +00:00
|
|
|
" <h2><span class=\"unavailable\">Quotes");
|
|
|
|
if(HasReferenceMenu)
|
2017-06-03 01:32:18 +00:00
|
|
|
{
|
2017-08-10 01:05:41 +00:00
|
|
|
CopyStringToBuffer(&Menus, ", </span>References ");
|
|
|
|
if(HasCreditsMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus, "and Credits Menus</h2>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus, "<span class=\"unavailable\">and Credits</span> Menus</h2>");
|
|
|
|
}
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-10 01:05:41 +00:00
|
|
|
CopyStringToBuffer(&Menus, ", References ");
|
|
|
|
if(HasCreditsMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus, "</span>and Credits Menus</h2>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus, "and Credits Menus</h2></span>");
|
|
|
|
}
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-08-10 01:05:41 +00:00
|
|
|
if(HasQuoteMenu || HasReferenceMenu || HasCreditsMenu)
|
2017-06-03 01:32:18 +00:00
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key\">o</span> <span class=\"help_text\">Open URL (in new tab)</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <span class=\"help_key unavailable\">o</span> <span class=\"help_text unavailable\">Open URL (in new tab)</span>\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
"\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
if(HasFilterMenu)
|
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <h2>Filter Menu</h2>\n"
|
|
|
|
" <span class=\"help_key\">x</span>, <span style=\"width: auto\" class=\"help_key\">Space</span> <span class=\"help_text\">Toggle category and focus next</span><br>\n"
|
|
|
|
" <span class=\"help_key\">X</span>, <span style=\"width: auto; margin-right: 0px\" class=\"help_key\">Shift</span><span style=\"width: auto\" class=\"help_key\">Space</span> <span class=\"help_text\">Toggle category and focus previous</span><br>\n"
|
|
|
|
" <span class=\"help_key\">v</span> <span class=\"help_text\">Invert topics / media as per focus</span>\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus,
|
|
|
|
" <h2><span class=\"unavailable\">Filter Menu</span></h2>\n"
|
|
|
|
" <span class=\"help_key unavailable\">x</span>, <span style=\"width: auto\" class=\"help_key unavailable\">Space</span> <span class=\"help_text unavailable\">Toggle category and focus next</span><br>\n"
|
|
|
|
" <span class=\"help_key unavailable\">X</span>, <span style=\"width: auto; margin-right: 0px\" class=\"help_key unavailable\">Shift</span><span style=\"width: auto\" class=\"help_key unavailable\">Space</span> <span class=\"help_text unavailable\">Toggle category and focus previous</span><br>\n"
|
|
|
|
" <span class=\"help_key unavailable\">v</span> <span class=\"help_text unavailable\">Invert topics / media as per focus</span>\n");
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
if(HasCreditsMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus,
|
|
|
|
" <h2>Credits Menu</h2>\n"
|
|
|
|
" <span style=\"width: auto\" class=\"help_key\">Enter</span> <span class=\"help_text\">Open URL (in new tab)</span><br>\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Menus,
|
|
|
|
" <h2><span class=\"unavailable\">Credits Menu</span></h2>\n"
|
|
|
|
" <span style=\"width: auto\" class=\"help_key unavailable\">Enter</span> <span class=\"help_text unavailable\">Open URL (in new tab)</span><br>\n");
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&Menus,
|
|
|
|
" </div>\n"
|
|
|
|
" </div>\n"
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
" </div>");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-03-23 00:34:59 +00:00
|
|
|
CopyStringToBuffer(&Player,
|
2017-06-25 18:05:58 +00:00
|
|
|
" </div>\n"
|
|
|
|
" </div>");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-12 22:26:01 +00:00
|
|
|
// TODO(matt): Maybe do something about indentation levels
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Includes,
|
2017-06-25 18:05:58 +00:00
|
|
|
"<meta charset=\"UTF-8\">\n"
|
|
|
|
"\n"
|
|
|
|
" <!-- Load the player -->\n"
|
|
|
|
" <script type=\"text/javascript\" src=\"%s/cinera.js\"></script>\n"
|
|
|
|
" <link rel=\"stylesheet\" type=\"text/css\" href=\"%s/cinera.css\">\n"
|
|
|
|
" <link rel=\"stylesheet\" type=\"text/css\" href=\"%s/cinera__%s.css\">\n"
|
|
|
|
" <link rel=\"stylesheet\" type=\"text/css\" href=\"%s/cinera_topics.css\">",
|
|
|
|
JSDir,
|
|
|
|
CSSDir,
|
|
|
|
CSSDir,
|
|
|
|
HMML.metadata.project,
|
|
|
|
CSSDir);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
CopyStringToBuffer(&Script,
|
2017-06-25 18:05:58 +00:00
|
|
|
" <script type=\"text/javascript\">\n"
|
|
|
|
"var menuState = [];\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 03:47:07 +00:00
|
|
|
CopyStringToBuffer(&Script,
|
2017-06-25 18:05:58 +00:00
|
|
|
"var quotesMenu = document.querySelector(\".quotes_container\");\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasQuoteMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Script,
|
2017-06-25 18:05:58 +00:00
|
|
|
"if(quotesMenu)\n"
|
|
|
|
"{\n"
|
|
|
|
"menuState.push(quotesMenu);\n"
|
|
|
|
"var quoteItems = quotesMenu.querySelectorAll(\".ref\");\n"
|
|
|
|
"for(var i = 0; i < quoteItems.length; ++i)\n"
|
|
|
|
"{\n"
|
|
|
|
" quoteItems[i].addEventListener(\"mouseenter\", function(ev) {\n"
|
|
|
|
" mouseOverQuotes(this);\n"
|
|
|
|
" })\n"
|
|
|
|
"};\n"
|
|
|
|
"var lastFocusedQuote = null;\n"
|
|
|
|
"}\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&Script,
|
|
|
|
"var referencesMenu = document.querySelector(\".references_container\");\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasReferenceMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Script,
|
2017-06-25 18:05:58 +00:00
|
|
|
"if(referencesMenu)\n"
|
|
|
|
"{\n"
|
|
|
|
"menuState.push(referencesMenu);\n"
|
|
|
|
"var referenceItems = referencesMenu.querySelectorAll(\".ref\");\n"
|
|
|
|
"for(var i = 0; i < referenceItems.length; ++i)\n"
|
|
|
|
"{\n"
|
|
|
|
" referenceItems[i].addEventListener(\"mouseenter\", function(ev) {\n"
|
|
|
|
" mouseOverReferences(this);\n"
|
|
|
|
" })\n"
|
|
|
|
"};\n"
|
|
|
|
"var lastFocusedReference = null;\n"
|
|
|
|
"var lastFocusedIdentifier = null;\n"
|
|
|
|
"}\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-25 18:05:58 +00:00
|
|
|
CopyStringToBuffer(&Script,
|
|
|
|
"var filterMenu = document.querySelector(\".filter_container\");\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasFilterMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Script,
|
2017-06-25 18:05:58 +00:00
|
|
|
"if(filterMenu)\n"
|
|
|
|
"{\n"
|
|
|
|
" menuState.push(filterMenu);\n"
|
|
|
|
" var lastFocusedCategory = null;\n"
|
|
|
|
" var lastFocusedTopic = null;\n"
|
|
|
|
" var lastFocusedMedium = null;\n"
|
|
|
|
"\n"
|
|
|
|
" var filter = filterMenu.parentNode;\n"
|
|
|
|
"\n"
|
|
|
|
" var filterModeElement = filter.querySelector(\".filter_mode\");\n"
|
|
|
|
" filterModeElement.addEventListener(\"click\", function(ev) {\n"
|
|
|
|
" toggleFilterMode();\n"
|
|
|
|
" });\n"
|
|
|
|
"\n"
|
|
|
|
" var filterMode = filterModeElement.classList[1];\n"
|
|
|
|
" var filterItems = filter.querySelectorAll(\".filter_content\");\n"
|
|
|
|
" for(var i = 0; i < filterItems.length; ++i)\n"
|
|
|
|
" {\n"
|
|
|
|
" filterItems[i].addEventListener(\"mouseenter\", function(ev) {\n"
|
|
|
|
" navigateFilter(this);\n"
|
|
|
|
" })\n"
|
|
|
|
"\n"
|
|
|
|
" filterItems[i].addEventListener(\"click\", function(ev) {\n"
|
|
|
|
" filterItemToggle(this);\n"
|
|
|
|
" });\n"
|
|
|
|
"\n"
|
|
|
|
"%s"
|
|
|
|
" }\n"
|
|
|
|
"}\n", FilterState.Location);
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 03:47:07 +00:00
|
|
|
CopyStringToBuffer(&Script,
|
2017-06-25 18:05:58 +00:00
|
|
|
"var creditsMenu = document.querySelector(\".credits_container\");\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
if(HasCreditsMenu)
|
|
|
|
{
|
|
|
|
CopyStringToBuffer(&Script,
|
2017-06-25 18:05:58 +00:00
|
|
|
"if(creditsMenu)\n"
|
|
|
|
"{\n"
|
|
|
|
" menuState.push(creditsMenu);\n"
|
|
|
|
" var lastFocusedCreditItem = null;\n"
|
|
|
|
"\n"
|
|
|
|
" var creditItems = creditsMenu.querySelectorAll(\".person, .support\");\n"
|
|
|
|
" for(var i = 0; i < creditItems.length; ++i)\n"
|
|
|
|
" {\n"
|
|
|
|
" creditItems[i].addEventListener(\"mouseenter\", function(ev) {\n"
|
|
|
|
" if(this != lastFocusedCreditItem)\n"
|
|
|
|
" {\n"
|
|
|
|
" lastFocusedCreditItem.classList.remove(\"focused\");\n"
|
|
|
|
" lastFocusedCreditItem = this;\n"
|
|
|
|
" focusedElement = lastFocusedCreditItem;\n"
|
|
|
|
" focusedElement.classList.add(\"focused\");\n"
|
|
|
|
" }\n"
|
|
|
|
" })\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n");
|
2017-06-03 01:32:18 +00:00
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-03 01:32:18 +00:00
|
|
|
CopyStringToBuffer(&Script,
|
2017-06-25 18:05:58 +00:00
|
|
|
"var sourceMenus = document.querySelectorAll(\".menu\");\n"
|
|
|
|
"\n"
|
|
|
|
"var helpButton = document.querySelector(\".help\");\n"
|
|
|
|
"var helpDocumentation = helpButton.querySelector(\".help_container\");\n"
|
|
|
|
"helpButton.addEventListener(\"click\", function(ev) {\n"
|
|
|
|
" handleMouseOverMenu(this, ev.type);\n"
|
|
|
|
"})\n"
|
|
|
|
"\n"
|
|
|
|
"var focusedElement = null;\n"
|
|
|
|
"var focusedIdentifier = null;\n"
|
|
|
|
"\n"
|
|
|
|
"var playerContainer = document.querySelector(\".player_container\")\n"
|
|
|
|
"var player = new Player(playerContainer, onRefChanged);\n"
|
|
|
|
"window.addEventListener(\"resize\", function() { player.updateSize(); });\n"
|
|
|
|
"document.addEventListener(\"keydown\", function(ev) {\n"
|
|
|
|
" var key = ev.key;\n"
|
|
|
|
" if(ev.getModifierState(\"Shift\") && key == \" \")\n"
|
|
|
|
" {\n"
|
|
|
|
" key = \"capitalSpace\";\n"
|
|
|
|
" }\n"
|
|
|
|
"\n"
|
|
|
|
" if(handleKey(key) == true && focusedElement)\n"
|
|
|
|
" {\n"
|
|
|
|
" ev.preventDefault();\n"
|
|
|
|
" }\n"
|
|
|
|
"});\n"
|
|
|
|
"\n"
|
|
|
|
"for(var i = 0; i < sourceMenus.length; ++i)\n"
|
|
|
|
"{\n"
|
|
|
|
" sourceMenus[i].addEventListener(\"mouseenter\", function(ev) {\n"
|
|
|
|
" handleMouseOverMenu(this, ev.type);\n"
|
|
|
|
" })\n"
|
|
|
|
" sourceMenus[i].addEventListener(\"mouseleave\", function(ev) {\n"
|
|
|
|
" handleMouseOverMenu(this, ev.type);\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"
|
|
|
|
" mouseSkipToTimecode(player, time, ev);\n"
|
|
|
|
" }\n"
|
|
|
|
" });\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"var refSources = document.querySelectorAll(\".refs .ref\"); // This is for both quotes and refs\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"
|
|
|
|
"var testMarkers = playerContainer.querySelectorAll(\".marker\");\n"
|
|
|
|
"\n"
|
|
|
|
"window.addEventListener(\"blur\", function(){\n"
|
|
|
|
" document.getElementById(\"focus-warn\").style.display = \"block\";\n"
|
|
|
|
"});\n"
|
|
|
|
"\n"
|
|
|
|
"window.addEventListener(\"focus\", function(){\n"
|
|
|
|
" document.getElementById(\"focus-warn\").style.display = \"none\";\n"
|
|
|
|
"});\n"
|
|
|
|
"\n"
|
|
|
|
"var colouredItems = playerContainer.querySelectorAll(\".author, .member, .project\");\n"
|
|
|
|
"for(i = 0; i < colouredItems.length; ++i)\n"
|
|
|
|
"{\n"
|
|
|
|
" setTextLightness(colouredItems[i]);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"var topicDots = document.querySelectorAll(\".category\");\n"
|
|
|
|
"for(var i = 0; i < topicDots.length; ++i)\n"
|
|
|
|
"{\n"
|
|
|
|
" setDotLightness(topicDots[i]);\n"
|
|
|
|
"}\n"
|
2017-08-05 18:13:02 +00:00
|
|
|
"\n"
|
|
|
|
"if(location.hash) {\n"
|
|
|
|
" player.setTime(location.hash.startsWith('#') ? location.hash.substr(1) : location.hash);\n"
|
|
|
|
"}\n"
|
2017-06-25 18:05:58 +00:00
|
|
|
" </script>");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-12 22:26:01 +00:00
|
|
|
#if DEBUG
|
|
|
|
printf("Buffer Collation\n\n");
|
|
|
|
#endif
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-12 22:26:01 +00:00
|
|
|
if(CINERA_MODE && !StringsDiffer(CINERA_MODE, "INTEGRATE"))
|
|
|
|
{
|
2017-06-16 07:55:59 +00:00
|
|
|
buffer Output;
|
2017-06-21 20:30:05 +00:00
|
|
|
Output.Size = Template.Size + Master.Size;
|
2017-06-16 07:55:59 +00:00
|
|
|
Output.ID = "Output";
|
2017-06-21 20:30:05 +00:00
|
|
|
if(!(Output.Location = malloc(Output.Size)))
|
2017-06-12 22:26:01 +00:00
|
|
|
{
|
2017-07-29 00:36:14 +00:00
|
|
|
perror(Args[0]); free(Template.Location); hmml_free(&HMML); free(MemoryArena.Location); return 1;
|
2017-06-12 22:26:01 +00:00
|
|
|
}
|
2017-06-21 20:30:05 +00:00
|
|
|
Output.Ptr = Output.Location;
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-21 20:30:05 +00:00
|
|
|
char *IncludesTag = "__CINERA_INCLUDES__";
|
|
|
|
char *TitleTag = "__CINERA_TITLE__";
|
|
|
|
char *MenusTag = "__CINERA_MENUS__";
|
2017-06-13 22:13:03 +00:00
|
|
|
char *PlayerTag = "__CINERA_PLAYER__";
|
|
|
|
char *ScriptTag = "__CINERA_SCRIPT__";
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-16 07:55:59 +00:00
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
2017-06-12 22:26:01 +00:00
|
|
|
{
|
2017-06-16 07:55:59 +00:00
|
|
|
if(*Template.Ptr == '!' && (Template.Ptr > Template.Location && !StringsDifferT("<!--", &Template.Ptr[-1], 0)))
|
2017-06-12 22:26:01 +00:00
|
|
|
{
|
2017-06-16 07:55:59 +00:00
|
|
|
char *CommentStart = &Output.Ptr[-1];
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
2017-06-12 22:26:01 +00:00
|
|
|
{
|
2017-06-21 20:30:05 +00:00
|
|
|
if(!(StringsDifferT(IncludesTag, Template.Ptr, 0)))
|
2017-06-13 22:13:03 +00:00
|
|
|
{
|
2017-06-16 07:55:59 +00:00
|
|
|
Output.Ptr = CommentStart;
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyBuffer(&Output, &Includes);
|
2017-06-16 07:55:59 +00:00
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
2017-06-13 22:13:03 +00:00
|
|
|
{
|
2017-06-16 07:55:59 +00:00
|
|
|
if(!StringsDifferT("-->", Template.Ptr, 0))
|
2017-06-13 22:13:03 +00:00
|
|
|
{
|
2017-06-16 07:55:59 +00:00
|
|
|
Template.Ptr += StringLength("-->");
|
2017-06-15 22:10:36 +00:00
|
|
|
break;
|
2017-06-13 22:13:03 +00:00
|
|
|
}
|
2017-06-16 07:55:59 +00:00
|
|
|
++Template.Ptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-16 07:55:59 +00:00
|
|
|
else if(!(StringsDifferT(TitleTag, Template.Ptr, 0)))
|
|
|
|
{
|
|
|
|
Output.Ptr = CommentStart;
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyStringToBuffer(&Output, HMML.metadata.title);
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(!StringsDifferT("-->", Template.Ptr, 0))
|
|
|
|
{
|
|
|
|
Template.Ptr += StringLength("-->");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++Template.Ptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(!(StringsDifferT(MenusTag, Template.Ptr, 0)))
|
|
|
|
{
|
|
|
|
Output.Ptr = CommentStart;
|
|
|
|
CopyBuffer(&Output, &Menus);
|
2017-06-16 07:55:59 +00:00
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(!StringsDifferT("-->", Template.Ptr, 0))
|
2017-06-13 22:13:03 +00:00
|
|
|
{
|
2017-06-16 07:55:59 +00:00
|
|
|
Template.Ptr += StringLength("-->");
|
2017-06-15 22:10:36 +00:00
|
|
|
break;
|
2017-06-13 22:13:03 +00:00
|
|
|
}
|
2017-06-16 07:55:59 +00:00
|
|
|
++Template.Ptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(!(StringsDifferT(PlayerTag, Template.Ptr, 0)))
|
|
|
|
{
|
|
|
|
Output.Ptr = CommentStart;
|
|
|
|
CopyBuffer(&Output, &Player);
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(!StringsDifferT("-->", Template.Ptr, 0))
|
2017-06-13 22:13:03 +00:00
|
|
|
{
|
2017-06-16 07:55:59 +00:00
|
|
|
Template.Ptr += StringLength("-->");
|
2017-06-15 22:10:36 +00:00
|
|
|
break;
|
2017-06-13 22:13:03 +00:00
|
|
|
}
|
2017-06-16 07:55:59 +00:00
|
|
|
++Template.Ptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(!(StringsDifferT(ScriptTag, Template.Ptr, 0)))
|
|
|
|
{
|
|
|
|
Output.Ptr = CommentStart;
|
|
|
|
CopyBuffer(&Output, &Script);
|
|
|
|
while(Template.Ptr - Template.Location < Template.Size)
|
|
|
|
{
|
|
|
|
if(!StringsDifferT("-->", Template.Ptr, 0))
|
2017-06-13 22:13:03 +00:00
|
|
|
{
|
2017-06-16 07:55:59 +00:00
|
|
|
Template.Ptr += StringLength("-->");
|
2017-06-15 22:10:36 +00:00
|
|
|
break;
|
2017-06-13 22:13:03 +00:00
|
|
|
}
|
2017-06-16 07:55:59 +00:00
|
|
|
++Template.Ptr;
|
2017-06-13 22:13:03 +00:00
|
|
|
}
|
2017-06-16 07:55:59 +00:00
|
|
|
break;
|
2017-06-13 22:13:03 +00:00
|
|
|
}
|
2017-06-16 07:55:59 +00:00
|
|
|
else if(!StringsDifferT("-->", Template.Ptr, 0))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*Output.Ptr++ = *Template.Ptr++;
|
2017-06-12 22:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-16 07:55:59 +00:00
|
|
|
*Output.Ptr++ = *Template.Ptr++;
|
2017-06-12 22:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-08-08 19:26:54 +00:00
|
|
|
FILE *OutFile;
|
|
|
|
if(!(OutFile = fopen(OutIntegratedLocation, "w")))
|
2017-06-12 22:26:01 +00:00
|
|
|
{
|
2017-08-08 19:26:54 +00:00
|
|
|
perror(OutIntegratedLocation); free(Template.Location); free(Output.Location); hmml_free(&HMML); free(MemoryArena.Location); return 1;
|
2017-06-12 22:26:01 +00:00
|
|
|
}
|
2017-08-08 19:26:54 +00:00
|
|
|
fwrite(Output.Location, Output.Ptr - Output.Location, 1, OutFile);
|
|
|
|
fclose(OutFile);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-16 07:55:59 +00:00
|
|
|
free(Template.Location);
|
|
|
|
free(Output.Location);
|
2017-06-12 22:26:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// NOTE(matt): Perform the normal collation into Master, and write-out to out.html
|
|
|
|
CopyStringToBuffer(&Master,
|
2017-06-25 18:05:58 +00:00
|
|
|
"<html>\n"
|
|
|
|
" <head>\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-12 22:26:01 +00:00
|
|
|
//NOTE(matt): Here is where we do all our CopyBuffer() calls
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyBuffer(&Master, &Includes);
|
2017-06-13 22:13:03 +00:00
|
|
|
CopyStringToBuffer(&Master,
|
2017-06-25 18:05:58 +00:00
|
|
|
"\n"
|
|
|
|
" </head>\n"
|
|
|
|
" <body>\n");
|
2017-06-21 20:30:05 +00:00
|
|
|
CopyBuffer(&Master, &Menus);
|
2017-06-16 07:55:59 +00:00
|
|
|
CopyStringToBuffer(&Master, "\n");
|
2017-06-12 22:26:01 +00:00
|
|
|
CopyBuffer(&Master, &Player);
|
2017-06-16 07:55:59 +00:00
|
|
|
CopyStringToBuffer(&Master, "\n");
|
2017-06-12 22:26:01 +00:00
|
|
|
CopyBuffer(&Master, &Script);
|
2017-06-13 22:13:03 +00:00
|
|
|
CopyStringToBuffer(&Master, "\n");
|
2017-06-12 22:26:01 +00:00
|
|
|
//
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-12 22:26:01 +00:00
|
|
|
CopyStringToBuffer(&Master,
|
2017-06-25 18:05:58 +00:00
|
|
|
" </body>\n"
|
|
|
|
"</html>\n");
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-12 22:26:01 +00:00
|
|
|
FILE *OutFile;
|
2017-06-25 18:05:58 +00:00
|
|
|
if(!(OutFile = fopen(OutLocation, "w")))
|
2017-06-12 22:26:01 +00:00
|
|
|
{
|
2017-07-29 00:36:14 +00:00
|
|
|
perror(OutLocation); hmml_free(&HMML); free(MemoryArena.Location); return 1;
|
2017-06-12 22:26:01 +00:00
|
|
|
}
|
|
|
|
fwrite(Master.Location, Master.Ptr - Master.Location, 1, OutFile);
|
|
|
|
fclose(OutFile);
|
|
|
|
}
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-22 15:33:53 +00:00
|
|
|
// NOTE(matt): Tree structure of "global" buffer dependencies
|
2017-06-03 01:32:18 +00:00
|
|
|
// FilterState
|
|
|
|
// Script
|
2017-05-22 15:33:53 +00:00
|
|
|
// 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
|
2017-06-21 20:30:05 +00:00
|
|
|
// Menus
|
|
|
|
// Includes
|
2017-06-13 22:13:03 +00:00
|
|
|
// Master
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-05-21 06:35:16 +00:00
|
|
|
DeclaimBuffer(&FilterState, &ClaimedMemory);
|
2017-06-03 01:32:18 +00:00
|
|
|
DeclaimBuffer(&Script, &ClaimedMemory);
|
2017-05-22 15:33:53 +00:00
|
|
|
DeclaimBuffer(&Annotation, &ClaimedMemory);
|
|
|
|
DeclaimBuffer(&Colour, &ClaimedMemory);
|
|
|
|
DeclaimBuffer(&Player, &ClaimedMemory);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
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-06-21 20:30:05 +00:00
|
|
|
DeclaimBuffer(&Menus, &ClaimedMemory);
|
2017-06-25 18:22:54 +00:00
|
|
|
|
2017-06-21 20:30:05 +00:00
|
|
|
DeclaimBuffer(&Includes, &ClaimedMemory);
|
2017-06-13 22:13:03 +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-07-29 00:36:14 +00:00
|
|
|
free(MemoryArena.Location);
|
2017-03-10 14:19:25 +00:00
|
|
|
}
|