Skip to content
Snippets Groups Projects
Commit 5569648c authored by Lyndon Brown's avatar Lyndon Brown Committed by Hugo Beauzée-Luyssen
Browse files

config: add and use index-of helpers for cat/subcat array iteration

these 'index-of' helpers find the index for the given cat/subcat. this
allows us to de-duplicate the code from the other helper functions (both
for those that already exist and ones to be added in further commits).
they loop based upon array length rather than looking out for some
particular condition of varying properties in an end marker record,
allowing us to also drop those.

i used an index-of design here rather than have functions that return
pointers because there will be a secondary use for index-of helpers in
later commits.
parent e9edfd60
No related branches found
No related tags found
No related merge requests found
......@@ -215,8 +215,6 @@ static const struct config_category_t categories_array[] =
{ CAT_SOUT, SOUT_TITLE, SOUT_HELP },
{ CAT_PLAYLIST, PLAYLIST_TITLE, PLAYLIST_HELP },
{ CAT_ADVANCED, AADVANCED_TITLE, AADVANCED_HELP },
{ -1, NULL, NULL }
};
static const struct config_subcategory_t subcategories_array[] =
......@@ -260,72 +258,70 @@ static const struct config_subcategory_t subcategories_array[] =
{ SUBCAT_ADVANCED_MISC, MISC_TITLE, AADVANCED_HELP },
{ SUBCAT_ADVANCED_NETWORK, ANETWORK_TITLE, ANETWORK_HELP },
{ -1, NULL, NULL }
};
/** Get the name for a category. */
/** Get the table index for the given category entry. */
VLC_USED
static inline const char *vlc_config_cat_GetName( int cat )
static inline int vlc_config_cat_IndexOf( int cat )
{
int i = 0;
while( categories_array[i].name != NULL )
int index = -1;
for( unsigned i = 0; i < ARRAY_SIZE(categories_array); i++ )
{
if( categories_array[i].id == cat )
{
return vlc_gettext(categories_array[i].name);
index = i;
break;
}
i++;
}
return NULL;
return index;
}
/** Get the help text for a category. */
/** Get the table index for the given subcategory entry. */
VLC_USED
static inline const char *vlc_config_cat_GetHelp( int cat )
static inline int vlc_config_subcat_IndexOf( int subcat )
{
int i = 0;
while( categories_array[i].help != NULL )
int index = -1;
for( unsigned i = 0; i < ARRAY_SIZE(subcategories_array); i++ )
{
if( categories_array[i].id == cat )
if( subcategories_array[i].id == subcat )
{
return vlc_gettext(categories_array[i].help);
index = i;
break;
}
i++;
}
return NULL;
return index;
}
/** Get the name for a category. */
VLC_USED
static inline const char *vlc_config_cat_GetName( int cat )
{
int i = vlc_config_cat_IndexOf( cat );
return (i != -1) ? vlc_gettext(categories_array[i].name) : NULL;
}
/** Get the help text for a category. */
VLC_USED
static inline const char *vlc_config_cat_GetHelp( int cat )
{
int i = vlc_config_cat_IndexOf( cat );
return (i != -1) ? vlc_gettext(categories_array[i].help) : NULL;
}
/** Get the name for a subcategory. */
VLC_USED
static inline const char *vlc_config_subcat_GetName( int subcat )
{
int i = 0;
while( subcategories_array[i].name != NULL )
{
if( subcategories_array[i].id == subcat )
{
return vlc_gettext(subcategories_array[i].name);
}
i++;
}
return NULL;
int i = vlc_config_subcat_IndexOf( subcat );
return (i != -1) ? vlc_gettext(subcategories_array[i].name) : NULL;
}
/** Get the help text for a subcategory. */
VLC_USED
static inline const char *vlc_config_subcat_GetHelp( int subcat )
{
int i = 0;
while( subcategories_array[i].help != NULL )
{
if( subcategories_array[i].id == subcat )
{
return vlc_gettext(subcategories_array[i].help);
}
i++;
}
return NULL;
int i = vlc_config_subcat_IndexOf( subcat );
return (i != -1) ? vlc_gettext(subcategories_array[i].help) : NULL;
}
/** Check if the given subcategory is a "general" one.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment