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