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