diff --git a/hmml_to_html/hmml_to_html.c b/hmml_to_html/hmml_to_html.c index 487e710..5fae31a 100644 --- a/hmml_to_html/hmml_to_html.c +++ b/hmml_to_html/hmml_to_html.c @@ -21,6 +21,13 @@ typedef unsigned int bool; #define Kilobytes(Bytes) Bytes << 10 #define Megabytes(Bytes) Bytes << 20 +enum +{ + EDITION_SINGLE = 0, + EDITION_PROJECT = 1, + EDITION_NETWORK = 2 +} EDITION; + typedef struct { char *Location; @@ -72,6 +79,8 @@ char *Credentials[ ][5] = { "abnercoimbre", "Abner Coimbre", "https://handmade.network/m/abnercoimbre", "patreon_logo.png", "https://patreon.com/handmade_dev"}, }; +#define EDITION EDITION_SINGLE + #define ArrayCount(A) sizeof(A)/sizeof(*(A)) void @@ -239,6 +248,45 @@ CopyStringToBufferHTMLSafe(buffer *Dest, char *String) } } +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 '<': + CopyStringToBuffer(Dest, "<"); + String++; + break; + case '>': + CopyStringToBuffer(Dest, ">"); + String++; + break; + case '&': + CopyStringToBuffer(Dest, "&"); + String++; + break; + case '\"': + CopyStringToBuffer(Dest, """); + String += 2; + break; + case '\'': + CopyStringToBuffer(Dest, "'"); + String++; + break; + default: + *Dest->Ptr++ = *String++; + break; + } + } +} + int StringsDiffer(char *A, char *B) { @@ -257,7 +305,7 @@ StringsDifferL(char *A, char *B, int LengthofA) { ++i; } - if(!A[i] && LengthofA == i) + if(!A[i] && LengthofA == i && B[i] == ' ') { return FALSE; } @@ -674,8 +722,6 @@ BuildQuote(quote_info *Info, char *Speaker, int ID) { // TODO(matt): Pull these paths from the config // Also notable that there are different paths for different projects - // - // TODO(matt): Handle csv's double quote escaping stuff char *QuoteDir = "/home/matt/git/GitHub/insofaras/25fc16d58a297a486334"; if(!StringsDiffer(Speaker, "handmade_hero")) @@ -708,7 +754,6 @@ BuildQuote(quote_info *Info, char *Speaker, int ID) while(InPtr - Buffer < Length) { - char InID[4] = { 0 }; char *OutPtr = InID; while(*InPtr != ',') @@ -1282,11 +1327,26 @@ TimecodeToSeconds(Anno->time)); CopyStringToBuffer(&AnnotationClass, " authored"); hsl_colour AuthorColour; StringToColourHash(&AuthorColour, Anno->author); - CopyStringToBuffer(&Text, + 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, +"%s ", +Anno->author, +AuthorColour.Hue, AuthorColour.Saturation, AuthorColour.Lightness, +AuthorColour.Hue, AuthorColour.Saturation, +Anno->author); + } + else + { + CopyStringToBuffer(&Text, "%s ", AuthorColour.Hue, AuthorColour.Saturation, AuthorColour.Lightness, AuthorColour.Hue, AuthorColour.Saturation, Anno->author); + } + if(!HasMedium) { HasMedium = TRUE; @@ -1308,14 +1368,26 @@ Anno->author); { hsl_colour MemberColour; StringToColourHash(&MemberColour, Anno->markers[MarkerIndex].marker); - CopyStringToBuffer(&Text, - // TODO(matt): Hoverbox - // We should get instructions on how to get this info in the config + 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, "%.*s", Anno->markers[MarkerIndex].marker, MemberColour.Hue, MemberColour.Saturation, MemberColour.Lightness, MemberColour.Hue, MemberColour.Saturation, StringLength(Readable), InPtr); + } + else + { + CopyStringToBuffer(&Text, +"%.*s", +MemberColour.Hue, MemberColour.Saturation, MemberColour.Lightness, +MemberColour.Hue, MemberColour.Saturation, +StringLength(Readable), InPtr); + } + InPtr += StringLength(Readable); ++MarkerIndex; } @@ -1323,14 +1395,25 @@ StringLength(Readable), InPtr); { hsl_colour ProjectColour; StringToColourHash(&ProjectColour, Anno->markers[MarkerIndex].marker); - CopyStringToBuffer(&Text, - // TODO(matt): Hoverbox - // We should get instructions on how to get this info in the config + 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, "%s", Anno->markers[MarkerIndex].marker, ProjectColour.Hue, ProjectColour.Saturation, ProjectColour.Lightness, ProjectColour.Hue, ProjectColour.Saturation, Readable); + } + else + { + CopyStringToBuffer(&Text, +"%s", +ProjectColour.Hue, ProjectColour.Saturation, ProjectColour.Lightness, +ProjectColour.Hue, ProjectColour.Saturation, +Readable); + } InPtr += StringLength(Readable); ++MarkerIndex; } @@ -1539,16 +1622,19 @@ AppendedIdentifier: " \n" " \n" "
Quote %d
\n" -"
%s
\n" +"
", +QuoteIdentifier, +Anno->quote.id); + + CopyStringToBufferCSVSafe(&QuoteMenu, QuoteInfo.Text); + + CopyStringToBuffer(&QuoteMenu, "
\n" " \n" "
\n" "
\n" " [&#%d;]%s\n" "
\n" "
\n", -QuoteIdentifier, -Anno->quote.id, -QuoteInfo.Text, HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member, QuoteInfo.Date, TimecodeToSeconds(Anno->time),