hmml_to_html.c: Coloured authors

This commit is contained in:
Matt Mascarenhas 2017-03-23 00:34:59 +00:00
parent 0adb9bf45a
commit 20ae5e8c1d
2 changed files with 42 additions and 44 deletions

View File

@ -1,21 +1,20 @@
#if 0 #if 0
ctime -begin ${0%.*}.ctm ctime -begin ${0%.*}.ctm
gcc -g -Wall -Wno-unused-variable -fsanitize=address $0 -o ${0%.*} hmml.a clang -g -Wall -Wno-unused-variable -fsanitize=address -std=c99 $0 -o ${0%.*} hmml.a
ctime -end ${0%.*}.ctm ctime -end ${0%.*}.ctm
exit exit
#endif #endif
#include <stdio.h> typedef unsigned int bool;
#include <stdlib.h>
#include "hmmlib.h"
#ifndef bool
typedef bool unsigned int;
#endif
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "hmmlib.h"
typedef struct typedef struct
{ {
char *Location; char *Location;
@ -105,13 +104,13 @@ CopyBuffer(buffer *Src, buffer *Dest)
} }
void void
CopyStringToBuffer(char *Src, buffer *Dest) CopyStringToBuffer(buffer *Dest, char *Format, ...)
{ {
while(*Src) va_list Args;
{ va_start(Args, Format);
*Dest->Ptr++ = *Src++; int Length = vsprintf(Dest->Ptr, Format, Args);
} va_end(Args);
*Dest->Ptr = '\0'; Dest->Ptr += Length;
} }
int int
@ -211,21 +210,17 @@ main(int ArgC, char **Args)
if(HMML.well_formed) if(HMML.well_formed)
{ {
int PrintLength;
ClaimBuffer(MemoryArena, &ClaimedMemory, &Title, 1024 * 16); ClaimBuffer(MemoryArena, &ClaimedMemory, &Title, 1024 * 16);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Player, 1024 * 256); ClaimBuffer(MemoryArena, &ClaimedMemory, &Player, 1024 * 256);
PrintLength = sprintf(Title.Ptr, CopyStringToBuffer(&Title,
" <div class=\"title\">\n" " <div class=\"title\">\n"
" <span class=\"episode_name\">%s</span>\n", HMML.metadata.title); " <span class=\"episode_name\">%s</span>\n", HMML.metadata.title);
Title.Ptr += PrintLength;
PrintLength = sprintf(Player.Ptr, CopyStringToBuffer(&Player,
" <div class=\"player_container\">\n" " <div class=\"player_container\">\n"
" <div class=\"video_container\" data-videoId=\"%s\"></div>\n" " <div class=\"video_container\" data-videoId=\"%s\"></div>\n"
" <div class=\"markers_container\">\n", HMML.metadata.id); " <div class=\"markers_container\">\n", HMML.metadata.id);
Player.Ptr += PrintLength;
for(int AnnotationIndex = 0; AnnotationIndex < HMML.annotation_count; ++AnnotationIndex) for(int AnnotationIndex = 0; AnnotationIndex < HMML.annotation_count; ++AnnotationIndex)
{ {
@ -233,14 +228,23 @@ main(int ArgC, char **Args)
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, 128); ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, 128);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, 1024 * 4); ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, 1024 * 4);
PrintLength = sprintf(AnnotationHeader.Ptr, CopyStringToBuffer(&AnnotationHeader,
" <div data-timestamp=\"%d\"", " <div data-timestamp=\"%d\"",
TimecodeToSeconds(HMML.annotations[AnnotationIndex].time)); TimecodeToSeconds(HMML.annotations[AnnotationIndex].time));
AnnotationHeader.Ptr += PrintLength;
PrintLength = sprintf(AnnotationClass.Ptr, CopyStringToBuffer(&AnnotationClass,
" class=\"marker"); " class=\"marker");
AnnotationClass.Ptr += PrintLength;
#if 0
if(HMML.annotations[AnnotationIndex].author)
{
CopyStringToBuffer(&AnnotationClass, " authored");
CopyStringToBuffer(&Text,
"<span class=\"author\" style=\"color: #%X;\">%s</span> ",
StringToColourHash(HMML.annotations[AnnotationIndex].author),
HMML.annotations[AnnotationIndex].author);
}
#endif
@ -248,46 +252,42 @@ TimecodeToSeconds(HMML.annotations[AnnotationIndex].time));
//TODO(matt): Replace this CopyStringToBuffer() with real stuff! //TODO(matt): Replace this CopyStringToBuffer() with real stuff!
CopyStringToBuffer(HMML.annotations[AnnotationIndex].text, CopyStringToBuffer(&Text, HMML.annotations[AnnotationIndex].text);
&Text);
CopyStringToBuffer("\"", &AnnotationClass); CopyStringToBuffer(&AnnotationClass, "\"");
CopyBuffer(&AnnotationClass, &AnnotationHeader); CopyBuffer(&AnnotationClass, &AnnotationHeader);
CopyStringToBuffer(">\n", &AnnotationHeader); CopyStringToBuffer(&AnnotationHeader, ">\n");
ClaimBuffer(MemoryArena, &ClaimedMemory, &Annotation, 1024 * 4); ClaimBuffer(MemoryArena, &ClaimedMemory, &Annotation, 1024 * 4);
CopyBuffer(&AnnotationHeader, &Annotation); CopyBuffer(&AnnotationHeader, &Annotation);
sprintf(AnnotationHeader.Location, CopyStringToBuffer(&Annotation,
" <div class=\"content\"><span class=\"timecode\">%s</span>", " <div class=\"content\"><span class=\"timecode\">%s</span>",
HMML.annotations[AnnotationIndex].time); HMML.annotations[AnnotationIndex].time);
CopyBuffer(&AnnotationHeader, &Annotation);
CopyBuffer(&Text, &Annotation); CopyBuffer(&Text, &Annotation);
sprintf(AnnotationHeader.Location, "</div>\n" CopyStringToBuffer(&Annotation, "</div>\n"
" <div class=\"progress faded\">\n" " <div class=\"progress faded\">\n"
" <div class=\"content\"><span class=\"timecode\">%s</span>", " <div class=\"content\"><span class=\"timecode\">%s</span>",
HMML.annotations[AnnotationIndex].time); HMML.annotations[AnnotationIndex].time);
CopyBuffer(&AnnotationHeader, &Annotation);
CopyBuffer(&Text, &Annotation); CopyBuffer(&Text, &Annotation);
sprintf(AnnotationHeader.Location, "</div>\n" CopyStringToBuffer(&Annotation, "</div>\n"
" </div>\n" " </div>\n"
" <div class=\"progress main\">\n" " <div class=\"progress main\">\n"
" <div class=\"content\"><span class=\"timecode\">%s</span>", " <div class=\"content\"><span class=\"timecode\">%s</span>",
HMML.annotations[AnnotationIndex].time); HMML.annotations[AnnotationIndex].time);
CopyBuffer(&AnnotationHeader, &Annotation);
CopyBuffer(&Text, &Annotation); CopyBuffer(&Text, &Annotation);
CopyStringToBuffer("</div>\n" CopyStringToBuffer(&Annotation, "</div>\n"
" </div>\n" " </div>\n"
" </div>\n", &Annotation); " </div>\n");
CopyBuffer(&Annotation, &Player); CopyBuffer(&Annotation, &Player);
@ -297,18 +297,18 @@ HMML.annotations[AnnotationIndex].time);
ClaimedMemory -= Annotation.Size; ClaimedMemory -= Annotation.Size;
} }
sprintf(Title.Ptr, CopyStringToBuffer(&Title,
" <span class=\"annotator_container\">Annotator: <span class=\"annotator\">%s</span></span>\n" " <span class=\"annotator_container\">Annotator: <span class=\"annotator\">%s</span></span>\n"
" </div>\n", HMML.metadata.annotator); " </div>\n", HMML.metadata.annotator);
sprintf(Player.Ptr, CopyStringToBuffer(&Player,
" </div>\n" " </div>\n"
" </div>\n"); " </div>\n");
//NOTE(matt): Collate the buffers! //NOTE(matt): Collate the buffers!
ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, 1024 * 512); ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, 1024 * 512);
PrintLength = sprintf(Master.Ptr, CopyStringToBuffer(&Master,
"<!DOCTYPE html>\n" "<!DOCTYPE html>\n"
" <head>\n" " <head>\n"
" <meta charset=\"UTF-8\">\n" " <meta charset=\"UTF-8\">\n"
@ -318,14 +318,13 @@ HMML.annotations[AnnotationIndex].time);
" <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n" " <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n"
" </head>\n" " </head>\n"
" <body>\n"); " <body>\n");
Master.Ptr += PrintLength;
//NOTE(matt): Here is where we do all our CopyBuffer() calls //NOTE(matt): Here is where we do all our CopyBuffer() calls
CopyBuffer(&Title, &Master); CopyBuffer(&Title, &Master);
CopyBuffer(&Player, &Master); CopyBuffer(&Player, &Master);
// //
PrintLength = sprintf(Master.Ptr, CopyStringToBuffer(&Master,
" <script>\n" " <script>\n"
" var player = new Player(document.querySelector(\".player_container\"), onRefChanged);\n" " var player = new Player(document.querySelector(\".player_container\"), onRefChanged);\n"
" window.addEventListener(\"resize\", function() { player.updateSize(); });\n" " window.addEventListener(\"resize\", function() { player.updateSize(); });\n"
@ -404,8 +403,6 @@ HMML.annotations[AnnotationIndex].time);
" </body>\n" " </body>\n"
"</html>\n"); "</html>\n");
Master.Ptr += PrintLength;
FILE *OutFile; FILE *OutFile;
if(!(OutFile = fopen("out.html", "w"))) if(!(OutFile = fopen("out.html", "w")))
{ {
@ -614,7 +611,7 @@ HMML.annotations[AnnotationIndex].time);
*Out.Ptr++ = '>'; *Out.Ptr++ = '>';
*Out.Ptr++ = '\n'; *Out.Ptr++ = '\n';
CopyStringToBuffer(InPtr, &Text); CopyStringToBuffer(&Text, InPtr);
*Text.Ptr = '\0'; *Text.Ptr = '\0';
sprintf(Working.Location, sprintf(Working.Location,

View File

@ -8,6 +8,7 @@
.timecode { .timecode {
font-size: 9px; font-size: 9px;
font-style: normal;
padding-right: 8px; padding-right: 8px;
position: relative; position: relative;
top: -2px; top: -2px;