[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[603] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-12-26 17:16:50
|
Revision: 603 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=603&view=rev Author: nickols_k Date: 2012-12-26 17:16:39 +0000 (Wed, 26 Dec 2012) Log Message: ----------- more classes Modified Paths: -------------- mplayerxp/input2/input.cpp mplayerxp/input2/input.h mplayerxp/libmpcodecs/ad.cpp mplayerxp/libmpcodecs/vd.cpp mplayerxp/libmpcodecs/vd_divx4.cpp mplayerxp/libmpcodecs/vd_lavc.cpp mplayerxp/libmpconf/cfgparser.cpp mplayerxp/libmpconf/cfgparser.h mplayerxp/libplaytree/asxparser.cpp mplayerxp/libplaytree/playtree.cpp mplayerxp/libplaytree/playtree.h mplayerxp/libplaytree/playtree_msg.h mplayerxp/libplaytree/playtreeparser.cpp mplayerxp/mplayerxp.cpp mplayerxp/mpxp_msg.h mplayerxp/postproc/libmenu/menu.cpp mplayerxp/postproc/libmenu/menu.h mplayerxp/postproc/libmenu/menu_cmdlist.cpp mplayerxp/postproc/libmenu/menu_console.cpp mplayerxp/postproc/libmenu/menu_filesel.cpp mplayerxp/postproc/libmenu/menu_list.h mplayerxp/postproc/libmenu/menu_param.cpp mplayerxp/postproc/libmenu/menu_pt.cpp mplayerxp/postproc/libmenu/menu_txt.cpp Modified: mplayerxp/input2/input.cpp =================================================================== --- mplayerxp/input2/input.cpp 2012-12-26 11:39:18 UTC (rev 602) +++ mplayerxp/input2/input.cpp 2012-12-26 17:16:39 UTC (rev 603) @@ -523,12 +523,12 @@ return MPXP_Ok; } -mp_cmd_t* mp_input_parse_cmd(const char* _str) { +mp_cmd_t* mp_input_parse_cmd(const std::string& _str) { int i,l; char *ptr,*e; mp_cmd_t *cmd; const mp_cmd_t *cmd_def; - char *str=mp_strdup(_str); + char *str=mp_strdup(_str.c_str()); #ifdef MP_DEBUG assert(str != NULL); @@ -776,7 +776,7 @@ mp_cmd_t* ret; if(priv.cmd_binds) cmd = mp_input_find_bind_for_key(priv.cmd_binds,n,keys); - if(cmd == NULL) cmd = mp_input_find_bind_for_key(def_cmd_binds,n,keys); + if(cmd == NULL) cmd = mp_input_find_bind_for_key(def_cmd_binds,n,keys); if(cmd == NULL) { mpxp_warn<<"No bind found for key: "<<mp_input_get_key_name(priv,keys[0]); if(n > 1) { @@ -943,7 +943,7 @@ else if(r == MP_INPUT_DEAD) priv.cmd_fds[i].flags |= MP_FD_DEAD; continue; } - ret = mp_input_parse_cmd(cmd); + ret = mp_input_parse_cmd(cmd?cmd:""); delete cmd; if(!ret) continue; last_loop = i; Modified: mplayerxp/input2/input.h =================================================================== --- mplayerxp/input2/input.h 2012-12-26 11:39:18 UTC (rev 602) +++ mplayerxp/input2/input.h 2012-12-26 17:16:39 UTC (rev 603) @@ -145,7 +145,7 @@ // If pause is true, the next input will always return a pause command. extern mp_cmd_t* mp_input_get_cmd(libinput_t& handle,int time, int paused, int peek_only); - extern mp_cmd_t* mp_input_parse_cmd(const char* str); + extern mp_cmd_t* mp_input_parse_cmd(const std::string& str); /// These filter allow you to process the command before mplayer /// If a filter return a true value mp_input_get_cmd will return NULL Modified: mplayerxp/libmpcodecs/ad.cpp =================================================================== --- mplayerxp/libmpcodecs/ad.cpp 2012-12-26 11:39:18 UTC (rev 602) +++ mplayerxp/libmpcodecs/ad.cpp 2012-12-26 17:16:39 UTC (rev 603) @@ -91,16 +91,17 @@ unsigned i; const audio_probe_t* probe; for (i=0; mpcodecs_ad_drivers[i] != &mpcodecs_ad_null; i++) { - MSG_V("Probing: %s\n",mpcodecs_ad_drivers[i]->info->driver_name); + mpxp_v<<"Probing: "<<mpcodecs_ad_drivers[i]->info->driver_name<<std::endl; if((probe=mpcodecs_ad_drivers[i]->probe(sh->wtag))!=NULL) { Opaque* priv=mpcodecs_ad_drivers[i]->preinit(*probe,sh,afi); - MSG_V("Driver: %s supports these outfmt for 0x%X wtag:\n" - ,mpcodecs_ad_drivers[i]->info->driver_name,sh->wtag); + mpxp_v<<"Driver: "<<mpcodecs_ad_drivers[i]->info->driver_name<<" supports these outfmt for "; + fourcc(mpxp_v,sh->wtag); + mpxp_v<<std::endl; for(i=0;i<Audio_MaxOutSample;i++) { - MSG_V("%X ",probe->sample_fmt[i]); + mpxp_v<<std::hex<<probe->sample_fmt[i]<<" "; if(probe->sample_fmt[i]==-1||probe->sample_fmt[i]==0) break; } - MSG_V("\n"); + mpxp_v<<std::endl; mpcodecs_ad_drivers[i]->uninit(*priv); delete priv; return probe; @@ -111,11 +112,11 @@ void afm_help(void) { unsigned i; - MSG_INFO("Available audio codec families/drivers:\n"); + mpxp_info<<"Available audio codec families/drivers:"<<std::endl; for(i=0;i<nddrivers;i++) { if(mpcodecs_ad_drivers[i]) if(mpcodecs_ad_drivers[i]->options) - MSG_INFO("\t%-10s %s\n",mpcodecs_ad_drivers[i]->info->driver_name,mpcodecs_ad_drivers[i]->info->descr); + mpxp_info<<"\t"<<std::left<<std::setw(10)<<mpcodecs_ad_drivers[i]->info->driver_name<<" "<<mpcodecs_ad_drivers[i]->info->descr<<std::endl; } - MSG_INFO("\n"); + mpxp_info<<std::endl; } Modified: mplayerxp/libmpcodecs/vd.cpp =================================================================== --- mplayerxp/libmpcodecs/vd.cpp 2012-12-26 11:39:18 UTC (rev 602) +++ mplayerxp/libmpcodecs/vd.cpp 2012-12-26 17:16:39 UTC (rev 603) @@ -97,20 +97,19 @@ unsigned i; const video_probe_t* probe; for (i=0; mpcodecs_vd_drivers[i] != &mpcodecs_vd_null; i++) { - MSG_V("Probing: %s\n",mpcodecs_vd_drivers[i]->info->driver_name); + mpxp_v<<"Probing: "<<mpcodecs_vd_drivers[i]->info->driver_name<<std::endl; if((probe=mpcodecs_vd_drivers[i]->probe(sh->fourcc))!=NULL) { Opaque* priv=mpcodecs_vd_drivers[i]->preinit(*probe,sh,psi); if(priv) { - const char* pfcc = reinterpret_cast<const char*>(&sh->fourcc); - MSG_V("Driver: %s supports these outfmt for %c%c%c%c fourcc:\n" - ,mpcodecs_vd_drivers[i]->info->driver_name - ,pfcc[0],pfcc[1],pfcc[2],pfcc[3],probe->flags[i]); + mpxp_v<<"Driver: "<<mpcodecs_vd_drivers[i]->info->driver_name<<" supports these outfmt for "; + fourcc(mpxp_v,sh->fourcc); + mpxp_v<<" fourcc:"<<std::endl; for(i=0;i<Video_MaxOutFmt;i++) { - pfcc = reinterpret_cast<const char*>(&probe->pix_fmt[i]); - MSG_V("%c%c%c%c (flg=%X) ",pfcc[0],pfcc[1],pfcc[2],pfcc[3],probe->flags[i]); + fourcc(mpxp_v,probe->pix_fmt[i]); + mpxp_v<<" (flg="<<probe->flags[i]<<")"<<std::endl; if(probe->pix_fmt[i]==0||probe->pix_fmt[i]==-1) break; } - MSG_V("\n"); + mpxp_v<<std::endl; mpcodecs_vd_drivers[i]->uninit(*priv); delete priv; return probe; @@ -122,11 +121,11 @@ void vfm_help(void) { unsigned i; - MSG_INFO("Available video codec families/drivers:\n"); + mpxp_info<<"Available video codec families/drivers:"<<std::endl; for(i=0;i<nddrivers;i++) { if(mpcodecs_vd_drivers[i]) if(mpcodecs_vd_drivers[i]->options) - MSG_INFO("\t%-10s %s\n",mpcodecs_vd_drivers[i]->info->driver_name,mpcodecs_vd_drivers[i]->info->descr); + mpxp_info<<"\t"<<std::setw(10)<<std::left<<mpcodecs_vd_drivers[i]->info->driver_name<<" "<<mpcodecs_vd_drivers[i]->info->descr<<std::endl; } - MSG_INFO("\n"); + mpxp_info<<std::endl; } Modified: mplayerxp/libmpcodecs/vd_divx4.cpp =================================================================== --- mplayerxp/libmpcodecs/vd_divx4.cpp 2012-12-26 11:39:18 UTC (rev 602) +++ mplayerxp/libmpcodecs/vd_divx4.cpp 2012-12-26 17:16:39 UTC (rev 603) @@ -242,12 +242,13 @@ case IMGFMT_I420: case IMGFMT_IYUV: break; default: - MSG_ERR("Unsupported out_fmt: 0x%X\n",sh->codec->outfmt[sh->outfmtidx]); + mpxp_err<<"Unsupported out_fmt: "; fourcc(mpxp_err,sh->codec->outfmt[sh->outfmtidx]); + mpxp_err<<std::endl; return MPXP_False; } if(!(priv.decoder=priv.getDecore_ptr(sh->fourcc))) { - char *fcc=(char *)&(sh->fourcc); - MSG_ERR("Can't find decoder for %c%c%c%c fourcc\n",fcc[0],fcc[1],fcc[2],fcc[3]); + mpxp_err<<"Can't find decoder for "; fourcc(mpxp_err,sh->fourcc); + mpxp_err<<" fourcc"<<std::endl; return MPXP_False; } dinit.formatOut.fourCC=sh->codec->outfmt[sh->outfmtidx]; @@ -260,8 +261,8 @@ dinit.formatIn.fourCC=sh->fourcc; dinit.formatIn.framePeriod=sh->fps; if(priv.decoder(NULL, DEC_OPT_INIT, (any_t*) &priv.pHandle, &dinit)!=DEC_OK) { - char *fcc=(char *)&(dinit.formatOut); - MSG_ERR("Can't find decoder for %c%c%c%c fourcc\n",fcc[0],fcc[1],fcc[2],fcc[3]); + mpxp_err<<"Can't find decoder for "; fourcc(mpxp_err,dinit.formatOut.fourCC); + mpxp_err<<" fourcc"<<std::endl; } MSG_V("INFO: DivX4Linux (libdivx.so) video codec init OK!\n"); fflush(stdout); Modified: mplayerxp/libmpcodecs/vd_lavc.cpp =================================================================== --- mplayerxp/libmpcodecs/vd_lavc.cpp 2012-12-26 11:39:18 UTC (rev 602) +++ mplayerxp/libmpcodecs/vd_lavc.cpp 2012-12-26 17:16:39 UTC (rev 603) @@ -443,10 +443,8 @@ default: { const char *fmt; fmt = (const char *)&sh->codec->outfmt[sh->outfmtidx]; - MSG_WARN("Can't apply postprocessing for"); - if(isprint(fmt[0]) && isprint(fmt[1]) && isprint(fmt[2]) && isprint(fmt[3])) - MSG_WARN(" '%c%c%c%c'!\n",fmt[0],fmt[1],fmt[2],fmt[3]); - else MSG_ERR(" 0x%08X!\n",sh->codec->outfmt[sh->outfmtidx]); + mpxp_warn<<"Can't apply postprocessing for"; + fourcc(mpxp_warn,sh->codec->outfmt[sh->outfmtidx]); break; } } Modified: mplayerxp/libmpconf/cfgparser.cpp =================================================================== --- mplayerxp/libmpconf/cfgparser.cpp 2012-12-26 11:39:18 UTC (rev 602) +++ mplayerxp/libmpconf/cfgparser.cpp 2012-12-26 17:16:39 UTC (rev 603) @@ -8,9 +8,8 @@ * * subconfig support by alex */ +#include <algorithm> -//#define DEBUG - #include <stdlib.h> #include <stdio.h> #include <ctype.h> @@ -39,12 +38,12 @@ inline void SET_RUNNING(m_config_t& c) { c.flags |= CONFIG_RUNNING; } inline int IS_RUNNING(const m_config_t& c) { return c.flags & CONFIG_RUNNING; } -typedef int (*cfg_func_arg_param_t)(const config_t *,const char *,const char *); -typedef int (*cfg_func_param_t)(const config_t *,const char *); +typedef int (*cfg_func_arg_param_t)(const config_t *,const std::string& ,const std::string& ); +typedef int (*cfg_func_param_t)(const config_t *,const std::string& ); typedef int (*cfg_func_t)(const config_t *); static void -m_config_save_option(m_config_t& config,const config_t* conf,const char* opt,const char *param) { +m_config_save_option(m_config_t& config,const config_t* conf,const std::string& opt,const std::string& param) { config_save_t* save; int sl=0; @@ -56,14 +55,16 @@ ; } - MSG_DBG2("Saving option %s\n",opt); + mpxp_dbg2<<"Saving option "<<opt<<std::endl; save = config.config_stack[config.cs_level]; if(save) { + std::string lopt=opt; + std::transform(lopt.begin(),lopt.end(),lopt.begin(), ::tolower); 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)) + if(save[sl].opt == conf && (save[sl].opt_name == NULL || lopt==save[sl].opt_name)) break; } if(save[sl].opt) @@ -72,7 +73,7 @@ save = (config_save_t*)mp_realloc(save,(sl+2)*sizeof(config_save_t)); if(save == NULL) { - MSG_ERR( "Can't allocate %d bytes of memory : %s\n",(sl+2)*sizeof(config_save_t),strerror(errno)); + mpxp_err<<"Can't allocate "<<((sl+2)*sizeof(config_save_t))<<" bytes of memory : "<<strerror(errno)<<std::endl; return; } memset(&save[sl],0,2*sizeof(config_save_t)); @@ -91,10 +92,10 @@ save[sl].param.as_pointer = *((char**)conf->p); break; case CONF_TYPE_INCLUDE : - if(param) - save->param.as_pointer = mp_strdup(param); + if(!param.empty()) + save->param.as_pointer = mp_strdup(param.c_str()); default : - MSG_ERR("Should never append in m_config_save_option : conf->type=%d\n",conf->type); + mpxp_err<<"Should never append in m_config_save_option : conf->type="<<conf->type<<std::endl; } config.config_stack[config.cs_level] = save; @@ -106,7 +107,7 @@ int i=-1; arg = save->opt_name ? save->opt_name : save->opt->name; - MSG_DBG2("Reverting option %s\n",arg); + mpxp_dbg2<<"Reverting option: "<<arg<<std::endl; switch(save->opt->type) { case CONF_TYPE_FLAG: @@ -141,7 +142,7 @@ switch(iter->opt->type) { case CONF_TYPE_INCLUDE : if (iter->param.as_pointer == NULL) { - MSG_ERR("We lost param for option %s?\n",iter->opt->name); + mpxp_err<<"We lost param for option "<<iter->opt->name<<"?"<<std::endl; return -1; } if ((((cfg_func_param_t) iter->opt->p)(iter->opt, (char*)iter->param.as_pointer)) < 0) @@ -150,7 +151,7 @@ } break; default : - MSG_ERR("Why do we reverse this : name=%s type=%d ?\n",save->opt->name,save->opt->type); + mpxp_err<<"Why do we reverse this : name="<<save->opt->name<<" type="<<save->opt->type<<" ?"<<std::endl; } return 1; @@ -161,12 +162,12 @@ config.cs_level++; config.config_stack = (config_save_t**)mp_realloc(config.config_stack ,sizeof(config_save_t*)*(config.cs_level+1)); if(config.config_stack == NULL) { - MSG_ERR( "Can't allocate %d bytes of memory : %s\n",sizeof(config_save_t*)*(config.cs_level+1),strerror(errno)); + mpxp_err<<"Can't allocate "<<(sizeof(config_save_t*)*(config.cs_level+1))<<" bytes of memory : "<<strerror(errno)<<std::endl; config.cs_level = -1; return; } config.config_stack[config.cs_level] = NULL; - MSG_DBG2("Config pushed level=%d\n",config.cs_level); + mpxp_dbg2<<"Config pushed level="<<config.cs_level<<std::endl; } int m_config_pop(m_config_t& config) { @@ -184,11 +185,11 @@ config.config_stack = (config_save_t**)mp_realloc(config.config_stack ,sizeof(config_save_t*)*config.cs_level); config.cs_level--; if(config.cs_level > 0 && config.config_stack == NULL) { - MSG_ERR( "Can't allocate %d bytes of memory : %s\n",sizeof(config_save_t*)*config.cs_level,strerror(errno)); + mpxp_err<<"Can't allocate memory"<<std::endl; config.cs_level = -1; return -1; } - MSG_DBG2("Config poped level=%d\n",config.cs_level); + mpxp_dbg2<<"Config poped level="<<config.cs_level<<std::endl; return ret; } @@ -227,39 +228,37 @@ return 1; } -static int config_is_entry_option(m_config_t& config,const char *opt,const char *param) { - play_tree_t* entry = NULL; +static int config_is_entry_option(m_config_t& config,const std::string& opt,const std::string& param) { + play_tree_t* entry = NULL; - if(strcasecmp(opt,"playlist") == 0) { // We handle playlist here - if(!param) - return ERR_MISSING_PARAM; - entry = parse_playlist_file(config.libinput,param); - if(!entry) { - MSG_ERR( "Playlist parsing failed: %s\n",param); - return 1; + std::string lopt=opt; + std::transform(lopt.begin(),lopt.end(),lopt.begin(), ::tolower); + if(lopt=="playlist") { // We handle playlist here + if(param.empty()) return ERR_MISSING_PARAM; + entry = parse_playlist_file(config.libinput,param); + if(!entry) { + mpxp_err<<"Playlist parsing failed: "<<param<<std::endl; + return 1; + } } - } - 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 + 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; + } return 0; } -static MPXP_Rc cfg_include(m_config_t& conf,const char *filename){ +static MPXP_Rc cfg_include(m_config_t& conf,const std::string& filename){ return m_config_parse_config_file(conf, filename); } static int cfg_inc_int(int value){ return ++value; } -static int config_read_option(m_config_t& config,const config_t** conf_list,const char *opt,const char *param) +static int config_read_option(m_config_t& config,const config_t** conf_list,const std::string& opt,const std::string& param) { int i=0,nconf = 0; long tmp_int; @@ -268,36 +267,36 @@ char *endptr; const config_t* conf=NULL; - MSG_DBG3( "read_option: conf=%p opt='%s' param='%s'\n", - conf, opt, param); + mpxp_dbg3<<"read_option: opt='"<<opt<<"' param='"<<param<<"'"<<std::endl; + std::string lopt=opt; + std::transform(lopt.begin(),lopt.end(),lopt.begin(), ::tolower); for(nconf = 0 ; conf_list[nconf] != NULL; nconf++) { conf = conf_list[nconf]; for (i = 0; conf[i].name != NULL; i++) { + std::string lname=conf[i].name; + std::transform(lname.begin(),lname.end(),lname.begin(), ::tolower); int namelength; /* allow 'aa*' in config.name */ -// MSG_DBG3( "cmp_option: conf=%s opt='%s'\n",conf[i].name,opt); namelength=strlen(conf[i].name); if ( (conf[i].name[namelength-1]=='*') && - !memcmp(opt, conf[i].name, namelength-1)) + !memcmp(opt.c_str(), conf[i].name, namelength-1)) goto option_found; - if (!strcasecmp(opt, conf[i].name)) - goto option_found; + if (lopt==lname) goto option_found; } } - MSG_ERR( "invalid option: %s\n",opt); + mpxp_err<<"invalid option: "<<opt<<std::endl; ret = ERR_NOT_AN_OPTION; goto out; option_found : - MSG_DBG3( "read_option: name='%s' p=%p type=%d\n", - conf[i].name, conf[i].p, conf[i].type); + mpxp_dbg3<<"read_option: name='"<<conf[i].name<<"' type="<<conf[i].type<<std::endl; if (conf[i].flags & CONF_NOCFG && config.parser_mode == CONFIG_FILE) { - MSG_ERR( "this option can only be used on command line:\n", opt); + mpxp_err<<"this option can only be used on command line:"<<opt<<std::endl; ret = ERR_NOT_AN_OPTION; goto out; } if (conf[i].flags & CONF_NOCMD && config.parser_mode == COMMAND_LINE) { - MSG_ERR( "this option can only be used in config file:\n", opt); + mpxp_err<<"this option can only be used in config file:"<<opt<<std::endl; ret = ERR_NOT_AN_OPTION; goto out; } @@ -315,119 +314,118 @@ 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")) + std::string lparm=param; + std::transform(lparm.begin(),lparm.end(),lparm.begin(), ::tolower); + if (lparm=="yes" || /* any other language? */ + lparm=="ja" || + lparm=="si" || + lparm=="igen" || + lparm=="y" || + lparm=="j" || + lparm=="i" || + lparm=="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")) + else if (lparm=="no" || + lparm=="nein" || + lparm=="nicht" || + lparm=="nem" || + lparm=="n" || + lparm=="0") *((int *) conf[i].p) = conf[i].min; else { - MSG_ERR( "invalid parameter for flag: %s\n", param); + mpxp_err<<"invalid parameter for flag: "<<param<<std::endl; ret = ERR_OUT_OF_RANGE; goto out; } ret = 1; } else { /* parser_mode == COMMAND_LINE */ *((int *) conf[i].p) = conf[i].max; - MSG_DBG3("assigning %s=%i as flag value\n",conf[i].name,conf[i].max); + mpxp_dbg3<<"assigning "<<conf[i].name<<"="<<conf[i].max<<" as flag value"<<std::endl; ret = 0; } break; case CONF_TYPE_INT: - if (param == NULL) + if (param.empty()) goto err_missing_param; - tmp_int = strtol(param, &endptr, 0); + tmp_int = ::strtol(param.c_str(), &endptr, 0); if (*endptr) { - MSG_ERR( "parameter must be an integer: %s\n", param); + mpxp_err<<"parameter must be an integer: "<<param<<std::endl; ret = ERR_OUT_OF_RANGE; goto out; } if (conf[i].flags & CONF_MIN) if (tmp_int < conf[i].min) { - MSG_ERR( "parameter must be >= %d: %s\n", (int) conf[i].min, param); + mpxp_err<<"parameter must be >= "<<(int) conf[i].min<<": "<<param<<std::endl; ret = ERR_OUT_OF_RANGE; goto out; } if (conf[i].flags & CONF_MAX) if (tmp_int > conf[i].max) { - MSG_ERR( "parameter must be <= %d: %s\n", (int) conf[i].max, param); + mpxp_err<<"parameter must be <= "<<(int) conf[i].max<<": "<<param<<std::endl; ret = ERR_OUT_OF_RANGE; goto out; } *((int *) conf[i].p) = tmp_int; - MSG_DBG3("assigning %s=%i as int value\n",conf[i].name,tmp_int); + mpxp_dbg3<<"assigning "<<conf[i].name<<"="<<tmp_int<<" as int value"<<std::endl; ret = 1; break; case CONF_TYPE_FLOAT: - if (param == NULL) + if (param.empty()) goto err_missing_param; - tmp_float = strtod(param, &endptr); + tmp_float = ::strtod(param.c_str(), &endptr); if ((*endptr == ':') || (*endptr == '/')) - tmp_float /= strtod(endptr+1, &endptr); + tmp_float /= ::strtod(endptr+1, &endptr); if (*endptr) { - MSG_ERR( "parameter must be a floating point number" - " or a ratio (numerator[:/]denominator): %s\n", param); + mpxp_err<<"parameter must be a floating point number or a ratio (numerator[:/]denominator): "<<param<<std::endl; ret = ERR_MISSING_PARAM; goto out; } if (conf[i].flags & CONF_MIN) if (tmp_float < conf[i].min) { - MSG_ERR( "parameter must be >= %f: %s\n", conf[i].min, param); + mpxp_err<<"parameter must be >= "<<(float)conf[i].min<<": "<<param<<std::endl; ret = ERR_OUT_OF_RANGE; goto out; } if (conf[i].flags & CONF_MAX) if (tmp_float > conf[i].max) { - MSG_ERR( "parameter must be <= %f: %s\n", conf[i].max, param); + mpxp_err<<"parameter must be <= "<<(float)conf[i].max<<": "<<param<<std::endl; ret = ERR_OUT_OF_RANGE; goto out; } *((float *) conf[i].p) = tmp_float; - MSG_DBG3("assigning %s=%f as float value\n",conf[i].name,tmp_float); + mpxp_dbg3<<"assigning "<<conf[i].name<<"="<<tmp_float<<" as float value"<<std::endl; ret = 1; break; case CONF_TYPE_STRING: - if (param == NULL) + if (param.empty()) goto err_missing_param; if (conf[i].flags & CONF_MIN) - if (strlen(param) < conf[i].min) { - MSG_ERR( "parameter must be >= %d chars: %s\n", - (int) conf[i].min, param); + if (param.length() < conf[i].min) { + mpxp_err<<"parameter must be >= "<<(int) conf[i].min<<" chars: "<<param<<std::endl; ret = ERR_OUT_OF_RANGE; goto out; } if (conf[i].flags & CONF_MAX) - if (strlen(param) > conf[i].max) { - MSG_ERR( "parameter must be <= %d chars: %s\n", - (int) conf[i].max, param); + if (param.length() > conf[i].max) { + mpxp_err<<"parameter must be <= "<<(int) conf[i].max<<" chars: "<<param<<std::endl; ret = ERR_OUT_OF_RANGE; goto out; } - *((char **) conf[i].p) = mp_strdup(param); + *((char **) conf[i].p) = mp_strdup(param.c_str()); m_config_add_dynamic(config,*((char **) conf[i].p)); - MSG_DBG3("assigning %s=%s as string value\n",conf[i].name,param); + mpxp_dbg3<<"assigning "<<conf[i].name<<"="<<param<<" as string value"<<std::endl; ret = 1; break; case CONF_TYPE_INC: @@ -435,7 +433,7 @@ ret = 1; break; case CONF_TYPE_INCLUDE: - if (param == NULL) + if (param.empty()) goto err_missing_param; if (cfg_include(config, param) < 0) { ret = ERR_FUNC_ERR; @@ -444,103 +442,89 @@ ret = 1; break; case CONF_TYPE_PRINT: - MSG_INFO("%s", (char *) conf[i].p); + mpxp_info<<(char *)conf[i].p; exit(1); default: - MSG_ERR( "Unknown config type specified in conf-mplayerxp.h!\n"); + mpxp_err<<"Unknown config type specified in conf-mplayerxp.h!"<<std::endl; 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; - if(config.sub_conf) { - o = new char [(strlen(config.sub_conf) + 1 + strlen(opt) + 1)]; - sprintf(o,"%s:%s",config.sub_conf,opt); - } else - o =mp_strdup(opt); + std::string o; + if(config.sub_conf) o=std::string(config.sub_conf)+":"+opt; + else o=opt; if(ret == 0) - play_tree_set_param(dest,o,NULL); + play_tree_set_param(dest,o,""); else if(ret > 0) play_tree_set_param(dest,o,param); - delete o; m_config_pop(config); } return ret; err_missing_param: - MSG_ERR( "missing parameter for option: %s\n", opt); + mpxp_err<<"missing parameter for option: "<<opt<<std::endl; ret = ERR_MISSING_PARAM; goto out; } -static const config_t* m_config_find_option(const config_t**list,const char *name); +static const config_t* m_config_find_option(const config_t**list,const std::string& name); -int m_config_set_option(m_config_t& config,const char *opt,const char *param) { - const char *e; - const config_t**clist=config.opt_list; - MSG_DBG2( "Setting option %s=%s\n",opt,param); - clist = config.opt_list; +int m_config_set_option(m_config_t& config,const std::string& _opt,const std::string& param) { + size_t e; + const config_t**clist=config.opt_list; + std::string opt=_opt; + std::string s; + mpxp_dbg2<<"Setting option "<<opt<<"="<<param<<std::endl; + clist = config.opt_list; - if(strchr(opt,'.')) { - int flg,ret; - const config_t *subconf=NULL; - const config_t* olist[] = { NULL, NULL }; - MSG_DBG2("Parsing %s as subconfig\n",opt); - do { - if(!(e = strchr(opt,'.'))) break; - if((e-opt)>0) { - char* s = new char [e-opt+1]; - strncpy(s,opt,e-opt); - s[e-opt] = '\0'; - MSG_DBG2("Treat %s as subconfig name\n",s); + e=opt.find('.'); + if(e!=std::string::npos) { + int flg,ret; + const config_t *subconf=NULL; + const config_t* olist[] = { NULL, NULL }; + mpxp_dbg2<<"Parsing "<<opt<<" as subconfig"<<std::endl; + do { + if((e = opt.find('.'))==std::string::npos) break; + s=opt.substr(0,e); + mpxp_dbg2<<"Treat "<<s<<" as subconfig name"<<std::endl; subconf = m_config_find_option(clist?clist:olist,s); clist=NULL; - delete s; - MSG_DBG2("returned %p as subconfig name\n",subconf); if(!subconf) return ERR_NO_SUBCONF; if(subconf->type!=CONF_TYPE_SUBCONFIG) return ERR_NO_SUBCONF; olist[0] = reinterpret_cast<const config_t*>(subconf->p); - opt = e+1; - MSG_DBG2("switching next subconf=%s\n",subconf->name); - } - }while(1); - flg=config.flags; - config.flags|=CONFIG_GLOBAL; - ret=config_read_option(config,olist,opt,param); - config.flags=flg; - return ret; - } - - e = strchr(opt,':'); - if(e && e[1] != '\0') { - int ret; - const config_t* opt_list[] = { NULL, NULL }; - char* s = new char [e-opt+1]; - strncpy(s,opt,e-opt); - s[e-opt] = '\0'; - opt_list[0] = (const config_t*)m_config_get_option_ptr(config,s); - if(!opt_list[0]) { - MSG_ERR("m_config_set_option %s=%s : no %s subconfig\n",opt,param,s); - delete s; - return ERR_NOT_AN_OPTION; + opt = opt.substr(e+1); + mpxp_dbg2<<"switching next subconf="<<subconf->name<<std::endl; + }while(1); + flg=config.flags; + config.flags|=CONFIG_GLOBAL; + ret=config_read_option(config,olist,opt,param); + config.flags=flg; + return ret; } - e++; - s = (char*)mp_realloc(s,strlen(e) + 1); - strcpy(s,e); - ret = config_read_option(config,opt_list,s,param); - delete s; - return ret; - } - return config_read_option(config,config.opt_list,opt,param); + e = opt.find(':'); + if(e!=std::string::npos && e<(opt.length()-1)) { + int ret; + const config_t* opt_list[] = { NULL, NULL }; + s=opt.substr(0,e); + opt_list[0] = (const config_t*)m_config_get_option_ptr(config,s); + if(!opt_list[0]) { + mpxp_err<<"m_config_set_option "<<opt<<"="<<param<<" : no "<<s<<" subconfig"<<std::endl; + return ERR_NOT_AN_OPTION; + } + s=opt.substr(e+1); + ret = config_read_option(config,opt_list,s,param); + return ret; + } + return config_read_option(config,config.opt_list,opt,param); } static void PRINT_LINENUM(const std::string& conffile,int line_num) { mpxp_err<<conffile<<"("<<line_num<<")"<<std::endl; } static const int MAX_LINE_LEN=1000; static const int MAX_OPT_LEN=100; static const int MAX_PARAM_LEN=100; -MPXP_Rc m_config_parse_config_file(m_config_t& config,const char *conffile) +MPXP_Rc m_config_parse_config_file(m_config_t& config,const std::string& conffile) { FILE *fp; char *line; @@ -555,10 +539,10 @@ MPXP_Rc ret = MPXP_Ok; int errors = 0; - if (++config.recursion_depth > 1) MSG_INFO("Reading config file: %s", conffile); + if (++config.recursion_depth > 1) mpxp_info<<"Reading config file: "<<conffile<<std::endl; if (config.recursion_depth > MAX_RECURSION_DEPTH) { - MSG_FATAL(": too deep 'include'. check your configfiles\n"); + mpxp_fatal<<": too deep 'include'. check your configfiles"<<std::endl; ret = MPXP_False; goto out; } @@ -569,22 +553,22 @@ } if ((line = new char [MAX_LINE_LEN + 1]) == NULL) { - MSG_FATAL("\ncan't get memory for 'line': %s", strerror(errno)); + mpxp_fatal<<"can't get memory for 'line': "<<strerror(errno)<<std::endl; ret = MPXP_False; goto out; } - if ((fp = fopen(conffile, "r")) == NULL) { - if (config.recursion_depth > 1) MSG_ERR(": %s\n", strerror(errno)); + if ((fp = ::fopen(conffile.c_str(), "r")) == NULL) { + if (config.recursion_depth > 1) mpxp_err<<": "<<strerror(errno)<<std::endl; delete line; ret = MPXP_Ok; goto out; } - if (config.recursion_depth > 1) MSG_FATAL("\n"); + if (config.recursion_depth > 1) mpxp_fatal<<std::endl; while (fgets(line, MAX_LINE_LEN, fp)) { if (errors >= 16) { - MSG_FATAL("too many errors\n"); + mpxp_fatal<<"too many errors"<<std::endl; goto out; } @@ -739,7 +723,7 @@ if ((*opt == '-') && (*(opt+1) == '-')) { no_more_opts = 1; if (i+1 >= argc) { - MSG_ERR( "You added '--' but no filenames presented!\n"); + mpxp_err<<"You added '--' but no filenames presented!"<<std::endl; goto err_out; } continue; @@ -759,7 +743,7 @@ if((opt[0] == '}') && (opt[1] == '\0')) { if( ! config.last_parent || ! config.last_parent->parent) { - MSG_ERR( "too much }-\n"); + mpxp_err<<"too much }-"<<std::endl; goto err_out; } config.last_entry = config.last_parent; @@ -773,7 +757,7 @@ unsigned sz; opt++; - MSG_DBG2( "this_option: %s\n", opt); + mpxp_dbg2<<"this_option: "<<opt<<std::endl; parm = argv[i+1]; item=opt; assign = strchr(opt,'='); @@ -784,8 +768,8 @@ item[sz]='\0'; parm = mp_strdup(assign+1); } - tmp = m_config_set_option(config, item, parm); - if(!tmp && assign) MSG_ERR("Option '%s' doesn't require arguments\n",item); + tmp = m_config_set_option(config, std::string(item?item:""), std::string(parm?parm:"")); + if(!tmp && assign) mpxp_err<<"Option '"<<item<<"' doesn't require arguments"<<std::endl; if(assign) { delete item; delete parm; @@ -798,13 +782,12 @@ case ERR_OUT_OF_RANGE: case ERR_NO_SUBCONF: case ERR_FUNC_ERR: - MSG_ERR( "Error '%s' while parsing option: '%s'!\n" - ,tmp==ERR_NOT_AN_OPTION?"no-option": + mpxp_err<<"Error '"<< + (tmp==ERR_NOT_AN_OPTION?"no-option": tmp==ERR_MISSING_PARAM?"missing-param": tmp==ERR_OUT_OF_RANGE?"out-of-range": - tmp==ERR_NO_SUBCONF?"no-subconfig": - "func-error" - ,opt); + tmp==ERR_NO_SUBCONF?"no-subconfig":"func-error") + <<"' while parsing option: '"<<opt<<"'"<<std::endl; goto err_out; default: i += tmp; @@ -813,7 +796,7 @@ } } else /* filename */ { play_tree_t* entry = play_tree_new(); - MSG_DBG2("Adding file %s\n",argv[i]); + mpxp_dbg2<<"Adding file "<<argv[i]<<std::endl; 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 */ @@ -825,13 +808,13 @@ } --config.recursion_depth; - if(config.last_parent != config.pt) MSG_ERR("Missing }- ?\n"); + if(config.last_parent != config.pt) mpxp_err<<"Missing }- ?"<<std::endl; UNSET_GLOBAL(config); SET_RUNNING(config); return MPXP_Ok; err_out: --config.recursion_depth; - MSG_ERR( "command line: %s\n", argv[i]); + mpxp_err<<"command line: "<<argv[i]<<std::endl; return MPXP_False; } } // namespace mpxp @@ -847,7 +830,7 @@ conf_list = (const config_t**)mp_realloc(conf_list,sizeof(struct conf*)*(list_len+2)); if(conf_list == NULL) { - MSG_ERR( "Can't allocate %d bytes of memory : %s\n",sizeof(struct conf*)*(list_len+2),strerror(errno)); + mpxp_err<<"Can't allocate memory"<<std::endl; return 0; } conf_list[list_len] = args; @@ -858,42 +841,41 @@ return 1; } -static const config_t* m_config_find_option(const config_t **list,const char *name) { - unsigned i,j; - const config_t *conf; - if(list) { - for(j = 0; list[j] != NULL ; j++) { - conf = list[j]; - for(i=0; conf[i].name != NULL; i++) { - if(strcasecmp(conf[i].name,name) == 0) - return &conf[i]; - } +static const config_t* m_config_find_option(const config_t **list,const std::string& name) { + unsigned i,j; + const config_t *conf; + if(list) { + std::string ln=name; + std::transform(ln.begin(),ln.end(),ln.begin(), ::tolower); + for(j = 0; list[j] != NULL ; j++) { + conf = list[j]; + for(i=0; conf[i].name != NULL; i++) { + std::string lcn=conf[i].name; + std::transform(lcn.begin(),lcn.end(),lcn.begin(), ::tolower); + if(lcn==ln) return &conf[i]; + } + } } - } - return NULL; + return NULL; } -const config_t* m_config_get_option(const m_config_t& config,const char* arg) { - const char *e; - const config_t **conf_list; - const config_t* cl[] = { NULL, NULL }; +const config_t* m_config_get_option(const m_config_t& config,const std::string& arg) { + size_t e; + const config_t **conf_list; + const config_t* cl[] = { NULL, NULL }; - e = strchr(arg,':'); + e = arg.find(':'); - if(e) { - char *s; - s = new char [e-arg+1]; - strncpy(s,arg,e-arg); - s[e-arg] = '\0'; - cl[0] = m_config_get_option(config,s); - conf_list = cl; - delete s; - } else - conf_list = config.opt_list; - return m_config_find_option(conf_list,arg); + if(e!=std::string::npos) { + std::string s; + s=arg.substr(0,e); + cl[0] = m_config_get_option(config,s); + conf_list = cl; + } else conf_list = config.opt_list; + return m_config_find_option(conf_list,arg); } -any_t* m_config_get_option_ptr(const m_config_t& config,const char* arg) { +any_t* m_config_get_option_ptr(const m_config_t& config,const std::string& arg) { const config_t* conf; conf = m_config_get_option(config,arg); @@ -901,38 +883,34 @@ return conf->p; } -int m_config_get_int (const m_config_t& config,const char* arg,int* err_ret) { - int *ret; +int m_config_get_int (const m_config_t& config,const std::string& arg,int& err_ret) { + int *ret; - ret = (int*)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); + ret = (int*)m_config_get_option_ptr(config,arg); + err_ret = 0; + if(!ret) { + err_ret = 1; + return -1; + } + return *ret; } -float m_config_get_float (const m_config_t& config,const char* arg,int* err_ret) { - float *ret; +float m_config_get_float (const m_config_t& config,const std::string& arg,int& err_ret) { + float *ret; - ret = (float*)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); + ret = (float*)m_config_get_option_ptr(config,arg); + err_ret = 0; + if(!ret) { + err_ret = 1; + return -1; + } + return *ret; } inline int AS_INT(const config_t* c) { return *((int*)c->p); } inline void AS_INT(const config_t* c,int val) { *((int*)c->p)=val; } -int m_config_set_int(m_config_t& config,const char* arg,int val) { +int m_config_set_int(m_config_t& config,const std::string& arg,int val) { const config_t* opt; opt = m_config_get_option(config,arg); @@ -951,7 +929,7 @@ return 1; } -int m_config_set_float(m_config_t& config,const char* arg,float val) { +int m_config_set_float(m_config_t& config,const std::string& arg,float val) { const config_t* opt; opt = m_config_get_option(config,arg); @@ -971,7 +949,7 @@ } -int m_config_switch_flag(m_config_t& config,const char* opt) { +int m_config_switch_flag(m_config_t& config,const std::string& opt) { const config_t *conf; conf = m_config_get_option(config,opt); @@ -983,7 +961,7 @@ return 1; } -int m_config_set_flag(m_config_t& config,const char* opt, int state) { +int m_config_set_flag(m_config_t& config,const std::string& opt, int state) { const config_t *conf; conf = m_config_get_option(config,opt); @@ -993,7 +971,7 @@ return 1; } -int m_config_get_flag(const m_config_t& config,const char* opt) { +int m_config_get_flag(const m_config_t& config,const std::string& opt) { const config_t* conf = m_config_get_option(config,opt); if(!conf || conf->type != CONF_TYPE_FLAG) return -1; @@ -1002,7 +980,7 @@ return -1; } -int m_config_is_option_set(const m_config_t& config,const char* arg) { +int m_config_is_option_set(const m_config_t& config,const std::string& arg) { const config_t* opt; config_save_t* save; int l,i; @@ -1025,90 +1003,88 @@ return 0; } -static void __m_config_show_options(unsigned ntabs,const char *pfx,const config_t *opts) { +static void __m_config_show_options(unsigned ntabs,const std::string& pfx,const config_t* opts) { unsigned i,n; i=0; while(opts[i].name) { if(opts[i].type==CONF_TYPE_SUBCONFIG && opts[i].p) { - char *newpfx; + std::string newpfx; unsigned pfxlen; - for(n=0;n<ntabs;n++) MSG_INFO(" "); - MSG_INFO("%s:\n",opts[i].help); + for(n=0;n<ntabs;n++) mpxp_info<<" "; + mpxp_info<<opts[i].help<<":"<<std::endl; pfxlen=strlen(opts[i].name)+1; - if(pfx) pfxlen+=strlen(pfx); - newpfx=new char [pfxlen+1]; - if(pfx) strcpy(newpfx,pfx); - else newpfx[0]='\0'; - strcat(newpfx,opts[i].name); - strcat(newpfx,"."); + if(!pfx.empty()) pfxlen+=pfx.length(); + if(!pfx.empty()) newpfx=pfx; + else newpfx=""; + newpfx+=opts[i].name; + newpfx+="."; __m_config_show_options(ntabs+2,newpfx,(const config_t *)opts[i].p); - delete newpfx; } else if(opts[i].type<=CONF_TYPE_PRINT) { - for(n=0;n<ntabs;n++) MSG_INFO(" "); - if(pfx) MSG_INFO("-%-s",pfx); - else MSG_INFO("-"); - MSG_INFO("%-11s %s" - ,opts[i].name - ,(opts[i].type==CONF_TYPE_PRINT && strcmp(opts[i].help,"show help")!=0)?opts[i].p:opts[i].help); + for(n=0;n<ntabs;n++) mpxp_info<<" "; + if(!pfx.empty()) mpxp_info<<std::left<<pfx<<std::endl; + else mpxp_info<<"-"<<std::endl; + mpxp_info<<std::left<<opts[i].name<<" " + <<((opts[i].type==CONF_TYPE_PRINT && strcmp(opts[i].help,"show help")!=0)?opts[i].p:opts[i].help) + <<std::endl; if((opts[i].flags&CONF_NOCFG)==0) { - MSG_INFO(" {%s=", - opts[i].type==CONF_TYPE_FLAG?"flg": + mpxp_info<<" {"<< + (opts[i].type==CONF_TYPE_FLAG?"flg": opts[i].type==CONF_TYPE_INT?"int": opts[i].type==CONF_TYPE_FLOAT?"flt": - opts[i].type==CONF_TYPE_STRING?"str":""); + opts[i].type==CONF_TYPE_STRING?"str":"")<<"="; switch(opts[i].type) { case CONF_TYPE_FLAG: { int defv = (*((int*)(opts[i].p)))?1:0; int max = opts[i].max ? 1:0; int res = !(defv^max); - MSG_INFO("%s",res?"ON":"OFF"); + mpxp_info<<(res?"ON":"OFF"); } break; case CONF_TYPE_STRING: { const char **defv = (const char**)(opts[i].p); - if(defv) MSG_INFO("\"%s\"",*defv); + if(defv) mpxp_info<<"\""<<*defv<<"\""; } break; case CONF_TYPE_INT: { int defv = *((int*)(opts[i].p)); - MSG_INFO("%i",defv); + mpxp_info<<defv; if((opts[i].flags&CONF_RANGE)==CONF_RANGE) { - MSG_INFO(" [%i...%i]",(int)opts[i].min,(int)opts[i].max); + mpxp_info<<" ["<<(int)opts[i].min<<"..."<<(int)opts[i].max<<"]"; } else if((opts[i].flags&CONF_MIN)==CONF_MIN) { - MSG_INFO(" <min=%i>",(int)opts[i].min); + mpxp_info<<" <min="<<(int)opts[i].min<<">"; } else if((opts[i].flags&CONF_MAX)==CONF_MAX) { - MSG_INFO(" <max=%i>",(int)opts[i].max); + mpxp_info<<" <max="<<(int)opts[i].max<<">"; } } break; case CONF_TYPE_FLOAT: { float defv = *((float*)(opts[i].p)); - MSG_INFO("%f",defv); + mpxp_info<<defv; if((opts[i].flags&CONF_RANGE)==CONF_RANGE) { - MSG_INFO(" [%f...%f]",(float)opts[i].min,(float)opts[i].max); + mpxp_info<<" ["<<(float)opts[i].min<<"..."<<(float)opts[i].max<<"]"; } else if((opts[i].flags&CONF_MIN)==CONF_MIN) { - MSG_INFO(" <min=%f>",(float)opts[i].min); + mpxp_info<<" <min="<<(float)opts[i].min<<">"; } else if((opts[i].flags&CONF_MAX)==CONF_MAX) { - MSG_INFO(" <max=%f>",(float)opts[i].max); + mpxp_info<<" <max="<<(float)opts[i].max<<">"; } } break; default: break; } - MSG_INFO("}"); + mpxp_info<<"}"; } - MSG_INFO("\n"); + mpxp_info<<std::endl; } i++; }; @@ -1118,7 +1094,7 @@ unsigned j; const config_t *opts; j=0; - MSG_INFO("List of available command-line options:\n"); + mpxp_info<<"List of available command-line options:"<<std::endl; while((opts=args.opt_list[j])!=NULL) { __m_config_show_options(2,NULL,opts); j++; Modified: mplayerxp/libmpconf/cfgparser.h =================================================================== --- mplayerxp/libmpconf/cfgparser.h 2012-12-26 11:39:18 UTC (rev 602) +++ mplayerxp/libmpconf/cfgparser.h 2012-12-26 17:16:39 UTC (rev 603) @@ -46,10 +46,10 @@ float min,max; const char *help; }; -typedef void (*cfg_default_func_t)(config_t*,const char*); +typedef void (*cfg_default_func_t)(config_t*,const std::string&); struct config_save_t; -struct m_config_t { +struct m_config_t : public Opaque { m_config_t(libinput_t& _libinput):libinput(_libinput) {} ~m_config_t() {} @@ -83,7 +83,7 @@ * 0 if can't open configfile * 1 on success */ -MPXP_Rc m_config_parse_config_file(m_config_t& config,const char *conffile); +MPXP_Rc m_config_parse_config_file(m_config_t& config,const std::string& conffile); /* parse_command_line returns: * -1 on error (invalid option...) @@ -119,55 +119,55 @@ /** Return 1 on sucess 0 on failure **/ -int m_config_set_option(m_config_t& config,const char *opt,const char *param); +int m_config_set_option(m_config_t& config,const std::string& opt,const std::string& param); /** Get the config struct defining an option * @return NULL on error **/ -const config_t* m_config_get_option(const m_config_t& config,const char* arg); +const config_t* m_config_get_option(const m_config_t& config,const std::string& arg); /** Get the p field of the struct defining an option * @return NULL on error **/ -any_t* m_config_get_option_ptr(const m_config_t& config,const char* arg); +any_t* m_config_get_option_ptr(const m_config_t& config,const std::string& 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(const m_config_t& config,const char* arg); +int m_config_is_option_set(const m_config_t& config,const std::string& arg); /** Return 0 on error 1 on success **/ -int m_config_switch_flag(m_config_t& config,const char* opt); +int m_config_switch_flag(m_config_t& config,const std::string& opt); /** Return 0 on error 1 on success **/ -int m_config_set_flag(m_config_t& config,const char* opt, int max); +int m_config_set_flag(m_config_t& config,const std::string& opt, int max); /** Return the value of a flag (O or 1) and -1 on error **/ -int m_config_get_flag(const m_config_t& config,const char* opt); +int m_config_get_flag(const m_config_t& config,const std::string& opt); /** Set the value of an int option * @return 0 on error 1 on success **/ -int m_config_set_int(m_config_t& config,const char* arg,int val); +int m_config_set_int(m_config_t& config,const std::string& arg,int val); /** Get the value of an int option * @param err_ret If it is not NULL it's set to 1 on error * @return the option value or -1 on error **/ -int m_config_get_int (const m_config_t&,const char* arg,int* err_ret); +int m_config_get_int (const m_config_t&,const std::string& 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,const char* arg,float val); +int m_config_set_float(m_config_t& config,const std::string& arg,float val); /** Get the value of a float option * @param err_ret If it is not NULL it's set to 1 on error * @return the option value or -1 on error **/ -float m_config_get_float (const m_config_t&,const char* arg,int* err_ret); +float m_config_get_float (const m_config_t&,const std::string& arg,int& err_ret); #endif /* __CONFIG_H */ Modified: mplayerxp/libplaytree/asxparser.cpp =================================================================== --- mplayerxp/libplaytree/asxparser.cpp 2012-12-26 11:39:18 UTC (rev 602) +++ mplayerxp/libplaytree/asxparser.cpp 2012-12-26 17:16:39 UTC (rev 603) @@ -1,6 +1,8 @@ #include "mpxp_config.h" #include "osdep/mplib.h" using namespace mpxp; +#include <algorithm> + #include <ctype.h> #include <stdlib.h> #include <stdio.h> @@ -302,13 +304,13 @@ return; } val = cattribs.get("VALUE"); - if(m_config_get_option(*mpxp_context().mconfig,name.c_str()) == NULL) { + if(m_config_get_option(*mpxp_context().mconfig,name) == NULL) { mpxp_warn<<"Found unknow param in asx: "<<name<<std::endl; if(!val.empty())mpxp_warn<<"="<<val<<std::endl; else mpxp_warn<<std::endl; return; } - play_tree_set_param(pt,mp_strdup(name.c_str()),mp_strdup(val.c_str())); + play_tree_set_param(pt,name,val); } void ASX_Parser::ref(ASX_Attrib& cattribs, play_tree_t* pt) const { @@ -323,7 +325,7 @@ if (href.substr(0,7)=="http://") { href = "mms"+href; } - play_tree_add_file(pt,mp_strdup(href.c_str())); + play_tree_add_file(pt,href); mpxp_v<<"Adding file "<<href<<" to element entry"<<std::endl; } @@ -375,7 +377,9 @@ warning_body_parse_error("ENTRY"); return NULL; } else if (r == 0) break; // No more element - if(strcasecmp(element.name().c_str(),"REF") == 0) { + std::string uname=element.name(); + std::transform(uname.begin(),uname.end(),uname.begin(), ::toupper); + if(uname=="REF") { ref(element.attribs(),pt_ref); mpxp_dbg2<<"Adding element "<<element.name()<<" to entry"<<std::endl; nref++; @@ -412,28 +416,30 @@ warning_body_parse_error("REPEAT"); return NULL; } else if (r == 0) break; // No more element - if(strcasecmp(element.name().c_str(),"ENTRY") == 0) { + std::string uname=element.name(); + std::transform(uname.begin(),uname.end(),uname.begin(), ::toupper); + if(uname=="ENTRY") { pt_entry = entry(element.body().c_str(),element.attribs()); if(pt_entry) { if(!list) list = pt_entry; else play_tree_append_entry(list,pt_entry); mpxp_dbg2<<"Adding element "<<element.name()<<" to repeat"<<std::endl; } - } else if(strcasecmp(element.name().c_str(),"ENTRYREF") == 0) { + } else if(uname=="ENTRYREF") { pt_entry = entryref(libinput,element.body().c_str(),element.attribs()); if(pt_entry) { if(!list) list = pt_entry; else play_tree_append_entry(list,pt_entry); mpxp_dbg2<<"Adding element "<<element.name()<<" to repeat"<<std::endl; } - } else if(strcasecmp(element.name().c_str(),"REPEAT") == 0) { + } else if(uname=="REPEAT") { pt_entry = repeat(libinput,element.body().c_str(),element.attribs()); if(pt_entry) { if(!list) list = pt_entry; else play_tree_append_entry(list,pt_entry); mpxp_dbg2<<"Adding element "<<element.name()<<" to repeat"<<std::endl; } - } else if(strcasecmp(element.name().c_str(),"PARAM") == 0) { + } else if(uname=="PARAM") { param(element.attribs(),pt_repeat); } else mpxp_dbg2<<"Ignoring element "<<element.name()<<std::endl; } @@ -466,7 +472,9 @@ return NULL; } - if(strcasecmp(element.name().c_str(),"ASX") != 0) { + std::string uname=element.name(); + std::transform(uname.begin(),uname.end(),uname.begin(), ::toupper); + if(uname=="ASX") { mpxp_err<<"first element isn't ASX, it's "<<element.name()<<std::endl; delete &parser; return NULL; @@ -487,21 +495,23 @@ delete &parser; return NULL; } else if (r == 0) break; // No more element - if(strcasecmp(element.name().c_str(),"ENTRY") == 0) { + uname=element.name(); + std::transform(uname.begin(),uname.end(),uname.begin(), ::toupper); + if(uname=="ENTRY") { pt_entry = parser.entry(element.body().c_str(),element.attribs()); if(pt_entry) { if(!list) list = pt_entry; else play_tree_append_entry(list,pt_entry); mpxp_dbg2<<"Adding element "<<element.name()<<" to asx"<<std::endl; } - } else if(strcasecmp(element.name().c_str(),"ENTRYREF") == 0) { + } else if(uname=="ENTRYREF") { pt_entry = parser.entryref(libinput,element.body().c_str(),element.attribs()); if(pt_entry) { if(!list) list = pt_entry; else play_tree_append_entry(list,pt_entry); mpxp_dbg2<<"Adding element "<<element.name()<<" to asx"<<std::endl; } - } else if(strcasecmp(element.name().c_str(),"REPEAT") == 0) { + } else if(uname=="REPEAT") { pt_entry = parser.repeat(libinput,element.body().c_str(),element.attribs()); if(pt_entry) { if(!list) list = pt_entry; Modified: mplayerxp/libplaytree/playtree.cpp =================================================================== --- mplayerxp/libplaytree/playtree.cpp 2012-12-26 11:39:18 UTC (rev 602) +++ mplayerxp/libplaytree/playtree.cpp 2012-12-26 17:16:39 UTC (rev 603) @@ -1,6 +1,7 @@ #include "mpxp_config.h" #include "osdep/mplib.h" using namespace mpxp; +#include <algorithm> #include <stdlib.h> #include <string.h> @@ -19,7 +20,7 @@ play_tree_new(void) { play_tree_t* r = (play_tree_t*)mp_calloc(1,sizeof(play_tree_t)); if(r == NULL) - MSG_ERR("Can't allocate %d bytes of memory\n",sizeof(play_tree_t)); + mpxp_err<<"Can't allocate memory"<<std::endl; r->entry_type = PLAY_TREE_ENTRY_NODE; return r; } @@ -42,14 +43,6 @@ for(iter = pt->child ; iter != NULL ; iter = iter->next) iter->parent = NULL; - //if(pt->params) delete pt->params; - if(pt->files) { - int i; - for(i = 0 ; pt->files[i] != NULL ; i++) - delete pt->files[i]; - delete pt->files; - } - delete pt; } @@ -177,144 +170,101 @@ parent->child = iter; } else parent->child = pt; - } +void play_tree_add_file(play_tree_t* pt,const std::string& file) { + if(pt->entry_type != PLAY_TREE_ENTRY_NODE && + pt->entry_type != PLAY_TREE_ENTRY_FILE) + return; -void -play_tree_add_file(play_tree_t* pt,const char* file) { - int n = 0; - char* e; + size_t pos; + std::string tail,lf=file; + std::transform(lf.begin(),lf.end(),lf.begin(), ::tolower); - if(pt->entry_type != PLAY_TREE_ENTRY_NODE && - pt->entry_type != PLAY_TREE_ENTRY_FILE) - return; - - if(pt->files) { - for(n = 0 ; pt->files[n] != NULL ; n++) - /* NOTHING */; - } - pt->files = (char**)mp_realloc((any_t*)pt->files,(n+2)*sizeof(char*)); - if(pt->files ==NULL) { - MSG_ERR("Can't allocate %d bytes of memory\n",(n+2)*sizeof(char*)); - return; - } - - e = pt->files[n] = mp_strdup(file); - pt->files[n+1] = NULL; - - if(strncasecmp(e,"vcd://",6) == 0) { - pt->entry_type = PLAY_TREE_ENTRY_VCD; - memmove(e,e + 6,strlen(&e[6])+1); - } else if(strncasecmp(e,"dvd://",6) == 0) { - pt->entry_type = PLAY_TREE_ENTRY_DVD; - memmove(e,&e[6],strlen(&e[6])+1); - } else if(strncasecmp(e,"tv://",5) == 0) { - pt->entry_type = PLAY_TREE_ENTRY_TV; - memmove(e,&e[5],strlen(&e[5])+1); - } else - pt->entry_type = PLAY_TREE_ENTRY_FILE; - + if(lf.substr(0,6)=="vcd://") { + pt->entry_type = PLAY_TREE_ENTRY_VCD; + pos=6; + } else if(lf.substr(0,6)=="dvd://") { + pt->entry_type = PLAY_TREE_ENTRY_DVD; + pos=6; + } else if(lf.substr(0,5)=="tv://") { + pt->entry_type = PLAY_TREE_ENTRY_TV; + pos=5; + } else { + pt->entry_type = PLAY_TREE_ENTRY_FILE; + pos=0; + } + tail=file.substr(pos); + pt->files.push_back(tail); } -int -play_tree_remove_file(play_tree_t* pt,const char* file) { - int n,f = -1; +MPXP_Rc play_tree_remove_file(play_tree_t* pt,const std::string& file) { + int f = -1; + size_t n,sz=pt->files.size(); - for(n=0 ; pt->files[n] != NULL ; n++) { - if(strcmp(file,pt->files[n]) == 0) - f = n; - } + for(n=0; n<sz; n++) if(file==pt->files[n]) f = n; - if(f < 0) // Not found - return 0; + if(f < 0) return MPXP_False; // Not found - delete pt->files[f]; + pt->files.erase(pt->files.begin()+f); - if(n > 1) { - memmove(&pt->files[f],&pt->files[f+1],(n-f)*sizeof(char*)); - pt->files = (char**)mp_realloc((any_t*)pt->files,n*sizeof(char*)); - if(pt->files == NULL) { - MSG_ERR("Can't allocate %d bytes of memory\n",(n+2)*sizeof(char*)); - return -1; - } - } else { - delete pt->files; - pt->files = NULL; - } - - return 1; + return MPXP_Ok; } -void play_tree_set_param(play_tree_t* pt,const char* name,const char* val) { - int n = 0,ni = -1; +void play_tree_set_param(play_tree_t* pt,const std::string& name,const std::string& val) { + int ni = -1; + size_t n,sz=pt->params.size(); - if(pt->params) { - for( ; pt->params[n].name != NULL ; n++) { - if(strcasecmp(pt->params[n].name,name) == 0) - ni = n; + std::string lname=name; + std::transform(lname.begin(),lname.end(),lname.begin(), ::tolower); + if(!pt->params.empty()) { + for(n=0; n<sz; n++) { + std::string lparm=pt->params[n].name; + std::transform(lparm.begin(),lparm.end(),lparm.begin(), ::tolower); + if(lname==lparm) ni = n; + } } - } - if(ni > 0) { - if(pt->params[n].value != NULL) delete pt->params[n].value; - pt->params[n].value = val != NULL ? mp_strdup(val) : NULL; - return; - } + if(ni > 0) { + pt->params[n].value = val; + return; + } - pt->params = (play_tree_param_t*)mp_realloc(pt->params,(n+2)*sizeof(play_tree_param_t)); - if(pt->params == NULL) - { - MSG_FATAL("Can't mp_realloc params\n"); - return; - } - pt->params[n].name = mp_strdup(name); - pt->params[n].value = val != NULL ? mp_strdup(val) : NULL; - memset(&pt->params[n+1],0,sizeof(play_tree_param_t)); - - return; + play_tree_param_t param; + param.name=name; + param.value=val; + pt->params.push_back(param); } -int play_tree_unset_param(play_tree_t* pt,const char* name) { - int n,ni = -1; +MPXP_Rc play_tree_unset_param(play_tree_t* pt,const std::string& name) { + int ni = -1; + size_t n,sz=pt->params.size(); - for(n = 0 ; pt->params[n].name != NULL ; n++) { - if(strcasecmp(pt->params[n].name,name) == 0) - ni = n; - } + std::string lname=name; + std::transform(lname.begin(),lname.end(),lname.begin(), ::tolower); + for(n=0;n<sz;n++) { + std::string lparm=pt->params[n].name; + std::transform(lparm.begin(),lparm.end(),lparm.begin(), ::tolower); + if(lname==lparm) ni = n; + } - if(ni < 0) - return 0; + if(ni < 0) return MPXP_False; - if(pt->params[ni].name) delete pt->params[ni].name; - if(pt->params[ni].value) delete pt->params[ni].value; + if(n > 1) pt->params.erase(pt->params.begin()+ni); + else pt->params.clear(); - if(n > 1) { - memmove(&pt->params[ni],&pt->params[ni+1],(n-ni)*sizeof(play_tree_param_t)); - pt->params = (play_tree_param_t*)mp_realloc(pt->params,n*sizeof(play_tree_param_t)); - if(pt->params == NULL) { - MSG_ERR("Can't allocate %d bytes of memory\n",n*sizeof(play_tree_param_t)); - return -1; - } - } else { - delete pt->params; - pt->params = NULL; - } - - return 1; + return MPXP_Ok; } void play_tree_set_params_from(play_tree_t* dest,const play_tree_t* src) { - int i; + size_t i,sz=src->params.size(); - if(!src->params) - return; + if(src->params.empty()) return; - for(i = 0; src->params[i].name != NULL ; i++) - play_tree_set_param(dest,src->params[i].name,src->params[i].value); - if(src->flags & PLAY_TREE_RND) // pass the random flag too - dest->flags |= PLAY_TREE_RND; - + for(i=0;i<sz; i++) + play_tree_set_param(dest,src->params[i].name,src->params[i].value); + if(src->flags & PLAY_TREE_RND) // pass the random flag too + dest->flags |= PLAY_TREE_RND; } // all children if deep < 0 @@ -374,7 +324,7 @@ if(!(i->flags & PLAY_TREE_RND_PLAYED)) return i; } - MSG_ERR("Random stepping error r=%i\n",rnd); + mpxp_err<<"Random stepping error r="<<rnd<<std::endl; return NULL; } @@ -398,7 +348,6 @@ _PlayTree_Iter::~_PlayTree_Iter() {} void _PlayTree_Iter::push_params() { - int n; play_tree_t* pt; pt = tree; @@ -407,9 +356,10 @@ // while playing m_config_push(config); - if(pt->params == NULL) return; + if(pt->params.empty()) return; + size_t n,sz=pt->params.size(); - for(n = 0; pt->params[n].name != NULL ; n++) { + for(n=0; n<sz; n++) { int e; if((e = m_config_set_option(config,pt->params[n].name,pt->params[n].value)) < 0) mpxp_err<<"Error "<<e<<" while setting option '"<<pt->params[n].name<<"' with value '"<<pt->params[n].value<<"'"<<std::endl; @@ -493,8 +443,7 @@ tree = pt; - for(d = 0 ; tree->files[d] != NULL ; d++) /* NOTHING */; - num_files = d; + num_files = tree->files.size(); push_params(); entry_pushed = 1; @@ -535,9 +484,9 @@ } std::string _PlayTree_Iter::get_file(int d) { - const char* entry; + std::string entry; - if(tree->files == NULL) return ""; + if(tree->files.empty()) return ""; if(file >= num_files-1 || file < -1) return ""; if(d > 0) { if(file >= num_files - 1) file = 0; @@ -550,28 +499,27 @@ switch(tree->entry_type) { case PLAY_TREE_ENTRY_DVD : - if(strlen(entry) == 0) entry = "1"; + if(entry.length() == 0) entry = "1"; m_config_set_option(config,"dvd",entry); return std::string("DVD title ")+entry; case PLAY_TREE_ENTRY_VCD : - if(strlen(entry) == 0) entry = "1"; + if(entry.length() == 0) entry = "1"; m_config_set_option(config,"vcd",entry); return std::string("vcd://")+entry; case PLAY_TREE_ENTRY_TV: { - if(strlen(entry) != 0) { - char *val = new char [strlen(entry) + 11 + 1]; - const char* e; + if(entry.length() != 0) { + std::string val; + size_t e; std::string rs; - sprintf(val,"on:channel=%s",entry); + val="on:channel="+entry; m_config_set_option(config,"tv",val); rs="TV channel "; - e = strchr(entry,':'); - if(!e) rs+=std::string(entry).substr(0,255-11); + e = entry.find(':'); + if(e==std::string::npos) rs+=entry.substr(0,255-11); else { - if(entry-e > 255) e = entry+255; - rs+=std::string(entry).substr(0,val-e); + if(e > 255) e = 255; + rs+=entry.substr(0,e); } - delete val; return rs; } else m_config_set_option(config,"tv","on"); return "TV"; @@ -697,7 +645,7 @@ } //Add a new file as a new entry -void pt_add_file(play_tree_t** ppt,const char* filename) +void pt_add_file(play_tree_t** ppt,const std::string& filename) { play_tree_t *pt = *ppt, *entry = play_tree_new(); @@ -712,18 +660,12 @@ play_tree_set_params_from(entry,pt); } -void pt_add_gui_file(play_tree_t** ppt,const char* path,const char* file) +void pt_add_gui_file(play_tree_t** ppt,const std::string& path,const std::string& file) { - char* wholename = new char [strlen(path)+strlen(file)+... [truncated message content] |