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