vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Wed Aug 15 00:01:18 2012 +0300| [40ec61728a9469213c7242c04b2b5f06628af53e] | committer: Rémi Denis-Courmont
config_GetIntChoices: function to retrieve config item choices (integer) > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=40ec61728a9469213c7242c04b2b5f06628af53e --- include/vlc_configuration.h | 2 ++ src/config/core.c | 47 ++++++++++++++++++++++++++++++++++++++++++- src/libvlccore.sym | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h index 1e68778..30e309e 100644 --- a/include/vlc_configuration.h +++ b/include/vlc_configuration.h @@ -96,6 +96,8 @@ VLC_API float config_GetFloat(vlc_object_t *, const char *) VLC_USED; VLC_API void config_PutFloat(vlc_object_t *, const char *, float); VLC_API char * config_GetPsz(vlc_object_t *, const char *) VLC_USED VLC_MALLOC; VLC_API void config_PutPsz(vlc_object_t *, const char *, const char *); +VLC_API ssize_t config_GetIntChoices(vlc_object_t *, const char *, + int64_t **, char ***) VLC_USED; VLC_API ssize_t config_GetPszChoices(vlc_object_t *, const char *, char ***, char ***) VLC_USED; diff --git a/src/config/core.c b/src/config/core.c index 2978205..d2795a5 100644 --- a/src/config/core.c +++ b/src/config/core.c @@ -331,7 +331,52 @@ void config_PutFloat( vlc_object_t *p_this, } /** - * Determines a list of suggested values for a configuration item. + * Determines a list of suggested values for an integer configuration item. + * \param values pointer to a table of integer values [OUT] + * \param texts pointer to a table of descriptions strings [OUT] + * \return number of choices, or -1 on error + * \note the caller is responsible for calling free() on all descriptions and + * on both tables. In case of error, both pointers are set to NULL. + */ +ssize_t config_GetIntChoices (vlc_object_t *obj, const char *name, + int64_t **restrict values, char ***restrict texts) +{ + *values = NULL; + *texts = NULL; + + module_config_t *cfg = config_FindConfig (obj, name); + if (cfg == NULL) + { + msg_Warn (obj, "option %s does not exist", name); + errno = ENOENT; + return -1; + } + + size_t count = cfg->i_list; + if (count == 0) + return 0; + + int64_t *vals = malloc (sizeof (*vals) * count); + char **txts = malloc (sizeof (*txts) * count); + if (unlikely(vals == NULL || txts == NULL)) + abort (); + + for (size_t i = 0; i < count; i++) + { + vals[i] = cfg->pi_list[i]; + txts[i] = strdup (cfg->ppsz_list_text[i]); + if (unlikely(txts[i] == NULL)) + abort (); + } + + *values = vals; + *texts = txts; + return count; +} + + +/** + * Determines a list of suggested values for a string configuration item. * \param values pointer to a table of value strings [OUT] * \param texts pointer to a table of descriptions strings [OUT] * \return number of choices, or -1 on error diff --git a/src/libvlccore.sym b/src/libvlccore.sym index 3a1fb96..2188f9d 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -44,6 +44,7 @@ config_GetLibDir config_GetFloat config_GetUserDir config_GetInt +config_GetIntChoices config_GetPsz config_GetPszChoices config_GetType _______________________________________________ vlc-commits mailing list [email protected] http://mailman.videolan.org/listinfo/vlc-commits
