diff --git a/hmml_to_html/hmml_to_html.c b/hmml_to_html/hmml_to_html.c index b5edc2d..9374f72 100644 --- a/hmml_to_html/hmml_to_html.c +++ b/hmml_to_html/hmml_to_html.c @@ -5,9 +5,7 @@ ctime -end ${0%.*}.ctm exit #endif -#define DEBUG 1 - -// TODO(matt): Fully investigate the ClaimedMemory situation +#define DEBUG 0 typedef unsigned int bool; @@ -367,19 +365,22 @@ BuildReference(ref_info *ReferencesArray, int RefIdentifier, int UniqueRefs, HMM char *CategoryMedium[][3] = { - // category icon written name - { "authored", "🗪", "Chat Comment"}, // TODO(matt): Conditionally handle Chat vs Guest Comments - { "blackboard", "🖌", "Blackboard"}, - { "owl", "🦉", "Owl of Shame"}, - { "default", "🖮", "Programming"}, // TODO(matt): Potentially make this configurable per project - { "rant", "💢", "Rant"}, - { "research", "📖", "Research"}, - { "run", "🏃", "In-Game"} // TODO(matt): Potentially make this configurable per project + // medium icon written name + { "authored", "🗪", "Chat Comment"}, // TODO(matt): Conditionally handle Chat vs Guest Comments + { "blackboard", "🖌", "Blackboard"}, + { "default", "🖮", "Programming"}, // TODO(matt): Potentially make this configurable per project + { "experience", "🍷", "Experience"}, + { "owl", "🦉", "Owl of Shame"}, + { "rant", "💢", "Rant"}, + { "research", "📖", "Research"}, + { "run", "🏃", "In-Game"}, // TODO(matt): Potentially make this configurable per project + { "trivia", "🎲", "Trivia"}, }; void BuildFilter(category_info *CategoriesArray, int *UniqueCategories, char *Marker) { + int Offset = 0; int i = 0; for(i = 0; i < *UniqueCategories; ++i) { @@ -387,28 +388,52 @@ BuildFilter(category_info *CategoriesArray, int *UniqueCategories, char *Marker) { return; } + if((Offset = StringsDiffer(Marker, CategoriesArray[i].Category)) < 0) + { + int j; + for(j = *UniqueCategories; j > i; --j) + { + CopyString(CategoriesArray[j].Category, CategoriesArray[j-1].Category); + CategoriesArray[j].IsMedium = CategoriesArray[j-1].IsMedium; + } + + CopyString(CategoriesArray[j].Category, Marker); + CategoriesArray[j].IsMedium = FALSE; + break; + } + } + + // This really ought to sort by the Alternative Text + + if(i == *UniqueCategories) + { + CopyString(CategoriesArray[i].Category, Marker); } ++*UniqueCategories; - CopyString(CategoriesArray[i].Category, Marker); - for(int j = 0; j < ArrayCount(CategoryMedium); ++j) + + for(int k = 0; k < ArrayCount(CategoryMedium); ++k) { - if(!StringsDiffer(CategoryMedium[j][0], Marker)) + if(!StringsDiffer(CategoryMedium[k][0], Marker)) { CategoriesArray[i].IsMedium = TRUE; } } - // TODO(matt): Sort the CategoriesArray } void -BuildCategories(buffer *AnnotationClass, buffer *Category, int *MarkerIndex, bool *HasCategory, char *Marker) +BuildCategories(buffer *AnnotationClass, buffer *Category, int *MarkerIndex, bool *HasCategory, bool *HasMedium, char *Marker) { + // NOTE(matt): This guy could also sort, so that the dots appear in a consistent order in the annotations + // If so, the Category buffer would have to only contain the category names and no more until collation time + // BuildCategories() would have to parse the Category.Location out to an array, sort that array and write it back in + // The code in the "annotation loop" would then have to write both the head and tail of the category stuff for(int i = 0; i < ArrayCount(CategoryMedium); ++i) { if(!StringsDiffer(CategoryMedium[i][0], Marker)) { CopyStringToBuffer(AnnotationClass, " %s", SanitisePunctuation(Marker)); + *HasMedium = TRUE; ++*MarkerIndex; return; } @@ -996,6 +1021,7 @@ main(int ArgC, char **Args) #endif HMML_Annotation *Anno = HMML.annotations + AnnotationIndex; bool HasCategory = FALSE; + bool HasMedium = FALSE; bool HasQuote = FALSE; bool HasReference = FALSE; @@ -1079,7 +1105,7 @@ Readable); HasFilterMenu = TRUE; } BuildFilter(CategoriesArray, &UniqueCategories, Anno->markers[MarkerIndex].marker); - BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, Anno->markers[MarkerIndex].marker); + BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, Anno->markers[MarkerIndex].marker); } } @@ -1278,7 +1304,13 @@ Anno->time); { BuildFilter(CategoriesArray, &UniqueCategories, Anno->markers[MarkerIndex].marker); } - BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, Anno->markers[MarkerIndex].marker); + BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, Anno->markers[MarkerIndex].marker); + } + + if(!HasMedium) + { + BuildFilter(CategoriesArray, &UniqueCategories, "default"); + BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, "default"); } CopyStringToBuffer(&AnnotationClass, "\""); @@ -1296,21 +1328,13 @@ Anno->time); "
%s", Anno->time); -#if 0 - // TODO(matt): Handle special-cases, i.e. default media, and possibly other things - if(!HasCategory) - { - BuildFilter(CategoriesArray, &UniqueCategories, "default"); - BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, "default"); - } -#endif if(HasCategory) { CopyStringToBuffer(&Category, ""); CopyBuffer(&Text, &Category); } - + // NOTE(matt): This feels a bit janky... *Text.Ptr = '\0'; CopyBuffer(&Annotation, &Text);