Commit 497e82b1 authored by Sam Hocevar's avatar Sam Hocevar

  * ./src/misc/configuration.c: support for short options. -V, -A, -I
    are back, and we also have -4 and -6 for IPv4/IPv6.
parent ce25f1e8
......@@ -4,7 +4,7 @@
* It includes functions allowing to declare, get or set configuration options.
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: configuration.h,v 1.6 2002/04/21 11:23:03 gbazin Exp $
* $Id: configuration.h,v 1.7 2002/04/21 18:32:12 sam Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
......@@ -47,16 +47,17 @@
typedef struct module_config_s
{
int i_type; /* Configuration type */
int i_type; /* Configuration type */
char *psz_name; /* Option name */
char i_short; /* Optional short option name */
char *psz_text; /* Short comment on the configuration option */
char *psz_longtext; /* Long comment on the configuration option */
char *psz_value; /* Option value */
int i_value; /* Option value */
float f_value; /* Option value */
int i_value; /* Option value */
float f_value; /* Option value */
void *p_callback; /* Function to call when commiting a change */
vlc_mutex_t *p_lock; /* lock to use when modifying the config */
boolean_t b_dirty; /* Dirty flag to indicate a config change */
boolean_t b_dirty; /* Dirty flag to indicate a config change */
} module_config_t;
......@@ -109,32 +110,53 @@ int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
static module_config_t p_config[] = {
#define MODULE_CONFIG_STOP \
{ MODULE_CONFIG_HINT_END, NULL, NULL, NULL, NULL, 0, 0, NULL, 0 } };
{ MODULE_CONFIG_HINT_END, NULL, '\0', NULL, NULL, NULL, 0, 0, NULL, 0 } };
#define ADD_CATEGORY_HINT( text, longtext ) \
{ MODULE_CONFIG_HINT_CATEGORY, NULL, text, longtext, NULL, 0, 0, NULL, \
NULL, 0 },
{ MODULE_CONFIG_HINT_CATEGORY, NULL, '\0', text, longtext, NULL, 0, 0, \
NULL, NULL, 0 },
#define ADD_SUBCATEGORY_HINT( text, longtext ) \
{ MODULE_CONFIG_HINT_SUBCATEGORY, NULL, text, longtext, NULL, 0, 0, NULL, \
NULL, 0 },
{ MODULE_CONFIG_HINT_SUBCATEGORY, NULL, '\0', text, longtext, NULL, 0, 0, \
NULL, NULL, 0 },
#define END_SUBCATEGORY_HINT \
{ MODULE_CONFIG_HINT_SUBCATEGORY_END, NULL, NULL, NULL, NULL, 0, 0, NULL, \
NULL, 0 },
{ MODULE_CONFIG_HINT_SUBCATEGORY_END, NULL, '\0', NULL, NULL, NULL, 0, 0, \
NULL, NULL, 0 },
#define ADD_STRING( name, value, p_callback, text, longtext ) \
{ MODULE_CONFIG_ITEM_STRING, name, text, longtext, value, 0, 0, \
{ MODULE_CONFIG_ITEM_STRING, name, '\0', text, longtext, value, 0, 0, \
p_callback, NULL, 0 },
#define ADD_FILE( name, psz_value, p_callback, text, longtext ) \
{ MODULE_CONFIG_ITEM_FILE, name, text, longtext, psz_value, 0, 0, \
{ MODULE_CONFIG_ITEM_FILE, name, '\0', text, longtext, psz_value, 0, 0, \
p_callback, NULL, 0 },
#define ADD_PLUGIN( name, i_capability, psz_value, p_callback, text, longtext)\
{ MODULE_CONFIG_ITEM_PLUGIN, name, text, longtext, psz_value, \
{ MODULE_CONFIG_ITEM_PLUGIN, name, '\0', text, longtext, psz_value, \
i_capability, 0, p_callback, NULL, 0 },
#define ADD_INTEGER( name, i_value, p_callback, text, longtext ) \
{ MODULE_CONFIG_ITEM_INTEGER, name, text, longtext, NULL, i_value, 0, \
p_callback, NULL, 0 },
{ MODULE_CONFIG_ITEM_INTEGER, name, '\0', text, longtext, NULL, i_value, \
0, p_callback, NULL, 0 },
#define ADD_FLOAT( name, f_value, p_callback, text, longtext ) \
{ MODULE_CONFIG_ITEM_FLOAT, name, text, longtext, NULL, 0, f_value, \
{ MODULE_CONFIG_ITEM_FLOAT, name, '\0', text, longtext, NULL, 0, f_value, \
p_callback, NULL, 0 },
#define ADD_BOOL( name, p_callback, text, longtext ) \
{ MODULE_CONFIG_ITEM_BOOL, name, text, longtext, NULL, 0, 0, p_callback, \
NULL, 0 },
{ MODULE_CONFIG_ITEM_BOOL, name, '\0', text, longtext, NULL, 0, 0, \
p_callback, NULL, 0 },
#define ADD_STRING_WITH_SHORT( name, ch, value, p_callback, text, longtext ) \
{ MODULE_CONFIG_ITEM_STRING, name, ch, text, longtext, value, 0, 0, \
p_callback, NULL, 0 },
#define ADD_FILE_WITH_SHORT( name, ch, psz_value, p_callback, text, longtext ) \
{ MODULE_CONFIG_ITEM_FILE, name, ch, text, longtext, psz_value, 0, 0, \
p_callback, NULL, 0 },
#define ADD_PLUGIN_WITH_SHORT( name, ch, i_capability, psz_value, p_callback, \
text, longtext) \
{ MODULE_CONFIG_ITEM_PLUGIN, name, ch, text, longtext, psz_value, \
i_capability, 0, p_callback, NULL, 0 },
#define ADD_INTEGER_WITH_SHORT( name, ch, i_value, p_callback, text, \
longtext ) \
{ MODULE_CONFIG_ITEM_INTEGER, name, ch, text, longtext, NULL, i_value, 0, \
p_callback, NULL, 0 },
#define ADD_FLOAT_WITH_SHORT( name, f_value, p_callback, text, longtext ) \
{ MODULE_CONFIG_ITEM_FLOAT, name, ch, text, longtext, NULL, 0, f_value, \
p_callback, NULL, 0 },
#define ADD_BOOL_WITH_SHORT( name, ch, p_callback, text, longtext ) \
{ MODULE_CONFIG_ITEM_BOOL, name, ch, text, longtext, NULL, 0, 0, \
p_callback, NULL, 0 },
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -4,7 +4,7 @@
* and spawn threads.
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
* $Id: main.c,v 1.182 2002/04/21 11:23:03 gbazin Exp $
* $Id: main.c,v 1.183 2002/04/21 18:32:12 sam Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
......@@ -335,15 +335,15 @@
MODULE_CONFIG_START
/* Interface options */
ADD_CATEGORY_HINT( N_("Interface"), NULL )
ADD_PLUGIN ( "intf", MODULE_CAPABILITY_INTF, NULL, NULL, INTF_TEXT, INTF_LONGTEXT )
ADD_CATEGORY_HINT( N_("Interface"), NULL)
ADD_PLUGIN_WITH_SHORT ( "intf", 'I', MODULE_CAPABILITY_INTF, NULL, NULL, INTF_TEXT, INTF_LONGTEXT )
ADD_INTEGER ( "warning", 0, NULL, WARNING_TEXT, WARNING_LONGTEXT )
ADD_BOOL ( "stats", NULL, STATS_TEXT, STATS_LONGTEXT )
ADD_STRING ( "search_path", NULL, NULL, INTF_PATH_TEXT, INTF_PATH_LONGTEXT )
/* Audio options */
ADD_CATEGORY_HINT( N_("Audio"), NULL)
ADD_PLUGIN ( "aout", MODULE_CAPABILITY_AOUT, NULL, NULL, AOUT_TEXT, AOUT_LONGTEXT )
ADD_PLUGIN_WITH_SHORT ( "aout", 'A', MODULE_CAPABILITY_AOUT, NULL, NULL, AOUT_TEXT, AOUT_LONGTEXT )
ADD_BOOL ( "noaudio", NULL, NOAUDIO_TEXT, NOAUDIO_LONGTEXT )
ADD_BOOL ( "mono", NULL, MONO_TEXT, MONO_LONGTEXT )
ADD_INTEGER ( "volume", VOLUME_DEFAULT, NULL, VOLUME_TEXT, VOLUME_LONGTEXT )
......@@ -354,7 +354,7 @@ ADD_INTEGER ( "aout_format", 0, NULL, FORMAT_TEXT,
/* Video options */
ADD_CATEGORY_HINT( N_("Video"), NULL )
ADD_PLUGIN ( "vout", MODULE_CAPABILITY_VOUT, NULL, NULL, VOUT_TEXT, VOUT_LONGTEXT )
ADD_PLUGIN_WITH_SHORT ( "vout", 'V', MODULE_CAPABILITY_VOUT, NULL, NULL, VOUT_TEXT, VOUT_LONGTEXT )
ADD_BOOL ( "novideo", NULL, NOVIDEO_TEXT, NOVIDEO_LONGTEXT )
ADD_INTEGER ( "width", -1, NULL, WIDTH_TEXT, WIDTH_LONGTEXT )
ADD_INTEGER ( "height", -1, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT )
......@@ -396,8 +396,8 @@ ADD_INTEGER ( "sat_lnb_slof", 11700, NULL, SAT_LNB_SLOF_TEXT,
SAT_LNB_SLOF_LONGTEXT )
#endif
ADD_BOOL ( "ipv6", NULL, IPV6_TEXT, IPV6_LONGTEXT )
ADD_BOOL ( "ipv4", NULL, IPV4_TEXT, IPV4_LONGTEXT )
ADD_BOOL_WITH_SHORT ( "ipv6", '6', NULL, IPV6_TEXT, IPV6_LONGTEXT )
ADD_BOOL_WITH_SHORT ( "ipv4", '4', NULL, IPV4_TEXT, IPV4_LONGTEXT )
/* Decoder options */
ADD_CATEGORY_HINT( N_("Decoders"), NULL )
......@@ -443,18 +443,21 @@ MODULE_DEACTIVATE_STOP
/* Hack for help options */
static module_t help_module;
static module_config_t p_help_config[] = {
{ MODULE_CONFIG_ITEM_BOOL, "help", N_("print help (or use -h)"),
NULL, NULL, 0, 0, NULL, NULL, 0 },
{ MODULE_CONFIG_ITEM_BOOL, "longhelp", N_("print detailed help (or use -H)"),
static module_config_t p_help_config[] =
{
{ MODULE_CONFIG_ITEM_BOOL, "help", 'h', N_("print help"),
NULL, NULL, 0, 0, NULL, NULL, 0 },
{ MODULE_CONFIG_ITEM_BOOL, "list", N_("print a list of available plugins "
"(or use -l)"), NULL, NULL, 0, 0, NULL, NULL, 0 },
{ MODULE_CONFIG_ITEM_STRING, "plugin", N_("print help on plugin "
"(or use -p)"), NULL, NULL, 0, 0, NULL, &help_module.config_lock, 0 },
{ MODULE_CONFIG_ITEM_BOOL, "version", N_("print version information"),
{ MODULE_CONFIG_ITEM_BOOL, "longhelp", 'H', N_("print detailed help"),
NULL, NULL, 0, 0, NULL, NULL, 0 },
{ MODULE_CONFIG_HINT_END, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL, 0 } };
{ MODULE_CONFIG_ITEM_BOOL, "list", 'l', N_("print a list of available "
"plugins"), NULL, NULL, 0, 0, NULL, NULL, 0 },
{ MODULE_CONFIG_ITEM_STRING, "plugin", 'p', N_("print help on plugin "
"<string>"), NULL, NULL, 0, 0, NULL, &help_module.config_lock, 0 },
{ MODULE_CONFIG_ITEM_BOOL, "version", '\0',
N_("print version information"), NULL, NULL, 0, 0, NULL, NULL, 0 },
{ MODULE_CONFIG_HINT_END, NULL, '\0', NULL, NULL, NULL, 0, 0,
NULL, NULL, 0 }
};
/*****************************************************************************
* End configuration.
......@@ -921,8 +924,10 @@ static void Usage( const char *psz_module_name )
module_t *p_module;
module_config_t *p_item;
char psz_spaces[30];
char psz_format[sizeof(" --%s%s%s %s")];
memset( psz_spaces, 32, 30 );
memset( psz_spaces, ' ', 30 );
memcpy( psz_format, " --%s%s%s %s", sizeof(psz_format) );
#ifdef WIN32
ShowConsole();
......@@ -933,7 +938,6 @@ static void Usage( const char *psz_module_name )
p_module != NULL ;
p_module = p_module->next )
{
if( psz_module_name && strcmp( psz_module_name, p_module->psz_name ) )
continue;
......@@ -949,6 +953,19 @@ static void Usage( const char *psz_module_name )
{
int i;
if( p_item->i_short )
{
psz_format[2] = '-';
psz_format[3] = p_item->i_short;
psz_format[4] = ',';
}
else
{
psz_format[2] = ' ';
psz_format[3] = ' ';
psz_format[4] = ' ';
}
switch( p_item->i_type )
{
case MODULE_CONFIG_HINT_CATEGORY:
......@@ -964,9 +981,9 @@ static void Usage( const char *psz_module_name )
- strlen(_(" <string>")) - 1;
if( i < 0 ) i = 0; psz_spaces[i] = 0;
intf_Msg( " --%s%s%s %s", p_item->psz_name,
intf_Msg( psz_format, p_item->psz_name,
_(" <string>"), psz_spaces, p_item->psz_text );
psz_spaces[i] = 32;
psz_spaces[i] = ' ';
break;
case MODULE_CONFIG_ITEM_INTEGER:
/* Nasty hack, but right now I'm too tired to think about
......@@ -975,9 +992,9 @@ static void Usage( const char *psz_module_name )
- strlen(_(" <integer>")) - 1;
if( i < 0 ) i = 0; psz_spaces[i] = 0;
intf_Msg( " --%s%s%s %s", p_item->psz_name,
intf_Msg( psz_format, p_item->psz_name,
_(" <integer>"), psz_spaces, p_item->psz_text );
psz_spaces[i] = 32;
psz_spaces[i] = ' ';
break;
case MODULE_CONFIG_ITEM_FLOAT:
/* Nasty hack, but right now I'm too tired to think about
......@@ -986,9 +1003,9 @@ static void Usage( const char *psz_module_name )
- strlen(_(" <float>")) - 1;
if( i < 0 ) i = 0; psz_spaces[i] = 0;
intf_Msg( " --%s%s%s %s", p_item->psz_name,
intf_Msg( psz_format, p_item->psz_name,
_(" <float>"), psz_spaces, p_item->psz_text );
psz_spaces[i] = 32;
psz_spaces[i] = ' ';
break;
case MODULE_CONFIG_ITEM_BOOL:
/* Nasty hack, but right now I'm too tired to think about
......@@ -996,9 +1013,9 @@ static void Usage( const char *psz_module_name )
i = 25 - strlen( p_item->psz_name ) - 1;
if( i < 0 ) i = 0; psz_spaces[i] = 0;
intf_Msg( " --%s%s %s",
p_item->psz_name, psz_spaces, p_item->psz_text );
psz_spaces[i] = 32;
intf_Msg( psz_format,
p_item->psz_name, "", psz_spaces, p_item->psz_text );
psz_spaces[i] = ' ';
break;
}
}
......@@ -1009,18 +1026,18 @@ static void Usage( const char *psz_module_name )
if( !strcmp( "main", p_module->psz_name ) )
{
intf_Msg( _("\nPlaylist items:"
"\n *.mpg, *.vob \tplain MPEG-1/2 files"
"\n *.mpg, *.vob plain MPEG-1/2 files"
"\n [dvd:][device][@raw_device][@[title][,[chapter][,angle]]]"
"\n \tDVD device"
"\n DVD device"
"\n [vcd:][device][@[title][,[chapter]]"
"\n \tVCD device"
"\n VCD device"
"\n udpstream:[@[<bind address>][:<bind port>]]"
"\n \tUDP stream sent by VLS"
"\n vlc:loop \tloop execution of the "
"\n UDP stream sent by VLS"
"\n vlc:loop loop execution of the "
"playlist"
"\n vlc:pause \tpause execution of "
"\n vlc:pause pause execution of "
"playlist items"
"\n vlc:quit \tquit VLC") );
"\n vlc:quit quit VLC") );
}
intf_Msg( "" );
......@@ -1318,7 +1335,7 @@ static u32 CPUCapabilities( void )
i_capabilities |= CPU_CAPABILITY_MMXEXT;
# ifdef CAN_COMPILE_SSE
/* We test if OS support the SSE instructions */
/* We test if OS supports the SSE instructions */
psz_capability = "SSE";
i_illegal = 0;
if( setjmp( env ) == 0 )
......@@ -1418,7 +1435,7 @@ static u32 CPUCapabilities( void )
/*****************************************************************************
* ShowConsole: On Win32, create an output console for debug messages
*****************************************************************************
* This function is usefull only on Win32.
* This function is useful only on Win32.
*****************************************************************************/
#ifdef WIN32 /* */
static void ShowConsole( void )
......
......@@ -2,7 +2,7 @@
* configuration.c management of the modules configuration
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: configuration.c,v 1.16 2002/04/21 11:23:03 gbazin Exp $
* $Id: configuration.c,v 1.17 2002/04/21 18:32:12 sam Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
......@@ -304,6 +304,7 @@ module_config_t *config_Duplicate( module_config_t *p_orig )
for( i = 0; i < i_lines ; i++ )
{
p_config[i].i_type = p_orig[i].i_type;
p_config[i].i_short = p_orig[i].i_short;
p_config[i].i_value = p_orig[i].i_value;
p_config[i].f_value = p_orig[i].f_value;
p_config[i].b_dirty = p_orig[i].b_dirty;
......@@ -725,13 +726,14 @@ int config_SaveConfigFile( const char *psz_module_name )
int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
boolean_t b_ignore_errors )
{
int i_cmd, i_index, i_longopts_size;
int i_cmd, i_index, i_opts, i_shortopts;
module_t *p_module;
module_config_t *p_item;
struct option *p_longopts;
/* Short options */
const char *psz_shortopts = "hHvlp:";
module_config_t *pp_shortopts[256];
char *psz_shortopts;
/* Set default configuration and copy arguments */
p_main->i_argc = *pi_argc;
......@@ -759,28 +761,42 @@ int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
}
#endif
/*
* Generate the longopts structure used by getopt_long
* Generate the longopts and shortopts structure used by getopt_long
*/
i_longopts_size = 0;
i_opts = 0;
for( p_module = p_module_bank->first;
p_module != NULL ;
p_module = p_module->next )
{
/* count the number of exported configuration options (to allocate
* longopts). */
i_longopts_size += p_module->i_config_items;
i_opts += p_module->i_config_items;
}
p_longopts = (struct option *)malloc( sizeof(struct option)
* (i_longopts_size + 1) );
p_longopts = malloc( sizeof(struct option) * (i_opts + 1) );
if( p_longopts == NULL )
{
intf_ErrMsg( "config error: couldn't allocate p_longopts" );
return( -1 );
}
psz_shortopts = malloc( sizeof( char ) * (2 * i_opts + 1) );
if( psz_shortopts == NULL )
{
intf_ErrMsg( "config error: couldn't allocate psz_shortopts" );
free( p_longopts );
return( -1 );
}
psz_shortopts[0] = 'v';
i_shortopts = 1;
for( i_index = 0; i_index < 256; i_index++ )
{
pp_shortopts[i_index] = NULL;
}
/* Fill the longopts structure */
i_index = 0;
for( p_module = p_module_bank->first ;
......@@ -800,12 +816,24 @@ int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
no_argument : required_argument;
p_longopts[i_index].flag = 0;
p_longopts[i_index].val = 0;
if( p_item->i_short )
{
pp_shortopts[(int)p_item->i_short] = p_item;
psz_shortopts[i_shortopts] = p_item->i_short;
i_shortopts++;
if( p_item->i_type != MODULE_CONFIG_ITEM_BOOL )
{
psz_shortopts[i_shortopts] = ':';
i_shortopts++;
}
}
i_index++;
}
}
/* Close the longopts structure */
memset( &p_longopts[i_index], 0, sizeof(struct option) );
/* Close the longopts and shortopts structures */
memset( &p_longopts[i_index], 0, sizeof(struct option) );
psz_shortopts[i_shortopts] = '\0';
/*
* Parse the command line options
......@@ -815,11 +843,9 @@ int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv, psz_shortopts,
p_longopts, &i_index ) ) != EOF )
{
/* A long option has been recognized */
if( i_cmd == 0 )
{
/* A long option has been recognized */
module_config_t *p_conf;
/* Store the configuration option */
......@@ -847,43 +873,47 @@ int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
continue;
}
/* short options handled here for now */
switch( i_cmd )
/* A short option has been recognized */
if( pp_shortopts[i_cmd] != NULL )
{
switch( pp_shortopts[i_cmd]->i_type )
{
case MODULE_CONFIG_ITEM_STRING:
case MODULE_CONFIG_ITEM_FILE:
case MODULE_CONFIG_ITEM_PLUGIN:
config_PutPszVariable( pp_shortopts[i_cmd]->psz_name, optarg );
break;
case MODULE_CONFIG_ITEM_INTEGER:
config_PutIntVariable( pp_shortopts[i_cmd]->psz_name,
atoi(optarg));
break;
case MODULE_CONFIG_ITEM_BOOL:
config_PutIntVariable( pp_shortopts[i_cmd]->psz_name, 1 );
break;
}
continue;
}
/* General/common options */
case 'h': /* -h, --help */
config_PutIntVariable( "help", 1 );
break;
case 'H': /* -H, --longhelp */
config_PutIntVariable( "longhelp", 1 );
break;
case 'l': /* -l, --list */
config_PutIntVariable( "list", 1 );
break;
case 'p': /* -p, --plugin */
config_PutPszVariable( "plugin", optarg );
break;
case 'v': /* -v, --verbose */
/* Either it's a -v or it's an unknown short option */
if( i_cmd == 'v' )
{
p_main->i_warning_level++;
break;
continue;
}
/* Internal error: unknown option */
case '?':
default:
if( !b_ignore_errors )
{
intf_ErrMsg( "config error: unknown option `%s'",
ppsz_argv[optind-1] );
intf_Msg( "Try `%s --help' for more information.\n",
p_main->psz_arg0 );
free( p_longopts );
return( -1 );
}
if( !b_ignore_errors )
{
intf_ErrMsg( "config error: unknown option `%s'",
ppsz_argv[optind-1] );
intf_Msg( "Try `%s --help' for more information.\n",
p_main->psz_arg0 );
free( p_longopts );
free( psz_shortopts );
return( -1 );
}
}
if( p_main->i_warning_level < 0 )
......@@ -892,6 +922,7 @@ int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
}
free( p_longopts );
free( psz_shortopts );
return( 0 );
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment