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