]> git.sesse.net Git - vlc/blobdiff - src/config/help.c
help: remove hacks for non-existent "help" module
[vlc] / src / config / help.c
index cf309ef2c2d83135251a2037bdb6b323cbcded5c..b49022fdb0fd74c4308175c5502804df764559c3 100644 (file)
@@ -1,48 +1,46 @@
 /*****************************************************************************
  * help.c: command line help
  *****************************************************************************
- * Copyright (C) 1998-2011 the VideoLAN team
+ * Copyright (C) 1998-2011 VLC authors and VideoLAN
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
 #include <vlc_common.h>
 #include <vlc_charset.h>
 #include <vlc_modules.h>
+#include <vlc_plugin.h>
 #include "modules/modules.h"
 #include "config/configuration.h"
 #include "libvlc.h"
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#elif defined( WIN32 ) && !defined( UNDER_CE )
-# include <io.h>
-#endif
-#if defined( WIN32 ) && !defined( UNDER_CE )
+#if defined( _WIN32 ) && !VLC_WINSTORE_APP
 static void ShowConsole (void);
 static void PauseConsole (void);
 #else
 # define ShowConsole() (void)0
 # define PauseConsole() (void)0
+# include <unistd.h>
 #endif
 
 static void Help (vlc_object_t *, const char *);
@@ -169,20 +167,19 @@ static void Help (vlc_object_t *p_this, char const *psz_help_name)
 
     if( psz_help_name && !strcmp( psz_help_name, "help" ) )
     {
-        utf8_fprintf( stdout, vlc_usage, "vlc" );
-        Usage( p_this, "=help" );
+        utf8_fprintf( stdout, _(vlc_usage), "vlc" );
         Usage( p_this, "=main" );
         print_help_on_full_help();
     }
     else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
     {
-        utf8_fprintf( stdout, vlc_usage, "vlc" );
+        utf8_fprintf( stdout, _(vlc_usage), "vlc" );
         Usage( p_this, NULL );
         print_help_on_full_help();
     }
     else if( psz_help_name && !strcmp( psz_help_name, "full-help" ) )
     {
-        utf8_fprintf( stdout, vlc_usage, "vlc" );
+        utf8_fprintf( stdout, _(vlc_usage), "vlc" );
         Usage( p_this, NULL );
     }
     else if( psz_help_name )
@@ -250,7 +247,7 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
 
 #define LINE_START 8
 #define PADDING_SPACES 25
-#ifdef WIN32
+#ifdef _WIN32
 #   define OPTION_VALUE_SEP "="
 #else
 #   define OPTION_VALUE_SEP " "
@@ -269,7 +266,7 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
     bool b_color       = var_InheritBool( p_this, "color" );
     bool b_has_advanced = false;
     bool b_found       = false;
-    int  i_only_advanced = 0; /* Number of modules ignored because they
+    unsigned i_only_advanced = 0; /* Number of modules ignored because they
                                * only have advanced options */
     bool b_strict = psz_search && *psz_search == '=';
     if( b_strict ) psz_search++;
@@ -278,7 +275,7 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
     psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
     memset( psz_spaces_longtext, ' ', LINE_START+2 );
     psz_spaces_longtext[LINE_START+2] = '\0';
-#ifndef WIN32
+#ifndef _WIN32
     if( !isatty( 1 ) )
 #endif
         b_color = false; // don't put color control codes in a .txt file
@@ -295,19 +292,12 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
     }
 
     /* List all modules */
-    module_t **list = module_list_get (NULL);
-    if (!list)
-        return;
-
-    /* Ugly hack to make sure that the help options always come first
-     * (part 1) */
-    if( !psz_search )
-        Usage( p_this, "help" );
+    size_t count;
+    module_t **list = module_list_get (&count);
 
     /* Enumerate the config for each module */
-    for (size_t i = 0; list[i]; i++)
+    for (size_t i = 0; i < count; i++)
     {
-        bool b_help_module;
         module_t *p_parser = list[i];
         module_config_t *p_item = NULL;
         module_config_t *p_section = NULL;
@@ -336,12 +326,6 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
             continue;
         }
 
-        b_help_module = !strcmp( "help", objname );
-        /* Ugly hack to make sure that the help options always come first
-         * (part 2) */
-        if( !psz_search && b_help_module )
-            continue;
-
         /* Ignore modules with only advanced config options if requested */
         if( !b_advanced )
         {
@@ -450,15 +434,15 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
                 psz_type = _("string");
                 psz_ket = ">";
 
-                if( p_item->ppsz_list )
+                if( p_item->list_count )
                 {
                     psz_bra = OPTION_VALUE_SEP "{";
                     psz_type = psz_buffer;
                     psz_buffer[0] = '\0';
-                    for( i = 0; p_item->ppsz_list[i]; i++ )
+                    for( i = 0; i < p_item->list_count; i++ )
                     {
                         if( i ) strcat( psz_buffer, "," );
-                        strcat( psz_buffer, p_item->ppsz_list[i] );
+                        strcat( psz_buffer, p_item->list.psz[i] );
                     }
                     psz_ket = "}";
                 }
@@ -478,17 +462,17 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
                     psz_type = psz_buffer;
                 }
 
