📄 configuration.c
字号:
&& (p_line[0] != '\t') ) { strcpy( p_index, p_line ); p_index += strlen( p_line ); } } if( file ) fclose( file ); /* * Save module config in file */ file = utf8_fopen( psz_filename, "wt" ); if( !file ) { msg_Warn( p_this, "could not open config file %s for writing", psz_filename ); free( psz_filename ); vlc_list_release( p_list ); vlc_mutex_unlock( &p_this->p_vlc->config_lock ); return -1; } #ifdef WIN32 /* Ugly kludge to not save --started-from-file (and not break the ABI). * See [17898] and #871 */ /* Just use the first mofule found*/ config_PutInt( (module_t *)p_list->p_values[0].p_object, "started-from-file", 0 );#endif fprintf( file, "\xEF\xBB\xBF###\n### " COPYRIGHT_MESSAGE "\n###\n\n" "###\n### lines begining with a '#' character are comments\n###\n\n" ); /* Look for the selected module, if NULL then save everything */ for( i_index = 0; i_index < p_list->i_count; i_index++ ) { p_parser = (module_t *)p_list->p_values[i_index].p_object ; if( psz_module_name && strcmp( psz_module_name, p_parser->psz_object_name ) ) continue; if( !p_parser->i_config_items ) continue; if( psz_module_name ) msg_Dbg( p_this, "saving config for module \"%s\"", p_parser->psz_object_name ); fprintf( file, "[%s]", p_parser->psz_object_name ); if( p_parser->psz_longname ) fprintf( file, " # %s\n\n", p_parser->psz_longname ); else fprintf( file, "\n\n" ); for( p_item = p_parser->p_config; p_item->i_type != CONFIG_HINT_END; p_item++ ) { char *psz_key; int i_value = p_item->i_value; float f_value = p_item->f_value; char *psz_value = p_item->psz_value; if( p_item->i_type & CONFIG_HINT ) /* ignore hints */ continue; /* Ignore deprecated options */ if( p_item->psz_current ) continue; if( b_autosave && !p_item->b_autosave ) { i_value = p_item->i_value_saved; f_value = p_item->f_value_saved; psz_value = p_item->psz_value_saved; if( !psz_value ) psz_value = p_item->psz_value_orig; } else { p_item->b_dirty = VLC_FALSE; } switch( p_item->i_type ) { case CONFIG_ITEM_BOOL: case CONFIG_ITEM_INTEGER: if( p_item->psz_text ) fprintf( file, "# %s (%s)\n", p_item->psz_text, (p_item->i_type == CONFIG_ITEM_BOOL) ? _("boolean") : _("integer") ); if( i_value == p_item->i_value_orig ) fputc( '#', file ); fprintf( file, "%s=%i\n", p_item->psz_name, i_value ); p_item->i_value_saved = i_value; break; case CONFIG_ITEM_KEY: if( p_item->psz_text ) fprintf( file, "# %s (%s)\n", p_item->psz_text, _("key") ); if( i_value == p_item->i_value_orig ) fputc( '#', file ); psz_key = ConfigKeyToString( i_value ); fprintf( file, "%s=%s\n", p_item->psz_name, psz_key ? psz_key : "" ); if ( psz_key ) free( psz_key ); p_item->i_value_saved = i_value; break; case CONFIG_ITEM_FLOAT: if( p_item->psz_text ) fprintf( file, "# %s (%s)\n", p_item->psz_text, _("float") ); if( f_value == p_item->f_value_orig ) fputc( '#', file ); fprintf( file, "%s=%f\n", p_item->psz_name, (double)f_value ); p_item->f_value_saved = f_value; break; default: if( p_item->psz_text ) fprintf( file, "# %s (%s)\n", p_item->psz_text, _("string") ); if( (!psz_value && !p_item->psz_value_orig) || (psz_value && p_item->psz_value_orig && !strcmp( psz_value, p_item->psz_value_orig )) ) fputc( '#', file ); fprintf( file, "%s=%s\n", p_item->psz_name, psz_value ? psz_value : "" ); if( b_autosave && !p_item->b_autosave ) break; if( p_item->psz_value_saved ) free( p_item->psz_value_saved ); p_item->psz_value_saved = 0; if( (psz_value && p_item->psz_value_orig && strcmp( psz_value, p_item->psz_value_orig )) || !psz_value || !p_item->psz_value_orig) p_item->psz_value_saved = psz_value ? strdup(psz_value):0; } } fputc( '\n', file ); } vlc_list_release( p_list ); /* * Restore old settings from the config in file */ fputs( p_bigbuffer, file ); free( p_bigbuffer ); fclose( file ); free( psz_filename ); vlc_mutex_unlock( &p_this->p_vlc->config_lock ); return 0;}int config_AutoSaveConfigFile( vlc_object_t *p_this ){ vlc_list_t *p_list; module_t *p_parser; module_config_t *p_item; int i_index, i_count; /* Check if there's anything to save */ vlc_mutex_lock( &p_this->p_vlc->config_lock ); p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); i_count = p_list->i_count; for( i_index = 0; i_index < i_count; i_index++ ) { p_parser = (module_t *)p_list->p_values[i_index].p_object ; if( !p_parser->i_config_items ) continue; for( p_item = p_parser->p_config; p_item->i_type != CONFIG_HINT_END; p_item++ ) { if( p_item->b_autosave && p_item->b_dirty ) break; } if( p_item->i_type != CONFIG_HINT_END ) break; } vlc_list_release( p_list ); vlc_mutex_unlock( &p_this->p_vlc->config_lock ); if( i_index == i_count ) return VLC_SUCCESS; return SaveConfigFile( p_this, 0, VLC_TRUE );}int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name ){ return SaveConfigFile( p_this, psz_module_name, VLC_FALSE );}/***************************************************************************** * config_LoadCmdLine: parse command line ***************************************************************************** * Parse command line for configuration options. * Now that the module_bank has been initialized, we can dynamically * generate the longopts structure used by getops. We have to do it this way * because we don't know (and don't want to know) in advance the configuration * options used (ie. exported) by each module. *****************************************************************************/int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], vlc_bool_t b_ignore_errors ){ int i_cmd, i_index, i_opts, i_shortopts, flag, i_verbose = 0; module_t *p_parser; vlc_list_t *p_list; module_config_t *p_item; struct option *p_longopts; int i_modules_index; /* Short options */ module_config_t *pp_shortopts[256]; char *psz_shortopts; /* Set default configuration and copy arguments */ p_this->p_vlc->i_argc = *pi_argc; p_this->p_vlc->ppsz_argv = ppsz_argv;#ifdef __APPLE__ /* When VLC.app is run by double clicking in Mac OS X, the 2nd arg * is the PSN - process serial number (a unique PID-ish thingie) * still ok for real Darwin & when run from command line */ if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) ) /* for example -psn_0_9306113 */ { /* GDMF!... I can't do this or else the MacOSX window server will * not pick up the PSN and not register the app and we crash... * hence the following kludge otherwise we'll get confused w/ argv[1] * being an input file name */#if 0 ppsz_argv[ 1 ] = NULL;#endif *pi_argc = *pi_argc - 1; pi_argc--; return 0; }#endif /* List all modules */ p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); /* * Generate the longopts and shortopts structures used by getopt_long */ i_opts = 0; for( i_modules_index = 0; i_modules_index < p_list->i_count; i_modules_index++ ) { p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ; /* count the number of exported configuration options (to allocate * longopts). We also need to allocate space for two options when * dealing with boolean to allow for --foo and --no-foo */ i_opts += p_parser->i_config_items + 2 * p_parser->i_bool_items; } p_longopts = malloc( sizeof(struct option) * (i_opts + 1) ); if( p_longopts == NULL ) { msg_Err( p_this, "out of memory" ); vlc_list_release( p_list ); return -1; } psz_shortopts = malloc( sizeof( char ) * (2 * i_opts + 1) ); if( psz_shortopts == NULL ) { msg_Err( p_this, "out of memory" ); free( p_longopts ); vlc_list_release( p_list ); return -1; } /* If we are requested to ignore errors, then we must work on a copy * of the ppsz_argv array, otherwise getopt_long will reorder it for * us, ignoring the arity of the options */ if( b_ignore_errors ) { ppsz_argv = (char**)malloc( *pi_argc * sizeof(char *) ); if( ppsz_argv == NULL ) { msg_Err( p_this, "out of memory" ); free( psz_shortopts ); free( p_longopts ); vlc_list_release( p_list ); return -1; } memcpy( ppsz_argv, p_this->p_vlc->ppsz_argv, *pi_argc * sizeof(char *) ); } i_shortopts = 0; for( i_index = 0; i_index < 256; i_index++ ) { pp_shortopts[i_index] = NULL; } /* Fill the p_longopts and psz_shortopts structures */ i_index = 0; for( i_modules_index = 0; i_modules_index < p_list->i_count; i_modules_index++ ) { p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ; if( !p_parser->i_config_items ) continue; for( p_item = p_parser->p_config; p_item->i_type != CONFIG_HINT_END; p_item++ ) { /* Ignore hints */ if( p_item->i_type & CONFIG_HINT ) continue; /* Add item to long options */ p_longopts[i_index].name = strdup( p_item->psz_name ); if( p_longopts[i_index].name == NULL ) continue; p_longopts[i_index].has_arg = (p_item->i_type == CONFIG_ITEM_BOOL)? no_argument : required_argument; p_longopts[i_index].flag = &flag; p_longopts[i_index].val = 0; i_index++; /* When dealing with bools we also need to add the --no-foo * option */ if( p_item->i_type == CONFIG_ITEM_BOOL ) { char *psz_name = malloc( strlen(p_item->psz_name) + 3 ); if( psz_name == NULL ) continue; strcpy( psz_name, "no" ); strcat( psz_name, p_item->psz_name ); p_longopts[i_index].name = psz_name; p_longopts[i_index].has_arg = no_argument; p_longopts[i_index].flag = &flag; p_longopts[i_index].val = 1; i_index++; psz_name = malloc( strlen(p_item->psz_name) + 4 ); if( psz_name == NULL ) continue; strcpy( psz_name, "no-" ); strcat( psz_name, p_item->psz_name ); p_longopts[i_index].name = psz_name; p_longopts[i_index].has_arg = no_argument; p_longopts[i_index].flag = &flag; p_longopts[i_index].val = 1; i_index++; } /* If item also has a short option, add it */ if( p_item->i_short ) { pp_shortopts[(int)p_item->i_short] = p_item; psz_shortopts[i_shortopts] = p_item->i_short; i_shortopts++; if( p_item->i_type != CONFIG_ITEM_BOOL ) { psz_shortopts[i_shortopts] = ':'; i_shortopts++; if( p_item->i_short == 'v' ) { psz_shortopts[i_shortopts] = ':'; i_shortopts++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -