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 *****************************************************************************/
26 #include "vlc_charset.h"
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 #include "configuration.h"
68 static int ConfigStringToKey( const char * );
69 static char *ConfigKeyToString( int );
71 static inline void freenull (const void *p)
77 static inline char *strdupnull (const char *src)
84 static inline char *_strdupnull (const char *src)
88 return strdup (_(src));
92 /*****************************************************************************
93 * config_GetType: get the type of a variable (bool, int, float, string)
94 *****************************************************************************
95 * This function is used to get the type of a variable from its name.
96 * Beware, this is quite slow.
97 *****************************************************************************/
98 int __config_GetType( vlc_object_t *p_this, const char *psz_name )
100 module_config_t *p_config;
103 p_config = config_FindConfig( p_this, psz_name );
111 switch( p_config->i_type )
113 case CONFIG_ITEM_BOOL:
114 i_type = VLC_VAR_BOOL;
117 case CONFIG_ITEM_INTEGER:
118 i_type = VLC_VAR_INTEGER;
121 case CONFIG_ITEM_FLOAT:
122 i_type = VLC_VAR_FLOAT;
125 case CONFIG_ITEM_MODULE:
126 case CONFIG_ITEM_MODULE_CAT:
127 case CONFIG_ITEM_MODULE_LIST:
128 case CONFIG_ITEM_MODULE_LIST_CAT:
129 i_type = VLC_VAR_MODULE;
132 case CONFIG_ITEM_STRING:
133 i_type = VLC_VAR_STRING;
136 case CONFIG_ITEM_FILE:
137 i_type = VLC_VAR_FILE;
140 case CONFIG_ITEM_DIRECTORY:
141 i_type = VLC_VAR_DIRECTORY;
152 /*****************************************************************************
153 * config_GetInt: get the value of an int variable
154 *****************************************************************************
155 * This function is used to get the value of variables which are internally
156 * represented by an integer (CONFIG_ITEM_INTEGER and
158 *****************************************************************************/
159 int __config_GetInt( vlc_object_t *p_this, const char *psz_name )
161 module_config_t *p_config;
163 p_config = config_FindConfig( p_this, psz_name );
168 msg_Err( p_this, "option %s does not exist", psz_name );
172 if (!IsConfigIntegerType (p_config->i_type))
174 msg_Err( p_this, "option %s does not refer to an int", psz_name );
178 return p_config->value.i;
181 /*****************************************************************************
182 * config_GetFloat: get the value of a float variable
183 *****************************************************************************
184 * This function is used to get the value of variables which are internally
185 * represented by a float (CONFIG_ITEM_FLOAT).
186 *****************************************************************************/
187 float __config_GetFloat( vlc_object_t *p_this, const char *psz_name )
189 module_config_t *p_config;
191 p_config = config_FindConfig( p_this, psz_name );
196 msg_Err( p_this, "option %s does not exist", psz_name );
200 if (!IsConfigFloatType (p_config->i_type))
202 msg_Err( p_this, "option %s does not refer to a float", psz_name );
206 return p_config->value.f;
209 /*****************************************************************************
210 * config_GetPsz: get the string value of a string variable
211 *****************************************************************************
212 * This function is used to get the value of variables which are internally
213 * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
214 * CONFIG_ITEM_DIRECTORY, and CONFIG_ITEM_MODULE).
216 * Important note: remember to free() the returned char* because it's a
217 * duplicate of the actual value. It isn't safe to return a pointer to the
218 * actual value as it can be modified at any time.
219 *****************************************************************************/
220 char * __config_GetPsz( vlc_object_t *p_this, const char *psz_name )
222 module_config_t *p_config;
224 p_config = config_FindConfig( p_this, psz_name );
229 msg_Err( p_this, "option %s does not exist", psz_name );
233 if (!IsConfigStringType (p_config->i_type))
235 msg_Err( p_this, "option %s does not refer to a string", psz_name );
239 /* return a copy of the string */
240 vlc_mutex_lock( p_config->p_lock );
241 char *psz_value = strdupnull (p_config->value.psz);
242 vlc_mutex_unlock( p_config->p_lock );
247 /*****************************************************************************
248 * config_PutPsz: set the string value of a string variable
249 *****************************************************************************
250 * This function is used to set the value of variables which are internally
251 * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
252 * CONFIG_ITEM_DIRECTORY, and CONFIG_ITEM_MODULE).
253 *****************************************************************************/
254 void __config_PutPsz( vlc_object_t *p_this,
255 const char *psz_name, const char *psz_value )
257 module_config_t *p_config;
258 vlc_value_t oldval, val;
260 p_config = config_FindConfig( p_this, psz_name );
266 msg_Warn( p_this, "option %s does not exist", psz_name );
270 if (!IsConfigStringType (p_config->i_type))
272 msg_Err( p_this, "option %s does not refer to a string", psz_name );
276 vlc_mutex_lock( p_config->p_lock );
278 /* backup old value */
279 oldval.psz_string = (char *)p_config->value.psz;
281 if ((psz_value != NULL) && *psz_value)
282 p_config->value.psz = strdup (psz_value);
284 p_config->value.psz = NULL;
286 p_config->b_dirty = VLC_TRUE;
288 val.psz_string = (char *)p_config->value.psz;
290 vlc_mutex_unlock( p_config->p_lock );
292 if( p_config->pf_callback )
294 p_config->pf_callback( p_this, psz_name, oldval, val,
295 p_config->p_callback_data );
298 /* free old string */
299 if( oldval.psz_string ) free( oldval.psz_string );
302 /*****************************************************************************
303 * config_PutInt: set the integer value of an int variable
304 *****************************************************************************
305 * This function is used to set the value of variables which are internally
306 * represented by an integer (CONFIG_ITEM_INTEGER and
308 *****************************************************************************/
309 void __config_PutInt( vlc_object_t *p_this, const char *psz_name, int i_value )
311 module_config_t *p_config;
312 vlc_value_t oldval, val;
314 p_config = config_FindConfig( p_this, psz_name );
319 msg_Warn( p_this, "option %s does not exist", psz_name );
323 if (!IsConfigIntegerType (p_config->i_type))
325 msg_Err( p_this, "option %s does not refer to an int", psz_name );
329 /* backup old value */
330 oldval.i_int = p_config->value.i;
332 /* if i_min == i_max == 0, then do not use them */
333 if ((p_config->min.i == 0) && (p_config->max.i == 0))
335 p_config->value.i = i_value;
337 else if (i_value < p_config->min.i)
339 p_config->value.i = p_config->min.i;
341 else if (i_value > p_config->max.i)
343 p_config->value.i = p_config->max.i;
347 p_config->value.i = i_value;
350 p_config->b_dirty = VLC_TRUE;
352 val.i_int = p_config->value.i;
354 if( p_config->pf_callback )
356 p_config->pf_callback( p_this, psz_name, oldval, val,
357 p_config->p_callback_data );
361 /*****************************************************************************
362 * config_PutFloat: set the value of a float variable
363 *****************************************************************************
364 * This function is used to set the value of variables which are internally
365 * represented by a float (CONFIG_ITEM_FLOAT).
366 *****************************************************************************/
367 void __config_PutFloat( vlc_object_t *p_this,
368 const char *psz_name, float f_value )
370 module_config_t *p_config;
371 vlc_value_t oldval, val;
373 p_config = config_FindConfig( p_this, psz_name );
378 msg_Warn( p_this, "option %s does not exist", psz_name );
382 if (!IsConfigFloatType (p_config->i_type))
384 msg_Err( p_this, "option %s does not refer to a float", psz_name );
388 /* backup old value */
389 oldval.f_float = p_config->value.f;
391 /* if f_min == f_max == 0, then do not use them */
392 if ((p_config->min.f == 0) && (p_config->max.f == 0))
394 p_config->value.f = f_value;
396 else if (f_value < p_config->min.f)
398 p_config->value.f = p_config->min.f;
400 else if (f_value > p_config->max.f)
402 p_config->value.f = p_config->max.f;
406 p_config->value.f = f_value;
409 p_config->b_dirty = VLC_TRUE;
411 val.f_float = p_config->value.f;
413 if( p_config->pf_callback )
415 p_config->pf_callback( p_this, psz_name, oldval, val,
416 p_config->p_callback_data );
420 /*****************************************************************************
421 * config_FindConfig: find the config structure associated with an option.
422 *****************************************************************************
423 * FIXME: This function really needs to be optimized.
424 * FIXME: And now even more.
425 *****************************************************************************/
426 module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name )
431 if( !psz_name ) return NULL;
433 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
435 for( i_index = 0; i_index < p_list->i_count; i_index++ )
437 module_config_t *p_item, *p_end;
438 module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object;
440 if( !p_parser->i_config_items )
443 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
447 if( p_item->i_type & CONFIG_HINT )
450 if( !strcmp( psz_name, p_item->psz_name ) )
452 vlc_list_release( p_list );
458 vlc_list_release( p_list );
463 /*****************************************************************************
464 * config_FindModule: find a specific module structure.
465 *****************************************************************************/
466 module_t *config_FindModule( vlc_object_t *p_this, const char *psz_name )
469 module_t *p_module, *p_result = NULL;
472 if( !psz_name ) return NULL;
474 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
476 for( i_index = 0; i_index < p_list->i_count; i_index++ )
478 p_module = (module_t *)p_list->p_values[i_index].p_object;
479 if( !strcmp( p_module->psz_object_name, psz_name ) )
486 vlc_list_release( p_list );
491 /*****************************************************************************
492 * config_Duplicate: creates a duplicate of a module's configuration data.
493 *****************************************************************************
494 * Unfortunatly we cannot work directly with the module's config data as
495 * this module might be unloaded from memory at any time (remember HideModule).
496 * This is why we need to create an exact copy of the config data.
497 *****************************************************************************/
498 int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
502 const module_config_t *p_item, *p_end = p_orig + n;
504 /* Calculate the structure length */
505 p_module->i_config_items = 0;
506 p_module->i_bool_items = 0;
508 for( p_item = p_orig; p_item < p_end; p_item++ )
510 if( p_item->i_type & CONFIG_ITEM )
512 p_module->i_config_items++;
515 if( p_item->i_type == CONFIG_ITEM_BOOL )
517 p_module->i_bool_items++;
521 /* Allocate memory */
522 p_module->p_config = (module_config_t *)calloc( n, sizeof(*p_orig) );
523 if( p_module->p_config == NULL )
525 msg_Err( p_module, "config error: can't duplicate p_config" );
528 p_module->confsize = n;
530 /* Do the duplication job */
531 for( size_t i = 0; i < n ; i++ )
533 p_module->p_config[i] = p_orig[i];
535 if (IsConfigIntegerType (p_module->p_config[i].i_type))
537 p_module->p_config[i].orig.i = p_orig[i].value.i;
538 p_module->p_config[i].saved.i = p_orig[i].value.i;
541 if (IsConfigFloatType (p_module->p_config[i].i_type))
543 p_module->p_config[i].orig.f = p_orig[i].value.f;
544 p_module->p_config[i].saved.f = p_orig[i].value.f;
547 if (IsConfigStringType (p_module->p_config[i].i_type))
549 p_module->p_config[i].value.psz = strdupnull (p_orig[i].value.psz);
550 p_module->p_config[i].orig.psz = strdupnull (p_orig[i].value.psz);
551 p_module->p_config[i].saved.psz = NULL;
554 p_module->p_config[i].psz_type = strdupnull (p_orig[i].psz_type);
555 p_module->p_config[i].psz_name = strdupnull (p_orig[i].psz_name);
556 p_module->p_config[i].psz_current = strdupnull (p_orig[i].psz_current);
557 p_module->p_config[i].psz_text = _strdupnull (p_orig[i].psz_text);
558 p_module->p_config[i].psz_longtext = _strdupnull (p_orig[i].psz_longtext);
560 p_module->p_config[i].p_lock = &p_module->object_lock;
562 /* duplicate the string list */
563 if( p_orig[i].i_list )
565 if( p_orig[i].ppsz_list )
567 p_module->p_config[i].ppsz_list =
568 malloc( (p_orig[i].i_list + 1) * sizeof(char *) );
569 if( p_module->p_config[i].ppsz_list )
571 for( j = 0; j < p_orig[i].i_list; j++ )
572 p_module->p_config[i].ppsz_list[j] =
573 strdupnull (p_orig[i].ppsz_list[j]);
574 p_module->p_config[i].ppsz_list[j] = NULL;
577 if( p_orig[i].ppsz_list_text )
579 p_module->p_config[i].ppsz_list_text =
580 calloc( (p_orig[i].i_list + 1), sizeof(char *) );
581 if( p_module->p_config[i].ppsz_list_text )
583 for( j = 0; j < p_orig[i].i_list; j++ )
584 p_module->p_config[i].ppsz_list_text[j] =
585 strdupnull (_(p_orig[i].ppsz_list_text[j]));
586 p_module->p_config[i].ppsz_list_text[j] = NULL;
589 if( p_orig[i].pi_list )
591 p_module->p_config[i].pi_list =
592 malloc( (p_orig[i].i_list + 1) * sizeof(int) );
593 if( p_module->p_config[i].pi_list )
595 for( j = 0; j < p_orig[i].i_list; j++ )
596 p_module->p_config[i].pi_list[j] =
597 p_orig[i].pi_list[j];
602 /* duplicate the actions list */
603 if( p_orig[i].i_action )
607 p_module->p_config[i].ppf_action =
608 malloc( p_orig[i].i_action * sizeof(void *) );
609 p_module->p_config[i].ppsz_action_text =
610 malloc( p_orig[i].i_action * sizeof(char *) );
612 for( j = 0; j < p_orig[i].i_action; j++ )
614 p_module->p_config[i].ppf_action[j] =
615 p_orig[i].ppf_action[j];
616 p_module->p_config[i].ppsz_action_text[j] =
617 strdupnull (p_orig[i].ppsz_action_text[j]);
621 p_module->p_config[i].pf_callback = p_orig[i].pf_callback;
627 /*****************************************************************************
628 * config_Free: frees a duplicated module's configuration data.
629 *****************************************************************************
630 * This function frees all the data duplicated by config_Duplicate.
631 *****************************************************************************/
632 void config_Free( module_t *p_module )
636 for (size_t j = 0; j < p_module->confsize; j++)
638 module_config_t *p_item = p_module->p_config + j;
640 free( (char*) p_item->psz_type );
641 free( (char*) p_item->psz_name );
642 free( (char*) p_item->psz_current );
643 free( (char*) p_item->psz_text );
644 free( (char*) p_item->psz_longtext );
646 if (IsConfigStringType (p_item->i_type))
648 freenull (p_item->value.psz);
649 freenull (p_item->orig.psz);
650 freenull (p_item->saved.psz);
655 for( i = 0; i < p_item->i_list; i++ )
657 if( p_item->ppsz_list && p_item->ppsz_list[i] )
658 free( (char*) p_item->ppsz_list[i] );
659 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i] )
660 free( (char*) p_item->ppsz_list_text[i] );
662 if( p_item->ppsz_list ) free( p_item->ppsz_list );
663 if( p_item->ppsz_list_text ) free( p_item->ppsz_list_text );
664 if( p_item->pi_list ) free( p_item->pi_list );
667 if( p_item->i_action )
669 for( i = 0; i < p_item->i_action; i++ )
671 free( (char*) p_item->ppsz_action_text[i] );
673 if( p_item->ppf_action ) free( p_item->ppf_action );
674 if( p_item->ppsz_action_text ) free( p_item->ppsz_action_text );
678 if (p_module->p_config != NULL)
680 free (p_module->p_config);
681 p_module->p_config = NULL;
685 /*****************************************************************************
686 * config_SetCallbacks: sets callback functions in the duplicate p_config.
687 *****************************************************************************
688 * Unfortunatly we cannot work directly with the module's config data as
689 * this module might be unloaded from memory at any time (remember HideModule).
690 * This is why we need to duplicate callbacks each time we reload the module.
691 *****************************************************************************/
692 void config_SetCallbacks( module_config_t *p_new, module_config_t *p_orig,
695 for (size_t i = 0; i < n; i++)
697 p_new->pf_callback = p_orig->pf_callback;
703 /*****************************************************************************
704 * config_UnsetCallbacks: unsets callback functions in the duplicate p_config.
705 *****************************************************************************
706 * We simply undo what we did in config_SetCallbacks.
707 *****************************************************************************/
708 void config_UnsetCallbacks( module_config_t *p_new, size_t n )
710 for (size_t i = 0; i < n; i++)
712 p_new->pf_callback = NULL;
717 /*****************************************************************************
718 * config_ResetAll: reset the configuration data for all the modules.
719 *****************************************************************************/
720 void __config_ResetAll( vlc_object_t *p_this )
726 /* Acquire config file lock */
727 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
729 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
731 for( i_index = 0; i_index < p_list->i_count; i_index++ )
733 p_module = (module_t *)p_list->p_values[i_index].p_object ;
734 if( p_module->b_submodule ) continue;
736 for (size_t i = 0; i < p_module->confsize; i++ )
738 if (IsConfigIntegerType (p_module->p_config[i].i_type))
739 p_module->p_config[i].value.i = p_module->p_config[i].orig.i;
741 if (IsConfigFloatType (p_module->p_config[i].i_type))
742 p_module->p_config[i].value.f = p_module->p_config[i].orig.f;
744 if (IsConfigStringType (p_module->p_config[i].i_type))
746 freenull (p_module->p_config[i].value.psz);
747 p_module->p_config[i].value.psz =
748 strdupnull (p_module->p_config[i].orig.psz);
753 vlc_list_release( p_list );
754 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
758 static FILE *config_OpenConfigFile( vlc_object_t *p_obj, const char *mode )
760 static const char psz_subpath[] = DIR_SEP CONFIG_DIR DIR_SEP CONFIG_FILE;
761 const char *psz_filename = p_obj->p_libvlc->psz_configfile;
762 const char *psz_homedir;
766 if( psz_filename == NULL )
768 psz_homedir = p_obj->p_libvlc->psz_homedir;
769 if( psz_homedir == NULL )
771 msg_Err( p_obj, "no home directory defined" );
775 i_buflen = strlen(psz_homedir) + sizeof(psz_subpath) + 1;
779 if( psz_filename == NULL )
781 sprintf( buf, "%s%s", psz_homedir, psz_subpath );
785 msg_Dbg( p_obj, "opening config file (%s)", psz_filename );
786 p_stream = utf8_fopen( psz_filename, mode );
787 if( p_stream == NULL && errno != ENOENT )
788 msg_Err( p_obj, "cannot open config file (%s): %s", psz_filename, strerror(errno) );
794 /*****************************************************************************
795 * config_LoadConfigFile: loads the configuration file.
796 *****************************************************************************
797 * This function is called to load the config options stored in the config
799 *****************************************************************************/
800 int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
805 file = config_OpenConfigFile (p_this, "rt");
809 /* Acquire config file lock */
810 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
812 /* Look for the selected module, if NULL then save everything */
813 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
815 /* Look for UTF-8 Byte Order Mark */
816 char * (*convert) (const char *) = strdupnull;
819 if ((fread (bom, 1, 3, file) != 3)
820 || memcmp (bom, "\xEF\xBB\xBF", 3))
822 convert = FromLocaleDup;
823 rewind (file); // no BOM, rewind
826 module_t *module = NULL;
827 char line[1024], section[1022];
830 while (fgets (line, 1024, file) != NULL)
832 // Ignore comments and empty lines
843 char *ptr = strchr (line, ']');
845 continue; // syntax error;
848 // New section ( = a given module)
849 strcpy (section, line + 1);
852 if ((psz_module_name == NULL)
853 || (strcmp (psz_module_name, section) == 0))
855 for (int i = 0; i < p_list->i_count; i++)
857 module_t *m = (module_t *)p_list->p_values[i].p_object;
859 if ((strcmp (section, m->psz_object_name) == 0)
860 && (m->i_config_items > 0)) // ignore config-less modules
863 if (psz_module_name != NULL)
865 "loading config for module \"%s\"",
876 continue; // no need to parse if there is no matching module
878 char *ptr = strchr (line, '\n');
882 /* look for option name */
883 const char *psz_option_name = line;
885 ptr = strchr (line, '=');
887 continue; // syntax error
890 const char *psz_option_value = ptr + 1;
892 /* try to match this option with one of the module's options */
893 for (size_t i = 0; i < module->confsize; i++)
895 module_config_t *p_item = module->p_config + i;
897 if ((p_item->i_type & CONFIG_HINT)
898 || strcmp (p_item->psz_name, psz_option_name))
902 switch( p_item->i_type )
904 case CONFIG_ITEM_BOOL:
905 case CONFIG_ITEM_INTEGER:
906 if( !*psz_option_value )
907 break; /* ignore empty option */
908 p_item->value.i = strtol( psz_option_value, 0, 0 );
909 p_item->saved.i = p_item->value.i;
911 /*msg_Dbg (p_this, "option \"%s\", value %i",
912 psz_option_name, p_item->value.i);*/
915 case CONFIG_ITEM_FLOAT:
916 if( !*psz_option_value )
917 break; /* ignore empty option */
918 p_item->value.f = (float)i18n_atof( psz_option_value);
919 p_item->saved.f = p_item->value.f;
921 /*msg_Dbg (p_this, "option \"%s\", value %f",
922 psz_option_name, (double)p_item->value.f);*/
925 case CONFIG_ITEM_KEY:
926 if( !*psz_option_value )
927 break; /* ignore empty option */
928 p_item->value.i = ConfigStringToKey(psz_option_value);
929 p_item->saved.i = p_item->value.i;
933 vlc_mutex_lock( p_item->p_lock );
935 /* free old string */
936 free( (char*) p_item->value.psz );
937 free( (char*) p_item->saved.psz );
939 p_item->value.psz = convert (psz_option_value);
940 p_item->saved.psz = strdupnull (p_item->value.psz);
942 vlc_mutex_unlock( p_item->p_lock );
944 /*msg_Dbg (p_this, "option \"%s\", value \"%s\"",
945 psz_option_name, psz_option_value ?: "");*/
953 vlc_list_release( p_list );
957 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
961 /*****************************************************************************
962 * config_CreateDir: Create configuration directory if it doesn't exist.
963 *****************************************************************************/
964 int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname )
966 if( !psz_dirname && !*psz_dirname ) return -1;
968 if( utf8_mkdir( psz_dirname ) && ( errno != EEXIST ) )
970 msg_Err( p_this, "could not create %s (%s)",
971 psz_dirname, strerror(errno) );
978 /*****************************************************************************
979 * config_SaveConfigFile: Save a module's config options.
980 *****************************************************************************
981 * This will save the specified module's config options to the config file.
982 * If psz_module_name is NULL then we save all the modules config options.
983 * It's no use to save the config options that kept their default values, so
984 * we'll try to be a bit clever here.
986 * When we save we mustn't delete the config options of the modules that
987 * haven't been loaded. So we cannot just create a new config file with the
988 * config structures we've got in memory.
989 * I don't really know how to deal with this nicely, so I will use a completly
991 * I will load the config file in memory, but skipping all the sections of the
992 * modules we want to save. Then I will create a brand new file, dump the file
993 * loaded in memory and then append the sections of the modules we want to
996 *****************************************************************************/
997 static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
998 vlc_bool_t b_autosave )
1003 char p_line[1024], *p_index2;
1005 char *p_bigbuffer, *p_index;
1006 vlc_bool_t b_backup;
1009 /* Acquire config file lock */
1010 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
1012 if (p_this->p_libvlc->psz_configfile == NULL)
1014 const char *psz_homedir = p_this->p_libvlc->psz_homedir;
1017 msg_Err( p_this, "no home directory defined" );
1018 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1022 char dirname[strlen (psz_homedir) + sizeof (DIR_SEP CONFIG_DIR)];
1023 sprintf (dirname, "%s" DIR_SEP CONFIG_DIR, psz_homedir);
1024 config_CreateDir (p_this, dirname);
1027 file = config_OpenConfigFile (p_this, "rt");
1030 /* look for file size */
1031 fseek( file, 0L, SEEK_END );
1032 i_sizebuf = ftell( file );
1033 fseek( file, 0L, SEEK_SET );
1036 p_bigbuffer = p_index = malloc( i_sizebuf+1 );
1039 msg_Err( p_this, "out of memory" );
1040 if( file ) fclose( file );
1041 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1046 /* List all available modules */
1047 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1049 /* backup file into memory, we only need to backup the sections we won't
1052 while( file && fgets( p_line, 1024, file ) )
1054 if( (p_line[0] == '[') && (p_index2 = strchr(p_line,']')))
1057 /* we found a section, check if we need to do a backup */
1058 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1060 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1062 if( ((p_index2 - &p_line[1])
1063 == (int)strlen(p_parser->psz_object_name) )
1064 && !memcmp( &p_line[1], p_parser->psz_object_name,
1065 strlen(p_parser->psz_object_name) ) )
1067 if( !psz_module_name )
1069 else if( !strcmp( psz_module_name,
1070 p_parser->psz_object_name ) )
1075 if( i_index == p_list->i_count )
1077 /* we don't have this section in our list so we need to back
1081 msg_Dbg( p_this, "backing up config for unknown module \"%s\"",
1094 /* save line if requested and line is valid (doesn't begin with a
1095 * space, tab, or eol) */
1096 if( b_backup && (p_line[0] != '\n') && (p_line[0] != ' ')
1097 && (p_line[0] != '\t') )
1099 strcpy( p_index, p_line );
1100 p_index += strlen( p_line );
1103 if( file ) fclose( file );
1107 * Save module config in file
1110 file = config_OpenConfigFile (p_this, "wt");
1113 vlc_list_release( p_list );
1114 free( p_bigbuffer );
1115 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1119 fprintf( file, "\xEF\xBB\xBF###\n### " COPYRIGHT_MESSAGE "\n###\n\n"
1120 "###\n### lines begining with a '#' character are comments\n###\n\n" );
1122 /* Look for the selected module, if NULL then save everything */
1123 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1125 module_config_t *p_item, *p_end;
1126 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1128 if( psz_module_name && strcmp( psz_module_name,
1129 p_parser->psz_object_name ) )
1132 if( !p_parser->i_config_items )
1135 if( psz_module_name )
1136 msg_Dbg( p_this, "saving config for module \"%s\"",
1137 p_parser->psz_object_name );
1139 fprintf( file, "[%s]", p_parser->psz_object_name );
1140 if( p_parser->psz_longname )
1141 fprintf( file, " # %s\n\n", p_parser->psz_longname );
1143 fprintf( file, "\n\n" );
1145 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
1150 int i_value = p_item->value.i;
1151 float f_value = p_item->value.f;
1152 const char *psz_value = p_item->value.psz;
1154 if( p_item->i_type & CONFIG_HINT )
1157 /* Ignore deprecated options */
1158 if( p_item->psz_current )
1160 if( p_item->b_unsaveable )
1164 if( b_autosave && !p_item->b_autosave )
1166 i_value = p_item->saved.i;
1167 f_value = p_item->saved.f;
1168 psz_value = p_item->saved.psz;
1169 if( !psz_value ) psz_value = p_item->orig.psz;
1173 p_item->b_dirty = VLC_FALSE;
1176 switch( p_item->i_type )
1178 case CONFIG_ITEM_BOOL:
1179 case CONFIG_ITEM_INTEGER:
1180 if( p_item->psz_text )
1181 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1182 (p_item->i_type == CONFIG_ITEM_BOOL) ?
1183 _("boolean") : _("integer") );
1184 if( i_value == p_item->orig.i )
1186 fprintf( file, "%s=%i\n", p_item->psz_name, i_value );
1188 p_item->saved.i = i_value;
1191 case CONFIG_ITEM_KEY:
1192 if( p_item->psz_text )
1193 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1195 if( i_value == p_item->orig.i )
1197 psz_key = ConfigKeyToString( i_value );
1198 fprintf( file, "%s=%s\n", p_item->psz_name,
1199 psz_key ? psz_key : "" );
1202 p_item->saved.i = i_value;
1205 case CONFIG_ITEM_FLOAT:
1206 if( p_item->psz_text )
1207 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1209 if( f_value == p_item->orig.f )
1211 fprintf( file, "%s=%f\n", p_item->psz_name, (double)f_value );
1213 p_item->saved.f = f_value;
1217 if( p_item->psz_text )
1218 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1220 if( (!psz_value && !p_item->orig.psz) ||
1221 (psz_value && p_item->orig.psz &&
1222 !strcmp( psz_value, p_item->orig.psz )) )
1224 fprintf( file, "%s=%s\n", p_item->psz_name,
1227 if( b_autosave && !p_item->b_autosave ) break;
1229 freenull (p_item->saved.psz);
1230 if( (psz_value && p_item->orig.psz &&
1231 strcmp( psz_value, p_item->orig.psz )) ||
1232 !psz_value || !p_item->orig.psz)
1233 p_item->saved.psz = strdupnull (psz_value);
1235 p_item->saved.psz = NULL;
1242 vlc_list_release( p_list );
1245 * Restore old settings from the config in file
1247 fputs( p_bigbuffer, file );
1248 free( p_bigbuffer );
1251 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1256 int config_AutoSaveConfigFile( vlc_object_t *p_this )
1259 int i_index, i_count;
1261 if( !p_this ) return -1;
1263 /* Check if there's anything to save */
1264 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
1265 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1266 i_count = p_list->i_count;
1267 for( i_index = 0; i_index < i_count; i_index++ )
1269 module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1270 module_config_t *p_item, *p_end;
1272 if( !p_parser->i_config_items ) continue;
1274 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
1278 if( p_item->b_autosave && p_item->b_dirty ) break;
1282 vlc_list_release( p_list );
1283 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1285 if( i_index == i_count ) return VLC_SUCCESS;
1286 return SaveConfigFile( p_this, 0, VLC_TRUE );
1289 int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
1291 return SaveConfigFile( p_this, psz_module_name, VLC_FALSE );
1294 /*****************************************************************************
1295 * config_LoadCmdLine: parse command line
1296 *****************************************************************************
1297 * Parse command line for configuration options.
1298 * Now that the module_bank has been initialized, we can dynamically
1299 * generate the longopts structure used by getops. We have to do it this way
1300 * because we don't know (and don't want to know) in advance the configuration
1301 * options used (ie. exported) by each module.
1302 *****************************************************************************/
1303 int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
1304 vlc_bool_t b_ignore_errors )
1306 int i_cmd, i_index, i_opts, i_shortopts, flag, i_verbose = 0;
1309 struct option *p_longopts;
1310 int i_modules_index;
1313 module_config_t *pp_shortopts[256];
1314 char *psz_shortopts;
1316 /* Set default configuration and copy arguments */
1317 p_this->p_libvlc->i_argc = *pi_argc;
1318 p_this->p_libvlc->ppsz_argv = ppsz_argv;
1321 /* When VLC.app is run by double clicking in Mac OS X, the 2nd arg
1322 * is the PSN - process serial number (a unique PID-ish thingie)
1323 * still ok for real Darwin & when run from command line */
1324 if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
1325 /* for example -psn_0_9306113 */
1327 /* GDMF!... I can't do this or else the MacOSX window server will
1328 * not pick up the PSN and not register the app and we crash...
1329 * hence the following kludge otherwise we'll get confused w/ argv[1]
1330 * being an input file name */
1332 ppsz_argv[ 1 ] = NULL;
1334 *pi_argc = *pi_argc - 1;
1340 /* List all modules */
1341 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1344 * Generate the longopts and shortopts structures used by getopt_long
1348 for( i_modules_index = 0; i_modules_index < p_list->i_count;
1351 p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ;
1353 /* count the number of exported configuration options (to allocate
1354 * longopts). We also need to allocate space for two options when
1355 * dealing with boolean to allow for --foo and --no-foo */
1356 i_opts += p_parser->i_config_items
1357 + 2 * p_parser->i_bool_items;
1360 p_longopts = malloc( sizeof(struct option) * (i_opts + 1) );
1361 if( p_longopts == NULL )
1363 msg_Err( p_this, "out of memory" );
1364 vlc_list_release( p_list );
1368 psz_shortopts = malloc( sizeof( char ) * (2 * i_opts + 1) );
1369 if( psz_shortopts == NULL )
1371 msg_Err( p_this, "out of memory" );
1373 vlc_list_release( p_list );
1377 /* If we are requested to ignore errors, then we must work on a copy
1378 * of the ppsz_argv array, otherwise getopt_long will reorder it for
1379 * us, ignoring the arity of the options */
1380 if( b_ignore_errors )
1382 ppsz_argv = (char**)malloc( *pi_argc * sizeof(char *) );
1383 if( ppsz_argv == NULL )
1385 msg_Err( p_this, "out of memory" );
1386 free( psz_shortopts );
1388 vlc_list_release( p_list );
1391 memcpy( ppsz_argv, p_this->p_libvlc->ppsz_argv,
1392 *pi_argc * sizeof(char *) );
1396 for( i_index = 0; i_index < 256; i_index++ )
1398 pp_shortopts[i_index] = NULL;
1401 /* Fill the p_longopts and psz_shortopts structures */
1403 for( i_modules_index = 0; i_modules_index < p_list->i_count;
1406 module_config_t *p_item, *p_end;
1407 p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ;
1409 if( !p_parser->i_config_items )
1412 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
1417 if( p_item->i_type & CONFIG_HINT )
1420 /* Add item to long options */
1421 p_longopts[i_index].name = strdup( p_item->psz_name );
1422 if( p_longopts[i_index].name == NULL ) continue;
1423 p_longopts[i_index].has_arg =
1424 (p_item->i_type == CONFIG_ITEM_BOOL)?
1425 no_argument : required_argument;
1426 p_longopts[i_index].flag = &flag;
1427 p_longopts[i_index].val = 0;
1430 /* When dealing with bools we also need to add the --no-foo
1432 if( p_item->i_type == CONFIG_ITEM_BOOL )
1434 char *psz_name = malloc( strlen(p_item->psz_name) + 3 );
1435 if( psz_name == NULL ) continue;
1436 strcpy( psz_name, "no" );
1437 strcat( psz_name, p_item->psz_name );
1439 p_longopts[i_index].name = psz_name;
1440 p_longopts[i_index].has_arg = no_argument;
1441 p_longopts[i_index].flag = &flag;
1442 p_longopts[i_index].val = 1;
1445 psz_name = malloc( strlen(p_item->psz_name) + 4 );
1446 if( psz_name == NULL ) continue;
1447 strcpy( psz_name, "no-" );
1448 strcat( psz_name, p_item->psz_name );
1450 p_longopts[i_index].name = psz_name;
1451 p_longopts[i_index].has_arg = no_argument;
1452 p_longopts[i_index].flag = &flag;
1453 p_longopts[i_index].val = 1;
1457 /* If item also has a short option, add it */
1458 if( p_item->i_short )
1460 pp_shortopts[(int)p_item->i_short] = p_item;
1461 psz_shortopts[i_shortopts] = p_item->i_short;
1463 if( p_item->i_type != CONFIG_ITEM_BOOL )
1465 psz_shortopts[i_shortopts] = ':';
1468 if( p_item->i_short == 'v' )
1470 psz_shortopts[i_shortopts] = ':';
1478 /* We don't need the module list anymore */
1479 vlc_list_release( p_list );
1481 /* Close the longopts and shortopts structures */
1482 memset( &p_longopts[i_index], 0, sizeof(struct option) );
1483 psz_shortopts[i_shortopts] = '\0';
1486 * Parse the command line options
1489 optind = 0; // set to 0 to tell GNU getopt to reinitialize
1490 while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv, psz_shortopts,
1491 p_longopts, &i_index ) ) != -1 )
1493 /* A long option has been recognized */
1496 module_config_t *p_conf;
1497 char *psz_name = (char *)p_longopts[i_index].name;
1499 /* Check if we deal with a --nofoo or --no-foo long option */
1500 if( flag ) psz_name += psz_name[2] == '-' ? 3 : 2;
1502 /* Store the configuration option */
1503 p_conf = config_FindConfig( p_this, psz_name );
1506 /* Check if the option is deprecated */
1507 if( p_conf->psz_current )
1509 if( !strcmp(p_conf->psz_current,"SUPPRESSED") )
1511 if( !b_ignore_errors )
1514 "Warning: option --%s is no longer used.\n",
1519 if( !b_ignore_errors )
1521 if( p_conf->b_strict )
1524 "Error: option --%s is deprecated. "
1525 "Use --%s instead.\n",
1526 p_conf->psz_name, p_conf->psz_current);
1528 for( i_index = 0; p_longopts[i_index].name; i_index++ )
1529 free( (char *)p_longopts[i_index].name );
1532 free( psz_shortopts );
1536 "Warning: option --%s is deprecated. "
1537 "You should use --%s instead.\n",
1538 p_conf->psz_name, p_conf->psz_current);
1540 *psz_name = *(p_conf->psz_current);
1541 p_conf = config_FindConfig( p_this, psz_name );
1544 switch( p_conf->i_type )
1546 case CONFIG_ITEM_STRING:
1547 case CONFIG_ITEM_FILE:
1548 case CONFIG_ITEM_DIRECTORY:
1549 case CONFIG_ITEM_MODULE:
1550 case CONFIG_ITEM_MODULE_LIST:
1551 case CONFIG_ITEM_MODULE_LIST_CAT:
1552 case CONFIG_ITEM_MODULE_CAT:
1553 config_PutPsz( p_this, psz_name, optarg );
1555 case CONFIG_ITEM_INTEGER:
1556 config_PutInt( p_this, psz_name, strtol(optarg, 0, 0));
1558 case CONFIG_ITEM_FLOAT:
1559 config_PutFloat( p_this, psz_name, (float)atof(optarg) );
1561 case CONFIG_ITEM_KEY:
1562 config_PutInt( p_this, psz_name, ConfigStringToKey( optarg ) );
1564 case CONFIG_ITEM_BOOL:
1565 config_PutInt( p_this, psz_name, !flag );
1572 /* A short option has been recognized */
1573 if( pp_shortopts[i_cmd] != NULL )
1575 switch( pp_shortopts[i_cmd]->i_type )
1577 case CONFIG_ITEM_STRING:
1578 case CONFIG_ITEM_FILE:
1579 case CONFIG_ITEM_DIRECTORY:
1580 case CONFIG_ITEM_MODULE:
1581 case CONFIG_ITEM_MODULE_CAT:
1582 case CONFIG_ITEM_MODULE_LIST:
1583 case CONFIG_ITEM_MODULE_LIST_CAT:
1584 config_PutPsz( p_this, pp_shortopts[i_cmd]->psz_name, optarg );
1586 case CONFIG_ITEM_INTEGER:
1591 if( *optarg == 'v' ) /* eg. -vvv */
1594 while( *optarg == 'v' )
1602 i_verbose += atoi( optarg ); /* eg. -v2 */
1607 i_verbose++; /* -v */
1609 config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name,
1614 config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name,
1615 strtol(optarg, 0, 0) );
1618 case CONFIG_ITEM_BOOL:
1619 config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name, 1 );
1626 /* Internal error: unknown option */
1627 if( !b_ignore_errors )
1629 fprintf( stderr, "%s: unknown option"
1630 " or missing mandatory argument ",
1631 p_this->p_libvlc->psz_object_name );
1634 fprintf( stderr, "`-%c'\n", optopt );
1638 fprintf( stderr, "`%s'\n", ppsz_argv[optind-1] );
1640 fprintf( stderr, "Try `%s --help' for more information.\n",
1641 p_this->p_libvlc->psz_object_name );
1643 for( i_index = 0; p_longopts[i_index].name; i_index++ )
1644 free( (char *)p_longopts[i_index].name );
1646 free( psz_shortopts );
1651 /* Free allocated resources */
1652 for( i_index = 0; p_longopts[i_index].name; i_index++ )
1653 free( (char *)p_longopts[i_index].name );
1655 free( psz_shortopts );
1656 if( b_ignore_errors ) free( ppsz_argv );
1662 * config_GetDataDir: find directory where shared data is installed
1664 * @return a string (always succeeds).
1666 const char *config_GetDataDir( const vlc_object_t *p_this )
1668 #if defined (WIN32) || defined (UNDER_CE)
1669 return p_this->p_libvlc_global->psz_vlcpath;
1670 #elif defined(__APPLE__) || defined (SYS_BEOS)
1671 static char path[PATH_MAX] = "";
1675 snprintf( path, sizeof( path ), "%s/share",
1676 p_this->p_libvlc_global->psz_vlcpath );
1677 path[sizeof( path ) - 1] = '\0';
1685 /*****************************************************************************
1686 * config_GetHomeDir, config_GetUserDir: find the user's home directory.
1687 *****************************************************************************
1688 * This function will try by different ways to find the user's home path.
1689 * Note that this function is not reentrant, it should be called only once
1690 * at the beginning of main where the result will be stored for later use.
1691 *****************************************************************************/
1692 static char *GetDir( vlc_bool_t b_appdata )
1694 const char *psz_localhome = NULL;
1696 #if defined(HAVE_GETPWUID)
1697 struct passwd *p_pw = NULL;
1700 #if defined(WIN32) && !defined(UNDER_CE)
1701 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
1703 #ifndef CSIDL_FLAG_CREATE
1704 # define CSIDL_FLAG_CREATE 0x8000
1706 #ifndef CSIDL_APPDATA
1707 # define CSIDL_APPDATA 0x1A
1709 #ifndef CSIDL_PROFILE
1710 # define CSIDL_PROFILE 0x28
1712 #ifndef SHGFP_TYPE_CURRENT
1713 # define SHGFP_TYPE_CURRENT 0
1716 HINSTANCE shfolder_dll;
1717 SHGETFOLDERPATH SHGetFolderPath ;
1719 /* load the shfolder dll to retrieve SHGetFolderPath */
1720 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
1722 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
1723 _T("SHGetFolderPathW") );
1724 if ( SHGetFolderPath != NULL )
1726 wchar_t whomedir[MAX_PATH];
1728 /* get the "Application Data" folder for the current user */
1729 if( S_OK == SHGetFolderPath( NULL,
1730 (b_appdata ? CSIDL_APPDATA :
1731 CSIDL_PROFILE) | CSIDL_FLAG_CREATE,
1732 NULL, SHGFP_TYPE_CURRENT,
1735 FreeLibrary( shfolder_dll );
1736 return FromWide( whomedir );
1739 FreeLibrary( shfolder_dll );
1742 #elif defined(UNDER_CE)
1744 #ifndef CSIDL_APPDATA
1745 # define CSIDL_APPDATA 0x1A
1748 wchar_t whomedir[MAX_PATH];
1750 /* get the "Application Data" folder for the current user */
1751 if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) )
1752 return FromWide( whomedir );
1755 #if defined(HAVE_GETPWUID)
1756 if( ( p_pw = getpwuid( getuid() ) ) == NULL )
1759 psz_localhome = getenv( "HOME" );
1760 if( psz_localhome == NULL )
1762 psz_localhome = getenv( "TMP" );
1763 if( psz_localhome == NULL )
1764 psz_localhome = "/tmp";
1767 #if defined(HAVE_GETPWUID)
1769 psz_localhome = p_pw->pw_dir;
1772 return FromLocaleDup( psz_localhome );
1775 char *config_GetHomeDir( void )
1777 return GetDir( VLC_TRUE );
1780 char *config_GetUserDir( void )
1782 return GetDir( VLC_FALSE );
1786 static int ConfigStringToKey( const char *psz_key )
1790 const char *psz_parser = strchr( psz_key, '-' );
1791 while( psz_parser && psz_parser != psz_key )
1793 for( i = 0; i < sizeof(vlc_modifiers) / sizeof(key_descriptor_t); i++ )
1795 if( !strncasecmp( vlc_modifiers[i].psz_key_string, psz_key,
1796 strlen( vlc_modifiers[i].psz_key_string ) ) )
1798 i_key |= vlc_modifiers[i].i_key_code;
1801 psz_key = psz_parser + 1;
1802 psz_parser = strchr( psz_key, '-' );
1804 for( i = 0; i < sizeof(vlc_keys) / sizeof( key_descriptor_t ); i++ )
1806 if( !strcasecmp( vlc_keys[i].psz_key_string, psz_key ) )
1808 i_key |= vlc_keys[i].i_key_code;
1815 static char *ConfigKeyToString( int i_key )
1817 char *psz_key = malloc( 100 );
1827 for( index = 0; index < (sizeof(vlc_modifiers) / sizeof(key_descriptor_t));
1830 if( i_key & vlc_modifiers[index].i_key_code )
1832 p += sprintf( p, "%s-", vlc_modifiers[index].psz_key_string );
1835 for( index = 0; index < (sizeof(vlc_keys) / sizeof( key_descriptor_t));
1838 if( (int)( i_key & ~KEY_MODIFIER ) == vlc_keys[index].i_key_code )
1840 p += sprintf( p, "%s", vlc_keys[index].psz_key_string );