X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fconfig%2Fcmdline.c;h=264f84ed2f9670e21e734439c44b84aeb67b1ad1;hb=4ab00885f95809f3065340a69d3f87fe4d9b56b0;hp=acb96b3749c045304acbacf57d6f5a184b5241b5;hpb=93d9a388cab3b40a5361df3b779cbc5ff6e25140;p=vlc diff --git a/src/config/cmdline.c b/src/config/cmdline.c index acb96b3749..264f84ed2f 100644 --- a/src/config/cmdline.c +++ b/src/config/cmdline.c @@ -25,9 +25,10 @@ # include "config.h" #endif -#include +#include #include "../libvlc.h" -#include "vlc_keys.h" +#include +#include #ifdef HAVE_GETOPT_LONG # ifdef HAVE_GETOPT_H @@ -40,6 +41,8 @@ #include "configuration.h" #include "modules/modules.h" +#include + /***************************************************************************** * config_LoadCmdLine: parse command line ***************************************************************************** @@ -55,9 +58,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, { int i_cmd, i_index, i_opts, i_shortopts, flag, i_verbose = 0; module_t *p_parser; - vlc_list_t *p_list; struct option *p_longopts; - int i_modules_index; const char **argv_copy = NULL; /* Short options */ @@ -83,29 +84,23 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, #endif /* List all modules */ - p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); + module_t **list = module_list_get (NULL); /* * Generate the longopts and shortopts structures used by getopt_long */ i_opts = 0; - for( i_modules_index = 0; i_modules_index < p_list->i_count; - i_modules_index++ ) - { - p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ; - + for (size_t i = 0; (p_parser = list[i]) != NULL; i++) /* count the number of exported configuration options (to allocate * longopts). We also need to allocate space for two options when * dealing with boolean to allow for --foo and --no-foo */ - i_opts += p_parser->i_config_items - + 2 * p_parser->i_bool_items; - } + i_opts += p_parser->i_config_items + 2 * p_parser->i_bool_items; p_longopts = malloc( sizeof(struct option) * (i_opts + 1) ); if( p_longopts == NULL ) { - vlc_list_release( p_list ); + module_list_free (list); return -1; } @@ -113,7 +108,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, if( psz_shortopts == NULL ) { free( p_longopts ); - vlc_list_release( p_list ); + module_list_free (list); return -1; } @@ -127,7 +122,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, { free( psz_shortopts ); free( p_longopts ); - vlc_list_release( p_list ); + module_list_free (list); return -1; } memcpy( argv_copy, ppsz_argv, *pi_argc * sizeof(char *) ); @@ -142,11 +137,9 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, /* Fill the p_longopts and psz_shortopts structures */ i_index = 0; - for( i_modules_index = 0; i_modules_index < p_list->i_count; - i_modules_index++ ) + for (size_t i = 0; (p_parser = list[i]) != NULL; i++) { module_config_t *p_item, *p_end; - p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ; if( !p_parser->i_config_items ) continue; @@ -163,8 +156,14 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, p_longopts[i_index].name = strdup( p_item->psz_name ); if( p_longopts[i_index].name == NULL ) continue; p_longopts[i_index].has_arg = - (p_item->i_type == CONFIG_ITEM_BOOL)? - no_argument : required_argument; + (p_item->i_type == CONFIG_ITEM_BOOL) ? no_argument : +#ifndef __APPLE__ + required_argument; +#else +/* It seems that required_argument is broken on Darwin. + * Radar ticket #6113829 */ + optional_argument; +#endif p_longopts[i_index].flag = &flag; p_longopts[i_index].val = 0; i_index++; @@ -218,7 +217,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, } /* We don't need the module list anymore */ - vlc_list_release( p_list ); + module_list_free( list ); /* Close the longopts and shortopts structures */ memset( &p_longopts[i_index], 0, sizeof(struct option) ); @@ -274,7 +273,14 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, psz_name = p_conf->psz_name; } - +#ifdef __APPLE__ + if( p_conf->i_type != CONFIG_ITEM_BOOL && !optarg ) + { + fprintf( stderr, "Warning: missing argument for option --%s\n", p_conf->psz_name ); + fprintf( stderr, "Try specifying options as '--optionname=value' instead of '--optionname value'\n" ); + continue; + } +#endif switch( p_conf->i_type ) { case CONFIG_ITEM_STRING: @@ -291,7 +297,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, config_PutInt( p_this, psz_name, strtol(optarg, 0, 0)); break; case CONFIG_ITEM_FLOAT: - config_PutFloat( p_this, psz_name, (float)atof(optarg) ); + config_PutFloat( p_this, psz_name, us_atof(optarg) ); break; case CONFIG_ITEM_KEY: config_PutInt( p_this, psz_name, ConfigStringToKey( optarg ) ); @@ -362,9 +368,8 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, /* Internal error: unknown option */ if( !b_ignore_errors ) { - fprintf( stderr, "%s: unknown option" - " or missing mandatory argument ", - p_this->p_libvlc->psz_object_name ); + fputs( "vlc: unknown option" + " or missing mandatory argument ", stderr ); if( optopt ) { fprintf( stderr, "`-%c'\n", optopt ); @@ -373,8 +378,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, { fprintf( stderr, "`%s'\n", ppsz_argv[optind-1] ); } - fprintf( stderr, "Try `%s --help' for more information.\n", - p_this->p_libvlc->psz_object_name ); + fputs( "Try `vlc --help' for more information.\n", stderr ); for( i_index = 0; p_longopts[i_index].name; i_index++ ) free( (char *)p_longopts[i_index].name );