# HG changeset patch # User alex # Date 1060792172 0 # Node ID 57bdcdb061d78f84fa8cf51ec04a408a7d2e5867 # Parent 27711ab2889f7f0124784b01d9027299ee4b674c Removed the historic cfgparser and switched full to the new config parser (altought some macros still remain for compatibility). As a side effect 90% of the warning messages are gone from the core. Things should be cleaner now and less confusing for newbies. diff -r 27711ab2889f -r 57bdcdb061d7 Gui/cfg.c --- a/Gui/cfg.c Wed Aug 13 16:01:53 2003 +0000 +++ b/Gui/cfg.c Wed Aug 13 16:29:32 2003 +0000 @@ -6,7 +6,8 @@ #include "../config.h" #include "../mp_msg.h" #include "../mplayer.h" -#include "../cfgparser.h" +#include "../m_config.h" +#include "../m_option.h" #ifdef USE_SETLOCALE #include @@ -73,7 +74,7 @@ extern int stop_xscreensaver; static m_config_t * gui_conf; -static config_t gui_opts[] = +static m_option_t gui_opts[] = { { "enable_audio_equ",>kEnableAudioEqualizer,CONF_TYPE_FLAG,0,0,1,NULL }, @@ -199,11 +200,7 @@ // -- read configuration mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[cfg] read config file: %s\n",cfg ); - gui_conf=m_config_new( -#ifndef NEW_CONFIG - play_tree_new() -#endif - ); + gui_conf=m_config_new(); m_config_register_options( gui_conf,gui_opts ); if ( m_config_parse_config_file( gui_conf,cfg ) < 0 ) { @@ -283,33 +280,12 @@ { for ( i=0;gui_opts[i].name;i++ ) { -#ifdef NEW_CONFIG char* v = m_option_print(&gui_opts[i],gui_opts[i].p); if(v) { fprintf( f,"%s = \"%s\"\n",gui_opts[i].name, v); free(v); } else if((int)v == -1) mp_msg(MSGT_GPLAYER,MSGL_WARN,"Unable to save the %s option\n"); -#else - switch ( gui_opts[i].type ) - { - case CONF_TYPE_INT: - case CONF_TYPE_FLAG: fprintf( f,"%s = %d\n",gui_opts[i].name,*( (int *)gui_opts[i].p ) ); break; - case CONF_TYPE_FLOAT: fprintf( f,"%s = %f\n",gui_opts[i].name,*( (float *)gui_opts[i].p ) ); break; - case CONF_TYPE_STRING: - { - char * tmp = *( (char **)gui_opts[i].p ); - if ( tmp && tmp[0] ) fprintf( f,"%s = \"%s\"\n",gui_opts[i].name,tmp ); - break; - } - case CONF_TYPE_STRING_LIST: - { - char ** tmp = *( (char ***)gui_opts[i].p ); - if ( tmp && tmp[0] && tmp[0][0] ) fprintf( f,"%s = \"%s\"\n",gui_opts[i].name,tmp[0] ); - break; - } - } -#endif } fclose( f ); } diff -r 27711ab2889f -r 57bdcdb061d7 Gui/interface.c --- a/Gui/interface.c Wed Aug 13 16:01:53 2003 +0000 +++ b/Gui/interface.c Wed Aug 13 16:29:32 2003 +0000 @@ -39,14 +39,8 @@ #include "../libmpdemux/stheader.h" #include "../libmpcodecs/dec_video.h" - -#ifdef NEW_CONFIG - #include "../m_option.h" - #include "../m_config.h" -#else - #include "../cfgparser.h" -#endif -#include "../cfg-mplayer-def.h" +#include "../m_config.h" +#include "../m_option.h" guiInterface_t guiIntfStruct; int guiWinID=-1; diff -r 27711ab2889f -r 57bdcdb061d7 Makefile --- a/Makefile Wed Aug 13 16:01:53 2003 +0000 +++ b/Makefile Wed Aug 13 16:29:32 2003 +0000 @@ -22,7 +22,7 @@ DO_MAKE = @ for i in $(SUBDIRS); do $(MAKE) -C $$i $@; done endif -SRCS_COMMON = cpudetect.c codec-cfg.c cfgparser.c spudec.c playtree.c playtreeparser.c asxparser.c vobsub.c subreader.c sub_cc.c find_sub.c m_config.c m_option.c parser-cfg.c m_struct.c +SRCS_COMMON = cpudetect.c codec-cfg.c spudec.c playtree.c playtreeparser.c asxparser.c vobsub.c subreader.c sub_cc.c find_sub.c m_config.c m_option.c parser-cfg.c m_struct.c SRCS_MENCODER = mencoder.c mp_msg-mencoder.c $(SRCS_COMMON) libao2/afmt.c divx4_vbr.c libvo/aclib.c libvo/osd.c libvo/sub.c libvo/font_load.c libvo/font_load_ft.c xvid_vbr.c parser-mecmd.c SRCS_MPLAYER = mplayer.c mp_msg.c $(SRCS_COMMON) mixer.c parser-mpcmd.c diff -r 27711ab2889f -r 57bdcdb061d7 cfg-common.h --- a/cfg-common.h Wed Aug 13 16:01:53 2003 +0000 +++ b/cfg-common.h Wed Aug 13 16:29:32 2003 +0000 @@ -266,9 +266,9 @@ /* defined in libmpdemux: */ extern int hr_mp3_seek; -extern config_t demux_rawaudio_opts[]; -extern config_t demux_rawvideo_opts[]; -extern config_t cdda_opts[]; +extern m_option_t demux_rawaudio_opts[]; +extern m_option_t demux_rawvideo_opts[]; +extern m_option_t cdda_opts[]; extern char* audio_stream; extern char* sub_stream; @@ -283,7 +283,7 @@ #endif #ifdef USE_TV -struct config tvopts_conf[]={ +m_option_t tvopts_conf[]={ {"on", "-tv on is deprecated, use tv:// instead\n", CONF_TYPE_PRINT, 0, 0, 0, NULL}, #ifdef HAVE_TV_BSDBT848 {"immediatemode", &tv_param_immediate, CONF_TYPE_FLAG, 0, 0, 0, NULL}, @@ -345,7 +345,7 @@ extern float sws_chr_sharpen; extern float sws_lum_sharpen; -struct config scaler_filter_conf[]={ +m_option_t scaler_filter_conf[]={ {"lgb", &sws_lum_gblur, CONF_TYPE_FLOAT, 0, 0, 100.0, NULL}, {"cgb", &sws_chr_gblur, CONF_TYPE_FLOAT, 0, 0, 100.0, NULL}, {"cvs", &sws_chr_vshift, CONF_TYPE_INT, 0, 0, 0, NULL}, @@ -366,7 +366,7 @@ extern int vivo_param_vformat; extern char *dvd_device, *cdrom_device; -struct config vivoopts_conf[]={ +m_option_t vivoopts_conf[]={ {"version", &vivo_param_version, CONF_TYPE_INT, 0, 0, 0, NULL}, /* audio options */ {"acodec", &vivo_param_acodec, CONF_TYPE_STRING, 0, 0, 0, NULL}, @@ -387,7 +387,7 @@ extern m_obj_settings_t* vf_settings; extern m_obj_list_t vf_obj_list; -struct config mfopts_conf[]={ +m_option_t mfopts_conf[]={ {"on", "-mf on is deprecated, use mf://files instead\n", CONF_TYPE_PRINT, 0, 0, 1, NULL}, {"w", &mf_w, CONF_TYPE_INT, 0, 0, 0, NULL}, {"h", &mf_h, CONF_TYPE_INT, 0, 0, 0, NULL}, @@ -400,18 +400,20 @@ #include "libaf/af.h" extern af_cfg_t af_cfg; // Audio filter configuration, defined in libmpcodecs/dec_audio.c -struct config audio_filter_conf[]={ +m_option_t audio_filter_conf[]={ {"list", &af_cfg.list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, {"force", &af_cfg.force, CONF_TYPE_INT, CONF_RANGE, 0, 7, NULL}, {NULL, NULL, 0, 0, 0, 0, NULL} }; #ifdef USE_LIBAVCODEC -extern struct config lavc_decode_opts_conf[]; +extern m_option_t lavc_decode_opts_conf[]; #endif #ifdef HAVE_XVID -extern struct config xvid_dec_opts[]; +extern m_option_t xvid_dec_opts[]; #endif +int dvd_parse_chapter_range(m_option_t*, const char*); + #endif diff -r 27711ab2889f -r 57bdcdb061d7 cfg-mencoder.h --- a/cfg-mencoder.h Wed Aug 13 16:01:53 2003 +0000 +++ b/cfg-mencoder.h Wed Aug 13 16:29:32 2003 +0000 @@ -17,11 +17,11 @@ extern char *pp_help; #ifdef HAVE_DIVX4ENCORE -extern struct config divx4opts_conf[]; +extern m_option_t divx4opts_conf[]; #endif #ifdef HAVE_MP3LAME -struct config lameopts_conf[]={ +m_option_t lameopts_conf[]={ {"q", &lame_param_quality, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL}, {"aq", &lame_param_algqual, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL}, {"vbr", &lame_param_vbr, CONF_TYPE_INT, CONF_RANGE, 0, vbr_max_indicator, NULL}, @@ -45,20 +45,20 @@ #endif #ifdef USE_LIBAVCODEC -extern struct config lavcopts_conf[]; +extern m_option_t lavcopts_conf[]; #endif #ifdef USE_WIN32DLL -extern struct config vfwopts_conf[]; +extern m_option_t vfwopts_conf[]; #endif #ifdef HAVE_XVID -extern struct config xvidencopts_conf[]; +extern m_option_t xvidencopts_conf[]; #endif -extern struct config nuvopts_conf[]; +extern m_option_t nuvopts_conf[]; -struct config ovc_conf[]={ +m_option_t ovc_conf[]={ {"copy", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_COPY, NULL}, {"frameno", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_FRAMENO, NULL}, {"divx4", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_DIVX4, NULL}, @@ -99,7 +99,7 @@ {NULL, NULL, 0, 0, 0, 0, NULL} }; -struct config oac_conf[]={ +m_option_t oac_conf[]={ {"copy", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_COPY, NULL}, {"pcm", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_PCM, NULL}, #ifdef HAVE_MP3LAME @@ -117,7 +117,7 @@ {NULL, NULL, 0, 0, 0, 0, NULL} }; -struct config info_conf[]={ +m_option_t info_conf[]={ {"name", &info_name, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"artist", &info_artist, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"genre", &info_genre, CONF_TYPE_STRING, 0, 0, 0, NULL}, @@ -137,7 +137,7 @@ {NULL, NULL, 0, 0, 0, 0, NULL} }; -struct config of_conf[]={ +m_option_t of_conf[]={ {"avi", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_AVI, NULL}, {"mpeg", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_MPEG, NULL}, {"help", "\nAvailable output formats:\n" @@ -147,7 +147,7 @@ {NULL, NULL, 0, 0, 0, 0, NULL} }; -static config_t mencoder_opts[]={ +m_option_t mencoder_opts[]={ /* name, pointer, type, flags, min, max */ {"include", cfg_include, CONF_TYPE_FUNC_PARAM, CONF_NOSAVE, 0, 0, NULL}, /* this must be the first!!! */ diff -r 27711ab2889f -r 57bdcdb061d7 cfg-mplayer.h --- a/cfg-mplayer.h Wed Aug 13 16:01:53 2003 +0000 +++ b/cfg-mplayer.h Wed Aug 13 16:29:32 2003 +0000 @@ -86,17 +86,17 @@ #endif #ifdef HAVE_AA -extern int vo_aa_parseoption(struct config * conf, char *opt, char * param); -extern void vo_aa_revertoption(config_t* opt,char* param); +extern int vo_aa_parseoption(m_option_t* conf, char *opt, char * param); +extern void vo_aa_revertoption(m_option_t* opt,char* param); #endif #ifdef HAVE_ZR -extern int vo_zr_parseoption(struct config * conf, char *opt, char * param); -extern void vo_zr_revertoption(config_t* opt,char* pram); +extern int vo_zr_parseoption(m_option_t* conf, char *opt, char * param); +extern void vo_zr_revertoption(m_option_t* opt,char* pram); #endif #ifdef HAVE_DXR2 -extern config_t dxr2_opts[]; +extern m_option_t dxr2_opts[]; #endif #ifdef STREAMING_LIVE_DOT_COM @@ -126,7 +126,7 @@ extern float monitor_aspect; /* Options related to audio out plugins */ -struct config ao_plugin_conf[]={ +m_option_t ao_plugin_conf[]={ {"list", &ao_plugin_cfg.plugin_list, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"delay", &ao_plugin_cfg.pl_delay_len, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, {"format", &ao_plugin_cfg.pl_format_type, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, @@ -138,7 +138,7 @@ }; #ifdef HAVE_JPEG -struct config jpeg_conf[]={ +m_option_t jpeg_conf[]={ {"progressive", &jpeg_progressive_mode, CONF_TYPE_FLAG, 0, 0, 1, NULL}, {"noprogressive", &jpeg_progressive_mode, CONF_TYPE_FLAG, 0, 1, 0, NULL}, {"baseline", &jpeg_baseline, CONF_TYPE_FLAG, 0, 0, 1, NULL}, @@ -169,7 +169,7 @@ * by Folke */ -static config_t mplayer_opts[]={ +m_option_t mplayer_opts[]={ /* name, pointer, type, flags, min, max */ {"include", cfg_include, CONF_TYPE_FUNC_PARAM, CONF_NOSAVE, 0, 0, NULL}, /* this don't need anymore to be the first!!! */ diff -r 27711ab2889f -r 57bdcdb061d7 cfgparser.c --- a/cfgparser.c Wed Aug 13 16:01:53 2003 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1548 +0,0 @@ -/* - * command line and config file parser - * by Szabolcs Berecz - * (C) 2001 - * - * subconfig support by alex - */ - -//#define DEBUG - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "config.h" - -#ifndef NEW_CONFIG - -#ifdef USE_SETLOCALE -#include -#endif - -#include "mp_msg.h" - -#define COMMAND_LINE 0 -#define CONFIG_FILE 1 - -#define LIST_SEPARATOR ',' - -#define CONFIG_GLOBAL (1<<0) -#define CONFIG_RUNNING (1<<1) - -#define SET_GLOBAL(c) (c->flags |= CONFIG_GLOBAL) -#ifdef GLOBAL_OPTIONS_ONLY -#define UNSET_GLOBAL(c) -#else -#define UNSET_GLOBAL(c) (c->flags &= (!CONFIG_GLOBAL)) -#endif -#define IS_GLOBAL(c) (c->flags & CONFIG_GLOBAL) -#define SET_RUNNING(c) (c->flags |= CONFIG_RUNNING) -#define IS_RUNNING(c) (c->flags & CONFIG_RUNNING) - -#define MAX_RECURSION_DEPTH 8 - -#ifdef MP_DEBUG -#include -#endif - -#include "cfgparser.h" -#include "playtree.h" - -static void m_config_list_options(m_config_t *config); -static void m_config_error(int err,char* opt,char* val); - -static void -m_config_save_option(m_config_t* config, config_t* conf,char* opt, char *param) { - config_save_t* save; - int sl=0; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(config->cs_level >= 0); - assert(conf != NULL); - assert(opt != NULL); - assert( ! (conf->flags & CONF_NOSAVE)); -#endif - - switch(conf->type) { - case CONF_TYPE_PRINT : - case CONF_TYPE_PRINT_INDIRECT : - case CONF_TYPE_SUBCONFIG : - return; - default : - ; - } - - mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Saving option %s\n",opt); - - save = config->config_stack[config->cs_level]; - - if(save) { - for(sl = 0; save[sl].opt != NULL; sl++){ - // Check to not save the same arg two times - if(save[sl].opt == conf && (save[sl].opt_name == NULL || strcasecmp(save[sl].opt_name,opt) == 0)) - break; - } - if(save[sl].opt) - return; - } - - save = (config_save_t*)realloc(save,(sl+2)*sizeof(config_save_t)); - if(save == NULL) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",(sl+2)*sizeof(config_save_t),strerror(errno)); - return; - } - memset(&save[sl],0,2*sizeof(config_save_t)); - save[sl].opt = conf; - - switch(conf->type) { - case CONF_TYPE_FLAG : - case CONF_TYPE_INT : - save[sl].param.as_int = *((int*)conf->p); - break; - case CONF_TYPE_FLOAT : - save[sl].param.as_float = *((float*)conf->p); - break; - case CONF_TYPE_STRING : - save[sl].param.as_pointer = *((char**)conf->p); - break; - case CONF_TYPE_FUNC_FULL : - if(strcasecmp(conf->name,opt) != 0) save->opt_name = strdup(opt); - case CONF_TYPE_FUNC_PARAM : - if(param) - save->param.as_pointer = strdup(param); - case CONF_TYPE_FUNC : - break; - case CONF_TYPE_STRING_LIST : - save[sl].param.as_pointer = *((char***)conf->p); - break; - case CONF_TYPE_POSITION : - save[sl].param.as_off_t = *((off_t*)conf->p); - break; - default : - mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Should never append in m_config_save_option : conf->type=%d\n",conf->type); - } - - config->config_stack[config->cs_level] = save; -} - -static int -m_config_revert_option(m_config_t* config, config_save_t* save) { - char* arg = NULL; - config_save_t* iter=NULL; - int i=-1; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(config->cs_level >= 0); - assert(save != NULL); -#endif - - - arg = save->opt_name ? save->opt_name : save->opt->name; - mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Reverting option %s\n",arg); - - if(save->opt->default_func) - save->opt->default_func(save->opt,arg); - - switch(save->opt->type) { - case CONF_TYPE_FLAG : - case CONF_TYPE_INT : - *((int*)save->opt->p) = save->param.as_int; - break; - case CONF_TYPE_FLOAT : - *((float*)save->opt->p) = save->param.as_float; - break; - case CONF_TYPE_STRING : - *((char**)save->opt->p) = save->param.as_pointer; - break; - case CONF_TYPE_STRING_LIST : - *((char***)save->opt->p) = save->param.as_pointer; - break; - case CONF_TYPE_FUNC_PARAM : - case CONF_TYPE_FUNC_FULL : - case CONF_TYPE_FUNC : - if(config->cs_level > 0) { - for(i = config->cs_level - 1 ; i >= 0 ; i--){ - if(config->config_stack[i] == NULL) continue; - for(iter = config->config_stack[i]; iter != NULL && iter->opt != NULL ; iter++) { - if(iter->opt == save->opt && - ((save->param.as_pointer == NULL || iter->param.as_pointer == NULL) || strcasecmp(save->param.as_pointer,iter->param.as_pointer) == 0) && - (save->opt_name == NULL || - (iter->opt_name && strcasecmp(save->opt_name,iter->opt_name)))) break; - } - } - } - free(save->param.as_pointer); - if(save->opt_name) free(save->opt_name); - save->opt_name = save->param.as_pointer = NULL; - if(i < 0) break; - arg = iter->opt_name ? iter->opt_name : iter->opt->name; - switch(iter->opt->type) { - case CONF_TYPE_FUNC : - if ((((cfg_func_t) iter->opt->p)(iter->opt)) < 0) - return -1; - break; - case CONF_TYPE_FUNC_PARAM : - if (iter->param.as_pointer == NULL) { - mp_msg(MSGT_CFGPARSER,MSGL_ERR,"We lost param for option %s?\n",iter->opt->name); - return -1; - } - if ((((cfg_func_param_t) iter->opt->p)(iter->opt, (char*)iter->param.as_pointer)) < 0) - return -1; - break; - case CONF_TYPE_FUNC_FULL : - if (iter->param.as_pointer != NULL && ((char*)iter->param.as_pointer)[0]=='-'){ - if( ((cfg_func_arg_param_t) iter->opt->p)(iter->opt, arg, NULL) < 0) - return -1; - }else { - if (((cfg_func_arg_param_t) save->opt->p)(iter->opt, arg, (char*)iter->param.as_pointer) < 0) - return -1; - - } - break; - } - break; - case CONF_TYPE_POSITION : - *((off_t*)save->opt->p) = save->param.as_off_t; - break; - default : - mp_msg(MSGT_CFGPARSER,MSGL_WARN,"Why do we reverse this : name=%s type=%d ?\n",save->opt->name,save->opt->type); - } - - return 1; -} - -void -m_config_push(m_config_t* config) { - -#ifdef MP_DEBUG - assert(config != NULL); - assert(config->cs_level >= 0); -#endif - - config->cs_level++; - config->config_stack = (config_save_t**)realloc(config->config_stack ,sizeof(config_save_t*)*(config->cs_level+1)); - if(config->config_stack == NULL) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(config_save_t*)*(config->cs_level+1),strerror(errno)); - config->cs_level = -1; - return; - } - config->config_stack[config->cs_level] = NULL; - mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config pushed level=%d\n",config->cs_level); -} - -int -m_config_pop(m_config_t* config) { - int i,ret= 1; - config_save_t* cs; - -#ifdef MP_DEBUG - assert(config != NULL); - //assert(config->cs_level > 0); -#endif - - if(config->config_stack[config->cs_level] != NULL) { - cs = config->config_stack[config->cs_level]; - for(i=0; cs[i].opt != NULL ; i++ ) { - if (m_config_revert_option(config,&cs[i]) < 0) - ret = -1; - } - free(config->config_stack[config->cs_level]); - } - config->config_stack = (config_save_t**)realloc(config->config_stack ,sizeof(config_save_t*)*config->cs_level); - config->cs_level--; - if(config->cs_level > 0 && config->config_stack == NULL) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(config_save_t*)*config->cs_level,strerror(errno)); - config->cs_level = -1; - return -1; - } - mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Config poped level=%d\n",config->cs_level); - return ret; -} - -m_config_t* -m_config_new(play_tree_t* pt) { - m_config_t* config; - -#ifdef MP_DEBUG - assert(pt != NULL); -#endif - - config = (m_config_t*)calloc(1,sizeof(m_config_t)); - if(config == NULL) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(m_config_t),strerror(errno)); - return NULL; - } - config->config_stack = (config_save_t**)calloc(1,sizeof(config_save_t*)); - if(config->config_stack == NULL) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(config_save_t*),strerror(errno)); - free(config); - return NULL; - } - SET_GLOBAL(config); // We always start with global options - config->pt = pt; - return config; -} - -void -m_config_free(m_config_t* config) { - -#ifdef MP_DEBUG - assert(config != NULL); -#endif - - free(config->opt_list); - free(config->config_stack); - free(config); -} - - -static int init_conf(m_config_t *config, int mode) -{ -#ifdef MP_DEBUG - assert(config != NULL); - assert(config->pt != NULL); - assert(config->last_entry == NULL || config->last_entry->parent == config->pt); - - if (mode != COMMAND_LINE && mode != CONFIG_FILE) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "init_conf: wrong mode!\n"); - return -1; - } -#endif - config->parser_mode = mode; - return 1; -} - -static int config_is_entry_option(m_config_t *config, char *opt, char *param) { - play_tree_t* entry = NULL; - -#ifdef MP_DEBUG - assert(config->pt != NULL); -#endif - - if(strcasecmp(opt,"playlist") == 0) { // We handle playlist here - if(!param) - return ERR_MISSING_PARAM; - entry = parse_playlist_file(param); - if(!entry) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Playlist parsing failed: %s\n",param); - return 1; - } - } - - if(! IS_RUNNING(config)) { - if(strcasecmp(opt,"vcd") == 0) { - char* s; - if(!param) - return ERR_MISSING_PARAM; - s = (char*)malloc((strlen(param) + 6 + 1)*sizeof(char)); - sprintf(s,"vcd://%s",param); - entry = play_tree_new(); - play_tree_add_file(entry,s); - free(s); - } else if(strcasecmp(opt,"dvd") == 0) { - char* s; - if(!param) - return ERR_MISSING_PARAM; - s = (char*)malloc((strlen(param) + 6 + 1)*sizeof(char)); - sprintf(s,"dvd://%s",param); - entry = play_tree_new(); - play_tree_add_file(entry,s); - free(s); - } else if(strcasecmp(opt,"tv") == 0) { - char *s,*pr,*prs; - char *ps,*pe,*channel=NULL; - char *as; - int on=0; - if(!param) - return ERR_MISSING_PARAM; - ps = param; - pe = strchr(param,':'); - pr = prs = (char*)malloc((strlen(param)+1)*sizeof(char)); - pr[0] = '\0'; - while(ps) { - if(!pe) - pe = ps + strlen(ps); - - as = strchr(ps,'='); - if(as && as[1] != '\0' && pe-as > 0) - as++; - else - as = NULL; - if( !as && pe-ps == 2 && strncasecmp("on",ps,2) == 0 ) - on = 1; - else if(as && as-ps == 8 && strncasecmp("channel",ps,6) == 0 && pe-as > 0) { - channel = (char*)realloc(channel,(pe-as+1)*sizeof(char)); - strncpy(channel,as,pe-as); - channel[pe-as] = '\0'; - } else if(pe-ps > 0) { - if(prs != pr) { - prs[0] = ':'; - prs++; - } - strncpy(prs,ps,pe-ps); - prs += pe-ps; - prs[0] = '\0'; - } - - if(pe[0] != '\0') { - ps = pe+1; - pe = strchr(ps,':'); - } else - ps = NULL; - } - - if(on) { - int l=5; - - if(channel) - l += strlen(channel); - s = (char*) malloc((l+1)*sizeof(char)); - if(channel) - sprintf(s,"tv://%s",channel); - else - sprintf(s,"tv://"); - entry = play_tree_new(); - play_tree_add_file(entry,s); - if(strlen(pr) > 0) - play_tree_set_param(entry,"tv",pr); - free(s); - } - free(pr); - if(channel) - free(channel); - - } - } - - if(entry) { - if(config->last_entry) - play_tree_append_entry(config->last_entry,entry); - else - play_tree_set_child(config->pt,entry); - config->last_entry = entry; - if(config->parser_mode == COMMAND_LINE) - UNSET_GLOBAL(config); - return 1; - } else - return 0; -} - - - -static int config_read_option(m_config_t *config,config_t** conf_list, char *opt, char *param) -{ - int i=0,nconf = 0; - long tmp_int; - off_t tmp_off; - double tmp_float; - int dummy; - int ret = -1; - char *endptr; - config_t* conf=NULL; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(conf_list != NULL); - assert(opt != NULL); -#endif - - mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "read_option: conf=%p opt='%s' param='%s'\n", - conf, opt, param); - for(nconf = 0 ; conf_list[nconf] != NULL; nconf++) { - conf = conf_list[nconf]; - for (i = 0; conf[i].name != NULL; i++) { - int namelength; - /* allow 'aa*' in config.name */ - namelength=strlen(conf[i].name); - if ( (conf[i].name[namelength-1]=='*') && - !memcmp(opt, conf[i].name, namelength-1)) - goto option_found; - if (!strcasecmp(opt, conf[i].name)) - goto option_found; - } - } - if (config->parser_mode == CONFIG_FILE) - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "invalid option: %s\n",opt); - ret = ERR_NOT_AN_OPTION; - goto out; - option_found : - mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "read_option: name='%s' p=%p type=%d\n", - conf[i].name, conf[i].p, conf[i].type); - - if (conf[i].flags & CONF_NOCFG && config->parser_mode == CONFIG_FILE) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "this option can only be used on command line:\n", opt); - ret = ERR_NOT_AN_OPTION; - goto out; - } - if (conf[i].flags & CONF_NOCMD && config->parser_mode == COMMAND_LINE) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "this option can only be used in config file:\n", opt); - ret = ERR_NOT_AN_OPTION; - goto out; - } - ret = config_is_entry_option(config,opt,param); - if(ret != 0) - return ret; - else - ret = -1; - if(! IS_RUNNING(config) && ! IS_GLOBAL(config) && - ! (conf[i].flags & CONF_GLOBAL) && conf[i].type != CONF_TYPE_SUBCONFIG ) - m_config_push(config); - if( !(conf[i].flags & CONF_NOSAVE) && ! (conf[i].flags & CONF_GLOBAL) ) - m_config_save_option(config,&conf[i],opt,param); - switch (conf[i].type) { - case CONF_TYPE_FLAG: - /* flags need a parameter in config file */ - if (config->parser_mode == CONFIG_FILE) { - if (!strcasecmp(param, "yes") || /* any other language? */ - !strcasecmp(param, "ja") || - !strcasecmp(param, "si") || - !strcasecmp(param, "igen") || - !strcasecmp(param, "y") || - !strcasecmp(param, "j") || - !strcasecmp(param, "i") || - !strcmp(param, "1")) - *((int *) conf[i].p) = conf[i].max; - else if (!strcasecmp(param, "no") || - !strcasecmp(param, "nein") || - !strcasecmp(param, "nicht") || - !strcasecmp(param, "nem") || - !strcasecmp(param, "n") || - !strcmp(param, "0")) - *((int *) conf[i].p) = conf[i].min; - else { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "invalid parameter for flag: %s\n", param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - ret = 1; - } else { /* parser_mode == COMMAND_LINE */ - *((int *) conf[i].p) = conf[i].max; - ret = 0; - } - break; - case CONF_TYPE_INT: - if (param == NULL) - goto err_missing_param; - - tmp_int = strtol(param, &endptr, 0); - if (*endptr) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be an integer: %s\n", param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - - if (conf[i].flags & CONF_MIN) - if (tmp_int < conf[i].min) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be >= %d: %s\n", (int) conf[i].min, param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - - if (conf[i].flags & CONF_MAX) - if (tmp_int > conf[i].max) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be <= %d: %s\n", (int) conf[i].max, param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - - *((int *) conf[i].p) = tmp_int; - ret = 1; - break; - case CONF_TYPE_FLOAT: - if (param == NULL) - goto err_missing_param; - /* Use portable C locale for parsing floats: */ -#ifdef USE_SETLOCALE - setlocale(LC_NUMERIC, "C"); -#endif - tmp_float = strtod(param, &endptr); - - switch(*endptr) { - case ':': - case '/': - tmp_float /= strtod(endptr+1, &endptr); - default: - break; - } -#ifdef USE_SETLOCALE - setlocale(LC_NUMERIC, ""); -#endif - - if (*endptr) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be a floating point number" - " or a ratio (numerator[:/]denominator): %s\n", param); - ret = ERR_MISSING_PARAM; - goto out; - } - - if (conf[i].flags & CONF_MIN) - if (tmp_float < conf[i].min) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be >= %f: %s\n", conf[i].min, param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - - if (conf[i].flags & CONF_MAX) - if (tmp_float > conf[i].max) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be <= %f: %s\n", conf[i].max, param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - - *((float *) conf[i].p) = tmp_float; - ret = 1; - break; - case CONF_TYPE_STRING: - if (param == NULL) - goto err_missing_param; - - if (conf[i].flags & CONF_MIN) - if (strlen(param) < conf[i].min) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be >= %d chars: %s\n", - (int) conf[i].min, param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - - if (conf[i].flags & CONF_MAX) - if (strlen(param) > conf[i].max) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be <= %d chars: %s\n", - (int) conf[i].max, param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - *((char **) conf[i].p) = strdup(param); - ret = 1; - break; - case CONF_TYPE_STRING_LIST: - if (param == NULL) - goto err_missing_param; - else { - int n = 0,len; - char *ptr = param, *last_ptr, **res; - - while(ptr[0] != '\0') { - last_ptr = ptr; - ptr = strchr(ptr,LIST_SEPARATOR); - if(!ptr) { -// if(strlen(last_ptr) > 0) - n++; - break; - } - ptr++; - n++; - } - if(n == 0) - goto err_missing_param; - else if( (conf[i].flags & CONF_MIN && n < conf[i].min) || - (conf[i].flags & CONF_MAX && n > conf[i].max) ) { - ret = ERR_OUT_OF_RANGE; - goto out; - } - ret = 1; - res = malloc((n+2)*sizeof(char*)); - ptr = param; - n = 0; -// while(ptr[0] != '\0') { - while(1) { - last_ptr = ptr; - ptr = strchr(ptr,LIST_SEPARATOR); - if(!ptr) { - //if(strlen(last_ptr) > 0) - { - res[n] = strdup(last_ptr); - n++; - } - break; - } - len = ptr - last_ptr; - res[n] = (char*)malloc(len + 1); - if(len) strncpy(res[n],last_ptr,len); - res[n][len] = '\0'; - ptr++; - n++; - } - res[n] = NULL; - *((char ***) conf[i].p) = res; - } - break; - case CONF_TYPE_FUNC_PARAM: - if (param == NULL) - goto err_missing_param; - if ((((cfg_func_param_t) conf[i].p)(conf + i, param)) < 0) { - ret = ERR_FUNC_ERR; - goto out; - } - ret = 1; - break; - case CONF_TYPE_FUNC_FULL: - if (param!=NULL && param[0]=='-'){ - ret=((cfg_func_arg_param_t) conf[i].p)(conf + i, opt, NULL); - if (ret>=0) ret=0; - /* if we return >=0: param is processed again (if there is any) */ - }else{ - ret=((cfg_func_arg_param_t) conf[i].p)(conf + i, opt, param); - /* if we return 0: need no param, precess it again */ - /* if we return 1: accepted param */ - } - break; - case CONF_TYPE_FUNC: - if ((((cfg_func_t) conf[i].p)(conf + i)) < 0) { - ret = ERR_FUNC_ERR; - goto out; - } - ret = 0; - break; - case CONF_TYPE_SUBCONFIG: - { - char *subparam; - char *subopt; - int subconf_optnr; - config_t *subconf; - config_t *sublist[] = { NULL , NULL }; - char *token; - char *p; - - if (param == NULL) - goto err_missing_param; - - subparam = malloc(strlen(param)+1); - subopt = malloc(strlen(param)+1); - p = strdup(param); // In case that param is a static string (cf man strtok) - - subconf = conf[i].p; - sublist[0] = subconf; - for (subconf_optnr = 0; subconf[subconf_optnr].name != NULL; subconf_optnr++) - /* NOTHING */; - config->sub_conf = opt; - token = strtok(p, (char *)&(":")); - while(token) - { - int sscanf_ret; - /* clear out */ - subopt[0] = subparam[0] = 0; - - sscanf_ret = sscanf(token, "%[^=]=%[^:]", subopt, subparam); - - mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "token: '%s', i=%d, subopt='%s', subparam='%s' (ret: %d)\n", token, i, subopt, subparam, sscanf_ret); - switch(sscanf_ret) - { - case 1: - subparam[0] = 0; - case 2: - if ((ret = config_read_option(config,sublist, subopt, subparam)) < 0) - { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Subconfig parsing returned error: %d in token: %s\n", - ret, token); - goto out; - } - break; - default: - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid subconfig argument! ('%s')\n", token); - ret = ERR_NOT_AN_OPTION; - goto out; - } - token = strtok(NULL, (char *)&(":")); - } - config->sub_conf = NULL; - free(subparam); - free(subopt); - free(p); - ret = 1; - break; - } - case CONF_TYPE_PRINT: - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", (char *) conf[i].p); - exit(1); - case CONF_TYPE_PRINT_INDIRECT: - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", *(char **) conf[i].p); - exit(1); - case CONF_TYPE_POSITION: - if (param == NULL) - goto err_missing_param; - - if (sscanf(param, sizeof(off_t) == sizeof(int) ? - "%d%c" : "%lld%c", &tmp_off, (char *)&dummy) != 1) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be an integer: %s\n", param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - - if (conf[i].flags & CONF_MIN) - if (tmp_off < conf[i].min) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - (sizeof(off_t) == sizeof(int) ? - "parameter must be >= %d: %s\n" : - "parameter must be >= %lld: %s\n"), - (off_t) conf[i].min, param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - - if (conf[i].flags & CONF_MAX) - if (tmp_off > conf[i].max) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - (sizeof(off_t) == sizeof(int) ? - "parameter must be <= %d: %s\n" : - "parameter must be <= %lld: %s\n"), - (off_t) conf[i].max, param); - ret = ERR_OUT_OF_RANGE; - goto out; - } - - *((off_t *) conf[i].p) = tmp_off; - ret = 1; - break; - default: - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknown config type specified in conf-mplayer.h!\n"); - break; - } -out: - if(ret >= 0 && ! IS_RUNNING(config) && ! IS_GLOBAL(config) && ! (conf[i].flags & CONF_GLOBAL) && conf[i].type != CONF_TYPE_SUBCONFIG ) { - play_tree_t* dest = config->last_entry ? config->last_entry : config->last_parent; - char* o; -#ifdef MP_DEBUG - assert(dest != NULL); -#endif - if(config->sub_conf) { - o = (char*)malloc((strlen(config->sub_conf) + 1 + strlen(opt) + 1)*sizeof(char)); - sprintf(o,"%s:%s",config->sub_conf,opt); - } else - o =strdup(opt); - - if(ret == 0) - play_tree_set_param(dest,o,NULL); - else if(ret > 0) - play_tree_set_param(dest,o,param); - free(o); - m_config_pop(config); - } - return ret; -err_missing_param: - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "missing parameter for option: %s\n", opt); - ret = ERR_MISSING_PARAM; - goto out; -} - -int m_config_set_option(m_config_t *config,char *opt, char *param) { - char *e; -#ifdef MP_DEBUG - assert(config != NULL); - assert(config->opt_list != NULL); - assert(opt != NULL); -#endif - mp_msg(MSGT_CFGPARSER, MSGL_DBG2, "Setting option %s=%s\n",opt,param); - e = strchr(opt,':'); - if(e && e[1] != '\0') { - int ret; - config_t* opt_list[] = { NULL, NULL }; - char* s = (char*)malloc((e-opt+1)*sizeof(char)); - strncpy(s,opt,e-opt); - s[e-opt] = '\0'; - opt_list[0] = m_config_get_option_ptr(config,s); - if(!opt_list[0]) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR,"m_config_set_option %s=%s : no %s subconfig\n",opt,param,s); - free(s); - return ERR_NOT_AN_OPTION; - } - e++; - s = (char*)realloc(s,strlen(e) + 1); - strcpy(s,e); - ret = config_read_option(config,opt_list,s,param); - free(s); - return ret; - } - - return config_read_option(config,config->opt_list,opt,param); -} - -int m_config_parse_config_file(m_config_t *config, char *conffile) -{ -#define PRINT_LINENUM mp_msg(MSGT_CFGPARSER,MSGL_INFO,"%s(%d): ", conffile, line_num) -#define MAX_LINE_LEN 10000 -#define MAX_OPT_LEN 1000 -#define MAX_PARAM_LEN 1000 - FILE *fp; - char *line; - char opt[MAX_OPT_LEN + 1]; - char param[MAX_PARAM_LEN + 1]; - char c; /* for the "" and '' check */ - int tmp; - int line_num = 0; - int line_pos; /* line pos */ - int opt_pos; /* opt pos */ - int param_pos; /* param pos */ - int ret = 1; - int errors = 0; - -#ifdef MP_DEBUG - assert(config != NULL); - // assert(conf_list != NULL); -#endif - if (++config->recursion_depth > 1) - mp_msg(MSGT_CFGPARSER,MSGL_INFO,"Reading config file: %s", conffile); - - if (config->recursion_depth > MAX_RECURSION_DEPTH) { - mp_msg(MSGT_CFGPARSER,MSGL_ERR,": too deep 'include'. check your configfiles\n"); - ret = -1; - goto out; - } - - if (init_conf(config, CONFIG_FILE) == -1) { - ret = -1; - goto out; - } - - if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) { - mp_msg(MSGT_CFGPARSER,MSGL_FATAL,"\ncan't get memory for 'line': %s", strerror(errno)); - ret = -1; - goto out; - } - - if ((fp = fopen(conffile, "r")) == NULL) { - if (config->recursion_depth > 1) - mp_msg(MSGT_CFGPARSER,MSGL_ERR,": %s\n", strerror(errno)); - free(line); - ret = 0; - goto out; - } - if (config->recursion_depth > 1) - mp_msg(MSGT_CFGPARSER,MSGL_INFO,"\n"); - - while (fgets(line, MAX_LINE_LEN, fp)) { - if (errors >= 16) { - mp_msg(MSGT_CFGPARSER,MSGL_FATAL,"too many errors\n"); - goto out; - } - - line_num++; - line_pos = 0; - - /* skip whitespaces */ - while (isspace(line[line_pos])) - ++line_pos; - - /* EOL / comment */ - if (line[line_pos] == '\0' || line[line_pos] == '#') - continue; - - /* read option. */ - for (opt_pos = 0; isprint(line[line_pos]) && - line[line_pos] != ' ' && - line[line_pos] != '#' && - line[line_pos] != '='; /* NOTHING */) { - opt[opt_pos++] = line[line_pos++]; - if (opt_pos >= MAX_OPT_LEN) { - PRINT_LINENUM; - mp_msg(MSGT_CFGPARSER,MSGL_ERR,"too long option\n"); - errors++; - ret = -1; - goto nextline; - } - } - if (opt_pos == 0) { - PRINT_LINENUM; - mp_msg(MSGT_CFGPARSER,MSGL_ERR,"parse error\n"); - ret = -1; - errors++; - continue; - } - opt[opt_pos] = '\0'; - -#ifdef MP_DEBUG - PRINT_LINENUM; - mp_msg(MSGT_CFGPARSER,MSGL_INFO,"option: %s\n", opt); -#endif - - /* skip whitespaces */ - while (isspace(line[line_pos])) - ++line_pos; - - /* check '=' */ - if (line[line_pos++] != '=') { - PRINT_LINENUM; - mp_msg(MSGT_CFGPARSER,MSGL_ERR,"option without parameter\n"); - ret = -1; - errors++; - continue; - } - - /* whitespaces... */ - while (isspace(line[line_pos])) - ++line_pos; - - /* read the parameter */ - if (line[line_pos] == '"' || line[line_pos] == '\'') { - c = line[line_pos]; - ++line_pos; - for (param_pos = 0; line[line_pos] != c; /* NOTHING */) { - param[param_pos++] = line[line_pos++]; - if (param_pos >= MAX_PARAM_LEN) { - PRINT_LINENUM; - mp_msg(MSGT_CFGPARSER,MSGL_ERR,"too long parameter\n"); - ret = -1; - errors++; - goto nextline; - } - } - line_pos++; /* skip the closing " or ' */ - } else { - for (param_pos = 0; isprint(line[line_pos]) && !isspace(line[line_pos]) - && line[line_pos] != '#'; /* NOTHING */) { - param[param_pos++] = line[line_pos++]; - if (param_pos >= MAX_PARAM_LEN) { - PRINT_LINENUM; - mp_msg(MSGT_CFGPARSER,MSGL_ERR,"too long parameter\n"); - ret = -1; - errors++; - goto nextline; - } - } - } - param[param_pos] = '\0'; - - /* did we read a parameter? */ - if (param_pos == 0) { - PRINT_LINENUM; - mp_msg(MSGT_CFGPARSER,MSGL_ERR,"option without parameter\n"); - ret = -1; - errors++; - continue; - } - -#ifdef MP_DEBUG - PRINT_LINENUM; - mp_msg(MSGT_CFGPARSER,MSGL_INFO,"parameter: %s\n", param); -#endif - - /* now, check if we have some more chars on the line */ - /* whitespace... */ - while (isspace(line[line_pos])) - ++line_pos; - - /* EOL / comment */ - if (line[line_pos] != '\0' && line[line_pos] != '#') { - PRINT_LINENUM; - mp_msg(MSGT_CFGPARSER,MSGL_WARN,"extra characters on line: %s\n", line+line_pos); - ret = -1; - } - - tmp = m_config_set_option(config, opt, param); - switch (tmp) { - case ERR_NOT_AN_OPTION: - case ERR_MISSING_PARAM: - case ERR_OUT_OF_RANGE: - case ERR_FUNC_ERR: - PRINT_LINENUM; - mp_msg(MSGT_CFGPARSER,MSGL_INFO,"%s\n", opt); - ret = -1; - errors++; - continue; - /* break */ - } -nextline: - ; - } - - free(line); - fclose(fp); -out: - --config->recursion_depth; - return ret; -} - -int m_config_parse_command_line(m_config_t *config, int argc, char **argv) -{ - int i; - int tmp; - char *opt; - int no_more_opts = 0; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(config->pt != NULL); - assert(argv != NULL); - assert(argc >= 1); -#endif - - if (init_conf(config, COMMAND_LINE) == -1) - return -1; - if(config->last_parent == NULL) - config->last_parent = config->pt; - /* in order to work recursion detection properly in parse_config_file */ - ++config->recursion_depth; - - for (i = 1; i < argc; i++) { - //next: - opt = argv[i]; - /* check for -- (no more options id.) except --help! */ - if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) != 'h')) - { - no_more_opts = 1; - if (i+1 >= argc) - { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "You added '--' but no filenames presented!\n"); - goto err_out; - } - continue; - } - if((opt[0] == '{') && (opt[1] == '\0')) - { - play_tree_t* entry = play_tree_new(); - UNSET_GLOBAL(config); - if(config->last_entry == NULL) { - play_tree_set_child(config->last_parent,entry); - } else { - play_tree_append_entry(config->last_entry,entry); - config->last_entry = NULL; - } - config->last_parent = entry; - continue; - } - - if((opt[0] == '}') && (opt[1] == '\0')) - { - if( ! config->last_parent || ! config->last_parent->parent) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too much }-\n"); - goto err_out; - } - config->last_entry = config->last_parent; - config->last_parent = config->last_entry->parent; - continue; - } - - if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */ - { - /* remove trailing '-' */ - opt++; - - mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt); - // We handle here some specific option - if(strcasecmp(opt,"list-options") == 0) { - m_config_list_options(config); - exit(1); - // Loop option when it apply to a group - } else if(strcasecmp(opt,"loop") == 0 && - (! config->last_entry || config->last_entry->child) ) { - int l; - char* end; - l = strtol(argv[i+1],&end,0); - if(!end) - tmp = ERR_OUT_OF_RANGE; - else { - play_tree_t* pt = config->last_entry ? config->last_entry : config->last_parent; - l = l <= 0 ? -1 : l; - pt->loop = l; - tmp = 1; - } - } else // All normal options - tmp = m_config_set_option(config, opt, argv[i + 1]); - - switch (tmp) { - case ERR_NOT_AN_OPTION: - case ERR_MISSING_PARAM: - case ERR_OUT_OF_RANGE: - case ERR_FUNC_ERR: - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Error: "); - m_config_error(tmp,opt,argv[i+1]); - goto err_out; - default: - i += tmp; - break; - } - } - else /* filename */ - { - play_tree_t* entry = play_tree_new(); - mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]); - play_tree_add_file(entry,argv[i]); - if(strcasecmp(argv[i],"-") == 0) - m_config_set_option(config,"use-stdin",NULL); - /* opt is not an option -> treat it as a filename */ - UNSET_GLOBAL(config); // We start entry specific options - if(config->last_entry == NULL) - play_tree_set_child(config->last_parent,entry); - else - play_tree_append_entry(config->last_entry,entry); - config->last_entry = entry; - } - } - - --config->recursion_depth; - if(config->last_parent != config->pt) - mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n"); - config->flags &= (!CONFIG_GLOBAL); - SET_RUNNING(config); - return 1; -#if 0 -err_out_mem: - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "can't allocate memory for filenames (%s)\n", strerror(errno)); -#endif -err_out: - --config->recursion_depth; - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "command line: %s\n", argv[i]); - return -1; -} - -int -m_config_register_options(m_config_t *config,config_t *args) { - int list_len = 0; - config_t** conf_list = config->opt_list; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(args != NULL); -#endif - - if(conf_list) { - for ( ; conf_list[list_len] != NULL; list_len++) - /* NOTHING */; - } - - conf_list = (config_t**)realloc(conf_list,sizeof(struct conf*)*(list_len+2)); - if(conf_list == NULL) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Can't allocate %d bytes of memory : %s\n",sizeof(struct conf*)*(list_len+2),strerror(errno)); - return 0; - } - conf_list[list_len] = args; - conf_list[list_len+1] = NULL; - - config->opt_list = conf_list; - - return 1; -} - -config_t* -m_config_get_option(m_config_t *config, char* arg) { - int i,j; - char *e; - config_t *conf; - config_t **conf_list; - config_t* cl[] = { NULL, NULL }; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - - e = strchr(arg,':'); - - if(e) { - char *s; - s = (char*)malloc((e-arg+1)*sizeof(char)); - strncpy(s,arg,e-arg); - s[e-arg] = '\0'; - cl[0] = m_config_get_option(config,s); - conf_list = cl; - free(s); - } else - conf_list = config->opt_list; - - if(conf_list) { - for(j = 0 ; conf_list[j] != NULL ; j++) { - conf = conf_list[j]; - for(i=0; conf[i].name != NULL; i++) { - if(strcasecmp(conf[i].name,arg) == 0) - return &conf[i]; - } - } - } - return NULL; -} - -void* -m_config_get_option_ptr(m_config_t *config, char* arg) { - config_t* conf; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - - conf = m_config_get_option(config,arg); - if(!conf) return NULL; - return conf->p; -} - -int -m_config_get_int (m_config_t *config, char* arg,int* err_ret) { - int *ret; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - - ret = m_config_get_option_ptr(config,arg); - if(err_ret) - *err_ret = 0; - if(!ret) { - if(err_ret) - *err_ret = 1; - return -1; - } else - return (*ret); -} - -float -m_config_get_float (m_config_t *config, char* arg,int* err_ret) { - float *ret; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - - ret = m_config_get_option_ptr(config,arg); - if(err_ret) - *err_ret = 0; - if(!ret) { - if(err_ret) - *err_ret = 1; - return -1; - } else - return (*ret); -} - -#define AS_INT(c) (*((int*)c->p)) - -int -m_config_set_int(m_config_t *config, char* arg,int val) { - config_t* opt; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - - opt = m_config_get_option(config,arg); - - if(!opt || opt->type != CONF_TYPE_INT) - return ERR_NOT_AN_OPTION; - - if(opt->flags & CONF_MIN && val < opt->min) - return ERR_OUT_OF_RANGE; - if(opt->flags & CONF_MAX && val > opt->max) - return ERR_OUT_OF_RANGE; - - m_config_save_option(config,opt,arg,NULL); - AS_INT(opt) = val; - - return 1; -} - -int -m_config_set_float(m_config_t *config, char* arg,float val) { - config_t* opt; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - - opt = m_config_get_option(config,arg); - - if(!opt || opt->type != CONF_TYPE_FLOAT) - return ERR_NOT_AN_OPTION; - - if(opt->flags & CONF_MIN && val < opt->min) - return ERR_OUT_OF_RANGE; - if(opt->flags & CONF_MAX && val > opt->max) - return ERR_OUT_OF_RANGE; - - m_config_save_option(config,opt,arg,NULL); - *((float*)opt->p) = val; - - return 1; -} - - -int -m_config_switch_flag(m_config_t *config, char* opt) { - config_t *conf; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(opt != NULL); -#endif - - conf = m_config_get_option(config,opt); - if(!conf || conf->type != CONF_TYPE_FLAG) return 0; - if( AS_INT(conf) == conf->min) AS_INT(conf) = conf->max; - else if(AS_INT(conf) == conf->max) AS_INT(conf) = conf->min; - else return 0; - - return 1; -} - -int -m_config_set_flag(m_config_t *config, char* opt, int state) { - config_t *conf; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(opt != NULL); -#endif - - conf = m_config_get_option(config,opt); - if(!conf || conf->type != CONF_TYPE_FLAG) return 0; - if(state) AS_INT(conf) = conf->max; - else AS_INT(conf) = conf->min; - return 1; -} - -int -m_config_get_flag(m_config_t *config, char* opt) { - config_t *conf; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(opt != NULL); -#endif - - conf = m_config_get_option(config,opt); - if(!conf || conf->type != CONF_TYPE_FLAG) return -1; - if(AS_INT(conf) == conf->max) - return 1; - else if(AS_INT(conf) == conf->min) - return 0; - else - return -1; -} - -int m_config_is_option_set(m_config_t *config, char* arg) { - config_t* opt; - config_save_t* save; - int l,i; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - - opt = m_config_get_option(config,arg); - - if(!opt) - return -1; - - for(l = config->cs_level ; l >= 0 ; l--) { - save = config->config_stack[l]; - if(!save) - continue; - for(i = 0 ; save[i].opt != NULL ; i++) { - if(save[i].opt == opt) - return 1; - } - } - - return 0; -} - -#undef AS_INT - -static void m_config_print_option_list(char* prefix, config_t* opt_list) { - char* pf = NULL; - config_t* opt; - char min[50],max[50],*type; - - - for(opt = opt_list ; opt->name != NULL ; opt++) { - if(opt->type == CONF_TYPE_SUBCONFIG) { - if(prefix) { - pf = (char*)malloc(strlen(prefix) + strlen(opt->name) + 1); - sprintf(pf,"%s:%s",prefix,opt->name); - } else - pf = strdup(opt->name); - m_config_print_option_list(pf,(config_t*)opt->p); - free(pf); - continue; - } - if(prefix) - printf("%1.15s:",prefix); - if(opt->flags & CONF_MIN) - sprintf(min,"%-8.0f",opt->min); - else - strcpy(min,"No"); - if(opt->flags & CONF_MAX) - sprintf(max,"%-8.0f",opt->max); - else - strcpy(max,"No"); - switch(opt->type) { - case CONF_TYPE_FLAG: - type = "Flag"; - break; - case CONF_TYPE_INT: - type = "Integer"; - break; - case CONF_TYPE_FLOAT: - type = "Float"; - break; - case CONF_TYPE_STRING: - type = "String"; - break; - case CONF_TYPE_FUNC: - case CONF_TYPE_FUNC_PARAM: - case CONF_TYPE_FUNC_FULL: - type = "Function"; - break; - case CONF_TYPE_PRINT: - case CONF_TYPE_PRINT_INDIRECT: - type = "Print"; - break; - case CONF_TYPE_STRING_LIST: - type = "String list"; - break; - default: - type = ""; - break; - } - printf("%-*.15s %-13.13s %-10.10s %-10.10s %-3.3s %-3.3s %-3.3s\n", - 30 - (prefix ? strlen(prefix) + 1 : 0), - opt->name, - type, - min, - max, - opt->flags & CONF_GLOBAL ? "Yes" : "No", - opt->flags & CONF_NOCMD ? "No" : "Yes", - opt->flags & CONF_NOCFG ? "No" : "Yes"); - } - -} - - -static void m_config_list_options(m_config_t *config) { - int i; - - printf("\nName Type Min Max Glob CL Cfg\n\n"); - for(i = 0; config->opt_list[i] ; i++) - m_config_print_option_list(NULL,config->opt_list[i]); -} - - - -static void m_config_error(int err,char* opt,char* val) { - switch(err) { - case ERR_NOT_AN_OPTION: - mp_msg(MSGT_CFGPARSER, MSGL_ERR,"'%s' is not a mplayer/mencoder option\n",opt); - break; - case ERR_MISSING_PARAM: - mp_msg(MSGT_CFGPARSER, MSGL_ERR,"option '%s' need a parameter\n",opt); - break; - case ERR_OUT_OF_RANGE: - mp_msg(MSGT_CFGPARSER, MSGL_ERR,"value '%s' of option '%s' is out of range\n",val,opt); - break; - case ERR_FUNC_ERR: - mp_msg(MSGT_CFGPARSER, MSGL_ERR,"while parsing option '%s'\n",opt); - break; - } -} - -#endif diff -r 27711ab2889f -r 57bdcdb061d7 cfgparser.h --- a/cfgparser.h Wed Aug 13 16:01:53 2003 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,204 +0,0 @@ -/* - * command line and config file parser - */ - -#ifdef NEW_CONFIG -#ifdef MP_DEBUG -#warning "NEW_CONFIG defined but still using the old cfgparser.h" -#endif -#include "m_config.h" -#include "m_option.h" -#else - -#ifndef __CONFIG_H -#define __CONFIG_H - -#define CONF_TYPE_FLAG 0 -#define CONF_TYPE_INT 1 -#define CONF_TYPE_FLOAT 2 -#define CONF_TYPE_STRING 3 -#define CONF_TYPE_FUNC 4 -#define CONF_TYPE_FUNC_PARAM 5 -#define CONF_TYPE_PRINT 6 -#define CONF_TYPE_FUNC_FULL 7 -#define CONF_TYPE_SUBCONFIG 8 -#define CONF_TYPE_STRING_LIST 9 -#define CONF_TYPE_POSITION 10 -#define CONF_TYPE_PRINT_INDIRECT 11 - - -#define ERR_NOT_AN_OPTION -1 -#define ERR_MISSING_PARAM -2 -#define ERR_OUT_OF_RANGE -3 -#define ERR_FUNC_ERR -4 - - - -#define CONF_MIN (1<<0) -#define CONF_MAX (1<<1) -#define CONF_RANGE (CONF_MIN|CONF_MAX) -#define CONF_NOCFG (1<<2) -#define CONF_NOCMD (1<<3) -#define CONF_GLOBAL (1<<4) -#define CONF_NOSAVE (1<<5) -#define CONF_OLD (1<<6) - - -typedef struct config config_t; -typedef struct m_config m_config_t; -typedef struct config_save config_save_t; - -struct play_tree; - -typedef void (*cfg_default_func_t)(config_t *, char*); - -struct config { - char *name; - void *p; - unsigned int type; - unsigned int flags; - double min,max; - /* Use this field when your need to do something before a new value is - assigned to your option */ - cfg_default_func_t default_func; -}; - - - -struct m_config { - config_t** opt_list; - config_save_t** config_stack; - int cs_level; - int parser_mode; /* COMMAND_LINE or CONFIG_FILE */ - int flags; - char* sub_conf; // When we save a subconfig - struct play_tree* pt; // play tree we use for playlist option, etc - struct play_tree* last_entry; // last added entry - struct play_tree* last_parent; // if last_entry is NULL we must create child of this - int recursion_depth; -}; - -struct config_save { - config_t* opt; - union { - int as_int; - float as_float; - void* as_pointer; - off_t as_off_t; - } param; - char* opt_name; -}; - - -typedef int (*cfg_func_arg_param_t)(config_t *, char *, char *); -typedef int (*cfg_func_param_t)(config_t *, char *); -typedef int (*cfg_func_t)(config_t *); - -/* parse_config_file returns: - * -1 on error (can't malloc, invalid option...) - * 0 if can't open configfile - * 1 on success - */ -int m_config_parse_config_file(m_config_t *config, char *conffile); - -/* parse_command_line returns: - * -1 on error (invalid option...) - * 1 otherwise - */ -int m_config_parse_command_line(m_config_t* config, int argc, char **argv); - -m_config_t* m_config_new(struct play_tree* pt); - -void m_config_free(m_config_t* config); - -void m_config_push(m_config_t* config); - -/* - * Return 0 on error 1 on success - */ -int m_config_pop(m_config_t* config); - -/* - * Return 0 on error 1 on success - */ -int m_config_register_options(m_config_t *config,config_t *args); - -/* - * For all the following function when it's a subconfig option - * you must give an option name like 'tv:channel' and not just - * 'channel' - */ - -/* - * Return 1 on sucess 0 on failure - */ -int m_config_set_option(m_config_t *config,char *opt, char *param); - -/* - * Get the config struct defining an option - * Return NULL on error - */ -config_t* m_config_get_option(m_config_t *config, char* arg); - -/* - * Get the p field of the struct defining an option - * Return NULL on error - */ -void* m_config_get_option_ptr(m_config_t *config, char* arg); - -/* - * Tell is an option is alredy set or not - * Return -1 one error (requested option arg exist) - * Otherwise 0 or 1 - */ -int m_config_is_option_set(m_config_t *config, char* arg); - -/* - * Return 0 on error 1 on success - */ -int m_config_switch_flag(m_config_t *config, char* opt); - -/* - * Return 0 on error 1 on success - */ -int m_config_set_flag(m_config_t *config, char* opt, int max); - -/* - * Return the value of a flag (O or 1) and -1 on error - */ -int m_config_get_flag(m_config_t *config, char* opt); - -/* - * Set the value of an int option - * Return 0 on error 1 on success - */ -int -m_config_set_int(m_config_t *config, char* arg,int val); - -/* - * Get the value of an int option - * Return the option value or -1 on error - * If err_ret is not NULL it's set to 1 on error - */ -int -m_config_get_int (m_config_t *config, char* arg,int* err_ret); - -/* - * Set the value of a float option - * Return 0 on error 1 on success - */ -int -m_config_set_float(m_config_t *config, char* arg,float val); - - -/* - * Get the value of a float option - * Return the option value or -1 on error - * If err_ret is not NULL it's set to 1 on error - */ -float -m_config_get_float (m_config_t *config, char* arg,int* err_ret); - -#endif /* __CONFIG_H */ - -#endif /* NEW_CONFIG */ diff -r 27711ab2889f -r 57bdcdb061d7 configure --- a/configure Wed Aug 13 16:01:53 2003 +0000 +++ b/configure Wed Aug 13 16:29:32 2003 +0000 @@ -165,7 +165,6 @@ --disable-cdparanoia Disable cdparanoia support [autodetect] --disable-freetype Disable freetype2 font rendering support [autodetect] --disable-unrarlib Disable Unique RAR File Library [enabled] - --disable-new-conf Disable new experimental config parser code [enabled] --enable-menu Enable OSD menu support (NOT DVD MENU) [disabled] --disable-sortsub Disable subtitles sorting [enabled] --enable-fribidi Enable using the FriBiDi libs [disabled] @@ -1131,7 +1130,6 @@ _big_endian=auto _freetype=auto _shared_pp=no -_new_conf=yes _menu=no _qtx=auto _macosx=auto @@ -1355,9 +1353,6 @@ --enable-shared-pp) _shared_pp=yes ;; --disable-shared-pp) _shared_pp=no ;; - --enable-new-conf) _new_conf=yes ;; - --disable-new-conf) _new_conf=no ;; - --enable-menu) _menu=yes ;; --disable-menu) _menu=no ;; @@ -4980,17 +4975,8 @@ echocheck "shared postprocess lib" echores "$_shared_pp" -echocheck "New config" -if test "$_new_conf" = yes ; then - _def_new_conf='#define NEW_CONFIG 1' -else - _def_new_conf='#undef NEW_CONFIG' -fi -echores "$_new_conf" - echocheck "OSD menu" if test "$_menu" = yes ; then - test "$_new_conf" != yes && die "New config support needed for the OSD menu (--enable-new-conf)." _def_menu='#define HAVE_MENU 1' else _def_menu='#undef HAVE_MENU' @@ -5943,9 +5929,6 @@ /* enables / disables new input joystick support */ $_def_joystick -/* enables / disables new config */ -$_def_new_conf - /* enables / disables QTX codecs */ $_def_qtx diff -r 27711ab2889f -r 57bdcdb061d7 input/input.c --- a/input/input.c Wed Aug 13 16:01:53 2003 +0000 +++ b/input/input.c Wed Aug 13 16:29:32 2003 +0000 @@ -25,7 +25,8 @@ #include "../osdep/keycodes.h" #include "../osdep/timer.h" #include "../mp_msg.h" -#include "../cfgparser.h" +#include "../m_config.h" +#include "../m_option.h" #include "joystick.h" @@ -399,11 +400,11 @@ static char* in_file = NULL; static int in_file_fd = -1; -static int mp_input_print_key_list(config_t* cfg); -static int mp_input_print_cmd_list(config_t* cfg); +static int mp_input_print_key_list(m_option_t* cfg); +static int mp_input_print_cmd_list(m_option_t* cfg); // Our command line options -static config_t input_conf[] = { +static m_option_t input_conf[] = { { "conf", &config_file, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL }, { "ar-delay", &ar_delay, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL }, { "ar-rate", &ar_rate, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL }, @@ -414,7 +415,7 @@ { NULL, NULL, 0, 0, 0, 0, NULL} }; -static config_t mp_input_opts[] = { +static m_option_t mp_input_opts[] = { { "input", &input_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL}, { "nojoystick", &use_joystick, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL }, { "joystick", &use_joystick, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL }, @@ -1537,7 +1538,7 @@ m_config_register_options(cfg,mp_input_opts); } -static int mp_input_print_key_list(config_t* cfg) { +static int mp_input_print_key_list(m_option_t* cfg) { int i; printf("\n"); for(i= 0; key_names[i].name != NULL ; i++) @@ -1545,7 +1546,7 @@ exit(0); } -static int mp_input_print_cmd_list(config_t* cfg) { +static int mp_input_print_cmd_list(m_option_t* cfg) { mp_cmd_t *cmd; int i,j; char* type; @@ -1596,5 +1597,3 @@ mp_cmd_free(cmd); return 0; } - - diff -r 27711ab2889f -r 57bdcdb061d7 libmpcodecs/vd_ffmpeg.c --- a/libmpcodecs/vd_ffmpeg.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpcodecs/vd_ffmpeg.c Wed Aug 13 16:29:32 2003 +0000 @@ -78,7 +78,7 @@ //unsigned int lavc_pp=0; //#endif -#include "cfgparser.h" +#include "m_option.h" static int get_buffer(AVCodecContext *avctx, AVFrame *pic); static void release_buffer(AVCodecContext *avctx, AVFrame *pic); @@ -99,7 +99,7 @@ static int lavc_param_idct_algo=0; static int lavc_param_debug=0; -struct config lavc_decode_opts_conf[]={ +m_option_t lavc_decode_opts_conf[]={ {"bug", &lavc_param_workaround_bugs, CONF_TYPE_INT, CONF_RANGE, -1, 999999, NULL}, {"er", &lavc_param_error_resilience, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL}, {"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL}, diff -r 27711ab2889f -r 57bdcdb061d7 libmpcodecs/vd_xvid.c --- a/libmpcodecs/vd_xvid.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpcodecs/vd_xvid.c Wed Aug 13 16:29:32 2003 +0000 @@ -7,7 +7,7 @@ #ifdef HAVE_XVID #include "vd_internal.h" -#include "cfgparser.h" +#include "m_option.h" #include @@ -56,7 +56,7 @@ static int do_dr2 = 0; -struct config xvid_dec_opts[] = { +m_option_t xvid_dec_opts[] = { { "dr2", &do_dr2, CONF_TYPE_FLAG, 0, 0, 1, NULL}, { "nodr2", &do_dr2, CONF_TYPE_FLAG, 0, 1, 0, NULL}, {NULL, NULL, 0, 0, 0, 0, NULL} diff -r 27711ab2889f -r 57bdcdb061d7 libmpcodecs/ve_divx4.c --- a/libmpcodecs/ve_divx4.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpcodecs/ve_divx4.c Wed Aug 13 16:29:32 2003 +0000 @@ -68,9 +68,9 @@ static int vbrdebug = 0; #endif -#include "cfgparser.h" +#include "m_option.h" -struct config divx4opts_conf[]={ +m_option_t divx4opts_conf[]={ {"pass", &pass, CONF_TYPE_INT, CONF_RANGE,0,2, NULL}, {"br", &divx4_param.bitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, #if ENCORE_MAJOR_VERSION < 5200 diff -r 27711ab2889f -r 57bdcdb061d7 libmpcodecs/ve_lavc.c --- a/libmpcodecs/ve_lavc.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpcodecs/ve_lavc.c Wed Aug 13 16:29:32 2003 +0000 @@ -128,10 +128,10 @@ static int lavc_param_coder= 0; static int lavc_param_context= 0; -#include "cfgparser.h" +#include "m_option.h" #ifdef USE_LIBAVCODEC -struct config lavcopts_conf[]={ +m_option_t lavcopts_conf[]={ {"vcodec", &lavc_param_vcodec, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"vbitrate", &lavc_param_vbitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, {"vratetol", &lavc_param_vrate_tolerance, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, diff -r 27711ab2889f -r 57bdcdb061d7 libmpcodecs/ve_vfw.c --- a/libmpcodecs/ve_vfw.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpcodecs/ve_vfw.c Wed Aug 13 16:29:32 2003 +0000 @@ -29,9 +29,9 @@ static char *vfw_param_codec = NULL; -#include "cfgparser.h" +#include "m_option.h" -struct config vfwopts_conf[]={ +m_option_t vfwopts_conf[]={ {"codec", &vfw_param_codec, CONF_TYPE_STRING, 0, 0, 0, NULL}, {NULL, NULL, 0, 0, 0, 0, NULL} }; diff -r 27711ab2889f -r 57bdcdb061d7 libmpcodecs/ve_xvid.c --- a/libmpcodecs/ve_xvid.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpcodecs/ve_xvid.c Wed Aug 13 16:29:32 2003 +0000 @@ -28,7 +28,7 @@ #include #include "xvid_vbr.h" -#include "cfgparser.h" +#include "m_option.h" #ifdef XVID_API_UNSTABLE @@ -110,7 +110,7 @@ static uint64_t xvid_error[3]; #endif -struct config xvidencopts_conf[] = { +m_option_t xvidencopts_conf[] = { { "pass", &xvidenc_pass, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, { "me_quality", &xvidenc_quality, CONF_TYPE_INT, CONF_RANGE, 0, sizeof(motion_presets) / sizeof(motion_presets[0]) - 1, NULL}, diff -r 27711ab2889f -r 57bdcdb061d7 libmpdemux/demux_rawaudio.c --- a/libmpdemux/demux_rawaudio.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpdemux/demux_rawaudio.c Wed Aug 13 16:29:32 2003 +0000 @@ -7,7 +7,6 @@ #include #include "../m_option.h" -#include "../m_config.h" #include "stream.h" #include "demuxer.h" @@ -20,7 +19,7 @@ static int samplesize = 2; static int format = 0x1; // Raw PCM -config_t demux_rawaudio_opts[] = { +m_option_t demux_rawaudio_opts[] = { { "on", &demuxer_type, CONF_TYPE_FLAG, 0,0, DEMUXER_TYPE_RAWAUDIO, NULL }, { "channels", &channels, CONF_TYPE_INT,CONF_RANGE,1,8, NULL }, { "rate", &samplerate, CONF_TYPE_INT,CONF_RANGE,1000,8*48000, NULL }, diff -r 27711ab2889f -r 57bdcdb061d7 libmpdemux/demux_rawvideo.c --- a/libmpdemux/demux_rawvideo.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpdemux/demux_rawvideo.c Wed Aug 13 16:29:32 2003 +0000 @@ -7,7 +7,6 @@ #include #include "../m_option.h" -#include "../m_config.h" #include "stream.h" #include "demuxer.h" @@ -23,7 +22,7 @@ static float fps = 25; static int imgsize=0; -config_t demux_rawvideo_opts[] = { +m_option_t demux_rawvideo_opts[] = { { "on", &demuxer_type, CONF_TYPE_FLAG, 0,0, DEMUXER_TYPE_RAWVIDEO, NULL }, // size: { "w", &width, CONF_TYPE_INT,CONF_RANGE,1,8192, NULL }, diff -r 27711ab2889f -r 57bdcdb061d7 libmpdemux/demux_xmms.c --- a/libmpdemux/demux_xmms.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpdemux/demux_xmms.c Wed Aug 13 16:29:32 2003 +0000 @@ -12,7 +12,7 @@ #include #include -#include "../cfgparser.h" +#include "../m_option.h" #include "../libao2/afmt.h" #include "stream.h" #include "demuxer.h" diff -r 27711ab2889f -r 57bdcdb061d7 libmpdemux/open.c --- a/libmpdemux/open.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpdemux/open.c Wed Aug 13 16:29:32 2003 +0000 @@ -15,7 +15,7 @@ #include #endif -#include "../m_config.h" +#include "../m_option.h" #include "stream.h" #include "demuxer.h" #include "mf.h" @@ -532,7 +532,7 @@ return open_stream_full(filename,STREAM_READ,options,file_format); } -int dvd_parse_chapter_range(struct config *conf, const char *range){ +int dvd_parse_chapter_range(m_option_t *conf, const char *range){ const char *s; char *t; /* conf; prevent warning from GCC */ diff -r 27711ab2889f -r 57bdcdb061d7 libmpdemux/stream.h --- a/libmpdemux/stream.h Wed Aug 13 16:01:53 2003 +0000 +++ b/libmpdemux/stream.h Wed Aug 13 16:29:32 2003 +0000 @@ -241,12 +241,10 @@ stream_t* open_stream_full(char* filename,int mode, char** options, int* file_format); //#ifdef USE_DVDREAD -struct config; extern int dvd_title; extern int dvd_chapter; extern int dvd_last_chapter; extern int dvd_angle; -int dvd_parse_chapter_range(struct config*, const char*); //#endif extern int dvbin_param_on; diff -r 27711ab2889f -r 57bdcdb061d7 libvo/vo_bl.c --- a/libvo/vo_bl.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libvo/vo_bl.c Wed Aug 13 16:29:32 2003 +0000 @@ -39,7 +39,7 @@ #include "video_out.h" #include "video_out_internal.h" #include "../mp_msg.h" -#include "../cfgparser.h" +#include "../m_option.h" #include "fastmemcpy.h" static vo_info_t info = diff -r 27711ab2889f -r 57bdcdb061d7 libvo/vo_dxr2.c --- a/libvo/vo_dxr2.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libvo/vo_dxr2.c Wed Aug 13 16:29:32 2003 +0000 @@ -16,7 +16,7 @@ #include "video_out.h" #include "video_out_internal.h" #include "mp_msg.h" -#include "cfgparser.h" +#include "m_option.h" #include "sub.h" #ifdef X11_FULLSCREEN @@ -75,7 +75,7 @@ static int cr_left = 0, cr_right = 0; static int cr_top = 55, cr_bot = 300; -config_t dxr2_opts[] = { +m_option_t dxr2_opts[] = { { "overlay", &use_ol, CONF_TYPE_FLAG, 0, 0, 1, NULL}, { "nooverlay", &use_ol, CONF_TYPE_FLAG, 0, 1, 0, NULL}, { "overlay-ratio", &ol_ratio, CONF_TYPE_INT, CONF_RANGE, 1, 2500, NULL }, diff -r 27711ab2889f -r 57bdcdb061d7 libvo/vo_zr.c --- a/libvo/vo_zr.c Wed Aug 13 16:01:53 2003 +0000 +++ b/libvo/vo_zr.c Wed Aug 13 16:29:32 2003 +0000 @@ -25,7 +25,7 @@ #include "video_out.h" #include "video_out_internal.h" #include "../mp_msg.h" -#include "../cfgparser.h" +#include "../m_option.h" #include "fastmemcpy.h" #include "jpeg_enc.h" @@ -644,7 +644,7 @@ /* copied and adapted from vo_aa_parseoption */ int -vo_zr_parseoption(struct config * conf, char *opt, char *param){ +vo_zr_parseoption(m_option_t* conf, char *opt, char *param){ /* got an option starting with zr */ zr_info_t *zr = &zr_info[zr_parsing]; int i; @@ -780,7 +780,7 @@ return ERR_NOT_AN_OPTION; } -void vo_zr_revertoption(config_t* opt,char* param) { +void vo_zr_revertoption(m_option_t* opt,char* param) { zr_info_t *zr = &zr_info[1]; zr_count = 1; diff -r 27711ab2889f -r 57bdcdb061d7 m_config.c --- a/m_config.c Wed Aug 13 16:01:53 2003 +0000 +++ b/m_config.c Wed Aug 13 16:29:32 2003 +0000 @@ -1,8 +1,5 @@ - #include "config.h" -#ifdef NEW_CONFIG - #include #include #include @@ -11,7 +8,6 @@ #include #endif - #include "m_config.h" #include "m_option.h" #include "mp_msg.h" @@ -379,5 +375,3 @@ } printf("\nTotal: %d options\n",count); } - -#endif // NEW_CONFIG diff -r 27711ab2889f -r 57bdcdb061d7 m_config.h --- a/m_config.h Wed Aug 13 16:01:53 2003 +0000 +++ b/m_config.h Wed Aug 13 16:29:32 2003 +0000 @@ -1,7 +1,5 @@ - -#ifndef NEW_CONFIG -#warning "Including m_config.h but NEW_CONFIG is disabled" -#else +#ifndef _M_CONFIG_H +#define _M_CONFIG_H typedef struct m_config_option m_config_option_t; typedef struct m_config_save_slot m_config_save_slot_t; @@ -61,33 +59,4 @@ void m_config_print_option_list(m_config_t *config); -///////////////////////////////////////////////////////////////////////////////////// -/////////////////////////// Backward compat. stuff //////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////// - -typedef struct config config_t; -struct config { - char *name; - void *p; - struct m_option_type* type; - unsigned int flags; - double min,max; - void* priv; -}; - - -#define CONF_MIN (1<<0) -#define CONF_MAX (1<<1) -#define CONF_RANGE (CONF_MIN|CONF_MAX) -#define CONF_NOCFG (1<<2) -#define CONF_NOCMD (1<<3) -#define CONF_GLOBAL (1<<4) -#define CONF_NOSAVE (1<<5) -#define CONF_OLD (1<<6) - -#define ERR_NOT_AN_OPTION -1 -#define ERR_MISSING_PARAM -2 -#define ERR_OUT_OF_RANGE -3 -#define ERR_FUNC_ERR -4 - -#endif +#endif /* _M_CONFIG_H */ diff -r 27711ab2889f -r 57bdcdb061d7 m_option.c --- a/m_option.c Wed Aug 13 16:01:53 2003 +0000 +++ b/m_option.c Wed Aug 13 16:29:32 2003 +0000 @@ -1,8 +1,5 @@ - #include "config.h" -#ifdef NEW_CONFIG - #include #include #include @@ -1787,5 +1784,3 @@ NULL, NULL }; - -#endif diff -r 27711ab2889f -r 57bdcdb061d7 m_option.h --- a/m_option.h Wed Aug 13 16:01:53 2003 +0000 +++ b/m_option.h Wed Aug 13 16:29:32 2003 +0000 @@ -1,7 +1,5 @@ - -#ifndef NEW_CONFIG -#warning "Including m_option.h but NEW_CONFIG is disabled" -#else +#ifndef _M_OPTION_H +#define _M_OPTION_H typedef struct m_option_type m_option_type_t; typedef struct m_option m_option_t; @@ -76,25 +74,25 @@ extern m_obj_params_t m_span_params_def; -// Don't be stupid keep tho old names ;-) +// FIXME: backward compatibility #define CONF_TYPE_FLAG (&m_option_type_flag) #define CONF_TYPE_INT (&m_option_type_int) #define CONF_TYPE_FLOAT (&m_option_type_float) -#define CONF_TYPE_STRING (&m_option_type_string) +#define CONF_TYPE_STRING (&m_option_type_string) #define CONF_TYPE_FUNC (&m_option_type_func) #define CONF_TYPE_FUNC_PARAM (&m_option_type_func_param) #define CONF_TYPE_PRINT (&m_option_type_print) #define CONF_TYPE_PRINT_INDIRECT (&m_option_type_print_indirect) #define CONF_TYPE_FUNC_FULL (&m_option_type_func_full) #define CONF_TYPE_SUBCONFIG (&m_option_type_subconfig) -#define CONF_TYPE_STRING_LIST (&m_option_type_string_list) +#define CONF_TYPE_STRING_LIST (&m_option_type_string_list) #define CONF_TYPE_POSITION (&m_option_type_position) -#define CONF_TYPE_IMGFMT (&m_option_type_imgfmt) +#define CONF_TYPE_IMGFMT (&m_option_type_imgfmt) #define CONF_TYPE_SPAN (&m_option_type_span) #define CONF_TYPE_OBJ_SETTINGS_LIST (&m_option_type_obj_settings_list) -#define CONF_TYPE_OBJ_PRESETS (&m_option_type_obj_presets) -#define CONF_TYPE_CUSTOM_URL (&m_option_type_custom_url) -#define CONF_TYPE_OBJ_PARAMS (&m_option_type_obj_params) +#define CONF_TYPE_OBJ_PRESETS (&m_option_type_obj_presets) +#define CONF_TYPE_CUSTOM_URL (&m_option_type_custom_url) +#define CONF_TYPE_OBJ_PARAMS (&m_option_type_obj_params) ///////////////////////////////////////////////////////////////////////////////////////////// @@ -126,9 +124,6 @@ void (*free)(void* dst); }; -/// This is the same thing as a struct config it have been renamed -/// to remove this config_t, m_config_t mess. Sorry about that, -/// config_t is still provided for backward compat. struct m_option { char *name; void *p; @@ -161,6 +156,16 @@ // Emulate old behaviour by pushing the option only if it was set by the user #define M_OPT_OLD (1<<6) +// FIXME: backward compatibility +#define CONF_MIN M_OPT_MIN +#define CONF_MAX M_OPT_MAX +#define CONF_RANGE M_OPT_RANGE +#define CONF_NOCFG M_OPT_NOCFG +#define CONF_NOCMD M_OPT_NOCMD +#define CONF_GLOBAL M_OPT_GLOBAL +#define CONF_NOSAVE M_OPT_NOSAVE +#define CONF_OLD M_OPT_OLD + ///////////////////////////// Option type flags /////////////////////////////////// @@ -206,9 +211,15 @@ #define M_OPT_MISSING_PARAM -2 #define M_OPT_INVALID -3 #define M_OPT_OUT_OF_RANGE -4 -#define M_OPT_PARSER_ERR -5 +#define M_OPT_PARSER_ERR -5 #define M_OPT_EXIT -6 +// FIXME: backward compatibility +#define ERR_NOT_AN_OPTION M_OPT_UNKNOWN +#define ERR_MISSING_PARAM M_OPT_MISSING_PARAM +#define ERR_OUT_OF_RANGE M_OPT_OUT_OF_RANGE +#define ERR_FUNC_ERR M_OPT_PARSER_ERR + m_option_t* m_option_list_find(m_option_t* list,char* name); inline static int @@ -250,4 +261,4 @@ opt->type->free(dst); } -#endif +#endif /* _M_OPTION_H */ diff -r 27711ab2889f -r 57bdcdb061d7 m_struct.c --- a/m_struct.c Wed Aug 13 16:01:53 2003 +0000 +++ b/m_struct.c Wed Aug 13 16:29:32 2003 +0000 @@ -1,8 +1,5 @@ - #include "config.h" -#ifdef NEW_CONFIG - #include #include @@ -113,7 +110,3 @@ return r; } - - - -#endif // NEW_CONFIG diff -r 27711ab2889f -r 57bdcdb061d7 m_struct.h --- a/m_struct.h Wed Aug 13 16:01:53 2003 +0000 +++ b/m_struct.h Wed Aug 13 16:29:32 2003 +0000 @@ -1,7 +1,5 @@ - -#ifndef NEW_CONFIG -#warning "Including m_struct.h but NEW_CONFIG is disabled" -#else +#ifndef _M_STRUCT_H +#define _M_STRUCT_H ///////////////////// A struct setter //////////////////////// @@ -47,4 +45,4 @@ struct m_option* m_struct_get_field(m_struct_t* st,char* f); -#endif +#endif /* _M_STRUCT_H */ diff -r 27711ab2889f -r 57bdcdb061d7 mencoder.c --- a/mencoder.c Wed Aug 13 16:01:53 2003 +0000 +++ b/mencoder.c Wed Aug 13 16:29:32 2003 +0000 @@ -33,14 +33,9 @@ #include "cpudetect.h" #include "codec-cfg.h" -#ifdef NEW_CONFIG #include "m_option.h" #include "m_config.h" #include "parser-mecmd.h" -#else -#include "cfgparser.h" -#include "playtree.h" -#endif #include "libmpdemux/stream.h" #include "libmpdemux/demuxer.h" @@ -212,22 +207,18 @@ m_config_t* mconfig; -#ifdef NEW_CONFIG -extern int -m_config_parse_config_file(m_config_t* config, char *conffile); -#endif +extern int m_config_parse_config_file(m_config_t* config, char *conffile); +static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;} -static int cfg_inc_verbose(struct config *conf){ ++verbose; return 0;} - -static int cfg_include(struct config *conf, char *filename){ +static int cfg_include(m_option_t *conf, char *filename){ return m_config_parse_config_file(mconfig, filename); } static char *seek_to_sec=NULL; static off_t seek_to_byte=0; -static int parse_end_at(struct config *conf, const char* param); +static int parse_end_at(m_option_t *conf, const char* param); //static uint8_t* flip_upside_down(uint8_t* dst, const uint8_t* src, int width, int height); #include "get_path.c" @@ -343,12 +334,7 @@ double v_pts_corr=0; double v_timer_corr=0; -#ifdef NEW_CONFIG m_entry_t* filelist = NULL; -#else -play_tree_t* playtree; -play_tree_iter_t* playtree_iter; -#endif char* filename=NULL; char* frameno_filename="frameno.avi"; @@ -413,8 +399,6 @@ else mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized); } - // New config code -#ifdef NEW_CONFIG mconfig = m_config_new(); m_config_register_options(mconfig,mencoder_opts); parse_cfgfiles(mconfig); @@ -422,26 +406,6 @@ if(!filelist) mencoder_exit(1, "error parsing cmdline"); m_entry_set_options(mconfig,&filelist[0]); filename = filelist[0].name; - // Warn the user if he put more than 1 filename ? -#else - playtree = play_tree_new(); - mconfig = m_config_new(playtree); - m_config_register_options(mconfig,mencoder_opts); - parse_cfgfiles(mconfig); - - if(m_config_parse_command_line(mconfig, argc, argv) < 0) mencoder_exit(1, "error parsing cmdline"); - playtree = play_tree_cleanup(playtree); - if(playtree) { - playtree_iter = play_tree_iter_new(playtree,mconfig); - if(playtree_iter) { - if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) { - play_tree_iter_free(playtree_iter); - playtree_iter = NULL; - } - filename = play_tree_iter_get_file(playtree_iter,1); - } - } -#endif if(!filename){ printf(MSGTR_MissingFilename); @@ -1333,7 +1297,7 @@ return interrupted; } -static int parse_end_at(struct config *conf, const char* param) +static int parse_end_at(m_option_t *conf, const char* param) { end_at_type = END_AT_NONE; diff -r 27711ab2889f -r 57bdcdb061d7 mplayer.c --- a/mplayer.c Wed Aug 13 16:01:53 2003 +0000 +++ b/mplayer.c Wed Aug 13 16:29:32 2003 +0000 @@ -138,9 +138,9 @@ // Config file //**************************************************************************// -static int cfg_inc_verbose(struct config *conf){ ++verbose; return 0;} - -static int cfg_include(struct config *conf, char *filename){ +static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;} + +static int cfg_include(m_option_t *conf, char *filename){ return m_config_parse_config_file(mconfig, filename); } diff -r 27711ab2889f -r 57bdcdb061d7 parser-cfg.c --- a/parser-cfg.c Wed Aug 13 16:01:53 2003 +0000 +++ b/parser-cfg.c Wed Aug 13 16:29:32 2003 +0000 @@ -1,8 +1,5 @@ - #include "config.h" -#ifdef NEW_CONFIG - #include #include #include @@ -211,5 +208,3 @@ --recursion_depth; return ret; } - -#endif diff -r 27711ab2889f -r 57bdcdb061d7 parser-mecmd.c --- a/parser-mecmd.c Wed Aug 13 16:01:53 2003 +0000 +++ b/parser-mecmd.c Wed Aug 13 16:29:32 2003 +0000 @@ -1,8 +1,5 @@ - #include "config.h" -#ifdef NEW_CONFIG - #include #include #include @@ -17,7 +14,6 @@ #include "m_config.h" #include "parser-mecmd.h" - void m_entry_list_free(m_entry_t* lst) { int i,j; @@ -139,5 +135,3 @@ m_entry_list_free(lst); return NULL; } - -#endif diff -r 27711ab2889f -r 57bdcdb061d7 parser-mpcmd.c --- a/parser-mpcmd.c Wed Aug 13 16:01:53 2003 +0000 +++ b/parser-mpcmd.c Wed Aug 13 16:29:32 2003 +0000 @@ -1,8 +1,5 @@ - #include "config.h" -#ifdef NEW_CONFIG - #include #include #include @@ -219,5 +216,3 @@ play_tree_free(root,1); return NULL; } - -#endif