summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gui/cfg.c32
-rw-r--r--Gui/interface.c10
-rw-r--r--Makefile2
-rw-r--r--cfg-common.h22
-rw-r--r--cfg-mencoder.h22
-rw-r--r--cfg-mplayer.h16
-rw-r--r--cfgparser.c1548
-rw-r--r--cfgparser.h204
-rwxr-xr-xconfigure17
-rw-r--r--input/input.c17
-rw-r--r--libmpcodecs/vd_ffmpeg.c4
-rw-r--r--libmpcodecs/vd_xvid.c4
-rw-r--r--libmpcodecs/ve_divx4.c4
-rw-r--r--libmpcodecs/ve_lavc.c4
-rw-r--r--libmpcodecs/ve_vfw.c4
-rw-r--r--libmpcodecs/ve_xvid.c4
-rw-r--r--libmpdemux/demux_rawaudio.c3
-rw-r--r--libmpdemux/demux_rawvideo.c3
-rw-r--r--libmpdemux/demux_xmms.c2
-rw-r--r--libmpdemux/open.c4
-rw-r--r--libmpdemux/stream.h2
-rw-r--r--libvo/vo_bl.c2
-rw-r--r--libvo/vo_dxr2.c4
-rw-r--r--libvo/vo_zr.c6
-rw-r--r--m_config.c6
-rw-r--r--m_config.h37
-rw-r--r--m_option.c5
-rw-r--r--m_option.h43
-rw-r--r--m_struct.c7
-rw-r--r--m_struct.h8
-rw-r--r--mencoder.c46
-rw-r--r--mplayer.c4
-rw-r--r--parser-cfg.c5
-rw-r--r--parser-mecmd.c6
-rw-r--r--parser-mpcmd.c5
35 files changed, 109 insertions, 2003 deletions
diff --git a/Gui/cfg.c b/Gui/cfg.c
index 2160b0c01e..829ee8ece0 100644
--- a/Gui/cfg.c
+++ b/Gui/cfg.c
@@ -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 <locale.h>
@@ -73,7 +74,7 @@ extern int frame_dropping;
extern int stop_xscreensaver;
static m_config_t * gui_conf;
-static config_t gui_opts[] =
+static m_option_t gui_opts[] =
{
{ "enable_audio_equ",&gtkEnableAudioEqualizer,CONF_TYPE_FLAG,0,0,1,NULL },
@@ -199,11 +200,7 @@ int cfg_read( void )
// -- 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 @@ int cfg_write( void )
{
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 --git a/Gui/interface.c b/Gui/interface.c
index cd32ad638f..e52154ff7a 100644
--- a/Gui/interface.c
+++ b/Gui/interface.c
@@ -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 --git a/Makefile b/Makefile
index 4380fd19ae..e83de01fc7 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ SUBDIRS += libdha vidix
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 --git a/cfg-common.h b/cfg-common.h
index e913141c0a..bf08ada5aa 100644
--- a/cfg-common.h
+++ b/cfg-common.h
@@ -266,9 +266,9 @@ extern int network_ipv4_only_proxy;
/* 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 @@ extern char* edl_output_filename;
#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_lum_gblur;
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_height;
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 char * mf_type;
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 @@ extern m_obj_settings_t* vo_plugin_args;
#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 --git a/cfg-mencoder.h b/cfg-mencoder.h
index cb039cebc4..a872c49957 100644
--- a/cfg-mencoder.h
+++ b/cfg-mencoder.h
@@ -17,11 +17,11 @@ extern void revertPPOpt(void *conf, char* opt);
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 @@ struct config lameopts_conf[]={
#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 @@ struct config ovc_conf[]={
{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 @@ struct config oac_conf[]={
{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 @@ struct config info_conf[]={
{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 @@ struct config of_conf[]={
{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 --git a/cfg-mplayer.h b/cfg-mplayer.h
index 08c93e7281..4dfca1af6a 100644
--- a/cfg-mplayer.h
+++ b/cfg-mplayer.h
@@ -86,17 +86,17 @@ extern char **vo_fstype_list;
#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 int nortc;
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 @@ struct config ao_plugin_conf[]={
};
#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 @@ extern char* pp_help;
* 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 --git a/cfgparser.c b/cfgparser.c
deleted file mode 100644
index 1872c203f9..0000000000
--- a/cfgparser.c
+++ /dev/null
@@ -1,1548 +0,0 @@
-/*
- * command line and config file parser
- * by Szabolcs Berecz <szabi@inf.elte.hu>
- * (C) 2001
- *
- * subconfig support by alex
- */
-
-//#define DEBUG
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <math.h>
-
-#include "config.h"
-
-#ifndef NEW_CONFIG
-
-#ifdef USE_SETLOCALE
-#include <locale.h>
-#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 <assert.h>
-#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