diff --git a/hmml_to_html/hmml.a b/hmml_to_html/hmml.a index a45b16c..cbf8ed4 100644 Binary files a/hmml_to_html/hmml.a and b/hmml_to_html/hmml.a differ diff --git a/hmml_to_html/hmml_to_html.c b/hmml_to_html/hmml_to_html.c index cdc79af..c155f94 100644 --- a/hmml_to_html/hmml_to_html.c +++ b/hmml_to_html/hmml_to_html.c @@ -1,6 +1,7 @@ #if 0 ctime -begin ${0%.*}.ctm -clang -g -Wall -Wno-unused-variable -fsanitize=address -std=c99 $0 -o ${0%.*} hmml.a +#gcc -g -Wall -Wno-unused-variable -fsanitize=address -std=c99 $0 -o ${0%.*} hmml.a +gcc -g -Wall -fsanitize=address -std=c99 $0 -o ${0%.*} hmml.a ctime -end ${0%.*}.ctm exit #endif @@ -28,6 +29,8 @@ typedef struct char *RefTitle; } ref_info; +#define ArrayCount(A) sizeof(A)/sizeof(*(A)) + void ClaimBuffer(char *MemoryArena, int *ClaimedMemory, buffer *Buffer, int Size) { @@ -158,6 +161,48 @@ StringToColourHash(char *String) return Result / i; } +int +StringLength(char *String) +{ + int i = 0; + while(String[i]) + { + ++i; + } + return i; +} + +char * +SanitisePunctuation(char *String) +{ + char *Ptr = String; + while(*Ptr) + { + if(*Ptr == ' ') + { + *Ptr = '_'; + } + if((*Ptr < '0' || *Ptr > '9') && + (*Ptr < 'a' || *Ptr > 'z') && + (*Ptr < 'A' || *Ptr > 'Z')) + { + *Ptr = '-'; + } + ++Ptr; + } + return String; +} + +char *CategoryMedium[] = +{ + "blackboard", + "Blackboard", + "research", + "Research", + "run", + "Run", +}; + int main(int ArgC, char **Args) { @@ -224,6 +269,7 @@ main(int ArgC, char **Args) for(int AnnotationIndex = 0; AnnotationIndex < HMML.annotation_count; ++AnnotationIndex) { + bool HasCategory = FALSE; ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationHeader, 256); ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, 128); ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, 1024 * 4); @@ -235,7 +281,6 @@ TimecodeToSeconds(HMML.annotations[AnnotationIndex].time)); CopyStringToBuffer(&AnnotationClass, " class=\"marker"); -#if 0 if(HMML.annotations[AnnotationIndex].author) { CopyStringToBuffer(&AnnotationClass, " authored"); @@ -244,18 +289,102 @@ TimecodeToSeconds(HMML.annotations[AnnotationIndex].time)); StringToColourHash(HMML.annotations[AnnotationIndex].author), HMML.annotations[AnnotationIndex].author); } -#endif + InPtr = HMML.annotations[AnnotationIndex].text; + int MarkerIndex = 0, RefIndex = 0; + while(*InPtr) + { + if(MarkerIndex < HMML.annotations[AnnotationIndex].marker_count && + InPtr - HMML.annotations[AnnotationIndex].text == HMML.annotations[AnnotationIndex].markers[MarkerIndex].offset) + { + char *Readable = HMML.annotations[AnnotationIndex].markers[MarkerIndex].parameter + ? HMML.annotations[AnnotationIndex].markers[MarkerIndex].parameter + : HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker; + if(HMML.annotations[AnnotationIndex].markers[MarkerIndex].type == HMML_MEMBER) + { + CopyStringToBuffer(&Text, +"%s", +HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker, +StringToColourHash(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker), +Readable); + InPtr += StringLength(Readable); + } + else if(HMML.annotations[AnnotationIndex].markers[MarkerIndex].type == HMML_PROJECT) + { + CopyStringToBuffer(&Text, +"%s", +HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker, +StringToColourHash(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker), +Readable); + InPtr += StringLength(Readable); + } + else if(HMML.annotations[AnnotationIndex].markers[MarkerIndex].type == HMML_CATEGORY) + { + for(int i = 0; i < ArrayCount(CategoryMedium); ++i) + { + if(!StringsDiffer(CategoryMedium[i], HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker)) + { + CopyStringToBuffer(&AnnotationClass, " %s", SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker)); + goto NextCategory; + } + } + if(!HasCategory) + { + ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, 256); + CopyStringToBuffer(&Category, "
", + SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker)); + HasCategory = TRUE; + } + else + { + CopyStringToBuffer(&Category, "
", + SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker)); + } + CopyStringToBuffer(&AnnotationClass, " cat_%s", + SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker)); + } +NextCategory: ++MarkerIndex; + } + + if(RefIndex < HMML.annotations[AnnotationIndex].reference_count && + InPtr - HMML.annotations[AnnotationIndex].text == HMML.annotations[AnnotationIndex].references[RefIndex].offset) + { + ++RefIndex; + } + if(*InPtr) + { + *Text.Ptr++ = *InPtr++; + } + } - - - //TODO(matt): Replace this CopyStringToBuffer() with real stuff! - CopyStringToBuffer(&Text, HMML.annotations[AnnotationIndex].text); - - - + while(MarkerIndex < HMML.annotations[AnnotationIndex].marker_count) + { + for(int i = 0; i < ArrayCount(CategoryMedium); ++i) + { + if(!StringsDiffer(CategoryMedium[i], HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker)) + { + CopyStringToBuffer(&AnnotationClass, " %s", SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker)); + goto NextCategoryInNode; + } + } + if(!HasCategory) + { + ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, 256); + CopyStringToBuffer(&Category, "
", + SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker)); + HasCategory = TRUE; + } + else + { + CopyStringToBuffer(&Category, "
", + SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker)); + } + CopyStringToBuffer(&AnnotationClass, " cat_%s", + SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker)); +NextCategoryInNode: ++MarkerIndex; + } CopyStringToBuffer(&AnnotationClass, "\""); CopyBuffer(&AnnotationClass, &AnnotationHeader); @@ -268,6 +397,14 @@ HMML.annotations[AnnotationIndex].author); "
%s", HMML.annotations[AnnotationIndex].time); + if(HasCategory) + { + CopyStringToBuffer(&Category, ""); + CopyBuffer(&Category, &Text); + } + + *Text.Ptr = '\0'; + CopyBuffer(&Text, &Annotation); CopyStringToBuffer(&Annotation, "
\n" @@ -309,7 +446,7 @@ HMML.annotations[AnnotationIndex].time); ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, 1024 * 512); CopyStringToBuffer(&Master, -"\n" +"\n" " \n" " \n" "\n"