-                if( p_item->i_list )
+                if( p_item->list_count )
                 {
                     psz_bra = OPTION_VALUE_SEP "{";
                     psz_type = psz_buffer;
                     psz_buffer[0] = '\0';
-                    for( i = 0; p_item->ppsz_list_text[i]; i++ )
+                    for( i = 0; i < p_item->list_count; i++ )
                     {
                         if( i ) strcat( psz_buffer, ", " );
                         sprintf( psz_buffer + strlen(psz_buffer), "%i (%s)",
-                                 p_item->pi_list[i],
-                                 module_gettext( p_parser, p_item->ppsz_list_text[i] ) );
+                                 p_item->list.i[i],
+                                 module_gettext( p_parser, p_item->list_text[i] ) );
                     }
                     psz_ket = "}";
                 }
@@ -512,11 +496,8 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
                                     b_description );
                 p_section = NULL;
                 psz_bra = ""; psz_type = ""; psz_ket = "";
-                if( !b_help_module )
-                {
-                    psz_suf = p_item->value.i ? _(" (default enabled)") :
-                                                _(" (default disabled)");
-                }
+                psz_suf = p_item->value.i ? _(" (default enabled)") :
+                                            _(" (default disabled)");
                 break;
             }
 
@@ -539,8 +520,7 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
                  - strlen( psz_bra ) - strlen( psz_type )
                  - strlen( psz_ket ) - 1;
 
-            if( CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL
-             && !b_help_module )
+            if( CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL )
             {
                 psz_prefix =  ", --no-";
                 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
@@ -556,8 +536,7 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
                 psz_spaces[i] = '\0';
             }
 
-            if( CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL
-             && !b_help_module )
+            if( CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL )
             {
                 utf8_fprintf( stdout, psz_format_bool, psz_short,
                               p_item->psz_name, psz_prefix, p_item->psz_name,
@@ -690,15 +669,15 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
     if( i_only_advanced > 0 )
     {
         if( b_color )
-        {
             utf8_fprintf( stdout, "\n" WHITE "%s" GRAY " ", _( "Note:" ) );
-            utf8_fprintf( stdout, _( "%d module(s) were not displayed because they only have advanced options.\n" ), i_only_advanced );
-        }
         else
-        {
             utf8_fprintf( stdout, "\n%s ", _( "Note:" ) );
-            utf8_fprintf( stdout, _( "%d module(s) were not displayed because they only have advanced options.\n" ), i_only_advanced );
-        }
+
+        utf8_fprintf( stdout, vlc_ngettext("%u module was not displayed "
+                                     "because it only has advanced options.\n",
+                                           "%u modules were not displayed "
+                                  "because they only have advanced options.\n",
+                      i_only_advanced ), i_only_advanced );
     }
     else if( !b_found )
     {
@@ -724,12 +703,10 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
  *****************************************************************************/
 static void ListModules (vlc_object_t *p_this, bool b_verbose)
 {
-    module_t *p_parser;
-
     bool b_color = var_InheritBool( p_this, "color" );
 
     ShowConsole();
-#ifdef WIN32
+#ifdef _WIN32
     b_color = false; // don't put color control codes in a .txt file
 #else
     if( !isatty( 1 ) )
@@ -737,11 +714,13 @@ static void ListModules (vlc_object_t *p_this, bool b_verbose)
 #endif
 
     /* List all modules */
-    module_t **list = module_list_get (NULL);
+    size_t count;
+    module_t **list = module_list_get (&count);
 
     /* Enumerate each module */
-    for (size_t j = 0; (p_parser = list[j]) != NULL; j++)
+    for (size_t j = 0; j < count; j++)
     {
+        module_t *p_parser = list[j];
         const char *objname = module_get_object (p_parser);
         if( b_color )
             utf8_fprintf( stdout, GREEN"  %-22s "WHITE"%s\n"GRAY, objname,
@@ -799,7 +778,7 @@ static void Version( void )
     PauseConsole();
 }
 
-#if defined (WIN32) && !defined (UNDER_CE)
+#if defined( _WIN32 ) && !VLC_WINSTORE_APP
 /*****************************************************************************
  * ShowConsole: On Win32, create an output console for debug messages
  *****************************************************************************
@@ -811,12 +790,13 @@ static void ShowConsole( void )
 
     if( getenv( "PWD" ) ) return; /* Cygwin shell or Wine */
 
-    AllocConsole();
+    if( !AllocConsole() ) return;
+
     /* Use the ANSI code page (e.g. Windows-1252) as expected by the LibVLC
      * Unicode/locale subsystem. By default, we have the obsolecent OEM code
      * page (e.g. CP437 or CP850). */
     SetConsoleOutputCP (GetACP ());
-    SetConsoleTitle ("VLC media player version "PACKAGE_VERSION);
+    SetConsoleTitle (TEXT("VLC media player version "PACKAGE_VERSION));
 
     freopen( "CONOUT$", "w", stderr );
     freopen( "CONIN$", "r", stdin );
@@ -856,7 +836,7 @@ static int ConsoleWidth( void )
 {
     unsigned i_width = 80;
 
-#ifndef WIN32
+#ifndef _WIN32
     FILE *file = popen( "stty size 2>/dev/null", "r" );
     if (file != NULL)
     {
@@ -864,7 +844,7 @@ static int ConsoleWidth( void )
             i_width = 80;
         pclose( file );
     }
-#elif !defined (UNDER_CE)
+#elif !VLC_WINSTORE_APP
     CONSOLE_SCREEN_BUFFER_INFO buf;
 
     if (GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &buf))