hmml_to_html.c: Simplify InsertCategory()

Basically just relive it of taking HasTopic and HasCategory
This commit is contained in:
Matt Mascarenhas 2017-08-19 23:35:07 +01:00
parent f3899c2f35
commit 928d639c41
1 changed files with 55 additions and 79 deletions

View File

@ -737,7 +737,7 @@ BuildReference(ref_info *ReferencesArray, int RefIdentifier, int UniqueRefs, HMM
} }
void void
InsertCategory(categories *Topics, categories *Media, bool *HasTopic, bool *HasMedium, char *Marker) InsertCategory(categories *Topics, categories *Media, char *Marker)
{ {
bool IsMedium = FALSE; bool IsMedium = FALSE;
@ -747,7 +747,6 @@ InsertCategory(categories *Topics, categories *Media, bool *HasTopic, bool *HasM
if(!StringsDiffer(CategoryMedium[CategoryMediumIndex].Medium, Marker)) if(!StringsDiffer(CategoryMedium[CategoryMediumIndex].Medium, Marker))
{ {
IsMedium = TRUE; IsMedium = TRUE;
*HasMedium = TRUE;
break; break;
} }
} }
@ -786,7 +785,6 @@ InsertCategory(categories *Topics, categories *Media, bool *HasTopic, bool *HasM
} }
else else
{ {
*HasTopic = TRUE;
for(CategoryIndex = 0; CategoryIndex < Topics->Count; ++CategoryIndex) for(CategoryIndex = 0; CategoryIndex < Topics->Count; ++CategoryIndex)
{ {
if(!StringsDiffer(Marker, Topics->Category[CategoryIndex].Marker)) if(!StringsDiffer(Marker, Topics->Category[CategoryIndex].Marker))
@ -1909,9 +1907,7 @@ goto Cleanup;
#endif #endif
HMML_Annotation *Anno = HMML.annotations + AnnotationIndex; HMML_Annotation *Anno = HMML.annotations + AnnotationIndex;
categories LocalTopics = { 0 }; categories LocalTopics = { 0 };
bool HasTopic = FALSE;
categories LocalMedia = { 0 }; categories LocalMedia = { 0 };
bool HasMedium = FALSE;
bool HasQuote = FALSE; bool HasQuote = FALSE;
bool HasReference = FALSE; bool HasReference = FALSE;
@ -1943,7 +1939,7 @@ goto Cleanup;
{ {
HasFilterMenu = TRUE; HasFilterMenu = TRUE;
} }
InsertCategory(&Topics, &Media, &HasTopic, &HasMedium, "authored"); InsertCategory(&Topics, &Media, "authored");
CopyStringToBuffer(&AnnotationClass, " authored"); CopyStringToBuffer(&AnnotationClass, " authored");
hsl_colour AuthorColour; hsl_colour AuthorColour;
StringToColourHash(&AuthorColour, Anno->author); StringToColourHash(&AuthorColour, Anno->author);
@ -1967,10 +1963,6 @@ goto Cleanup;
Anno->author); Anno->author);
} }
if(!HasMedium)
{
HasMedium = TRUE;
}
} }
InPtr = Anno->text; InPtr = Anno->text;
@ -2044,8 +2036,8 @@ goto Cleanup;
{ {
HasFilterMenu = TRUE; HasFilterMenu = TRUE;
} }
InsertCategory(&Topics, &Media, &HasTopic, &HasMedium, Anno->markers[MarkerIndex].marker); // Global InsertCategory(&Topics, &Media, Anno->markers[MarkerIndex].marker); // Global
InsertCategory(&LocalTopics, &LocalMedia, &HasTopic, &HasMedium, Anno->markers[MarkerIndex].marker); // Local InsertCategory(&LocalTopics, &LocalMedia, Anno->markers[MarkerIndex].marker); // Local
} }
} }
@ -2308,16 +2300,16 @@ goto Cleanup;
} }
if(Anno->markers[MarkerIndex].marker) if(Anno->markers[MarkerIndex].marker)
{ {
InsertCategory(&Topics, &Media, &HasTopic, &HasMedium, Anno->markers[MarkerIndex].marker); InsertCategory(&Topics, &Media, Anno->markers[MarkerIndex].marker);
} }
InsertCategory(&LocalTopics, &LocalMedia, &HasTopic, &HasMedium, Anno->markers[MarkerIndex].marker); InsertCategory(&LocalTopics, &LocalMedia, Anno->markers[MarkerIndex].marker);
++MarkerIndex; ++MarkerIndex;
} }
if(!HasMedium) if(LocalMedia.Count == 0)
{ {
InsertCategory(&Topics, &Media, &HasTopic, &HasMedium, DefaultMedium); InsertCategory(&Topics, &Media, DefaultMedium);
InsertCategory(&LocalTopics, &LocalMedia, &HasTopic, &HasMedium, DefaultMedium); InsertCategory(&LocalTopics, &LocalMedia, DefaultMedium);
} }
BuildCategories(&AnnotationClass, &TopicDots, LocalTopics, LocalMedia, &MarkerIndex); BuildCategories(&AnnotationClass, &TopicDots, LocalTopics, LocalMedia, &MarkerIndex);
@ -2337,7 +2329,7 @@ goto Cleanup;
CopyBuffer(&Annotation, &Text); CopyBuffer(&Annotation, &Text);
if(HasTopic) if(LocalTopics.Count > 0)
{ {
CopyBuffer(&Annotation, &TopicDots); CopyBuffer(&Annotation, &TopicDots);
} }
@ -2448,61 +2440,55 @@ goto Cleanup;
if(HasFilterMenu) if(HasFilterMenu)
{ {
CopyStringToBuffer(&FilterState, CopyStringToBuffer(&FilterState,
" var filterState = {\n"); " var filterState = {\n");
for(int i = 0; i < Topics.Count; ++i) for(int i = 0; i < Topics.Count; ++i)
{ {
CopyStringToBuffer(&FilterState, "\"%s\":\t{ \"type\": \"%s\",\t\"off\": false },\n", CopyStringToBuffer(&FilterState, "\"%s\":\t{ \"type\": \"%s\",\t\"off\": false },\n",
Topics.Category[i].Marker, "topic"); Topics.Category[i].Marker, "topic");
} }
for(int i = 0; i < Media.Count; ++i) for(int i = 0; i < Media.Count; ++i)
{ {
CopyStringToBuffer(&FilterState, "\"%s\":\t{ \"type\": \"%s\",\t\"off\": false },\n", CopyStringToBuffer(&FilterState, "\"%s\":\t{ \"type\": \"%s\",\t\"off\": false },\n",
Media.Category[i].Marker, "medium"); Media.Category[i].Marker, "medium");
} }
CopyStringToBuffer(&FilterState, CopyStringToBuffer(&FilterState,
" };\n"); " };\n");
CopyStringToBuffer(&FilterMenu, CopyStringToBuffer(&FilterMenu,
" <div class=\"menu filter\">\n" " <div class=\"menu filter\">\n"
" <span><img src=\"%s/cinera_icon_filter.png\"></span>\n" " <span><img src=\"%s/cinera_icon_filter.png\"></span>\n"
" <div class=\"filter_container\">\n" " <div class=\"filter_container\">\n"
" <div class=\"filter_mode inclusive\">Filter mode: </div>\n" " <div class=\"filter_mode inclusive\">Filter mode: </div>\n"
" <div class=\"filters\">\n", ImagesDir); " <div class=\"filters\">\n", ImagesDir);
if(Topics.Count > 0)
{ {
bool HasTopic = FALSE; CopyStringToBuffer(&FilterMenu,
bool HasMedium = FALSE; " <div class=\"filter_topics\">\n"
" <div class=\"filter_title\">Topics</div>\n");
for(int i = 0; i < Topics.Count; ++i) for(int i = 0; i < Topics.Count; ++i)
{ {
if(!HasTopic)
{
CopyStringToBuffer(&FilterMenu,
" <div class=\"filter_topics\">\n"
" <div class=\"filter_title\">Topics</div>\n");
HasTopic = TRUE;
}
CopyStringToBuffer(&FilterTopics, CopyStringToBuffer(&FilterTopics,
" <div class=\"filter_content %s\">\n" " <div class=\"filter_content %s\">\n"
" <span class=\"icon category %s\"></span><span class=\"text\">%s</span>\n" " <span class=\"icon category %s\"></span><span class=\"text\">%s</span>\n"
" </div>\n", " </div>\n",
Topics.Category[i].Marker, Topics.Category[i].Marker,
Topics.Category[i].Marker, Topics.Category[i].Marker,
Topics.Category[i].Marker); Topics.Category[i].Marker);
} }
CopyStringToBuffer(&FilterTopics,
" </div>\n");
CopyBuffer(&FilterMenu, &FilterTopics);
}
if(Media.Count > 0)
{
CopyStringToBuffer(&FilterMedia,
" <div class=\"filter_media\">\n"
" <div class=\"filter_title\">Media</div>\n");
for(int i = 0; i < Media.Count; ++i) for(int i = 0; i < Media.Count; ++i)
{ {
if(!HasMedium)
{
CopyStringToBuffer(&FilterMedia,
" <div class=\"filter_media\">\n"
" <div class=\"filter_title\">Media</div>\n");
HasMedium = TRUE;
}
int j; int j;
for(j = 0; j < ArrayCount(CategoryMedium); ++j) for(j = 0; j < ArrayCount(CategoryMedium); ++j)
{ {
@ -2513,37 +2499,27 @@ goto Cleanup;
} }
CopyStringToBuffer(&FilterMedia, CopyStringToBuffer(&FilterMedia,
" <div class=\"filter_content %s\">\n" " <div class=\"filter_content %s\">\n"
" <span class=\"icon\">%s</span><span class=\"text\">%s</span>\n" " <span class=\"icon\">%s</span><span class=\"text\">%s</span>\n"
" </div>\n", " </div>\n",
Media.Category[i].Marker, Media.Category[i].Marker,
CategoryMedium[j].Icon, CategoryMedium[j].Icon,
CategoryMedium[j].WrittenName CategoryMedium[j].WrittenName
); );
}
if(HasTopic)
{
CopyStringToBuffer(&FilterTopics,
" </div>\n");
CopyBuffer(&FilterMenu, &FilterTopics);
}
if(HasMedium)
{
CopyStringToBuffer(&FilterMedia,
" </div>\n");
CopyBuffer(&FilterMenu, &FilterMedia);
} }
CopyStringToBuffer(&FilterMedia,
" </div>\n");
CopyBuffer(&FilterMenu, &FilterMedia);
} }
CopyStringToBuffer(&FilterMenu, CopyStringToBuffer(&FilterMenu,
" </div>\n" " </div>\n"
" </div>\n" " </div>\n"
" </div>\n"); " </div>\n");
}
CopyBuffer(&Menus, &FilterMenu); CopyBuffer(&Menus, &FilterMenu);
}
if(HasCreditsMenu) if(HasCreditsMenu)
{ {