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);
} }
@ -2469,20 +2461,14 @@ goto Cleanup;
" <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);
{
bool HasTopic = FALSE;
bool HasMedium = FALSE;
for(int i = 0; i < Topics.Count; ++i) if(Topics.Count > 0)
{
if(!HasTopic)
{ {
CopyStringToBuffer(&FilterMenu, CopyStringToBuffer(&FilterMenu,
" <div class=\"filter_topics\">\n" " <div class=\"filter_topics\">\n"
" <div class=\"filter_title\">Topics</div>\n"); " <div class=\"filter_title\">Topics</div>\n");
for(int i = 0; i < Topics.Count; ++i)
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"
@ -2491,18 +2477,18 @@ goto Cleanup;
Topics.Category[i].Marker, Topics.Category[i].Marker,
Topics.Category[i].Marker); Topics.Category[i].Marker);
} }
CopyStringToBuffer(&FilterTopics,
" </div>\n");
CopyBuffer(&FilterMenu, &FilterTopics);
}
for(int i = 0; i < Media.Count; ++i) if(Media.Count > 0)
{
if(!HasMedium)
{ {
CopyStringToBuffer(&FilterMedia, CopyStringToBuffer(&FilterMedia,
" <div class=\"filter_media\">\n" " <div class=\"filter_media\">\n"
" <div class=\"filter_title\">Media</div>\n"); " <div class=\"filter_title\">Media</div>\n");
for(int i = 0; i < Media.Count; ++i)
HasMedium = TRUE; {
}
int j; int j;
for(j = 0; j < ArrayCount(CategoryMedium); ++j) for(j = 0; j < ArrayCount(CategoryMedium); ++j)
{ {
@ -2521,30 +2507,20 @@ goto Cleanup;
CategoryMedium[j].WrittenName CategoryMedium[j].WrittenName
); );
} }
if(HasTopic)
{
CopyStringToBuffer(&FilterTopics,
" </div>\n");
CopyBuffer(&FilterMenu, &FilterTopics);
}
if(HasMedium)
{
CopyStringToBuffer(&FilterMedia, CopyStringToBuffer(&FilterMedia,
" </div>\n"); " </div>\n");
CopyBuffer(&FilterMenu, &FilterMedia); 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)
{ {
CopyBuffer(&Menus, &CreditsMenu); CopyBuffer(&Menus, &CreditsMenu);