Commit ec32355f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Define CONFIG_CLASS() macro and use it

parent 64f81867
......@@ -139,38 +139,35 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
/* Add item to long options */
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);
p_longopts[i_index].flag = &flag;
p_longopts[i_index].val = 0;
i_index++;
/* When dealing with bools we also need to add the --no-foo
* option */
if( p_item->i_type == CONFIG_ITEM_BOOL )
if( CONFIG_CLASS(p_item->i_type) != CONFIG_ITEM_BOOL )
p_longopts[i_index].has_arg = true;
else
/* Booleans also need --no-foo and --nofoo options */
{
char *psz_name = malloc( strlen(p_item->psz_name) + 3 );
if( psz_name == NULL ) continue;
strcpy( psz_name, "no" );
strcat( psz_name, p_item->psz_name );
char *psz_name;
p_longopts[i_index].has_arg = false;
i_index++;
if( asprintf( &psz_name, "no%s", p_item->psz_name ) == -1 )
continue;
p_longopts[i_index].name = psz_name;
p_longopts[i_index].has_arg = false;
p_longopts[i_index].flag = &flag;
p_longopts[i_index].val = 1;
i_index++;
psz_name = malloc( strlen(p_item->psz_name) + 4 );
if( psz_name == NULL ) continue;
strcpy( psz_name, "no-" );
strcat( psz_name, p_item->psz_name );
if( asprintf( &psz_name, "no-%s", p_item->psz_name ) == -1 )
continue;
p_longopts[i_index].name = psz_name;
p_longopts[i_index].has_arg = false;
p_longopts[i_index].flag = &flag;
p_longopts[i_index].val = 1;
i_index++;
}
i_index++;
/* If item also has a short option, add it */
if( p_item->i_short )
......@@ -242,23 +239,13 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
psz_name = p_conf->psz_name;
}
switch( p_conf->i_type )
switch( CONFIG_CLASS(p_conf->i_type) )
{
case CONFIG_ITEM_STRING:
case CONFIG_ITEM_PASSWORD:
case CONFIG_ITEM_LOADFILE:
case CONFIG_ITEM_SAVEFILE:
case CONFIG_ITEM_DIRECTORY:
case CONFIG_ITEM_KEY:
case CONFIG_ITEM_MODULE:
case CONFIG_ITEM_MODULE_LIST:
case CONFIG_ITEM_MODULE_LIST_CAT:
case CONFIG_ITEM_MODULE_CAT:
var_Create( p_this, psz_name, VLC_VAR_STRING );
var_SetString( p_this, psz_name, state.arg );
break;
case CONFIG_ITEM_INTEGER:
case CONFIG_ITEM_RGB:
var_Create( p_this, psz_name, VLC_VAR_INTEGER );
var_SetInteger( p_this, psz_name,
strtoll(state.arg, NULL, 0));
......@@ -280,17 +267,9 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
if( pp_shortopts[i_cmd] != NULL )
{
const char *name = pp_shortopts[i_cmd]->psz_name;
switch( pp_shortopts[i_cmd]->i_type )
switch( CONFIG_CLASS(pp_shortopts[i_cmd]->i_type) )
{
case CONFIG_ITEM_STRING:
case CONFIG_ITEM_PASSWORD:
case CONFIG_ITEM_LOADFILE:
case CONFIG_ITEM_SAVEFILE:
case CONFIG_ITEM_DIRECTORY:
case CONFIG_ITEM_MODULE:
case CONFIG_ITEM_MODULE_CAT:
case CONFIG_ITEM_MODULE_LIST:
case CONFIG_ITEM_MODULE_LIST_CAT:
var_Create( p_this, name, VLC_VAR_STRING );
var_SetString( p_this, name, state.arg );
break;
......
......@@ -42,6 +42,8 @@ void config_UnsortConfig (void);
char *config_GetDataDirDefault( void );
#define CONFIG_CLASS(x) ((x) & ~0x1F)
static inline bool IsConfigStringType(unsigned type)
{
return (type & CONFIG_ITEM_STRING) != 0;
......
......@@ -63,7 +63,7 @@ int config_GetType( vlc_object_t *p_this, const char *psz_name )
return 0;
}
switch( p_config->i_type & ~0x1F )
switch( CONFIG_CLASS(p_config->i_type) )
{
case CONFIG_ITEM_FLOAT:
i_type = VLC_VAR_FLOAT;
......
......@@ -213,7 +213,7 @@ int config_LoadConfigFile( vlc_object_t *p_this )
continue;
const char *psz_option_value = ptr + 1;
switch (item->i_type)
switch (CONFIG_CLASS(item->i_type))
{
case CONFIG_ITEM_BOOL:
case CONFIG_ITEM_INTEGER:
......@@ -521,7 +521,7 @@ static int SaveConfigFile (vlc_object_t *p_this)
{
int64_t val = p_item->value.i;
config_Write (file, p_item->psz_text,
(p_item->i_type == CONFIG_ITEM_BOOL)
(CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL)
? N_("boolean") : N_("integer"),
val == p_item->orig.i,
p_item->psz_name, "%"PRId64, val);
......
......@@ -1482,48 +1482,43 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
continue;
}
switch( p_item->i_type )
switch( CONFIG_CLASS(p_item->i_type) )
{
case CONFIG_HINT_CATEGORY:
case CONFIG_HINT_USAGE:
if( !strcmp( "main", p_parser->psz_object_name ) )
case 0: // hint class
switch( p_item->i_type )
{
if( b_color )
utf8_fprintf( stdout, GREEN "\n %s\n" GRAY,
module_gettext( p_parser, p_item->psz_text ) );
else
utf8_fprintf( stdout, "\n %s\n",
module_gettext( p_parser, p_item->psz_text ) );
}
if( b_description && p_item->psz_longtext )
{
if( b_color )
utf8_fprintf( stdout, CYAN " %s\n" GRAY,
module_gettext( p_parser, p_item->psz_longtext ) );
else
utf8_fprintf( stdout, " %s\n",
module_gettext( p_parser, p_item->psz_longtext ) );
case CONFIG_HINT_CATEGORY:
case CONFIG_HINT_USAGE:
if( !strcmp( "main", p_parser->psz_object_name ) )
{
if( b_color )
utf8_fprintf( stdout, GREEN "\n %s\n" GRAY,
module_gettext( p_parser, p_item->psz_text ) );
else
utf8_fprintf( stdout, "\n %s\n",
module_gettext( p_parser, p_item->psz_text ) );
}
if( b_description && p_item->psz_longtext )
{
if( b_color )
utf8_fprintf( stdout, CYAN " %s\n" GRAY,
module_gettext( p_parser, p_item->psz_longtext ) );
else
utf8_fprintf( stdout, " %s\n",
module_gettext( p_parser, p_item->psz_longtext ) );
}
break;
case CONFIG_HINT_SUBCATEGORY:
if( strcmp( "main", p_parser->psz_object_name ) )
case CONFIG_HINT_SUBCATEGORY:
if( strcmp( "main", p_parser->psz_object_name ) )
break;
case CONFIG_SECTION:
p_section = p_item;
break;
case CONFIG_SECTION:
p_section = p_item;
}
break;
case CONFIG_ITEM_STRING:
case CONFIG_ITEM_LOADFILE:
case CONFIG_ITEM_SAVEFILE:
case CONFIG_ITEM_DIRECTORY:
case CONFIG_ITEM_KEY:
case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
case CONFIG_ITEM_MODULE_CAT:
case CONFIG_ITEM_MODULE_LIST:
case CONFIG_ITEM_MODULE_LIST_CAT:
case CONFIG_ITEM_FONT:
case CONFIG_ITEM_PASSWORD:
print_help_section( p_parser, p_section, b_color,
b_description );
p_section = NULL;
......@@ -1545,7 +1540,6 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
}
break;
case CONFIG_ITEM_INTEGER:
case CONFIG_ITEM_RGB:
print_help_section( p_parser, p_section, b_color,
b_description );
p_section = NULL;
......@@ -1621,7 +1615,8 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
- strlen( psz_bra ) - strlen( psz_type )
- strlen( psz_ket ) - 1;
if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
if( CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL
&& !b_help_module )
{
psz_prefix = ", --no-";
i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
......@@ -1637,7 +1632,8 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
psz_spaces[i] = '\0';
}
if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
if( CONFIG_CLASS(p_item->i_type) == CONFIG_ITEM_BOOL
&& !b_help_module )
{
utf8_fprintf( stdout, psz_format_bool, psz_short,
p_item->psz_name, psz_prefix, p_item->psz_name,
......
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