hmml_to_html.c: Function lofting and ref style

PPiC 055
This commit is contained in:
Matt Mascarenhas 2017-03-16 00:56:58 +00:00
parent 388c60e942
commit dedb407dde
3 changed files with 66 additions and 66 deletions

View File

@ -23,6 +23,15 @@ typedef struct
int Size;
} buffer;
void
ClaimBuffer(char *MemoryArena, int *ClaimedMemory, buffer *Buffer, int Size)
{
Buffer->Location = MemoryArena + *ClaimedMemory;
Buffer->Size = Size;
*ClaimedMemory += Buffer->Size;
Buffer->Ptr = Buffer->Location;
}
int
TimecodeToSeconds(char *Timecode)
{
@ -55,6 +64,25 @@ TimecodeToSeconds(char *Timecode)
return HMS[2] * 60 * 60 + HMS[1] * 60 + HMS[0];
}
void
CopyBuffer(buffer *Src, buffer *Dest)
{
Src->Ptr = Src->Location;
while(*Src->Ptr)
{
*Dest->Ptr++ = *Src->Ptr++;
}
}
void
CopyStringToBuffer(char *Src, buffer *Dest)
{
while(*Src)
{
*Dest->Ptr++ = *Src++;
}
}
int
main(int ArgC, char **Args)
{
@ -66,8 +94,7 @@ main(int ArgC, char **Args)
// NOTE(matt): Init MemoryArena
char *MemoryArena;
// TODO(matt): Actually calculate how much memory I'll need
int ArenaSize = 1024 * 512;
int ArenaSize = 1024 * 1024;
if(!(MemoryArena = calloc(ArenaSize, 1)))
{
perror(Args[0]);
@ -81,9 +108,7 @@ main(int ArgC, char **Args)
buffer Text;
buffer Out;
Out.Location = MemoryArena + ClaimedMemory;
Out.Size = 1024 * 200;
ClaimedMemory += Out.Size;
ClaimBuffer(MemoryArena, &ClaimedMemory, &Out, 1024 * 512);
for(int FileIndex = 1; FileIndex < ArgC; ++FileIndex)
{
@ -100,9 +125,7 @@ main(int ArgC, char **Args)
if(HMML.well_formed)
{
Working.Location = MemoryArena + ClaimedMemory;
Working.Size = 1024 * 1;
ClaimedMemory += Working.Size;
ClaimBuffer(MemoryArena, &ClaimedMemory, &Working, 1024);
sprintf(Working.Location,
"<html>\n"
@ -117,13 +140,9 @@ main(int ArgC, char **Args)
" <div class=\"title\">\n"
" <span class=\"episode_name\">%s</span>\n", HMML.metadata.title);
Working.Ptr = Working.Location;
Out.Ptr = Out.Location;
while(*Working.Ptr)
{
*Out.Ptr++ = *Working.Ptr++;
}
CopyBuffer(&Working, &Out);
int AnnotationIndex = 0;
int ReferenceIndex = 1;
@ -137,11 +156,7 @@ main(int ArgC, char **Args)
" <div class=\"mouse_catcher\"></div>\n"
" <div class=\"refs\">\n");
Working.Ptr = Working.Location;
while(*Working.Ptr)
{
*Out.Ptr++ = *Working.Ptr++;
}
CopyBuffer(&Working, &Out);
while(AnnotationIndex < HMML.annotation_count)
{
@ -169,11 +184,7 @@ TimecodeToSeconds(HMML.annotations[AnnotationIndex].time),
ReferenceIndex,
HMML.annotations[AnnotationIndex].time);
Working.Ptr = Working.Location;
while(*Working.Ptr)
{
*Out.Ptr++ = *Working.Ptr++;
}
CopyBuffer(&Working, &Out);
++ReferenceIndex;
}
++AnnotationIndex;
@ -191,12 +202,7 @@ HMML.annotations[AnnotationIndex].time);
" <div class=\"video_container\" data-videoId=\"%s\"></div>\n"
" <div class=\"markers_container\">\n", HMML.metadata.annotator, HMML.metadata.id);
Working.Ptr = Working.Location;
while(*Working.Ptr)
{
*Out.Ptr++ = *Working.Ptr++;
}
CopyBuffer(&Working, &Out);
int DataRef = 1;
@ -204,10 +210,7 @@ HMML.annotations[AnnotationIndex].time);
{
InPtr = HMML.annotations[AnnotationIndex].text;
Text.Location = MemoryArena + ClaimedMemory;
Text.Size = 256;
ClaimedMemory += Text.Size;
Text.Ptr = Text.Location;
ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, 256);
if(HMML.annotations[AnnotationIndex].reference_count) // || HMML.annotations[AnnotationIndex].is_quote)
{
@ -257,28 +260,18 @@ HMML.annotations[AnnotationIndex].time);
Text.Ptr += Inc;
++DataRef;
}
while(*InPtr)
{
*Text.Ptr++ = *InPtr++;
}
CopyStringToBuffer(InPtr, &Text);
}
else
{
sprintf(Working.Location,
" <div class=\"marker\" data-timestamp=\"%d\">\n", TimecodeToSeconds(HMML.annotations[AnnotationIndex].time));
while(*InPtr)
{
*Text.Ptr++ = *InPtr++;
}
CopyStringToBuffer(InPtr, &Text);
}
*Text.Ptr = '\0';
Text.Ptr = Text.Location;
Working.Ptr = Working.Location;
while(*Working.Ptr)
{
*Out.Ptr++ = *Working.Ptr++;
}
CopyBuffer(&Working, &Out);
sprintf(Working.Location,
" <div class=\"content\"><span class=\"timecode\">%s</span>%s</div>\n"
@ -295,14 +288,10 @@ HMML.annotations[AnnotationIndex].time);
Text.Location,
HMML.annotations[AnnotationIndex].time,
Text.Location);
Working.Ptr = Working.Location;
ClaimedMemory -= Text.Size;
while(*Working.Ptr)
{
*Out.Ptr++ = *Working.Ptr++;
}
CopyBuffer(&Working, &Out);
}
sprintf(Working.Location,
@ -376,11 +365,7 @@ HMML.annotations[AnnotationIndex].time);
" </body>\n"
"</html>\n");
Working.Ptr = Working.Location;
while(*Working.Ptr)
{
*Out.Ptr++ = *Working.Ptr++;
}
CopyBuffer(&Working, &Out);
hmml_free(&HMML);

