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