]> git.sesse.net Git - vlc/blob - src/config/file.c
Always print numbers (floats) in American format in vlcrc
[vlc] / src / config / file.c
1 /*****************************************************************************
2  * file.c: configuration file handling
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc/vlc.h>
29 #include "../libvlc.h"
30 #include "vlc_charset.h"
31 #include "vlc_keys.h"
32
33 #include <errno.h>                                                  /* errno */
34 #include <assert.h>
35 #include <limits.h>
36 #include <locale.h>
37
38 #include "configuration.h"
39 #include "modules/modules.h"
40
41 static char *ConfigKeyToString( int );
42
43 static inline char *strdupnull (const char *src)
44 {
45     return src ? strdup (src) : NULL;
46 }
47
48 /**
49  * Get the user's configuration file
50  */
51 static char *config_GetConfigFile( void )
52 {
53     char *psz_dir = config_GetUserConfDir();
54     char *psz_configfile;
55
56     if( asprintf( &psz_configfile, "%s" DIR_SEP CONFIG_FILE, psz_dir ) == -1 )
57         psz_configfile = NULL;
58     free( psz_dir );
59     return psz_configfile;
60 }
61
62 static FILE *config_OpenConfigFile( vlc_object_t *p_obj, const char *mode )
63 {
64     char *psz_filename = libvlc_priv (p_obj->p_libvlc)->psz_configfile;
65     FILE *p_stream;
66
67     if( !psz_filename )
68     {
69         psz_filename = config_GetConfigFile();
70     }
71
72     msg_Dbg( p_obj, "opening config file (%s)", psz_filename );
73
74     p_stream = utf8_fopen( psz_filename, mode );
75     if( p_stream == NULL && errno != ENOENT )
76     {
77         msg_Err( p_obj, "cannot open config file (%s): %m",
78                  psz_filename );
79
80     }
81 #if !( defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS) )
82     else if( p_stream == NULL && errno == ENOENT && mode[0] == 'r' )
83     {
84         /* This is the fallback for pre XDG Base Directory
85          * Specification configs */
86         char *psz_old;
87         if( asprintf( &psz_old, "%s" DIR_SEP CONFIG_DIR DIR_SEP CONFIG_FILE,
88                   p_obj->p_libvlc->psz_homedir ) != -1 )
89         {
90             p_stream = utf8_fopen( psz_old, mode );
91             if( p_stream )
92             {
93                 /* Old config file found. We want to write it at the
94                  * new location now. */
95                 msg_Info( p_obj->p_libvlc, "Found old config file at %s. "
96                           "VLC will now use %s.", psz_old, psz_filename );
97                 char *psz_readme;
98                 if( asprintf(&psz_readme,"%s"DIR_SEP CONFIG_DIR DIR_SEP"README",
99                               p_obj->p_libvlc->psz_homedir ) != -1 )
100                 {
101                     FILE *p_readme = utf8_fopen( psz_readme, "wt" );
102                     if( p_readme )
103                     {
104                         fprintf( p_readme, "The VLC media player "
105                                  "configuration folder has moved to comply\n"
106                                  "with the XDG Base Directory Specification "
107                                  "version 0.6. Your\nconfiguration has been "
108                                  "copied to the new location:\n%s\nYou can "
109                                  "delete this directory and all its contents.",
110                                   psz_filename);
111                         fclose( p_readme );
112                     }
113                     free( psz_readme );
114                 }
115             }
116             free( psz_old );
117         }
118     }
119 #endif
120     else if( p_stream != NULL )
121     {
122         libvlc_priv (p_obj->p_libvlc)->psz_configfile = psz_filename;
123     }
124
125     return p_stream;
126 }
127
128
129 static int strtoi (const char *str)
130 {
131     char *end;
132     long l;
133
134     errno = 0;
135     l = strtol (str, &end, 0);
136
137     if (!errno)
138     {
139         if ((l > INT_MAX) || (l < INT_MIN))
140             errno = ERANGE;
141         if (*end)
142             errno = EINVAL;
143     }
144     return (int)l;
145 }
146
147
148 /*****************************************************************************
149  * config_LoadConfigFile: loads the configuration file.
150  *****************************************************************************
151  * This function is called to load the config options stored in the config
152  * file.
153  *****************************************************************************/
154 int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
155 {
156     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
157     vlc_list_t *p_list;
158     FILE *file;
159
160     file = config_OpenConfigFile (p_this, "rt");
161     if (file == NULL)
162         return VLC_EGENERIC;
163
164     /* Acquire config file lock */
165     vlc_mutex_lock( &priv->config_lock );
166
167     /* Look for the selected module, if NULL then save everything */
168     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
169
170     /* Look for UTF-8 Byte Order Mark */
171     char * (*convert) (const char *) = strdupnull;
172     char bom[3];
173
174     if ((fread (bom, 1, 3, file) != 3)
175      || memcmp (bom, "\xEF\xBB\xBF", 3))
176     {
177         convert = FromLocaleDup;
178         rewind (file); /* no BOM, rewind */
179     }
180
181     module_t *module = NULL;
182     char line[1024], section[1022];
183     section[0] = '\0';
184
185     while (fgets (line, 1024, file) != NULL)
186     {
187         /* Ignore comments and empty lines */
188         switch (line[0])
189         {
190             case '#':
191             case '\n':
192             case '\0':
193                 continue;
194         }
195
196         if (line[0] == '[')
197         {
198             char *ptr = strchr (line, ']');
199             if (ptr == NULL)
200                 continue; /* syntax error; */
201             *ptr = '\0';
202
203             /* New section ( = a given module) */
204             strcpy (section, line + 1);
205             module = NULL;
206
207             if ((psz_module_name == NULL)
208              || (strcmp (psz_module_name, section) == 0))
209             {
210                 for (int i = 0; i < p_list->i_count; i++)
211                 {
212                     module_t *m = (module_t *)p_list->p_values[i].p_object;
213
214                     if ((strcmp (section, m->psz_object_name) == 0)
215                      && (m->i_config_items > 0)) /* ignore config-less modules */
216                     {
217                         module = m;
218                         if (psz_module_name != NULL)
219                             msg_Dbg (p_this,
220                                      "loading config for module \"%s\"",
221                                      section);
222                         break;
223                     }
224                 }
225             }
226
227             continue;
228         }
229
230         if (module == NULL)
231             continue; /* no need to parse if there is no matching module */
232
233         char *ptr = strchr (line, '\n');
234         if (ptr != NULL)
235             *ptr = '\0';
236
237         /* look for option name */
238         const char *psz_option_name = line;
239
240         ptr = strchr (line, '=');
241         if (ptr == NULL)
242             continue; /* syntax error */
243
244         *ptr = '\0';
245         const char *psz_option_value = ptr + 1;
246
247         /* try to match this option with one of the module's options */
248         for (size_t i = 0; i < module->confsize; i++)
249         {
250             module_config_t *p_item = module->p_config + i;
251
252             if ((p_item->i_type & CONFIG_HINT)
253              || strcmp (p_item->psz_name, psz_option_name))
254                 continue;
255
256             /* We found it */
257             errno = 0;
258
259             switch( p_item->i_type )
260             {
261                 case CONFIG_ITEM_BOOL:
262                 case CONFIG_ITEM_INTEGER:
263                 {
264                     long l = strtoi (psz_option_value);
265                     if (errno)
266                         msg_Warn (p_this, "Integer value (%s) for %s: %m",
267                                   psz_option_value, psz_option_name);
268                     else
269                         p_item->saved.i = p_item->value.i = (int)l;
270                     break;
271                 }
272
273                 case CONFIG_ITEM_FLOAT:
274                     if( !*psz_option_value )
275                         break;                    /* ignore empty option */
276                     p_item->value.f = (float)i18n_atof( psz_option_value);
277                     p_item->saved.f = p_item->value.f;
278                     break;
279
280                 case CONFIG_ITEM_KEY:
281                     if( !*psz_option_value )
282                         break;                    /* ignore empty option */
283                     p_item->value.i = ConfigStringToKey(psz_option_value);
284                     p_item->saved.i = p_item->value.i;
285                     break;
286
287                 default:
288                     vlc_mutex_lock( p_item->p_lock );
289
290                     /* free old string */
291                     free( (char*) p_item->value.psz );
292                     free( (char*) p_item->saved.psz );
293
294                     p_item->value.psz = convert (psz_option_value);
295                     p_item->saved.psz = strdupnull (p_item->value.psz);
296
297                     vlc_mutex_unlock( p_item->p_lock );
298                     break;
299             }
300
301             break;
302         }
303     }
304
305     if (ferror (file))
306     {
307         msg_Err (p_this, "error reading configuration: %m");
308         clearerr (file);
309     }
310     fclose (file);
311
312     vlc_list_release( p_list );
313
314     vlc_mutex_unlock( &priv->config_lock );
315     return 0;
316 }
317
318 /*****************************************************************************
319  * config_CreateDir: Create configuration directory if it doesn't exist.
320  *****************************************************************************/
321 int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname )
322 {
323     if( !psz_dirname && !*psz_dirname ) return -1;
324
325     if( utf8_mkdir( psz_dirname, 0700 ) == 0 )
326         return 0;
327
328     switch( errno )
329     {
330         case EEXIST:
331             return 0;
332
333         case ENOENT:
334         {
335             /* Let's try to create the parent directory */
336             char psz_parent[strlen( psz_dirname ) + 1], *psz_end;
337             strcpy( psz_parent, psz_dirname );
338
339             psz_end = strrchr( psz_parent, DIR_SEP_CHAR );
340             if( psz_end && psz_end != psz_parent )
341             {
342                 *psz_end = '\0';
343                 if( config_CreateDir( p_this, psz_parent ) == 0 )
344                 {
345                     if( !utf8_mkdir( psz_dirname, 0700 ) )
346                         return 0;
347                 }
348             }
349         }
350     }
351
352     msg_Err( p_this, "could not create %s: %m", psz_dirname );
353     return -1;
354 }
355
356 static int
357 config_Write (FILE *file, const char *type, const char *desc,
358               bool comment, const char *name, const char *fmt, ...)
359 {
360     va_list ap;
361     int ret;
362
363     if (desc == NULL)
364         desc = "?";
365
366     if (fprintf (file, "# %s (%s)\n%s%s=", desc, _(type),
367                  comment ? "#" : "", name) < 0)
368         return -1;
369
370     va_start (ap, fmt);
371     ret = vfprintf (file, fmt, ap);
372     va_end (ap);
373     if (ret < 0)
374         return -1;
375
376     if (fputs ("\n\n", file) == EOF)
377         return -1;
378     return 0;
379 }
380
381
382 /*****************************************************************************
383  * config_SaveConfigFile: Save a module's config options.
384  *****************************************************************************
385  * This will save the specified module's config options to the config file.
386  * If psz_module_name is NULL then we save all the modules config options.
387  * It's no use to save the config options that kept their default values, so
388  * we'll try to be a bit clever here.
389  *
390  * When we save we mustn't delete the config options of the modules that
391  * haven't been loaded. So we cannot just create a new config file with the
392  * config structures we've got in memory.
393  * I don't really know how to deal with this nicely, so I will use a completly
394  * dumb method ;-)
395  * I will load the config file in memory, but skipping all the sections of the
396  * modules we want to save. Then I will create a brand new file, dump the file
397  * loaded in memory and then append the sections of the modules we want to
398  * save.
399  * Really stupid no ?
400  *****************************************************************************/
401 static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
402                            bool b_autosave )
403 {
404     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
405     module_t *p_parser;
406     vlc_list_t *p_list;
407     FILE *file;
408     char p_line[1024], *p_index2;
409     int i_sizebuf = 0;
410     char *p_bigbuffer, *p_index;
411     bool b_backup;
412     int i_index;
413
414     /* Acquire config file lock */
415     vlc_mutex_lock( &priv->config_lock );
416
417     if( libvlc_priv (p_this->p_libvlc)->psz_configfile == NULL )
418     {
419         char *psz_configdir = config_GetUserConfDir();
420         if( !psz_configdir ) /* XXX: This should never happen */
421         {
422             msg_Err( p_this, "no configuration directory defined" );
423             vlc_mutex_unlock( &priv->config_lock );
424             return -1;
425         }
426
427         config_CreateDir( p_this, psz_configdir );
428         free( psz_configdir );
429     }
430
431     file = config_OpenConfigFile( p_this, "rt" );
432     if( file != NULL )
433     {
434         /* look for file size */
435         fseek( file, 0L, SEEK_END );
436         i_sizebuf = ftell( file );
437         fseek( file, 0L, SEEK_SET );
438     }
439
440     p_bigbuffer = p_index = malloc( i_sizebuf+1 );
441     if( !p_bigbuffer )
442     {
443         if( file ) fclose( file );
444         vlc_mutex_unlock( &priv->config_lock );
445         return -1;
446     }
447     p_bigbuffer[0] = 0;
448
449     /* List all available modules */
450     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
451
452     /* backup file into memory, we only need to backup the sections we won't
453      * save later on */
454     b_backup = 0;
455     while( file && fgets( p_line, 1024, file ) )
456     {
457         if( (p_line[0] == '[') && (p_index2 = strchr(p_line,']')))
458         {
459
460             /* we found a section, check if we need to do a backup */
461             for( i_index = 0; i_index < p_list->i_count; i_index++ )
462             {
463                 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
464
465                 if( ((p_index2 - &p_line[1])
466                        == (int)strlen(p_parser->psz_object_name) )
467                     && !memcmp( &p_line[1], p_parser->psz_object_name,
468                                 strlen(p_parser->psz_object_name) ) )
469                 {
470                     if( !psz_module_name )
471                         break;
472                     else if( !strcmp( psz_module_name,
473                                       p_parser->psz_object_name ) )
474                         break;
475                 }
476             }
477
478             if( i_index == p_list->i_count )
479             {
480                 /* we don't have this section in our list so we need to back
481                  * it up */
482                 *p_index2 = 0;
483 #if 0
484                 msg_Dbg( p_this, "backing up config for unknown module \"%s\"",
485                                  &p_line[1] );
486 #endif
487                 *p_index2 = ']';
488
489                 b_backup = 1;
490             }
491             else
492             {
493                 b_backup = 0;
494             }
495         }
496
497         /* save line if requested and line is valid (doesn't begin with a
498          * space, tab, or eol) */
499         if( b_backup && (p_line[0] != '\n') && (p_line[0] != ' ')
500             && (p_line[0] != '\t') )
501         {
502             strcpy( p_index, p_line );
503             p_index += strlen( p_line );
504         }
505     }
506     if( file ) fclose( file );
507
508
509     /*
510      * Save module config in file
511      */
512
513     file = config_OpenConfigFile (p_this, "wt");
514     if( !file )
515     {
516         vlc_list_release( p_list );
517         free( p_bigbuffer );
518         vlc_mutex_unlock( &priv->config_lock );
519         return -1;
520     }
521
522     fprintf( file, "\xEF\xBB\xBF###\n###  " COPYRIGHT_MESSAGE "\n###\n\n"
523        "###\n### lines beginning with a '#' character are comments\n###\n\n" );
524
525     /* Ensure consistent number formatting... */
526     locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
527     locale_t baseloc = uselocale (loc);
528
529     /* Look for the selected module, if NULL then save everything */
530     for( i_index = 0; i_index < p_list->i_count; i_index++ )
531     {
532         module_config_t *p_item, *p_end;
533         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
534
535         if( psz_module_name && strcmp( psz_module_name,
536                                        p_parser->psz_object_name ) )
537             continue;
538
539         if( !p_parser->i_config_items )
540             continue;
541
542         if( psz_module_name )
543             msg_Dbg( p_this, "saving config for module \"%s\"",
544                      p_parser->psz_object_name );
545
546         fprintf( file, "[%s]", p_parser->psz_object_name );
547         if( p_parser->psz_longname )
548             fprintf( file, " # %s\n\n", p_parser->psz_longname );
549         else
550             fprintf( file, "\n\n" );
551
552         for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
553              p_item < p_end;
554              p_item++ )
555         {
556             /* Do not save the new value in the configuration file
557              * if doing an autosave, and the item is not an "autosaved" one. */
558             bool b_retain = b_autosave && !p_item->b_autosave;
559
560             if ((p_item->i_type & CONFIG_HINT) /* ignore hint */
561              || p_item->b_removed              /* ignore deprecated option */
562              || p_item->b_unsaveable)          /* ignore volatile option */
563                 continue;
564
565             if (IsConfigIntegerType (p_item->i_type))
566             {
567                 int val = b_retain ? p_item->saved.i : p_item->value.i;
568                 if (p_item->i_type == CONFIG_ITEM_KEY)
569                 {
570                     char *psz_key = ConfigKeyToString (val);
571                     config_Write (file, p_item->psz_text, N_("key"),
572                                   val == p_item->orig.i,
573                                   p_item->psz_name, "%s",
574                                   psz_key ? psz_key : "");
575                     free (psz_key);
576                 }
577                 else
578                     config_Write (file, p_item->psz_text,
579                                   (p_item->i_type == CONFIG_ITEM_BOOL)
580                                       ? N_("boolean") : N_("integer"),
581                                   val == p_item->orig.i,
582                                   p_item->psz_name, "%d", val);
583                 p_item->saved.i = val;
584             }
585             else
586             if (IsConfigFloatType (p_item->i_type))
587             {
588                 float val = b_retain ? p_item->saved.f : p_item->value.f;
589                 config_Write (file, p_item->psz_text, N_("float"),
590                               val == p_item->orig.f,
591                               p_item->psz_name, "%f", val);
592                 p_item->saved.f = val;
593             }
594             else
595             {
596                 const char *psz_value = b_retain ? p_item->saved.psz
597                                                  : p_item->value.psz;
598                 bool modified;
599
600                 assert (IsConfigStringType (p_item->i_type));
601
602                 if (b_retain && (psz_value == NULL)) /* FIXME: hack */
603                     psz_value = p_item->orig.psz;
604
605                 modified =
606                     (psz_value != NULL)
607                         ? ((p_item->orig.psz != NULL)
608                             ? (strcmp (psz_value, p_item->orig.psz) != 0)
609                             : true)
610                         : (p_item->orig.psz != NULL);
611
612                 config_Write (file, p_item->psz_text, N_("string"),
613                               !modified, p_item->psz_name, "%s",
614                               psz_value ? psz_value : "");
615
616                 if ( !b_retain )
617                 {
618
619                     free ((char *)p_item->saved.psz);
620                     if( (psz_value && p_item->orig.psz &&
621                          strcmp( psz_value, p_item->orig.psz )) ||
622                         !psz_value || !p_item->orig.psz)
623                         p_item->saved.psz = strdupnull (psz_value);
624                     else
625                         p_item->saved.psz = NULL;
626                 }
627             }
628
629             if (!b_retain)
630                 p_item->b_dirty = false;
631         }
632     }
633
634     vlc_list_release( p_list );
635     if (loc != (locale_t)0)
636     {
637         uselocale (baseloc);
638         freelocale (loc);
639     }
640
641     /*
642      * Restore old settings from the config in file
643      */
644     fputs( p_bigbuffer, file );
645     free( p_bigbuffer );
646
647     fclose( file );
648     vlc_mutex_unlock( &priv->config_lock );
649
650     return 0;
651 }
652
653 int config_AutoSaveConfigFile( vlc_object_t *p_this )
654 {
655     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
656     vlc_list_t *p_list;
657     int i_index, i_count;
658
659     assert( p_this );
660
661     /* Check if there's anything to save */
662     vlc_mutex_lock( &priv->config_lock );
663     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
664     i_count = p_list->i_count;
665     for( i_index = 0; i_index < i_count; i_index++ )
666     {
667         module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object ;
668         module_config_t *p_item, *p_end;
669
670         if( !p_parser->i_config_items ) continue;
671
672         for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
673              p_item < p_end;
674              p_item++ )
675         {
676             if( p_item->b_autosave && p_item->b_dirty ) break;
677         }
678         if( p_item < p_end ) break;
679     }
680     vlc_list_release( p_list );
681     vlc_mutex_unlock( &priv->config_lock );
682
683     if( i_index == i_count ) return VLC_SUCCESS;
684     return SaveConfigFile( p_this, 0, true );
685 }
686
687 int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
688 {
689     return SaveConfigFile( p_this, psz_module_name, false );
690 }
691
692 /**
693  * Get the user's configuration file when given with the --config option
694  */
695 char *config_GetCustomConfigFile( libvlc_int_t *p_libvlc )
696 {
697     char *psz_configfile = config_GetPsz( p_libvlc, "config" );
698     if( psz_configfile != NULL )
699     {
700         if( psz_configfile[0] == '~' && psz_configfile[1] == '/' )
701         {
702             /* This is incomplete: we should also support the ~cmassiot/ syntax */
703             char *psz_buf;
704             if( asprintf( &psz_buf, "%s/%s", p_libvlc->psz_homedir,
705                           psz_configfile + 2 ) == -1 )
706             {
707                 free( psz_configfile );
708                 return NULL;
709             }
710             free( psz_configfile );
711             psz_configfile = psz_buf;
712         }
713     }
714     return psz_configfile;
715 }
716
717 int ConfigStringToKey( const char *psz_key )
718 {
719     int i_key = 0;
720     unsigned int i;
721     const char *psz_parser = strchr( psz_key, '-' );
722     while( psz_parser && psz_parser != psz_key )
723     {
724         for( i = 0; i < sizeof(vlc_modifiers) / sizeof(key_descriptor_t); i++ )
725         {
726             if( !strncasecmp( vlc_modifiers[i].psz_key_string, psz_key,
727                               strlen( vlc_modifiers[i].psz_key_string ) ) )
728             {
729                 i_key |= vlc_modifiers[i].i_key_code;
730             }
731         }
732         psz_key = psz_parser + 1;
733         psz_parser = strchr( psz_key, '-' );
734     }
735     for( i = 0; i < sizeof(vlc_keys) / sizeof( key_descriptor_t ); i++ )
736     {
737         if( !strcasecmp( vlc_keys[i].psz_key_string, psz_key ) )
738         {
739             i_key |= vlc_keys[i].i_key_code;
740             break;
741         }
742     }
743     return i_key;
744 }
745
746 char *ConfigKeyToString( int i_key )
747 {
748     char *psz_key = malloc( 100 );
749     char *p;
750     size_t index;
751
752     if ( !psz_key )
753     {
754         return NULL;
755     }
756     *psz_key = '\0';
757     p = psz_key;
758
759     for( index = 0; index < (sizeof(vlc_modifiers) / sizeof(key_descriptor_t));
760          index++ )
761     {
762         if( i_key & vlc_modifiers[index].i_key_code )
763         {
764             p += sprintf( p, "%s-", vlc_modifiers[index].psz_key_string );
765         }
766     }
767     for( index = 0; index < (sizeof(vlc_keys) / sizeof( key_descriptor_t));
768          index++)
769     {
770         if( (int)( i_key & ~KEY_MODIFIER ) == vlc_keys[index].i_key_code )
771         {
772             p += sprintf( p, "%s", vlc_keys[index].psz_key_string );
773             break;
774         }
775     }
776     return psz_key;
777 }
778