View File

@ -18,42 +18,54 @@
<div class="source">GitHub</div>
<div class="ref_title">instructions.scala</div>
</span>
<span data-timestamp="543" class="timecode"><span class="ref_index">[1]</span><span class="time">9:03</span></span>
<div class="ref_indices">
<span data-timestamp="543" class="timecode"><span class="ref_index">[1]</span><span class="time">9:03</span></span>
</div>
</a>
<a data-id="3" href="https://en.wikipedia.org/wiki/Register-transfer_level" target="_blank" class="ref">
<span class="ref_content">
<div class="source">Wikipedia</div>
<div class="ref_title">Register-transfer level</div>
</span>
<span data-timestamp="543" class="timecode"><span class="ref_index">[2]</span><span class="time">9:03</span></span>
<div class="ref_indices">
<span data-timestamp="543" class="timecode"><span class="ref_index">[2]</span><span class="time">9:03</span></span>
</div>
</a>
<a data-id="4" href="https://forums.sifive.com/t/confusion-regarding-freedom-e-sdk-inline-asm/383" target="_blank" class="ref">
<span class="ref_content">
<div class="source">SiFive Forums</div>
<div class="ref_title">Confusion Regarding Freedom E SDK inline asm</div>
</span>
<span data-timestamp="955" class="timecode"><span class="ref_index">[3]</span><span class="time">15:55</span></span>
<div class="ref_indices">
<span data-timestamp="955" class="timecode"><span class="ref_index">[3]</span><span class="time">15:55</span></span>
</div>
</a>
<a data-id="6" href="https://riscv.org/specifications" target="_blank" class="ref">
<span class="ref_content">
<div class="source">RISC-V"</div>
<div class="source">RISC-V</div>
<div class="ref_title">User-Level ISA Specification v2.1</div>
</span>
<span data-timestamp="1344" class="timecode"><span class="ref_index">[4]</span><span class="time">22:24</span></span>
<div class="ref_indices">
<span data-timestamp="1344" class="timecode"><span class="ref_index">[4]</span><span class="time">22:24</span></span>
</div>
</a>
<a data-id="8" href="http://ericw.ca/notes/a-tiny-guide-to-gcc-inline-assembly.html" target="_blank" class="ref">
<span class="ref_content">
<div class="source">ericw.</div>
<div class="ref_title">A Tiny Guide to GCC Inline Assembly</div>
</span>
<span data-timestamp="1733" class="timecode"><span class="ref_index">[5]</span><span class="time">28:53</span></span>
<div class="ref_indices">
<span data-timestamp="1733" class="timecode"><span class="ref_index">[5]</span><span class="time">28:53</span></span>
</div>
</a>
<a data-id="10" href="https://riscv.org/specifications/privileged-isa/" target="_blank" class="ref">
<span class="ref_content">
<div class="source">RISC-V</div>
<div class="ref_title">Draft Privileged ISA Specification v1.9.1</div>
</span>
<span data-timestamp="2421" class="timecode"><span class="ref_index">[6]</span><span class="time">40:21</span></span>
<div class="ref_indices">
<span data-timestamp="2421" class="timecode"><span class="ref_index">[6]</span><span class="time">40:21</span></span>
</div>
</a>
</div>
</div>

View File

@ -213,7 +213,6 @@ body {
.refs .ref .ref_content {
width: 100%;
text-align: center;
}
.refs .ref .source {
@ -222,6 +221,10 @@ body {
line-height: 8px;
}
.refs .ref .ref_title {
font-style: oblique;
}
.refs .ref .timecode .ref_index {
margin-right: 4px;
}