]> git.sesse.net Git - vlc/blobdiff - src/config/help.c
decoder: remove tautology, add asserts to waiting code
[vlc] / src / config / help.c
index 155dc507fa985c0f59a7da5d1cfb2f34aa2174ef..26f2e5038b1a44b1257c08d2f02504b615baa818 100644 (file)
@@ -202,7 +202,7 @@ static void Help (vlc_object_t *p_this, char const *psz_help_name)
     if( psz_help_name && !strcmp( psz_help_name, "help" ) )
     {
         printf(_(vlc_usage), "vlc");
-        Usage( p_this, "=main" );
+        Usage( p_this, "=core" );
         print_help_on_full_help();
     }
     else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
@@ -351,8 +351,8 @@ static void print_item(const module_t *m, const module_config_t *item,
 # define OPTION_VALUE_SEP "="
 #endif
     const char *bra = OPTION_VALUE_SEP "<", *type, *ket = ">";
-    const char *prefix = NULL, *suffix = "";
-    char psz_buffer[10000]; // XXX
+    const char *prefix = NULL, *suffix = NULL;
+    char *typebuf = NULL;
 
     switch (CONFIG_CLASS(item->i_type))
     {
@@ -379,43 +379,64 @@ static void print_item(const module_t *m, const module_config_t *item,
             type = _("string");
             if (item->list_count > 0)
             {
+                size_t len = 0;
+
+                for (unsigned i = 0; i < item->list_count; i++)
+                    len += strlen(item->list.psz[i]) + 1;
+
+                typebuf = malloc(len);
+                if (typebuf == NULL)
+                    break;
+
                 bra = OPTION_VALUE_SEP "{";
-                type = psz_buffer;
-                psz_buffer[0] = '\0';
+                type = typebuf;
+                ket = "}";
 
+                *typebuf = 0;
                 for (unsigned i = 0; i < item->list_count; i++)
                 {
                     if (i > 0)
-                        strcat(psz_buffer, ",");
-                    strcat(psz_buffer, item->list.psz[i]);
+                        strcat(typebuf, ",");
+                    strcat(typebuf, item->list.psz[i]);
                 }
-                ket = "}";
             }
             break;
 
         case CONFIG_ITEM_INTEGER:
             type = _("integer");
-            if (item->min.i != 0 || item->max.i != 0)
-            {
-                sprintf (psz_buffer, "%s [%"PRId64" .. %"PRId64"]",
-                         type, item->min.i, item->max.i);
-                type = psz_buffer;
-            }
+
             if (item->list_count > 0)
             {
+                size_t len = 0;
+
+                for (unsigned i = 0; i < item->list_count; i++)
+                    len += strlen(item->list_text[i]) + 4 * sizeof (int) + 5;
+
+                typebuf = malloc(len);
+                if (typebuf == NULL)
+                    break;
+
                 bra = OPTION_VALUE_SEP "{";
-                type = psz_buffer;
-                psz_buffer[0] = '\0';
+                type = typebuf;
+                ket = "}";
 
+                *typebuf = 0;
                 for (unsigned i = 0; i < item->list_count; i++)
                 {
                     if (i != 0)
-                        strcat(psz_buffer, ", ");
-                    sprintf(psz_buffer + strlen(psz_buffer), "%i (%s)",
+                        strcat(typebuf, ", ");
+                    sprintf(typebuf + strlen(typebuf), "%i (%s)",
                             item->list.i[i],
                             module_gettext(m, item->list_text[i]));
                 }
-                ket = "}";
+            }
+            else if (item->min.i != 0 || item->max.i != 0)
+            {
+                if (asprintf(&typebuf, "%s [%"PRId64" .. %"PRId64"]",
+                             type, item->min.i, item->max.i) >= 0)
+                    type = typebuf;
+                else
+                    typebuf = NULL;
             }
             break;
 
@@ -423,17 +444,19 @@ static void print_item(const module_t *m, const module_config_t *item,
             type = _("float");
             if (item->min.f != 0.f || item->max.f != 0.f)
             {
-                sprintf(psz_buffer, "%s [%f .. %f]", type,
-                        item->min.f, item->max.f);
-                type = psz_buffer;
+                if (asprintf(&typebuf, "%s [%f .. %f]", type,
+                             item->min.f, item->max.f) >= 0)
+                    type = typebuf;
+                else
+                    typebuf = NULL;
             }
             break;
 
         case CONFIG_ITEM_BOOL:
             bra = type = ket = "";
             prefix = ", --no-";
-            suffix = item->value.i ? _(" (default enabled)")
-                                   : _(" (default disabled)");
+            suffix = item->value.i ? _("(default enabled)")
+                                   : _("(default disabled)");
             break;
        default:
             return;
@@ -467,18 +490,25 @@ static void print_item(const module_t *m, const module_config_t *item,
         putchar('\n');
         offset = PADDING_SPACES + LINE_START;
     }
+
     printf("%*s", offset, "");
+    print_desc(module_gettext(m, item->psz_longtext),
+               PADDING_SPACES + LINE_START, color);
 
-    sprintf(psz_buffer, "%s%s", module_gettext(m, item->psz_text), suffix);
-    print_desc(psz_buffer, PADDING_SPACES + LINE_START, color);
+    if (suffix != NULL)
+    {
+        printf("%*s", offset, "");
+        print_desc(suffix, PADDING_SPACES + LINE_START, color);
+    }
 
     if (desc && (item->psz_longtext != NULL && item->psz_longtext[0]))
     {   /* Wrap long description */
         printf("%*s", LINE_START + 2, "");
-        sprintf(psz_buffer, "%s%s", module_gettext(m, item->psz_longtext),
-                suffix);
-        print_desc(psz_buffer, LINE_START + 2, false);
+        print_desc(module_gettext(m, item->psz_longtext),
+                   LINE_START + 2, false);
     }
+
+    free(typebuf);
 }
 
 static bool module_match(const module_t *m, const char *pattern, bool strict)
@@ -566,16 +596,16 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
         }
 
         /* Print name of module */
-        printf(color ? "\n " GREEN "%s" GRAY " (%s)\n" : "\n %s\n",
+        printf(color ? "\n " GREEN "%s" GRAY " (%s)\n" : "\n %s (%s)\n",
                module_gettext(m, m->psz_longname), objname);
         if (m->psz_help != NULL)
             printf(color ? CYAN" %s\n"GRAY : " %s\n",
                    module_gettext(m, m->psz_help));
 
         /* Print module options */
-        for (size_t i = 0; i < m->confsize; i++)
+        for (size_t j = 0; j < m->confsize; j++)
         {
-            const module_config_t *item = m->p_config + i;
+            const module_config_t *item = m->p_config + j;
 
             if (item->b_removed)
                 continue; /* Skip removed options */
@@ -623,6 +653,8 @@ static void ListModules (vlc_object_t *p_this, bool b_verbose)
 #ifndef _WIN32
     if (isatty(STDOUT_FILENO))
         color = var_InheritBool(p_this, "color");
+#else
+    (void) p_this;
 #endif
 
     /* List all modules */