diff --git a/hmml_to_html/hmml_to_html.c b/hmml_to_html/hmml_to_html.c index 7cf5f75..cdc79af 100644 --- a/hmml_to_html/hmml_to_html.c +++ b/hmml_to_html/hmml_to_html.c @@ -1,21 +1,20 @@ #if 0 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 exit #endif -#include -#include -#include "hmmlib.h" - -#ifndef bool -typedef bool unsigned int; -#endif +typedef unsigned int bool; #define TRUE 1 #define FALSE 0 +#include +#include +#include +#include "hmmlib.h" + typedef struct { char *Location; @@ -105,13 +104,13 @@ CopyBuffer(buffer *Src, buffer *Dest) } void -CopyStringToBuffer(char *Src, buffer *Dest) +CopyStringToBuffer(buffer *Dest, char *Format, ...) { - while(*Src) - { - *Dest->Ptr++ = *Src++; - } - *Dest->Ptr = '\0'; + va_list Args; + va_start(Args, Format); + int Length = vsprintf(Dest->Ptr, Format, Args); + va_end(Args); + Dest->Ptr += Length; } int @@ -211,21 +210,17 @@ main(int ArgC, char **Args) if(HMML.well_formed) { - int PrintLength; - ClaimBuffer(MemoryArena, &ClaimedMemory, &Title, 1024 * 16); ClaimBuffer(MemoryArena, &ClaimedMemory, &Player, 1024 * 256); - PrintLength = sprintf(Title.Ptr, + CopyStringToBuffer(&Title, "
\n" " %s\n", HMML.metadata.title); - Title.Ptr += PrintLength; - PrintLength = sprintf(Player.Ptr, + CopyStringToBuffer(&Player, "
\n" "
\n" "
\n", HMML.metadata.id); - Player.Ptr += PrintLength; 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, &Text, 1024 * 4); - PrintLength = sprintf(AnnotationHeader.Ptr, + CopyStringToBuffer(&AnnotationHeader, "
%s ", +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! - CopyStringToBuffer(HMML.annotations[AnnotationIndex].text, - &Text); + CopyStringToBuffer(&Text, HMML.annotations[AnnotationIndex].text); - CopyStringToBuffer("\"", &AnnotationClass); + CopyStringToBuffer(&AnnotationClass, "\""); CopyBuffer(&AnnotationClass, &AnnotationHeader); - CopyStringToBuffer(">\n", &AnnotationHeader); + CopyStringToBuffer(&AnnotationHeader, ">\n"); ClaimBuffer(MemoryArena, &ClaimedMemory, &Annotation, 1024 * 4); CopyBuffer(&AnnotationHeader, &Annotation); - sprintf(AnnotationHeader.Location, + CopyStringToBuffer(&Annotation, "
%s", HMML.annotations[AnnotationIndex].time); - CopyBuffer(&AnnotationHeader, &Annotation); CopyBuffer(&Text, &Annotation); - sprintf(AnnotationHeader.Location, "
\n" + CopyStringToBuffer(&Annotation, "
\n" "
\n" "
%s", HMML.annotations[AnnotationIndex].time); - CopyBuffer(&AnnotationHeader, &Annotation); CopyBuffer(&Text, &Annotation); - sprintf(AnnotationHeader.Location, "
\n" + CopyStringToBuffer(&Annotation, "
\n" "
\n" "
\n" "
%s", HMML.annotations[AnnotationIndex].time); - CopyBuffer(&AnnotationHeader, &Annotation); CopyBuffer(&Text, &Annotation); - CopyStringToBuffer("
\n" + CopyStringToBuffer(&Annotation, "
\n" "
\n" -"
\n", &Annotation); +" \n"); CopyBuffer(&Annotation, &Player); @@ -297,18 +297,18 @@ HMML.annotations[AnnotationIndex].time); ClaimedMemory -= Annotation.Size; } - sprintf(Title.Ptr, + CopyStringToBuffer(&Title, " Annotator: %s\n" " \n", HMML.metadata.annotator); - sprintf(Player.Ptr, + CopyStringToBuffer(&Player, " \n" " \n"); //NOTE(matt): Collate the buffers! ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, 1024 * 512); - PrintLength = sprintf(Master.Ptr, + CopyStringToBuffer(&Master, "\n" " \n" " \n" @@ -318,14 +318,13 @@ HMML.annotations[AnnotationIndex].time); " \n" " \n" " \n"); - Master.Ptr += PrintLength; //NOTE(matt): Here is where we do all our CopyBuffer() calls CopyBuffer(&Title, &Master); CopyBuffer(&Player, &Master); // - PrintLength = sprintf(Master.Ptr, + CopyStringToBuffer(&Master, "