[vlc-devel] [PATCH] help: retreive choices from config rather than modules directly

Pierre Lamot pierre at videolabs.io
Fri Sep 29 18:20:21 CEST 2017


---
 src/config/help.c | 58 ++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 42 insertions(+), 16 deletions(-)

diff --git a/src/config/help.c b/src/config/help.c
index 5298f15ec3..9693dc0c08 100644
--- a/src/config/help.c
+++ b/src/config/help.c
@@ -345,7 +345,7 @@ static int vlc_swidth(const char *str)
     }
 }
 
-static void print_item(const module_t *m, const module_config_t *item,
+static void print_item(const vlc_object_t *p_this, const module_t *m, const module_config_t *item,
                        const module_config_t **section, bool color, bool desc)
 {
 #ifndef _WIN32
@@ -379,13 +379,20 @@ static void print_item(const module_t *m, const module_config_t *item,
             return;
 
         case CONFIG_ITEM_STRING:
+        {
             type = _("string");
-            if (item->list_count > 0)
+
+            char **ppsz_values = NULL;
+            char **ppsz_texts = NULL;
+
+            ssize_t i_count = config_GetPszChoices(VLC_OBJECT(p_this), item->psz_name, &ppsz_values, &ppsz_texts);
+
+            if (i_count > 0)
             {
                 size_t len = 0;
 
-                for (unsigned i = 0; i < item->list_count; i++)
-                    len += strlen(item->list.psz[i]) + 1;
+                for (unsigned i = 0; i < i_count; i++)
+                    len += strlen(ppsz_values[i]) + 1;
 
                 typebuf = malloc(len);
                 if (typebuf == NULL)
@@ -396,25 +403,39 @@ static void print_item(const module_t *m, const module_config_t *item,
                 ket = "}";
 
                 *typebuf = 0;
-                for (unsigned i = 0; i < item->list_count; i++)
+                for (unsigned i = 0; i < i_count; i++)
                 {
                     if (i > 0)
                         strcat(typebuf, ",");
-                    strcat(typebuf, item->list.psz[i]);
+                    strcat(typebuf, ppsz_values[i]);
                 }
             }
-            break;
 
+            for (unsigned i = 0; i < i_count; i++)
+            {
+                free(ppsz_values[i]);
+                free(ppsz_texts[i]);
+            }
+            free(ppsz_values);
+            free(ppsz_texts);
+            break;
+        }
         case CONFIG_ITEM_INTEGER:
+        {
             type = _("integer");
 
-            if (item->list_count > 0)
+            int64_t *pi_values = NULL;
+            char **ppsz_texts = NULL;
+
+            ssize_t i_count = config_GetIntChoices(VLC_OBJECT(p_this), item->psz_name, &pi_values, &ppsz_texts);
+
+            if (i_count > 0)
             {
                 size_t len = 0;
 
-                for (unsigned i = 0; i < item->list_count; i++)
-                    len += strlen(module_gettext(m, item->list_text[i]))
-                           + 4 * sizeof (int) + 5;
+                for (unsigned i = 0; i < i_count; i++)
+                    len += strlen(ppsz_texts[i])
+                           + 4 * sizeof (int64_t) + 5;
 
                 typebuf = malloc(len);
                 if (typebuf == NULL)
@@ -429,9 +450,9 @@ static void print_item(const module_t *m, const module_config_t *item,
                 {
                     if (i != 0)
                         strcat(typebuf, ", ");
-                    sprintf(typebuf + strlen(typebuf), "%i (%s)",
-                            item->list.i[i],
-                            module_gettext(m, item->list_text[i]));
+                    sprintf(typebuf + strlen(typebuf), "%li (%s)",
+                            pi_values[i],
+                            ppsz_texts[i]);
                 }
             }
             else if (item->min.i != INT64_MIN || item->max.i != INT64_MAX )
@@ -442,8 +463,13 @@ static void print_item(const module_t *m, const module_config_t *item,
                 else
                     typebuf = NULL;
             }
-            break;
 
+            for (unsigned i = 0; i < i_count; i++)
+                free(ppsz_texts[i]);
+            free(pi_values);
+            free(ppsz_texts);
+            break;
+        }
         case CONFIG_ITEM_FLOAT:
             type = _("float");
             if (item->min.f != FLT_MIN || item->max.f != FLT_MAX)
@@ -614,7 +640,7 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
                 b_has_advanced = true;
                 continue;
             }
-            print_item(m, item, &section, color, desc);
+            print_item(p_this, m, item, &section, color, desc);
         }
     }
 
-- 
2.14.2



More information about the vlc-devel mailing list