1 /*****************************************************************************
2 * configuration.c management of the modules configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2004 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include <stdio.h> /* sprintf() */
29 #include <stdlib.h> /* free(), strtol() */
30 #include <string.h> /* strdup() */
31 #include <errno.h> /* errno */
38 # include <unistd.h> /* getuid() */
41 #ifdef HAVE_GETOPT_LONG
43 # include <getopt.h> /* getopt() */
46 # include "../extras/getopt.h"
49 #if defined(HAVE_GETPWUID)
50 # include <pwd.h> /* getpwuid() */
53 #if defined( HAVE_SYS_STAT_H )
54 # include <sys/stat.h>
56 #if defined( HAVE_SYS_TYPES_H )
57 # include <sys/types.h>
60 # if !defined( UNDER_CE )
66 static int ConfigStringToKey( const char * );
67 static char *ConfigKeyToString( int );
69 static inline void freenull (const void *p)
75 static inline char *strdupnull (const char *src)
82 static inline char *_strdupnull (const char *src)
86 return strdup (_(src));
90 /*****************************************************************************
91 * config_GetType: get the type of a variable (bool, int, float, string)
92 *****************************************************************************
93 * This function is used to get the type of a variable from its name.
94 * Beware, this is quite slow.
95 *****************************************************************************/
96 int __config_GetType( vlc_object_t *p_this, const char *psz_name )
98 module_config_t *p_config;
101 p_config = config_FindConfig( p_this, psz_name );
109 switch( p_config->i_type )
111 case CONFIG_ITEM_BOOL:
112 i_type = VLC_VAR_BOOL;
115 case CONFIG_ITEM_INTEGER:
116 i_type = VLC_VAR_INTEGER;
119 case CONFIG_ITEM_FLOAT:
120 i_type = VLC_VAR_FLOAT;
123 case CONFIG_ITEM_MODULE:
124 case CONFIG_ITEM_MODULE_CAT:
125 case CONFIG_ITEM_MODULE_LIST:
126 case CONFIG_ITEM_MODULE_LIST_CAT:
127 i_type = VLC_VAR_MODULE;
130 case CONFIG_ITEM_STRING:
131 i_type = VLC_VAR_STRING;
134 case CONFIG_ITEM_FILE:
135 i_type = VLC_VAR_FILE;
138 case CONFIG_ITEM_DIRECTORY:
139 i_type = VLC_VAR_DIRECTORY;
150 /*****************************************************************************
151 * config_GetInt: get the value of an int variable
152 *****************************************************************************
153 * This function is used to get the value of variables which are internally
154 * represented by an integer (CONFIG_ITEM_INTEGER and
156 *****************************************************************************/
157 int __config_GetInt( vlc_object_t *p_this, const char *psz_name )
159 module_config_t *p_config;
161 p_config = config_FindConfig( p_this, psz_name );
166 msg_Err( p_this, "option %s does not exist", psz_name );
170 if (!IsConfigIntegerType (p_config->i_type))
172 msg_Err( p_this, "option %s does not refer to an int", psz_name );
176 return p_config->value.i;
179 /*****************************************************************************
180 * config_GetFloat: get the value of a float variable
181 *****************************************************************************
182 * This function is used to get the value of variables which are internally
183 * represented by a float (CONFIG_ITEM_FLOAT).
184 *****************************************************************************/
185 float __config_GetFloat( vlc_object_t *p_this, const char *psz_name )
187 module_config_t *p_config;
189 p_config = config_FindConfig( p_this, psz_name );
194 msg_Err( p_this, "option %s does not exist", psz_name );
198 if (!IsConfigFloatType (p_config->i_type))
200 msg_Err( p_this, "option %s does not refer to a float", psz_name );
204 return p_config->value.f;
207 /*****************************************************************************
208 * config_GetPsz: get the string value of a string variable
209 *****************************************************************************
210 * This function is used to get the value of variables which are internally
211 * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
212 * CONFIG_ITEM_DIRECTORY, and CONFIG_ITEM_MODULE).
214 * Important note: remember to free() the returned char* because it's a
215 * duplicate of the actual value. It isn't safe to return a pointer to the
216 * actual value as it can be modified at any time.
217 *****************************************************************************/
218 char * __config_GetPsz( vlc_object_t *p_this, const char *psz_name )
220 module_config_t *p_config;
222 p_config = config_FindConfig( p_this, psz_name );
227 msg_Err( p_this, "option %s does not exist", psz_name );
231 if (!IsConfigStringType (p_config->i_type))
233 msg_Err( p_this, "option %s does not refer to a string", psz_name );
237 /* return a copy of the string */
238 vlc_mutex_lock( p_config->p_lock );
239 char *psz_value = strdupnull (p_config->value.psz);
240 vlc_mutex_unlock( p_config->p_lock );
245 /*****************************************************************************
246 * config_PutPsz: set the string value of a string variable
247 *****************************************************************************
248 * This function is used to set the value of variables which are internally
249 * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
250 * CONFIG_ITEM_DIRECTORY, and CONFIG_ITEM_MODULE).
251 *****************************************************************************/
252 void __config_PutPsz( vlc_object_t *p_this,
253 const char *psz_name, const char *psz_value )
255 module_config_t *p_config;
256 vlc_value_t oldval, val;
258 p_config = config_FindConfig( p_this, psz_name );
264 msg_Warn( p_this, "option %s does not exist", psz_name );
268 if (!IsConfigStringType (p_config->i_type))
270 msg_Err( p_this, "option %s does not refer to a string", psz_name );
274 vlc_mutex_lock( p_config->p_lock );
276 /* backup old value */
277 oldval.psz_string = (char *)p_config->value.psz;
279 if ((psz_value != NULL) && *psz_value)
280 p_config->value.psz = strdup (psz_value);
282 p_config->value.psz = NULL;
284 p_config->b_dirty = VLC_TRUE;
286 val.psz_string = (char *)p_config->value.psz;
288 vlc_mutex_unlock( p_config->p_lock );
290 if( p_config->pf_callback )
292 p_config->pf_callback( p_this, psz_name, oldval, val,
293 p_config->p_callback_data );
296 /* free old string */
297 if( oldval.psz_string ) free( oldval.psz_string );
300 /*****************************************************************************
301 * config_PutInt: set the integer value of an int variable
302 *****************************************************************************
303 * This function is used to set the value of variables which are internally
304 * represented by an integer (CONFIG_ITEM_INTEGER and
306 *****************************************************************************/
307 void __config_PutInt( vlc_object_t *p_this, const char *psz_name, int i_value )
309 module_config_t *p_config;
310 vlc_value_t oldval, val;
312 p_config = config_FindConfig( p_this, psz_name );
317 msg_Warn( p_this, "option %s does not exist", psz_name );
321 if (!IsConfigIntegerType (p_config->i_type))
323 msg_Err( p_this, "option %s does not refer to an int", psz_name );
327 /* backup old value */
328 oldval.i_int = p_config->value.i;
330 /* if i_min == i_max == 0, then do not use them */
331 if ((p_config->min.i == 0) && (p_config->max.i == 0))
333 p_config->value.i = i_value;
335 else if (i_value < p_config->min.i)
337 p_config->value.i = p_config->min.i;
339 else if (i_value > p_config->max.i)
341 p_config->value.i = p_config->max.i;
345 p_config->value.i = i_value;
348 p_config->b_dirty = VLC_TRUE;
350 val.i_int = p_config->value.i;
352 if( p_config->pf_callback )
354 p_config->pf_callback( p_this, psz_name, oldval, val,
355 p_config->p_callback_data );
359 /*****************************************************************************
360 * config_PutFloat: set the value of a float variable
361 *****************************************************************************
362 * This function is used to set the value of variables which are internally
363 * represented by a float (CONFIG_ITEM_FLOAT).
364 *****************************************************************************/
365 void __config_PutFloat( vlc_object_t *p_this,
366 const char *psz_name, float f_value )
368 module_config_t *p_config;
369 vlc_value_t oldval, val;
371 p_config = config_FindConfig( p_this, psz_name );
376 msg_Warn( p_this, "option %s does not exist", psz_name );
380 if (!IsConfigFloatType (p_config->i_type))
382 msg_Err( p_this, "option %s does not refer to a float", psz_name );
386 /* backup old value */
387 oldval.f_float = p_config->value.f;
389 /* if f_min == f_max == 0, then do not use them */
390 if ((p_config->min.f == 0) && (p_config->max.f == 0))
392 p_config->value.f = f_value;
394 else if (f_value < p_config->min.f)
396 p_config->value.f = p_config->min.f;
398 else if (f_value > p_config->max.f)
400 p_config->value.f = p_config->max.f;
404 p_config->value.f = f_value;
407 p_config->b_dirty = VLC_TRUE;
409 val.f_float = p_config->value.f;
411 if( p_config->pf_callback )
413 p_config->pf_callback( p_this, psz_name, oldval, val,
414 p_config->p_callback_data );
418 /*****************************************************************************
419 * config_FindConfig: find the config structure associated with an option.
420 *****************************************************************************
421 * FIXME: This function really needs to be optimized.
422 * FIXME: And now even more.
423 *****************************************************************************/
424 module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name )
429 if( !psz_name ) return NULL;
431 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
433 for( i_index = 0; i_index < p_list->i_count; i_index++ )
435 module_config_t *p_item, *p_end;
436 module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object;
438 if( !p_parser->i_config_items )
441 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
445 if( p_item->i_type & CONFIG_HINT )
448 if( !strcmp( psz_name, p_item->psz_name ) )
450 vlc_list_release( p_list );
456 vlc_list_release( p_list );
461 /*****************************************************************************
462 * config_FindModule: find a specific module structure.
463 *****************************************************************************/
464 module_t *config_FindModule( vlc_object_t *p_this, const char *psz_name )
467 module_t *p_module, *p_result = NULL;
470 if( !psz_name ) return NULL;
472 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
474 for( i_index = 0; i_index < p_list->i_count; i_index++ )
476 p_module = (module_t *)p_list->p_values[i_index].p_object;
477 if( !strcmp( p_module->psz_object_name, psz_name ) )
484 vlc_list_release( p_list );
489 /*****************************************************************************
490 * config_Duplicate: creates a duplicate of a module's configuration data.
491 *****************************************************************************
492 * Unfortunatly we cannot work directly with the module's config data as
493 * this module might be unloaded from memory at any time (remember HideModule).
494 * This is why we need to create an exact copy of the config data.
495 *****************************************************************************/
496 int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
500 const module_config_t *p_item, *p_end = p_orig + n;
502 /* Calculate the structure length */
503 p_module->i_config_items = 0;
504 p_module->i_bool_items = 0;
506 for( p_item = p_orig; p_item < p_end; p_item++ )
508 if( p_item->i_type & CONFIG_ITEM )
510 p_module->i_config_items++;
513 if( p_item->i_type == CONFIG_ITEM_BOOL )
515 p_module->i_bool_items++;
519 /* Allocate memory */
520 p_module->p_config = (module_config_t *)calloc( n, sizeof(*p_orig) );
521 if( p_module->p_config == NULL )
523 msg_Err( p_module, "config error: can't duplicate p_config" );
526 p_module->confsize = n;
528 /* Do the duplication job */
529 for( size_t i = 0; i < n ; i++ )
531 p_module->p_config[i] = p_orig[i];
533 if (IsConfigIntegerType (p_module->p_config[i].i_type))
535 p_module->p_config[i].orig.i = p_orig[i].value.i;
536 p_module->p_config[i].saved.i = p_orig[i].value.i;
539 if (IsConfigFloatType (p_module->p_config[i].i_type))
541 p_module->p_config[i].orig.f = p_orig[i].value.f;
542 p_module->p_config[i].saved.f = p_orig[i].value.f;
545 if (IsConfigStringType (p_module->p_config[i].i_type))
547 p_module->p_config[i].value.psz = strdupnull (p_orig[i].value.psz);
548 p_module->p_config[i].orig.psz = strdupnull (p_orig[i].value.psz);
549 p_module->p_config[i].saved.psz = NULL;
552 p_module->p_config[i].psz_type = strdupnull (p_orig[i].psz_type);
553 p_module->p_config[i].psz_name = strdupnull (p_orig[i].psz_name);
554 p_module->p_config[i].psz_current = strdupnull (p_orig[i].psz_current);
555 p_module->p_config[i].psz_text = _strdupnull (p_orig[i].psz_text);
556 p_module->p_config[i].psz_longtext = _strdupnull (p_orig[i].psz_longtext);
558 p_module->p_config[i].p_lock = &p_module->object_lock;
560 /* duplicate the string list */
561 if( p_orig[i].i_list )
563 if( p_orig[i].ppsz_list )
565 p_module->p_config[i].ppsz_list =
566 malloc( (p_orig[i].i_list + 1) * sizeof(char *) );
567 if( p_module->p_config[i].ppsz_list )
569 for( j = 0; j < p_orig[i].i_list; j++ )
570 p_module->p_config[i].ppsz_list[j] =
571 strdupnull (p_orig[i].ppsz_list[j]);
572 p_module->p_config[i].ppsz_list[j] = NULL;
575 if( p_orig[i].ppsz_list_text )
577 p_module->p_config[i].ppsz_list_text =
578 calloc( (p_orig[i].i_list + 1), sizeof(char *) );
579 if( p_module->p_config[i].ppsz_list_text )
581 for( j = 0; j < p_orig[i].i_list; j++ )
582 p_module->p_config[i].ppsz_list_text[j] =
583 strdupnull (_(p_orig[i].ppsz_list_text[j]));
584 p_module->p_config[i].ppsz_list_text[j] = NULL;
587 if( p_orig[i].pi_list )
589 p_module->p_config[i].pi_list =
590 malloc( (p_orig[i].i_list + 1) * sizeof(int) );
591 if( p_module->p_config[i].pi_list )
593 for( j = 0; j < p_orig[i].i_list; j++ )
594 p_module->p_config[i].pi_list[j] =
595 p_orig[i].pi_list[j];
600 /* duplicate the actions list */
601 if( p_orig[i].i_action )
605 p_module->p_config[i].ppf_action =
606 malloc( p_orig[i].i_action * sizeof(void *) );
607 p_module->p_config[i].ppsz_action_text =
608 malloc( p_orig[i].i_action * sizeof(char *) );
610 for( j = 0; j < p_orig[i].i_action; j++ )
612 p_module->p_config[i].ppf_action[j] =
613 p_orig[i].ppf_action[j];
614 p_module->p_config[i].ppsz_action_text[j] =
615 strdupnull (p_orig[i].ppsz_action_text[j]);
619 p_module->p_config[i].pf_callback = p_orig[i].pf_callback;
625 /*****************************************************************************
626 * config_Free: frees a duplicated module's configuration data.
627 *****************************************************************************
628 * This function frees all the data duplicated by config_Duplicate.
629 *****************************************************************************/
630 void config_Free( module_t *p_module )
634 for (size_t j = 0; j < p_module->confsize; j++)
636 module_config_t *p_item = p_module->p_config + j;
638 if( p_item->psz_type )
639 free( p_item->psz_type );
641 if( p_item->psz_name )
642 free( p_item->psz_name );
644 if( p_item->psz_current )
645 free( p_item->psz_current );
647 if( p_item->psz_text )
648 free( p_item->psz_text );
650 if( p_item->psz_longtext )
651 free( p_item->psz_longtext );
653 if (IsConfigStringType (p_item->i_type))
655 freenull (p_item->value.psz);
656 freenull (p_item->orig.psz);
657 freenull (p_item->saved.psz);
662 for( i = 0; i < p_item->i_list; i++ )
664 if( p_item->ppsz_list && p_item->ppsz_list[i] )
665 free( p_item->ppsz_list[i] );
666 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i] )
667 free( p_item->ppsz_list_text[i] );
669 if( p_item->ppsz_list ) free( p_item->ppsz_list );
670 if( p_item->ppsz_list_text ) free( p_item->ppsz_list_text );
671 if( p_item->pi_list ) free( p_item->pi_list );
674 if( p_item->i_action )
676 for( i = 0; i < p_item->i_action; i++ )
678 if( p_item->ppsz_action_text[i] )
679 free( p_item->ppsz_action_text[i] );
681 if( p_item->ppf_action ) free( p_item->ppf_action );
682 if( p_item->ppsz_action_text ) free( p_item->ppsz_action_text );
686 if (p_module->p_config != NULL)
688 free (p_module->p_config);
689 p_module->p_config = NULL;
693 /*****************************************************************************
694 * config_SetCallbacks: sets callback functions in the duplicate p_config.
695 *****************************************************************************
696 * Unfortunatly we cannot work directly with the module's config data as
697 * this module might be unloaded from memory at any time (remember HideModule).
698 * This is why we need to duplicate callbacks each time we reload the module.
699 *****************************************************************************/
700 void config_SetCallbacks( module_config_t *p_new, module_config_t *p_orig,
703 for (size_t i = 0; i < n; i++)
705 p_new->pf_callback = p_orig->pf_callback;
711 /*****************************************************************************
712 * config_UnsetCallbacks: unsets callback functions in the duplicate p_config.
713 *****************************************************************************
714 * We simply undo what we did in config_SetCallbacks.
715 *****************************************************************************/
716 void config_UnsetCallbacks( module_config_t *p_new, size_t n )
718 for (size_t i = 0; i < n; i++)
720 p_new->pf_callback = NULL;
725 /*****************************************************************************
726 * config_ResetAll: reset the configuration data for all the modules.
727 *****************************************************************************/
728 void __config_ResetAll( vlc_object_t *p_this )
734 /* Acquire config file lock */
735 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
737 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
739 for( i_index = 0; i_index < p_list->i_count; i_index++ )
741 p_module = (module_t *)p_list->p_values[i_index].p_object ;
742 if( p_module->b_submodule ) continue;
744 for (size_t i = 0; i < p_module->confsize; i++ )
746 if (IsConfigIntegerType (p_module->p_config[i].i_type))
747 p_module->p_config[i].value.i = p_module->p_config[i].orig.i;
749 if (IsConfigFloatType (p_module->p_config[i].i_type))
750 p_module->p_config[i].value.f = p_module->p_config[i].orig.f;
752 if (IsConfigStringType (p_module->p_config[i].i_type))
754 freenull (p_module->p_config[i].value.psz);
755 p_module->p_config[i].value.psz =
756 strdupnull (p_module->p_config[i].orig.psz);
761 vlc_list_release( p_list );
762 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
766 static FILE *config_OpenConfigFile (vlc_object_t *obj, const char *mode)
768 static const char subpath[] = DIR_SEP CONFIG_DIR DIR_SEP CONFIG_FILE;
769 const char *filename = obj->p_libvlc->psz_configfile;
773 if (filename == NULL)
775 homedir = obj->p_libvlc->psz_homedir;
778 msg_Err (obj, "no home directory defined");
782 buflen = strlen (homedir) + sizeof (subpath);
786 if (filename == NULL)
788 sprintf (buf, "%s%s", homedir, subpath);
792 msg_Dbg (obj, "opening config file (%s)", filename);
793 FILE *stream = utf8_fopen (filename, mode);
794 if ((stream == NULL) && (errno != ENOENT))
795 msg_Err (obj, "cannot open config file (%s): %s", strerror (errno));
801 /*****************************************************************************
802 * config_LoadConfigFile: loads the configuration file.
803 *****************************************************************************
804 * This function is called to load the config options stored in the config
806 *****************************************************************************/
807 int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
814 file = config_OpenConfigFile (p_this, "rt");
818 /* Acquire config file lock */
819 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
821 /* Look for the selected module, if NULL then save everything */
822 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
824 for( i_index = 0; i_index < p_list->i_count; i_index++ )
826 module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object ;
830 && strcmp( psz_module_name, p_parser->psz_object_name ) )
835 /* The config file is organized in sections, one per module. Look for
836 * the interesting section ( a section is of the form [foo] ) */
837 fseek( file, 0L, SEEK_SET );
839 /* Look for UTF-8 Byte Order Mark */
840 char * (*convert) (const char *) = FromLocaleDup;
843 if ((fread (bom, 1, 3, file) == 3)
844 && (memcmp (bom, "\xEF\xBB\xBF", 3) == 0))
845 convert = strdupnull;
847 rewind (file); // no BOM, rewind
849 while( fgets( line, 1024, file ) )
852 && (p_index = strchr(line,']'))
853 && (p_index - &line[1]
854 == (int)strlen(p_parser->psz_object_name))
855 && !memcmp( &line[1], p_parser->psz_object_name,
856 strlen(p_parser->psz_object_name) ) )
859 msg_Dbg( p_this, "loading config for module \"%s\"",
860 p_parser->psz_object_name );
866 /* either we found the section or we're at the EOF */
868 /* Now try to load the options in this section */
869 while( fgets( line, 1024, file ) )
871 const char *psz_option_name, *psz_option_value;
872 module_config_t *p_item, *p_end;
874 if( line[0] == '[' ) break; /* end of section */
876 /* ignore comments or empty lines */
877 if( (line[0] == '#') || (line[0] == '\n') || (line[0] == (char)0) )
880 /* get rid of line feed */
881 if( line[strlen(line)-1] == '\n' )
882 line[strlen(line)-1] = (char)0;
884 /* look for option name */
885 psz_option_name = line;
886 psz_option_value = NULL;
887 p_index = strchr( line, '=' );
888 if( !p_index ) break; /* this ain't an option!!! */
891 psz_option_value = p_index + 1;
893 if( !p_parser->i_config_items )
898 /* try to match this option with one of the module's options */
899 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
903 if( p_item->i_type & CONFIG_HINT )
907 if( !strcmp( p_item->psz_name, psz_option_name ) )
910 switch( p_item->i_type )
912 case CONFIG_ITEM_BOOL:
913 case CONFIG_ITEM_INTEGER:
914 if( !*psz_option_value )
915 break; /* ignore empty option */
916 p_item->value.i = strtol( psz_option_value, 0, 0 );
917 p_item->saved.i = p_item->value.i;
919 msg_Dbg( p_this, "option \"%s\", value %i",
920 p_item->psz_name, p_item->i_value );
924 case CONFIG_ITEM_FLOAT:
925 if( !*psz_option_value )
926 break; /* ignore empty option */
927 p_item->value.f = (float)i18n_atof( psz_option_value);
928 p_item->saved.f = p_item->value.f;
930 msg_Dbg( p_this, "option \"%s\", value %f",
931 p_item->psz_name, (double)p_item->f_value );
934 case CONFIG_ITEM_KEY:
935 if( !*psz_option_value )
936 break; /* ignore empty option */
937 p_item->value.i = ConfigStringToKey(psz_option_value);
938 p_item->saved.i = p_item->value.i;
942 vlc_mutex_lock( p_item->p_lock );
944 /* free old string */
945 freenull (p_item->value.psz);
947 p_item->value.psz = convert (psz_option_value);
949 freenull (p_item->saved.psz);
950 p_item->saved.psz = NULL;
952 if( !p_item->value.psz || !p_item->orig.psz ||
953 (p_item->value.psz && p_item->orig.psz &&
954 strcmp(p_item->value.psz, p_item->orig.psz)))
955 p_item->saved.psz = convert (p_item->value.psz);
957 vlc_mutex_unlock( p_item->p_lock );
960 msg_Dbg( p_this, "option \"%s\", value \"%s\"",
962 p_item->psz_value ? p_item->psz_value : "" );
972 vlc_list_release( p_list );
976 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
980 /*****************************************************************************
981 * config_CreateDir: Create configuration directory if it doesn't exist.
982 *****************************************************************************/
983 int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname )
985 if( !psz_dirname && !*psz_dirname ) return -1;
987 if( utf8_mkdir( psz_dirname ) && ( errno != EEXIST ) )
989 msg_Err( p_this, "could not create %s (%s)",
990 psz_dirname, strerror(errno) );
997 /*****************************************************************************
998 * config_SaveConfigFile: Save a module's config options.
999 *****************************************************************************
1000 * This will save the specified module's config options to the config file.
1001 * If psz_module_name is NULL then we save all the modules config options.
1002 * It's no use to save the config options that kept their default values, so
1003 * we'll try to be a bit clever here.
1005 * When we save we mustn't delete the config options of the modules that
1006 * haven't been loaded. So we cannot just create a new config file with the
1007 * config structures we've got in memory.
1008 * I don't really know how to deal with this nicely, so I will use a completly
1010 * I will load the config file in memory, but skipping all the sections of the
1011 * modules we want to save. Then I will create a brand new file, dump the file
1012 * loaded in memory and then append the sections of the modules we want to
1014 * Really stupid no ?
1015 *****************************************************************************/
1016 static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
1017 vlc_bool_t b_autosave )
1022 char p_line[1024], *p_index2;
1024 char *p_bigbuffer, *p_index;
1025 vlc_bool_t b_backup;
1028 /* Acquire config file lock */
1029 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
1031 if (p_this->p_libvlc->psz_configfile == NULL)
1033 const char *psz_homedir = p_this->p_libvlc->psz_homedir;
1036 msg_Err( p_this, "no home directory defined" );
1037 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1041 char dirname[strlen (psz_homedir) + sizeof (DIR_SEP CONFIG_DIR)];
1042 sprintf (dirname, "%s" DIR_SEP CONFIG_DIR, psz_homedir);
1043 config_CreateDir (p_this, dirname);
1046 file = config_OpenConfigFile (p_this, "rt");
1049 /* look for file size */
1050 fseek( file, 0L, SEEK_END );
1051 i_sizebuf = ftell( file );
1052 fseek( file, 0L, SEEK_SET );
1055 p_bigbuffer = p_index = malloc( i_sizebuf+1 );
1058 msg_Err( p_this, "out of memory" );
1059 if( file ) fclose( file );
1060 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1065 /* List all available modules */
1066 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1068 /* backup file into memory, we only need to backup the sections we won't
1071 while( file && fgets( p_line, 1024, file ) )
1073 if( (p_line[0] == '[') && (p_index2 = strchr(p_line,']')))
1076 /* we found a section, check if we need to do a backup */
1077 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1079 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1081 if( ((p_index2 - &p_line[1])
1082 == (int)strlen(p_parser->psz_object_name) )
1083 && !memcmp( &p_line[1], p_parser->psz_object_name,
1084 strlen(p_parser->psz_object_name) ) )
1086 if( !psz_module_name )
1088 else if( !strcmp( psz_module_name,
1089 p_parser->psz_object_name ) )
1094 if( i_index == p_list->i_count )
1096 /* we don't have this section in our list so we need to back
1100 msg_Dbg( p_this, "backing up config for unknown module \"%s\"",
1113 /* save line if requested and line is valid (doesn't begin with a
1114 * space, tab, or eol) */
1115 if( b_backup && (p_line[0] != '\n') && (p_line[0] != ' ')
1116 && (p_line[0] != '\t') )
1118 strcpy( p_index, p_line );
1119 p_index += strlen( p_line );
1122 if( file ) fclose( file );
1126 * Save module config in file
1129 file = config_OpenConfigFile (p_this, "wt");
1132 vlc_list_release( p_list );
1133 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1137 fprintf( file, "\xEF\xBB\xBF###\n### " COPYRIGHT_MESSAGE "\n###\n\n"
1138 "###\n### lines begining with a '#' character are comments\n###\n\n" );
1140 /* Look for the selected module, if NULL then save everything */
1141 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1143 module_config_t *p_item, *p_end;
1144 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1146 if( psz_module_name && strcmp( psz_module_name,
1147 p_parser->psz_object_name ) )
1150 if( !p_parser->i_config_items )
1153 if( psz_module_name )
1154 msg_Dbg( p_this, "saving config for module \"%s\"",
1155 p_parser->psz_object_name );
1157 fprintf( file, "[%s]", p_parser->psz_object_name );
1158 if( p_parser->psz_longname )
1159 fprintf( file, " # %s\n\n", p_parser->psz_longname );
1161 fprintf( file, "\n\n" );
1163 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
1168 int i_value = p_item->value.i;
1169 float f_value = p_item->value.f;
1170 const char *psz_value = p_item->value.psz;
1172 if( p_item->i_type & CONFIG_HINT )
1175 /* Ignore deprecated options */
1176 if( p_item->psz_current )
1178 if( p_item->b_unsaveable )
1182 if( b_autosave && !p_item->b_autosave )
1184 i_value = p_item->saved.i;
1185 f_value = p_item->saved.f;
1186 psz_value = p_item->saved.psz;
1187 if( !psz_value ) psz_value = p_item->orig.psz;
1191 p_item->b_dirty = VLC_FALSE;
1194 switch( p_item->i_type )
1196 case CONFIG_ITEM_BOOL:
1197 case CONFIG_ITEM_INTEGER:
1198 if( p_item->psz_text )
1199 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1200 (p_item->i_type == CONFIG_ITEM_BOOL) ?
1201 _("boolean") : _("integer") );
1202 if( i_value == p_item->orig.i )
1204 fprintf( file, "%s=%i\n", p_item->psz_name, i_value );
1206 p_item->saved.i = i_value;
1209 case CONFIG_ITEM_KEY:
1210 if( p_item->psz_text )
1211 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1213 if( i_value == p_item->orig.i )
1215 psz_key = ConfigKeyToString( i_value );
1216 fprintf( file, "%s=%s\n", p_item->psz_name,
1217 psz_key ? psz_key : "" );
1220 p_item->saved.i = i_value;
1223 case CONFIG_ITEM_FLOAT:
1224 if( p_item->psz_text )
1225 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1227 if( f_value == p_item->orig.f )
1229 fprintf( file, "%s=%f\n", p_item->psz_name, (double)f_value );
1231 p_item->saved.f = f_value;
1235 if( p_item->psz_text )
1236 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1238 if( (!psz_value && !p_item->orig.psz) ||
1239 (psz_value && p_item->orig.psz &&
1240 !strcmp( psz_value, p_item->orig.psz )) )
1242 fprintf( file, "%s=%s\n", p_item->psz_name,
1245 if( b_autosave && !p_item->b_autosave ) break;
1247 freenull (p_item->saved.psz);
1248 if( (psz_value && p_item->orig.psz &&
1249 strcmp( psz_value, p_item->orig.psz )) ||
1250 !psz_value || !p_item->orig.psz)
1251 p_item->saved.psz = strdupnull (psz_value);
1253 p_item->saved.psz = NULL;
1260 vlc_list_release( p_list );
1263 * Restore old settings from the config in file
1265 fputs( p_bigbuffer, file );
1266 free( p_bigbuffer );
1269 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1274 int config_AutoSaveConfigFile( vlc_object_t *p_this )
1277 int i_index, i_count;
1279 /* Check if there's anything to save */
1280 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
1281 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1282 i_count = p_list->i_count;
1283 for( i_index = 0; i_index < i_count; i_index++ )
1285 module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1286 module_config_t *p_item, *p_end;
1288 if( !p_parser->i_config_items ) continue;
1290 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
1294 if( p_item->b_autosave && p_item->b_dirty ) break;
1298 vlc_list_release( p_list );
1299 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1301 if( i_index == i_count ) return VLC_SUCCESS;
1302 return SaveConfigFile( p_this, 0, VLC_TRUE );
1305 int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
1307 return SaveConfigFile( p_this, psz_module_name, VLC_FALSE );
1310 /*****************************************************************************
1311 * config_LoadCmdLine: parse command line
1312 *****************************************************************************
1313 * Parse command line for configuration options.
1314 * Now that the module_bank has been initialized, we can dynamically
1315 * generate the longopts structure used by getops. We have to do it this way
1316 * because we don't know (and don't want to know) in advance the configuration
1317 * options used (ie. exported) by each module.
1318 *****************************************************************************/
1319 int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
1320 vlc_bool_t b_ignore_errors )
1322 int i_cmd, i_index, i_opts, i_shortopts, flag, i_verbose = 0;
1325 struct option *p_longopts;
1326 int i_modules_index;
1329 module_config_t *pp_shortopts[256];
1330 char *psz_shortopts;
1332 /* Set default configuration and copy arguments */
1333 p_this->p_libvlc->i_argc = *pi_argc;
1334 p_this->p_libvlc->ppsz_argv = ppsz_argv;
1337 /* When VLC.app is run by double clicking in Mac OS X, the 2nd arg
1338 * is the PSN - process serial number (a unique PID-ish thingie)
1339 * still ok for real Darwin & when run from command line */
1340 if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
1341 /* for example -psn_0_9306113 */
1343 /* GDMF!... I can't do this or else the MacOSX window server will
1344 * not pick up the PSN and not register the app and we crash...
1345 * hence the following kludge otherwise we'll get confused w/ argv[1]
1346 * being an input file name */
1348 ppsz_argv[ 1 ] = NULL;
1350 *pi_argc = *pi_argc - 1;
1356 /* List all modules */
1357 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1360 * Generate the longopts and shortopts structures used by getopt_long
1364 for( i_modules_index = 0; i_modules_index < p_list->i_count;
1367 p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ;
1369 /* count the number of exported configuration options (to allocate
1370 * longopts). We also need to allocate space for two options when
1371 * dealing with boolean to allow for --foo and --no-foo */
1372 i_opts += p_parser->i_config_items
1373 + 2 * p_parser->i_bool_items;
1376 p_longopts = malloc( sizeof(struct option) * (i_opts + 1) );
1377 if( p_longopts == NULL )
1379 msg_Err( p_this, "out of memory" );
1380 vlc_list_release( p_list );
1384 psz_shortopts = malloc( sizeof( char ) * (2 * i_opts + 1) );
1385 if( psz_shortopts == NULL )
1387 msg_Err( p_this, "out of memory" );
1389 vlc_list_release( p_list );
1393 /* If we are requested to ignore errors, then we must work on a copy
1394 * of the ppsz_argv array, otherwise getopt_long will reorder it for
1395 * us, ignoring the arity of the options */
1396 if( b_ignore_errors )
1398 ppsz_argv = (char**)malloc( *pi_argc * sizeof(char *) );
1399 if( ppsz_argv == NULL )
1401 msg_Err( p_this, "out of memory" );
1402 free( psz_shortopts );
1404 vlc_list_release( p_list );
1407 memcpy( ppsz_argv, p_this->p_libvlc->ppsz_argv,
1408 *pi_argc * sizeof(char *) );
1412 for( i_index = 0; i_index < 256; i_index++ )
1414 pp_shortopts[i_index] = NULL;
1417 /* Fill the p_longopts and psz_shortopts structures */
1419 for( i_modules_index = 0; i_modules_index < p_list->i_count;
1422 module_config_t *p_item, *p_end;
1423 p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ;
1425 if( !p_parser->i_config_items )
1428 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
1433 if( p_item->i_type & CONFIG_HINT )
1436 /* Add item to long options */
1437 p_longopts[i_index].name = strdup( p_item->psz_name );
1438 if( p_longopts[i_index].name == NULL ) continue;
1439 p_longopts[i_index].has_arg =
1440 (p_item->i_type == CONFIG_ITEM_BOOL)?
1441 no_argument : required_argument;
1442 p_longopts[i_index].flag = &flag;
1443 p_longopts[i_index].val = 0;
1446 /* When dealing with bools we also need to add the --no-foo
1448 if( p_item->i_type == CONFIG_ITEM_BOOL )
1450 char *psz_name = malloc( strlen(p_item->psz_name) + 3 );
1451 if( psz_name == NULL ) continue;
1452 strcpy( psz_name, "no" );
1453 strcat( psz_name, p_item->psz_name );
1455 p_longopts[i_index].name = psz_name;
1456 p_longopts[i_index].has_arg = no_argument;
1457 p_longopts[i_index].flag = &flag;
1458 p_longopts[i_index].val = 1;
1461 psz_name = malloc( strlen(p_item->psz_name) + 4 );
1462 if( psz_name == NULL ) continue;
1463 strcpy( psz_name, "no-" );
1464 strcat( psz_name, p_item->psz_name );
1466 p_longopts[i_index].name = psz_name;
1467 p_longopts[i_index].has_arg = no_argument;
1468 p_longopts[i_index].flag = &flag;
1469 p_longopts[i_index].val = 1;
1473 /* If item also has a short option, add it */
1474 if( p_item->i_short )
1476 pp_shortopts[(int)p_item->i_short] = p_item;
1477 psz_shortopts[i_shortopts] = p_item->i_short;
1479 if( p_item->i_type != CONFIG_ITEM_BOOL )
1481 psz_shortopts[i_shortopts] = ':';
1484 if( p_item->i_short == 'v' )
1486 psz_shortopts[i_shortopts] = ':';
1494 /* We don't need the module list anymore */
1495 vlc_list_release( p_list );
1497 /* Close the longopts and shortopts structures */
1498 memset( &p_longopts[i_index], 0, sizeof(struct option) );
1499 psz_shortopts[i_shortopts] = '\0';
1502 * Parse the command line options
1506 while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv, psz_shortopts,
1507 p_longopts, &i_index ) ) != EOF )
1509 /* A long option has been recognized */
1512 module_config_t *p_conf;
1513 char *psz_name = (char *)p_longopts[i_index].name;
1515 /* Check if we deal with a --nofoo or --no-foo long option */
1516 if( flag ) psz_name += psz_name[2] == '-' ? 3 : 2;
1518 /* Store the configuration option */
1519 p_conf = config_FindConfig( p_this, psz_name );
1522 /* Check if the option is deprecated */
1523 if( p_conf->psz_current )
1525 if( !strcmp(p_conf->psz_current,"SUPPRESSED") )
1527 if( !b_ignore_errors )
1530 "Warning: option --%s is no longer used.\n",
1535 if( !b_ignore_errors )
1537 if( p_conf->b_strict )
1540 "Error: option --%s is deprecated. "
1541 "Use --%s instead.\n",
1542 p_conf->psz_name, p_conf->psz_current);
1544 for( i_index = 0; p_longopts[i_index].name; i_index++ )
1545 free( (char *)p_longopts[i_index].name );
1548 free( psz_shortopts );
1552 "Warning: option --%s is deprecated. "
1553 "You should use --%s instead.\n",
1554 p_conf->psz_name, p_conf->psz_current);
1556 psz_name=p_conf->psz_current;
1557 p_conf = config_FindConfig( p_this, psz_name );
1560 switch( p_conf->i_type )
1562 case CONFIG_ITEM_STRING:
1563 case CONFIG_ITEM_FILE:
1564 case CONFIG_ITEM_DIRECTORY:
1565 case CONFIG_ITEM_MODULE:
1566 case CONFIG_ITEM_MODULE_LIST:
1567 case CONFIG_ITEM_MODULE_LIST_CAT:
1568 case CONFIG_ITEM_MODULE_CAT:
1569 config_PutPsz( p_this, psz_name, optarg );
1571 case CONFIG_ITEM_INTEGER:
1572 config_PutInt( p_this, psz_name, strtol(optarg, 0, 0));
1574 case CONFIG_ITEM_FLOAT:
1575 config_PutFloat( p_this, psz_name, (float)atof(optarg) );
1577 case CONFIG_ITEM_KEY:
1578 config_PutInt( p_this, psz_name, ConfigStringToKey( optarg ) );
1580 case CONFIG_ITEM_BOOL:
1581 config_PutInt( p_this, psz_name, !flag );
1588 /* A short option has been recognized */
1589 if( pp_shortopts[i_cmd] != NULL )
1591 switch( pp_shortopts[i_cmd]->i_type )
1593 case CONFIG_ITEM_STRING:
1594 case CONFIG_ITEM_FILE:
1595 case CONFIG_ITEM_DIRECTORY:
1596 case CONFIG_ITEM_MODULE:
1597 case CONFIG_ITEM_MODULE_CAT:
1598 case CONFIG_ITEM_MODULE_LIST:
1599 case CONFIG_ITEM_MODULE_LIST_CAT:
1600 config_PutPsz( p_this, pp_shortopts[i_cmd]->psz_name, optarg );
1602 case CONFIG_ITEM_INTEGER:
1607 if( *optarg == 'v' ) /* eg. -vvv */
1610 while( *optarg == 'v' )
1618 i_verbose += atoi( optarg ); /* eg. -v2 */
1623 i_verbose++; /* -v */
1625 config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name,
1630 config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name,
1631 strtol(optarg, 0, 0) );
1634 case CONFIG_ITEM_BOOL:
1635 config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name, 1 );
1642 /* Internal error: unknown option */
1643 if( !b_ignore_errors )
1645 fprintf( stderr, "%s: unknown option"
1646 " or missing mandatory argument ",
1647 p_this->p_libvlc->psz_object_name );
1650 fprintf( stderr, "`-%c'\n", optopt );
1654 fprintf( stderr, "`%s'\n", ppsz_argv[optind-1] );
1656 fprintf( stderr, "Try `%s --help' for more information.\n",
1657 p_this->p_libvlc->psz_object_name );
1659 for( i_index = 0; p_longopts[i_index].name; i_index++ )
1660 free( (char *)p_longopts[i_index].name );
1662 free( psz_shortopts );
1667 /* Free allocated resources */
1668 for( i_index = 0; p_longopts[i_index].name; i_index++ )
1669 free( (char *)p_longopts[i_index].name );
1671 free( psz_shortopts );
1672 if( b_ignore_errors ) free( ppsz_argv );
1678 * config_GetDataDir: find directory where shared data is installed
1680 * @return a string (always succeeds).
1682 const char *config_GetDataDir( const vlc_object_t *p_this )
1684 #if defined (WIN32) || defined (UNDER_CE)
1685 return p_this->p_libvlc_global->psz_vlcpath;
1686 #elif defined(__APPLE__) || defined (SYS_BEOS)
1687 static char path[PATH_MAX] = "";
1691 snprintf( path, sizeof( path ), "%s/share",
1692 p_this->p_libvlc_global->psz_vlcpath );
1693 path[sizeof( path ) - 1] = '\0';
1701 /*****************************************************************************
1702 * config_GetHomeDir, config_GetUserDir: find the user's home directory.
1703 *****************************************************************************
1704 * This function will try by different ways to find the user's home path.
1705 * Note that this function is not reentrant, it should be called only once
1706 * at the beginning of main where the result will be stored for later use.
1707 *****************************************************************************/
1708 static char *GetDir( vlc_bool_t b_appdata )
1710 const char *psz_localhome = NULL;
1712 #if defined(HAVE_GETPWUID)
1713 struct passwd *p_pw = NULL;
1716 #if defined(WIN32) && !defined(UNDER_CE)
1717 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
1719 #ifndef CSIDL_FLAG_CREATE
1720 # define CSIDL_FLAG_CREATE 0x8000
1722 #ifndef CSIDL_APPDATA
1723 # define CSIDL_APPDATA 0x1A
1725 #ifndef CSIDL_PROFILE
1726 # define CSIDL_PROFILE 0x28
1728 #ifndef SHGFP_TYPE_CURRENT
1729 # define SHGFP_TYPE_CURRENT 0
1732 HINSTANCE shfolder_dll;
1733 SHGETFOLDERPATH SHGetFolderPath ;
1735 /* load the shfolder dll to retrieve SHGetFolderPath */
1736 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
1738 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
1739 _T("SHGetFolderPathW") );
1740 if ( SHGetFolderPath != NULL )
1742 wchar_t whomedir[MAX_PATH];
1744 /* get the "Application Data" folder for the current user */
1745 if( S_OK == SHGetFolderPath( NULL,
1746 (b_appdata ? CSIDL_APPDATA :
1747 CSIDL_PROFILE) | CSIDL_FLAG_CREATE,
1748 NULL, SHGFP_TYPE_CURRENT,
1751 FreeLibrary( shfolder_dll );
1752 return FromWide( whomedir );
1755 FreeLibrary( shfolder_dll );
1758 #elif defined(UNDER_CE)
1760 #ifndef CSIDL_APPDATA
1761 # define CSIDL_APPDATA 0x1A
1764 wchar_t whomedir[MAX_PATH];
1766 /* get the "Application Data" folder for the current user */
1767 if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) )
1768 return FromWide( whomedir );
1771 #if defined(HAVE_GETPWUID)
1772 if( ( p_pw = getpwuid( getuid() ) ) == NULL )
1775 psz_localhome = getenv( "HOME" );
1776 if( psz_localhome == NULL )
1778 psz_localhome = getenv( "TMP" );
1779 if( psz_localhome == NULL )
1780 psz_localhome = "/tmp";
1783 #if defined(HAVE_GETPWUID)
1785 psz_localhome = p_pw->pw_dir;
1788 return FromLocaleDup( psz_localhome );
1791 char *config_GetHomeDir( void )
1793 return GetDir( VLC_TRUE );
1796 char *config_GetUserDir( void )
1798 return GetDir( VLC_FALSE );
1802 static int ConfigStringToKey( const char *psz_key )
1806 const char *psz_parser = strchr( psz_key, '-' );
1807 while( psz_parser && psz_parser != psz_key )
1809 for( i = 0; i < sizeof(vlc_modifiers) / sizeof(key_descriptor_t); i++ )
1811 if( !strncasecmp( vlc_modifiers[i].psz_key_string, psz_key,
1812 strlen( vlc_modifiers[i].psz_key_string ) ) )
1814 i_key |= vlc_modifiers[i].i_key_code;
1817 psz_key = psz_parser + 1;
1818 psz_parser = strchr( psz_key, '-' );
1820 for( i = 0; i < sizeof(vlc_keys) / sizeof( key_descriptor_t ); i++ )
1822 if( !strcasecmp( vlc_keys[i].psz_key_string, psz_key ) )
1824 i_key |= vlc_keys[i].i_key_code;
1831 static char *ConfigKeyToString( int i_key )
1833 char *psz_key = malloc( 100 );
1843 for( index = 0; index < (sizeof(vlc_modifiers) / sizeof(key_descriptor_t));
1846 if( i_key & vlc_modifiers[index].i_key_code )
1848 p += sprintf( p, "%s-", vlc_modifiers[index].psz_key_string );
1851 for( index = 0; index < (sizeof(vlc_keys) / sizeof( key_descriptor_t));
1854 if( (int)( i_key & ~KEY_MODIFIER ) == vlc_keys[index].i_key_code )
1856 p += sprintf( p, "%s", vlc_keys[index].psz_key_string );