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