From b61fc1196c68b5d15626c78650aafb4efe6dbda1 Mon Sep 17 00:00:00 2001 From: Matt Mascarenhas Date: Sun, 23 Apr 2017 03:47:42 +0100 Subject: [PATCH] hmml_to_html.c: Introduce BuildQuote() [#20] Also move some structural styling out to style.css --- hmml_to_html/hmml_to_html.c | 119 ++++++++++++++++++++++++++++++++++-- hmml_to_html/obbg.css | 17 +++--- hmml_to_html/riscy.css | 13 ++-- hmml_to_html/style.css | 47 ++++++++------ 4 files changed, 163 insertions(+), 33 deletions(-) diff --git a/hmml_to_html/hmml_to_html.c b/hmml_to_html/hmml_to_html.c index 7bface7..cbde0c8 100644 --- a/hmml_to_html/hmml_to_html.c +++ b/hmml_to_html/hmml_to_html.c @@ -38,6 +38,12 @@ typedef struct int IdentifierCount; } ref_info; +typedef struct +{ + char Date[32]; + char Text[512]; +} quote_info; + #define ArrayCount(A) sizeof(A)/sizeof(*(A)) void @@ -337,6 +343,94 @@ BuildCategories(buffer *AnnotationClass, buffer *Category, int *MarkerIndex, boo return; } +#define QUOTE_DIR "/home/matt/git/GitHub/insofaras/25fc16d58a297a486334" + +int +StringToInt(char *String) +{ + int Result = 0; + while(*String) + { + Result = Result * 10 + (*String - '0'); + ++String; + } + return Result; +} + +int +BuildQuote(quote_info *Info, char *Speaker, int ID) +{ + char Path[255] = {0}; + sprintf(Path, "%s/#%s", QUOTE_DIR, Speaker); + FILE *File; + if(!(File = fopen(Path, "r"))) + { + perror("hmml_to_html"); + return 1; + } + + fseek(File, 0, SEEK_END); + int Length = ftell(File); + fseek(File, 0, SEEK_SET); + char *Buffer; + if(!(Buffer = malloc(Length))) + { + perror("hmml_to_html"); + } + fread(Buffer, Length, 1, File); + fclose(File); + char *InPtr = Buffer; + + while(InPtr - Buffer < Length) + { + char InID[4] = {0}; + + char *OutPtr = InID; + while(*InPtr != ',') + { + *OutPtr++ = *InPtr++; + } + *OutPtr = '\0'; + + if(StringToInt(InID) == ID) + { + InPtr += 2; + OutPtr = Info->Date; + while(*InPtr != '"') + { + *OutPtr++ = *InPtr++; + } + *OutPtr = '\0'; + + InPtr += 3; + OutPtr = Info->Text; + while(*InPtr != '\n') + { + if(*InPtr == '\\') + { + ++InPtr; + } + *OutPtr++ = *InPtr++; + } + *--OutPtr = '\0'; + + free(Buffer); + return 0; + } + else + { + while(*InPtr != '\n') + { + ++InPtr; + } + ++InPtr; + } + } + + free(Buffer); + return 1; +} + void GenerateTopicColours(buffer *Colour, char *Topic) { @@ -477,6 +571,8 @@ main(int ArgC, char **Args) bool HasQuote = FALSE; bool HasReference = FALSE; + quote_info QuoteInfo = { 0 }; + ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationHeader, 512); ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, 256); ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, 256); @@ -687,11 +783,25 @@ AppendedIdentifier: HasQuote = TRUE; + + if(BuildQuote(&QuoteInfo, HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member, Anno->quote.id) == 1) + { + fprintf(stderr, "%s:%d: Quote #%s %d not found! Consider pulling the latest quotes\n", + Args[FileIndex], + Anno->line, + HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member, + Anno->quote.id); + hmml_free(&HMML); + free(MemoryArena); + return 1; + } + CopyStringToBuffer(&QuoteMenu, " \n" " \n" -"
#%d • %s
\n" +"
Quote %d
\n" "
%s
\n" +" \n" "
\n" "
\n" " [&#%d;]%s\n" @@ -699,14 +809,15 @@ AppendedIdentifier: " \n", QuoteIdentifier, Anno->quote.id, -"Quote date", -"Quote text", +QuoteInfo.Text, +HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member, +QuoteInfo.Date, TimecodeToSeconds(Anno->time), QuoteIdentifier, Anno->time); if(!Anno->text[0]) { - CopyStringToBuffer(&Text, "“Quote text”"); + CopyStringToBuffer(&Text, "“%s”", QuoteInfo.Text); } CopyStringToBuffer(&Text, "&#%d;", QuoteIdentifier); ++QuoteIdentifier; diff --git a/hmml_to_html/obbg.css b/hmml_to_html/obbg.css index 696b314..d8d55dd 100644 --- a/hmml_to_html/obbg.css +++ b/hmml_to_html/obbg.css @@ -7,7 +7,7 @@ .title.obbg { background-color: #EEE; color: #000; - border-bottom: 1px solid #372F46; + border-color: #372F46; } .title.obbg .refs_container { @@ -25,12 +25,11 @@ .title.obbg .refs_container .refs { background-color: #EEE; - border: 2px solid #372F46; - border-top: none; + border-color: #372F46; } .title.obbg .refs_container > .refs .ref { - border-bottom: 1px solid #372F46; + border-color: #372F46; color: #000000; } @@ -40,17 +39,21 @@ } .title.obbg .refs_container > .refs .ref:hover { - background-color: #FFF8E7; + background-color: #DDD; } .title.obbg .refs_container > .refs .ref.current:hover { - background-color: rgba(55, 46, 65, 0.7); + background-color: #68557E; } .title.obbg .refs_container > .refs .ref .source { color: #888; } +.title.obbg .refs_container > .refs .ref .quote_byline { + color: #888; +} + .title.obbg .refs_container > .refs .ref.current .source { color: #FFF8E7; } @@ -61,7 +64,7 @@ } .markers_container.obbg > .marker { - border-bottom: 1px solid #888; + border-color: #888; } .markers_container.obbg > .marker:hover > .content { diff --git a/hmml_to_html/riscy.css b/hmml_to_html/riscy.css index 425ccec..7a5216c 100644 --- a/hmml_to_html/riscy.css +++ b/hmml_to_html/riscy.css @@ -1,7 +1,7 @@ .title.riscy { background-color: #EEE; color: #000000; - border-bottom: 1px solid rgba(246, 178, 26, 0.8); + border-color: rgba(246, 178, 26, 0.8); } .title.riscy .refs_container { @@ -19,12 +19,11 @@ .title.riscy .refs_container .refs { background-color: #EEE; - border: 2px solid rgba(246, 178, 26, 0.8); - border-top: none; + border-color: rgba(246, 178, 26, 0.8); } .title.riscy .refs_container > .refs .ref { - border-bottom: 1px solid rgba(246, 178, 26, 0.8); + border-color: rgba(246, 178, 26, 0.8); color: #000000; } @@ -45,6 +44,10 @@ color: #888; } +.title.riscy .refs_container > .refs .ref .quote_byline { + color: #888; +} + .title.riscy .refs_container > .refs .ref.current .source { color: #FFF8E7; } @@ -55,7 +58,7 @@ } .markers_container.riscy > .marker { - border-bottom: 1px solid rgba(246, 178, 26, 0.8); + border-color: rgba(246, 178, 26, 0.8); } .markers_container.riscy > .marker:hover > .content { diff --git a/hmml_to_html/style.css b/hmml_to_html/style.css index a8f23a2..e647390 100644 --- a/hmml_to_html/style.css +++ b/hmml_to_html/style.css @@ -3,6 +3,7 @@ .title { display: flex; flex-direction: row; + border-bottom: 1px solid; } .title > * { @@ -26,6 +27,8 @@ } .title .refs_container .refs { + border: 2px solid; + border-top:none; position: absolute; top: 100%; right: 0; @@ -39,6 +42,7 @@ } .title .refs_container > .refs .ref { + border-bottom: 1px solid; padding: 10px; display: flex; flex-direction: column; @@ -56,6 +60,31 @@ padding: 0; } +.title .refs_container > .refs .ref .timecode:hover .time { + text-decoration: underline; +} + +.title .refs_container > .refs .ref .ref_content { + margin-bottom: 8px; + width: 100%; +} + +.title .refs_container > .refs .ref .source { + font-size: 10px; + line-height: 8px; +} + +.title .refs_container > .refs .ref .ref_title { + font-style: oblique; +} + +.title .refs_container > .refs .ref .quote_byline { + font-size: 10px; + line-height: 8px; + text-align: right; + width: 100%; +} + .title .refs_container > .refs .ref .ref_indices { text-align: center; } @@ -74,23 +103,6 @@ margin: 0 4px; } -.title .refs_container > .refs .ref .timecode:hover .time { - text-decoration: underline; -} - -.title .refs_container > .refs .ref .ref_content { - width: 100%; -} - -.title .refs_container > .refs .ref .source { - font-size: 10px; - line-height: 8px; -} - -.title .refs_container > .refs .ref .ref_title { - font-style: oblique; -} - .title .refs_container > .refs .ref .timecode .ref_index { margin-right: 4px; } @@ -111,6 +123,7 @@ } .markers_container > .marker { + border-bottom: 1px solid; position: relative; cursor: pointer; }