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

View File

@ -18,42 +18,54 @@
<div class="source">GitHub</div> <div class="source">GitHub</div>
<div class="ref_title">instructions.scala</div> <div class="ref_title">instructions.scala</div>
</span> </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>
<a data-id="3" href="https://en.wikipedia.org/wiki/Register-transfer_level" target="_blank" class="ref"> <a data-id="3" href="https://en.wikipedia.org/wiki/Register-transfer_level" target="_blank" class="ref">
<span class="ref_content"> <span class="ref_content">
<div class="source">Wikipedia</div> <div class="source">Wikipedia</div>
<div class="ref_title">Register-transfer level</div> <div class="ref_title">Register-transfer level</div>
</span> </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>
<a data-id="4" href="https://forums.sifive.com/t/confusion-regarding-freedom-e-sdk-inline-asm/383" target="_blank" class="ref"> <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"> <span class="ref_content">
<div class="source">SiFive Forums</div> <div class="source">SiFive Forums</div>
<div class="ref_title">Confusion Regarding Freedom E SDK inline asm</div> <div class="ref_title">Confusion Regarding Freedom E SDK inline asm</div>
</span> </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>
<a data-id="6" href="https://riscv.org/specifications" target="_blank" class="ref"> <a data-id="6" href="https://riscv.org/specifications" target="_blank" class="ref">
<span class="ref_content"> <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> <div class="ref_title">User-Level ISA Specification v2.1</div>
</span> </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>
<a data-id="8" href="http://ericw.ca/notes/a-tiny-guide-to-gcc-inline-assembly.html" target="_blank" class="ref"> <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"> <span class="ref_content">
<div class="source">ericw.</div> <div class="source">ericw.</div>
<div class="ref_title">A Tiny Guide to GCC Inline Assembly</div> <div class="ref_title">A Tiny Guide to GCC Inline Assembly</div>
</span> </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>
<a data-id="10" href="https://riscv.org/specifications/privileged-isa/" target="_blank" class="ref"> <a data-id="10" href="https://riscv.org/specifications/privileged-isa/" target="_blank" class="ref">
<span class="ref_content"> <span class="ref_content">
<div class="source">RISC-V</div> <div class="source">RISC-V</div>
<div class="ref_title">Draft Privileged ISA Specification v1.9.1</div> <div class="ref_title">Draft Privileged ISA Specification v1.9.1</div>
</span> </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> </a>
</div> </div>
</div> </div>

View File

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