diff --git a/hmml_to_html/hmml_to_html.c b/hmml_to_html/hmml_to_html.c index f359eaa..f2bfcaa 100644 --- a/hmml_to_html/hmml_to_html.c +++ b/hmml_to_html/hmml_to_html.c @@ -14,6 +14,7 @@ typedef unsigned int bool; #include #include #include +#include #include "hmmlib.h" typedef struct @@ -25,8 +26,18 @@ typedef struct typedef struct { - char *Source; - char *RefTitle; + char Timecode[8]; + int Identifier; +} identifier; + +typedef struct +{ + char ID[1024]; + char RefTitle[512]; + char URL[372]; + char Source[128]; + identifier Identifier[12]; + int IdentifierCount; } ref_info; #define ArrayCount(A) sizeof(A)/sizeof(*(A)) @@ -40,6 +51,8 @@ ClaimBuffer(char *MemoryArena, int *ClaimedMemory, buffer *Buffer, int Size) Buffer->Ptr = Buffer->Location; } +#if 0 +//TODO(matt): Rewrite me ref_info ParseRef(HMML_Reference RefInput) { @@ -63,6 +76,9 @@ ParseRef(HMML_Reference RefInput) return Info; } } +#endif + +// TODO(matt): MakeReference() int TimecodeToSeconds(char *Timecode) @@ -97,7 +113,7 @@ TimecodeToSeconds(char *Timecode) } void -CopyBuffer(buffer *Src, buffer *Dest) +CopyBuffer(buffer *Dest, buffer *Src) { Src->Ptr = Src->Location; while(*Src->Ptr) @@ -106,6 +122,18 @@ CopyBuffer(buffer *Src, buffer *Dest) } } +void +CopyString(char Dest[], char *Src) +{ + int i = 0; + while(*Src) + { + Dest[i] = *Src++; + ++i; + } + Dest[i] = '\0'; +} + __attribute__ ((format (printf, 2, 3))) void CopyStringToBuffer(buffer *Dest, char *Format, ...) @@ -248,7 +276,6 @@ main(int ArgC, char **Args) int ClaimedMemory = 0; // NOTE(matt): Setup buffers and ptrs -#if 1 char *InPtr; buffer Title; @@ -281,13 +308,16 @@ main(int ArgC, char **Args) if(HMML.well_formed) { ClaimBuffer(MemoryArena, &ClaimedMemory, &Title, 1024 * 16); + ref_info ReferencesArray[200]; + memset(ReferencesArray, 0, sizeof(ReferencesArray)); ClaimBuffer(MemoryArena, &ClaimedMemory, &Player, 1024 * 256); bool HasQuoteMenu = FALSE; bool HasReferenceMenu = FALSE; - int QuoteIdentifier = 945; + int QuoteIdentifier = 0x3b1; int RefIdentifier = 1; + int UniqueRefs = 0; CopyStringToBuffer(&Title, "
\n" @@ -377,9 +407,41 @@ Readable); "
\n" "
\n"); + CopyString(ReferencesArray[RefIdentifier - 1].ID, CurrentRef->editor); + CopyString(ReferencesArray[RefIdentifier - 1].RefTitle, "Title"); + CopyString(ReferencesArray[RefIdentifier - 1].URL, "http://example.com/"); + CopyString(ReferencesArray[RefIdentifier - 1].Source, "Source"); + CopyString(ReferencesArray[RefIdentifier - 1].Identifier[ReferencesArray[RefIdentifier - 1].IdentifierCount].Timecode, Anno->time); + ReferencesArray[RefIdentifier - 1].Identifier[ReferencesArray[RefIdentifier - 1].IdentifierCount].Identifier = RefIdentifier; + ++ReferencesArray[RefIdentifier - 1].IdentifierCount; + + ++UniqueRefs; + HasReferenceMenu = TRUE; } + else + { + for(int i = 0; i < UniqueRefs; ++i) + { + if(!StringsDiffer(CurrentRef->editor, 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; + } + } + CopyString(ReferencesArray[UniqueRefs].ID, CurrentRef->editor); + CopyString(ReferencesArray[UniqueRefs].RefTitle, "Title"); + CopyString(ReferencesArray[UniqueRefs].URL, "http://example.com/"); + CopyString(ReferencesArray[UniqueRefs].Source, "Source"); + CopyString(ReferencesArray[UniqueRefs].Identifier[ReferencesArray[UniqueRefs].IdentifierCount].Timecode, Anno->time); + ReferencesArray[UniqueRefs].Identifier[ReferencesArray[UniqueRefs].IdentifierCount].Identifier = RefIdentifier; + ++ReferencesArray[UniqueRefs].IdentifierCount; + ++UniqueRefs; + } +AppendedIdentifier: if(!HasReference) { ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, 128); @@ -392,27 +454,6 @@ Readable); CopyStringToBuffer(&AnnotationData, ",%s", CurrentRef->editor); } - CopyStringToBuffer(&ReferenceMenu, -" \n" -" \n" -"
%s
\n" -"
%s
\n" -"
\n" -// TODO(matt): Fill the div class="ref_indices" with <= 3 span -// class="ref_index" and ensure to put these <=3 spans on the same line without -// a space between them -"
\n" -" [%d]%s\n" -"
\n" -"
\n", -CurrentRef->editor, -"http://example.com/", -"Source", -"Title", -TimecodeToSeconds(Anno->time), -RefIdentifier, -Anno->time); - CopyStringToBuffer(&Text, "%d", RefIdentifier); ++RefIndex; @@ -482,18 +523,18 @@ Anno->time); } CopyStringToBuffer(&AnnotationClass, "\""); - CopyBuffer(&AnnotationClass, &AnnotationHeader); + CopyBuffer(&AnnotationHeader, &AnnotationClass); if(HasQuote || HasReference) { CopyStringToBuffer(&AnnotationData, "\""); - CopyBuffer(&AnnotationData, &AnnotationHeader); + CopyBuffer(&AnnotationHeader, &AnnotationData); } CopyStringToBuffer(&AnnotationHeader, ">\n"); ClaimBuffer(MemoryArena, &ClaimedMemory, &Annotation, 1024 * 4); - CopyBuffer(&AnnotationHeader, &Annotation); + CopyBuffer(&Annotation, &AnnotationHeader); CopyStringToBuffer(&Annotation, "
%s", Anno->time); @@ -501,19 +542,19 @@ Anno->time); if(HasCategory) { CopyStringToBuffer(&Category, ""); - CopyBuffer(&Category, &Text); + CopyBuffer(&Text, &Category); } *Text.Ptr = '\0'; - CopyBuffer(&Text, &Annotation); + CopyBuffer(&Annotation, &Text); CopyStringToBuffer(&Annotation, "
\n" "
\n" "
%s", Anno->time); - CopyBuffer(&Text, &Annotation); + CopyBuffer(&Annotation, &Text); CopyStringToBuffer(&Annotation, "
\n" "
\n" @@ -521,13 +562,13 @@ Anno->time); "
%s", Anno->time); - CopyBuffer(&Text, &Annotation); + CopyBuffer(&Annotation, &Text); CopyStringToBuffer(&Annotation, "
\n" "
\n" "
\n"); - CopyBuffer(&Annotation, &Player); + CopyBuffer(&Player, &Annotation); ClaimedMemory -= Text.Size; ClaimedMemory -= AnnotationHeader.Size; @@ -541,15 +582,45 @@ Anno->time); CopyStringToBuffer(&QuoteMenu, " \n" " \n"); - CopyBuffer(&QuoteMenu, &Title); + CopyBuffer(&Title, &QuoteMenu); } if(HasReferenceMenu) { + for(int i = 0; i < UniqueRefs; ++i) + { + CopyStringToBuffer(&ReferenceMenu, +" \n" +" \n" +"
%s
\n" +"
%s
\n" +"
\n" +// TODO(matt): Fill the div class="ref_indices" with <= 3 span +// class="ref_index" and ensure to put these <=3 spans on the same line without +// a space between them +"
\n", +ReferencesArray[i].ID, +"http://example.com/", +"Source", +"Title"); + for(int j = 0; j < ReferencesArray[i].IdentifierCount; ++j) + { + CopyStringToBuffer(&ReferenceMenu, +" [%d]%s\n", +TimecodeToSeconds(ReferencesArray[i].Identifier[j].Timecode), +ReferencesArray[i].Identifier[j].Identifier, +ReferencesArray[i].Identifier[j].Timecode); + } + + CopyStringToBuffer(&ReferenceMenu, +"
\n" +"
\n"); + } + CopyStringToBuffer(&ReferenceMenu, " \n" " \n"); - CopyBuffer(&ReferenceMenu, &Title); + CopyBuffer(&Title, &ReferenceMenu); } CopyStringToBuffer(&Title, @@ -575,8 +646,8 @@ Anno->time); " \n"); //NOTE(matt): Here is where we do all our CopyBuffer() calls - CopyBuffer(&Title, &Master); - CopyBuffer(&Player, &Master); + CopyBuffer(&Master, &Title); + CopyBuffer(&Master, &Player); // CopyStringToBuffer(&Master, @@ -679,319 +750,5 @@ Anno->time); } hmml_free(&HMML); } -#else - char *InPtr; - buffer Working; - buffer Text; - buffer Out; - - ClaimBuffer(MemoryArena, &ClaimedMemory, &Out, 1024 * 512); - - for(int FileIndex = 1; FileIndex < ArgC; ++FileIndex) - { - FILE *InFile; - if(!(InFile = fopen(Args[FileIndex], "r"))) - { - perror(Args[0]); - free(MemoryArena); - return 1; - } - - HMML_Output HMML = hmml_parse_file(InFile); - fclose(InFile); - - if(HMML.well_formed) - { - ClaimBuffer(MemoryArena, &ClaimedMemory, &Working, 1024 * 4); - - sprintf(Working.Location, -"\n" -" \n" -" \n" -"\n" -" \n" -" \n" -" \n" -" \n" -" \n" -"
\n" -" %s\n", HMML.metadata.title); - CopyBuffer(&Working, &Out); - - int AnnotationIndex = 0; - int ReferenceIndex = 1; - while(AnnotationIndex < HMML.annotation_count) - { - if(HMML.annotations[AnnotationIndex].reference_count) - { - sprintf(Working.Location, -"
\n" -" References ▼\n" -"
\n" -"
\n"); - CopyBuffer(&Working, &Out); - - while(AnnotationIndex < HMML.annotation_count) - { - for(int i = 0; i < HMML.annotations[AnnotationIndex].reference_count; ++i) - { - HMML_Reference *CurrentRef = HMML.annotations[AnnotationIndex].references + i; - // NOTE(matt): Consider removing the ref_index class if it ain't needed - sprintf(Working.Location, -" \n" -" \n" -"
%s
\n" -"
%s
\n" -"
\n" -// TODO(matt): Fill the div class="ref_indices" with <= 3 span -// class="ref_index" and ensure to put these <=3 spans on the same line without -// a space between them -"
\n" -" [%d]%s\n" -"
\n" -"
\n", -AnnotationIndex, -CurrentRef->url, -ParseRef(*CurrentRef).Source, -ParseRef(*CurrentRef).RefTitle, -TimecodeToSeconds(HMML.annotations[AnnotationIndex].time), -ReferenceIndex, -HMML.annotations[AnnotationIndex].time); - CopyBuffer(&Working, &Out); - - ++ReferenceIndex; - } - ++AnnotationIndex; - } - sprintf(Working.Location, -"
\n" -"
\n"); - CopyBuffer(&Working, &Out); - } - ++AnnotationIndex; - } - - sprintf(Working.Location, -" Annotator: %s\n" -"
\n" -"
\n" -"
\n" -"
\n", HMML.metadata.annotator, HMML.metadata.id); - CopyBuffer(&Working, &Out); - - int DataRef = 1; - - for(int AnnotationIndex = 0; AnnotationIndex < HMML.annotation_count; ++AnnotationIndex) - { - sprintf(Working.Location, -"
%s ", - StringToColourHash(HMML.annotations[AnnotationIndex].author), HMML.annotations[AnnotationIndex].author); - Text.Ptr += Inc; - } - - if(HMML.annotations[AnnotationIndex].marker_count) - { - for(int MarkerIndex = 0; MarkerIndex < HMML.annotations[AnnotationIndex].marker_count; ++MarkerIndex) - { - if(!StringsDiffer("blackboard", HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker) && - HMML.annotations[AnnotationIndex].markers[MarkerIndex].type == HMML_CATEGORY) - { - sprintf(Working.Location, " blackboard"); - CopyBuffer(&Working, &Out); - } - } - } - - sprintf(Working.Location, "\" data-timestamp=\"%d\"", TimecodeToSeconds(HMML.annotations[AnnotationIndex].time)); - CopyBuffer(&Working, &Out); - - InPtr = HMML.annotations[AnnotationIndex].text; - - if(HMML.annotations[AnnotationIndex].reference_count) // || HMML.annotations[AnnotationIndex].is_quote) - { - sprintf(Working.Location, " data-ref=\"%d\"", AnnotationIndex); - CopyBuffer(&Working, &Out); - - for(int RefLocalIndex = 0; RefLocalIndex < HMML.annotations[AnnotationIndex].reference_count; ++RefLocalIndex) - { - while(InPtr - HMML.annotations[AnnotationIndex].text < HMML.annotations[AnnotationIndex].references[RefLocalIndex].offset) - { - *Text.Ptr++ = *InPtr++; - } - - if(HMML.annotations[AnnotationIndex].references[RefLocalIndex].offset <= 2) - { - if(HMML.annotations[AnnotationIndex].references[RefLocalIndex].page) - { - Inc = sprintf(Text.Ptr, "%s", - HMML.annotations[AnnotationIndex].references[RefLocalIndex].page); - } - else if(HMML.annotations[AnnotationIndex].references[RefLocalIndex].site) - { - Inc = sprintf(Text.Ptr, "%s", - HMML.annotations[AnnotationIndex].references[RefLocalIndex].site); - } - else if(HMML.annotations[AnnotationIndex].references[RefLocalIndex].title) - { - Inc = sprintf(Text.Ptr, "%s", - HMML.annotations[AnnotationIndex].references[RefLocalIndex].title); - } - else - { - fprintf(stderr, "%s: Potentially incomplete reference at %s:%d\n", - Args[0], - Args[FileIndex], - HMML.annotations[AnnotationIndex].line); - } - Text.Ptr += Inc; - } - - if(HMML.annotations[AnnotationIndex].references[RefLocalIndex].offset <= 2 && Text.Ptr[-1] == ' ') - { - --Text.Ptr; - } - Inc = sprintf(Text.Ptr, "%d", DataRef); - Text.Ptr += Inc; - ++DataRef; - } - } - - *Out.Ptr++ = '>'; - *Out.Ptr++ = '\n'; - CopyStringToBuffer(&Text, InPtr); - *Text.Ptr = '\0'; - - sprintf(Working.Location, -"
%s%s
\n" -"
\n" -"
%s%s
\n" -"
\n" -"
\n" -"
%s%s
\n" -"
\n" -"
\n", - HMML.annotations[AnnotationIndex].time, - Text.Location, - HMML.annotations[AnnotationIndex].time, - Text.Location, - HMML.annotations[AnnotationIndex].time, - Text.Location); - CopyBuffer(&Working, &Out); - - ClaimedMemory -= Text.Size; - } - - sprintf(Working.Location, -"
\n" -"
\n" -" \n" -" \n" -"\n"); - CopyBuffer(&Working, &Out); - - FILE *OutFile; - //char *OutFilename; - //sprintf(OutFilename, "%s.html", Args[FileIndex]); - if(!(OutFile = fopen("out.html", "w"))) - { - perror(Args[0]); - return 1; - } - - fwrite(Out.Location, Out.Ptr - Out.Location, 1, OutFile); - fclose(OutFile); - } - else - { - fprintf(stderr, "%s:%d: %s\n", Args[FileIndex], HMML.error.line, HMML.error.message); - } - hmml_free(&HMML); - } -#endif free(MemoryArena); } diff --git a/hmml_to_html/out.html b/hmml_to_html/out.html index 578edcc..32fc6f8 100644 --- a/hmml_to_html/out.html +++ b/hmml_to_html/out.html @@ -8,63 +8,52 @@
- Studying the Machine Interrupt Registers + Coloured Nicks +
+ Quotes ▼ +
+
+ + +
#1 • Quote date
+
Quote text
+
+
+ [α]2:56 +
+
+ + +
#2 • Quote date
+
Quote text
+
+
+ [β]5:12 +
+
+
+
References ▼
@@ -74,157 +63,49 @@
-
-
0:06Recap and set the stage for the day
+
+
1:00insofaras Some text referring to Zilarrezko about this thing1 regarding triangle intersections he saw in the milton forums2
-
0:06Recap and set the stage for the day
+
1:00insofaras Some text referring to Zilarrezko about this thing1 regarding triangle intersections he saw in the milton forums2
-
0:06Recap and set the stage for the day
+
1:00insofaras Some text referring to Zilarrezko about this thing1 regarding triangle intersections he saw in the milton forums2
-
-
0:51Intuition on two's complement
+
+
2:56“Quote text”α
-
0:51Intuition on two's complement
+
2:56“Quote text”α
-
0:51Intuition on two's complement
+
2:56“Quote text”α
-
-
4:10We are counting with zeroes
+
+
5:12Matrix multiplicationβ
-
4:10We are counting with zeroes
+
5:12Matrix multiplicationβ
-
4:10We are counting with zeroes
+
5:12Matrix multiplicationβ
-
-
9:03Revisit instructions.scala1 and research register-transfer level2
+
+
10:24More stuff referring to the milton forum post3
-
9:03Revisit instructions.scala1 and research register-transfer level2
+
10:24More stuff referring to the milton forum post3
-
9:03Revisit instructions.scala1 and research register-transfer level2
+
10:24More stuff referring to the milton forum post3
-
-
15:55Come to understand how to specify that rs1 represents an immediate or a register, thanks to the reply to the "Confusion Regarding Freedom E SDK inline asm" forum thread3
+
+
10:42Some text. Simples!
-
15:55Come to understand how to specify that rs1 represents an immediate or a register, thanks to the reply to the "Confusion Regarding Freedom E SDK inline asm" forum thread3
+
10:42Some text. Simples!
-
15:55Come to understand how to specify that rs1 represents an immediate or a register, thanks to the reply to the "Confusion Regarding Freedom E SDK inline asm" forum thread3
-
-
-
-
18:25Read clear_csr() to put csrrc into perspective with our new understanding of pseudo-instructions and the i vs r hints
-
-
18:25Read clear_csr() to put csrrc into perspective with our new understanding of pseudo-instructions and the i vs r hints
-
-
-
18:25Read clear_csr() to put csrrc into perspective with our new understanding of pseudo-instructions and the i vs r hints
-
-
-
-
22:24Read about CSRRCI in the CSR Instructions section of the User-Level ISA Specification4
-
-
22:24Read about CSRRCI in the CSR Instructions section of the User-Level ISA Specification4
-
-
-
22:24Read about CSRRCI in the CSR Instructions section of the User-Level ISA Specification4
-
-
-
-
23:05Walk through clear_csr() again
-
-
23:05Walk through clear_csr() again
-
-
-
23:05Walk through clear_csr() again
-
-
-
-
28:53GNU Assembly Syntax: Constraints and Syntax5
-
-
28:53GNU Assembly Syntax: Constraints and Syntax5
-
-
-
28:53GNU Assembly Syntax: Constraints and Syntax5
-
-
-
-
35:15Continue reading clear_csr()
-
-
35:15Continue reading clear_csr()
-
-
-
35:15Continue reading clear_csr()
-
-
-
-
40:21Pop back up to the top of the stack, to reset_demo(), and read about the currently allocated RISC-V machine-level CSR addresses6
-
-
40:21Pop back up to the top of the stack, to reset_demo(), and read about the currently allocated RISC-V machine-level CSR addresses6
-
-
-
40:21Pop back up to the top of the stack, to reset_demo(), and read about the currently allocated RISC-V machine-level CSR addresses6
-
-
-
-
44:11Read about Machine Interrupt Registers, including the mie (machine interrupt-enable) register
-
-
44:11Read about Machine Interrupt Registers, including the mie (machine interrupt-enable) register
-
-
-
44:11Read about Machine Interrupt Registers, including the mie (machine interrupt-enable) register
-
-
-
-
49:26Note how common it is in plic_driver.c for us to compute an address of a memory mapped register in order to mess with interrupts
-
-
49:26Note how common it is in plic_driver.c for us to compute an address of a memory mapped register in order to mess with interrupts
-
-
-
49:26Note how common it is in plic_driver.c for us to compute an address of a memory mapped register in order to mess with interrupts
-
-
-
-
51:45A few words on the sponge mode that we're in
-
-
51:45A few words on the sponge mode that we're in
-
-
-
51:45A few words on the sponge mode that we're in
-
-
-
-
52:50Continue reading about the Machine Interrupt Registers
-
-
52:50Continue reading about the Machine Interrupt Registers
-
-
-
52:50Continue reading about the Machine Interrupt Registers
-
-
-
-
58:33Return to demo_gpio.c and come to understand the clear_csr() calls in relation to the documentation
-
-
58:33Return to demo_gpio.c and come to understand the clear_csr() calls in relation to the documentation
-
-
-
58:33Return to demo_gpio.c and come to understand the clear_csr() calls in relation to the documentation
-
-
-
-
1:06:48We're out of time for today
-
-
1:06:48We're out of time for today
-
-
-
1:06:48We're out of time for today
+
10:42Some text. Simples!
@@ -272,27 +153,37 @@ for (var i = 0; i < refSources.length; ++i) { } function onRefChanged(ref) { - if (ref !== undefined && ref !== null) { - document.querySelector(".refs_container").classList.add("current"); - var refElements = document.querySelectorAll(".refs .ref"); - var refs = ref.split(","); + var sourceMenus = document.querySelectorAll(".refs_container"); + for (var MenuIndex = 0; MenuIndex < sourceMenus.length; ++MenuIndex) + { + var SetMenu = 0; + if (ref !== undefined && ref !== null) { + var refElements = sourceMenus[MenuIndex].querySelectorAll(".refs .ref"); + var refs = ref.split(","); - for (var i = 0; i < refElements.length; ++i) { - if (refs.includes(refElements[i].getAttribute("data-id"))) { - refElements[i].classList.add("current"); - } else { - refElements[i].classList.remove("current"); + for (var i = 0; i < refElements.length; ++i) { + if (refs.includes(refElements[i].getAttribute("data-id"))) { + refElements[i].classList.add("current"); + SetMenu = 1; + } else { + refElements[i].classList.remove("current"); + } + } + if(SetMenu) { + sourceMenus[MenuIndex].classList.add("current"); + } else { + sourceMenus[MenuIndex].classList.remove("current"); + } + + } else { + sourceMenus[MenuIndex].classList.remove("current"); + var refs = sourceMenus[MenuIndex].querySelectorAll(".refs .ref"); + for (var i = 0; i < refs.length; ++i) { + refs[i].classList.remove("current"); } - } - } else { - document.querySelector(".refs_container").classList.remove("current"); - var refs = document.querySelectorAll(".refs .ref"); - for (var i = 0; i < refs.length; ++i) { - refs[i].classList.remove("current"); } } } -