[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[199] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-10-25 07:50:25
|
Revision: 199 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=199&view=rev Author: nickols_k Date: 2012-10-25 07:50:09 +0000 (Thu, 25 Oct 2012) Log Message: ----------- reorder source tree Modified Paths: -------------- mplayerxp/Makefile mplayerxp/dump.c mplayerxp/input/Makefile mplayerxp/input/input.c mplayerxp/libmpcodecs/Makefile mplayerxp/libmpcodecs/ad.c mplayerxp/libmpcodecs/ad.h mplayerxp/libmpcodecs/ad_internal.h mplayerxp/libmpcodecs/dec_audio.c mplayerxp/libmpcodecs/dec_video.c mplayerxp/libmpcodecs/vd.c mplayerxp/libmpcodecs/vd.h mplayerxp/libmpcodecs/vd_internal.h mplayerxp/libmpcodecs/vd_xanim.c mplayerxp/libmpdemux/Makefile mplayerxp/libmpdemux/cdd.h mplayerxp/libmpdemux/cdda.c mplayerxp/libmpdemux/cddb.c mplayerxp/libmpdemux/demux_aiff.c mplayerxp/libmpdemux/demux_audio.c mplayerxp/libmpdemux/demux_avi.c mplayerxp/libmpdemux/demux_lavf.c mplayerxp/libmpdemux/demux_mkv.c mplayerxp/libmpdemux/demux_mpxp64.c mplayerxp/libmpdemux/demux_ogg.c mplayerxp/libmpdemux/demux_rawaudio.c mplayerxp/libmpdemux/demux_rawvideo.c mplayerxp/libmpdemux/demux_viv.c mplayerxp/libmpdemux/demux_vqf.c mplayerxp/libmpdemux/demuxer.c mplayerxp/libmpdemux/demuxer.h mplayerxp/libmpdemux/demuxer_r.c mplayerxp/libmpdemux/network.c mplayerxp/libmpdemux/s_dvdnav.c mplayerxp/libmpdemux/stream.h mplayerxp/libmpdemux/sub_cc.c mplayerxp/libplaytree/asxparser.c mplayerxp/libplaytree/playtree.h mplayerxp/libvo/vo_opengl.c mplayerxp/mp-opt-reg.c mplayerxp/mplayer.c mplayerxp/postproc/libmenu/Makefile mplayerxp/postproc/libmenu/menu.c mplayerxp/postproc/libmenu/menu_cmdlist.c mplayerxp/postproc/libmenu/menu_console.c mplayerxp/postproc/libmenu/menu_filesel.c mplayerxp/postproc/libmenu/menu_list.c mplayerxp/postproc/libmenu/menu_param.c mplayerxp/postproc/libmenu/menu_pt.c mplayerxp/postproc/libmenu/menu_txt.c mplayerxp/postproc/vf.c mplayerxp/postproc/vf.h mplayerxp/postproc/vf_menu.c Added Paths: ----------- mplayerxp/libmpconf/ mplayerxp/libmpconf/cfgparser.c mplayerxp/libmpconf/cfgparser.h mplayerxp/libmpconf/codec-cfg.c mplayerxp/libmpconf/codec-cfg.h mplayerxp/libmpconf/m_option.c mplayerxp/libmpconf/m_option.h mplayerxp/libmpconf/m_property.c mplayerxp/libmpconf/m_property.h mplayerxp/libmpconf/m_struct.c mplayerxp/libmpconf/m_struct.h mplayerxp/libmpconf/subopt-helper.c mplayerxp/libmpconf/subopt-helper.h Removed Paths: ------------- mplayerxp/cfgparser.c mplayerxp/cfgparser.h mplayerxp/codec-cfg.c mplayerxp/codec-cfg.h mplayerxp/m_option.c mplayerxp/m_option.h mplayerxp/m_property.c mplayerxp/m_property.h mplayerxp/m_struct.c mplayerxp/m_struct.h mplayerxp/subopt-helper.c mplayerxp/subopt-helper.h Modified: mplayerxp/Makefile =================================================================== --- mplayerxp/Makefile 2012-10-25 06:52:41 UTC (rev 198) +++ mplayerxp/Makefile 2012-10-25 07:50:09 UTC (rev 199) @@ -13,7 +13,7 @@ PRG_FIBMAP = fibmap_mplayerxp PRG_CFG = codec-cfg-xp # these subdirectories required installation due binaries within them -SUBDIRS = libmpdemux libmpsub libplaytree libmpcodecs libao2 osdep postproc input nls libvo +SUBDIRS = libmpdemux libmpsub libplaytree libmpcodecs libmpconf libao2 osdep postproc input nls libvo ifeq ($(TARGET_ARCH_X86),yes) SUBDIRS+=loader endif @@ -23,8 +23,8 @@ MANDIR = ${prefix}/man LDFLAGS += -Wl,-rpath,${CODECDIR}/codecs -SRCS_COMMON = cpudetect.c mp_msg.c codec-cfg.c cfgparser.c my_profile.c my_malloc.c mp_image.c subopt-helper.c -SRCS_MPLAYER = mplayer.c fifo.c $(SRCS_COMMON) mixer.c mp-opt-reg.c sig_hand.c dump.c dec_ahead.c m_option.c m_property.c m_struct.c +SRCS_COMMON = cpudetect.c mp_msg.c my_profile.c my_malloc.c mp_image.c +SRCS_MPLAYER = mplayer.c fifo.c $(SRCS_COMMON) mixer.c mp-opt-reg.c sig_hand.c dump.c dec_ahead.c OBJS_MPLAYER = $(SRCS_MPLAYER:.c=.o) @@ -43,13 +43,14 @@ input/libinput.a \ libvo/libvo.a \ osdep/libosdep.a \ - nls/libnls.a + nls/libnls.a \ + libmpconf/libmpconf.a ifeq ($(TARGET_ARCH_X86),yes) MP_LIBS += loader/libloader.a endif COMMON_LIBS = $(MP_LIBS) $(FF_LIBS) $(EXTRALIBS) -lm -CFLAGS = $(OPTFLAGS) -Ilibmpsub -Ilibmpdemux -Ilibvo $(EXTRA_INC) +CFLAGS = $(OPTFLAGS) $(EXTRA_INC) ALL_PRG = $(PRG) ifeq ($(HAVE_CSS),yes) Deleted: mplayerxp/cfgparser.c =================================================================== --- mplayerxp/cfgparser.c 2012-10-25 06:52:41 UTC (rev 198) +++ mplayerxp/cfgparser.c 2012-10-25 07:50:09 UTC (rev 199) @@ -1,1395 +0,0 @@ -/* - * command line and config file parser - * by Szabolcs Berecz <sz...@in...> - * (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 "mp_config.h" - -#define COMMAND_LINE 0 -#define CONFIG_FILE 1 - -#define CONFIG_GLOBAL (1<<0) -#define CONFIG_RUNNING (1<<1) - -#define SET_GLOBAL(c) (c->flags |= CONFIG_GLOBAL) -#define UNSET_GLOBAL(c) (c->flags &= (!CONFIG_GLOBAL)) -#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 "libmpdemux/stream.h" -#include "cfgparser.h" -#define MSGT_CLASS MSGT_CFGPARSER -#include "__mp_msg.h" - -typedef int (*cfg_func_arg_param_t)(config_t *,const char *,const char *); -typedef int (*cfg_func_param_t)(config_t *,const char *); -typedef int (*cfg_func_t)(config_t *); - -static void -m_config_save_option(m_config_t* config, config_t* conf,const char* opt,const 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_SUBCONFIG : - return; - default : - ; - } - - MSG_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) { - MSG_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; - default : - MSG_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) { - const 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; - MSG_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_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) { - MSG_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; - default : - MSG_ERR("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) { - MSG_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; - MSG_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) { - MSG_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; - } - MSG_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) { - MSG_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) { - MSG_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; -} - -static void m_config_add_dynamic(m_config_t *conf,any_t*ptr) { - if(!conf->dynasize) conf->dynamics = malloc(sizeof(any_t*)); - else conf->dynamics = realloc(conf->dynamics,(conf->dynasize+1)*sizeof(any_t*)); - conf->dynamics[conf->dynasize] = ptr; - conf->dynasize++; -} - -void m_config_free(m_config_t* config) { - unsigned i; -#ifdef MP_DEBUG - assert(config != NULL); -#endif - for(i=0;i<config->dynasize;i++) free(config->dynamics[i]); - free(config->dynamics); - config->dynasize=0; - 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) { - MSG_ERR( "init_conf: wrong mode!\n"); - return -1; - } -#endif - config->parser_mode = mode; - config->dynamics=NULL; - config->dynasize=0; - - return 1; -} - -static int config_is_entry_option(m_config_t *config,const char *opt,const 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) { - MSG_ERR( "Playlist parsing failed: %s\n",param); - 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 - return 0; -} - -static int config_read_option(m_config_t *config,config_t** conf_list,const char *opt,const char *param) -{ - int i=0,nconf = 0; - long tmp_int; - double tmp_float; - int ret = -1; - char *endptr; - config_t* conf=NULL; - -#ifdef MP_DEBUG - assert(config != NULL); - assert(conf_list != NULL); - assert(opt != NULL); -#endif - - MSG_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 */ -// 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)) - goto option_found; - if (!strcasecmp(opt, conf[i].name)) - goto option_found; - } - } - MSG_ERR( "invalid option: %s\n",opt); - 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); - - if (conf[i].flags & CONF_NOCFG && config->parser_mode == CONFIG_FILE) { - MSG_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) { - MSG_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 { - MSG_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; - MSG_DBG3("assigning %s=%i as flag value\n",conf[i].name,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) { - MSG_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) { - MSG_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) { - MSG_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; - MSG_DBG3("assigning %s=%i as int value\n",conf[i].name,tmp_int); - ret = 1; - break; - case CONF_TYPE_FLOAT: - if (param == NULL) - goto err_missing_param; - - tmp_float = strtod(param, &endptr); - - if ((*endptr == ':') || (*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); - 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); - 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); - 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); - 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) { - MSG_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) { - MSG_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); - m_config_add_dynamic(config,*((char **) conf[i].p)); - MSG_DBG3("assigning %s=%s as string value\n",conf[i].name,param); - ret = 1; - 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; -#if 0 -// we have handled it in other function - 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, "%[^=]=%s", subopt, subparam); - - MSG_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) - { - MSG_ERR( "Subconfig parsing returned error: %d in token: %s\n", - ret, token); - goto out; - } - break; - default: - MSG_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; - } -#endif - case CONF_TYPE_PRINT: - MSG_INFO("%s", (char *) conf[i].p); - exit(1); - default: - MSG_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: - MSG_ERR( "missing parameter for option: %s\n", opt); - ret = ERR_MISSING_PARAM; - goto out; -} - -static const config_t* m_config_find_option(const config_t **list,const char *name); - -int m_config_set_option(m_config_t *config,const char *opt,const char *param) { - char *e; - const config_t **clist=config->opt_list; -#ifdef MP_DEBUG - assert(config != NULL); - assert(config->opt_list != NULL); - assert(opt != NULL); -#endif - MSG_DBG2( "Setting option %s=%s\n",opt,param); - clist = config->opt_list; -#if 1 - if(strchr(opt,'.')) { - int flg,ret; - const config_t *subconf=NULL; - 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 = (char*)malloc((e-opt+1)*sizeof(char)); - strncpy(s,opt,e-opt); - s[e-opt] = '\0'; - MSG_DBG2("Treat %s as subconfig name\n",s); - subconf = m_config_find_option(clist?clist:olist,s); - clist=NULL; - free(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] = 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; - } -#endif - 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]) { - MSG_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 MSG_ERR("%s(%d): ", conffile, line_num) -#define MAX_LINE_LEN 1000 -#define MAX_OPT_LEN 100 -#define MAX_PARAM_LEN 100 - 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) - MSG_INFO("Reading config file: %s", conffile); - - if (config->recursion_depth > MAX_RECURSION_DEPTH) { - MSG_FATAL(": 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) { - MSG_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) - MSG_ERR(": %s\n", strerror(errno)); - free(line); - ret = 0; - goto out; - } - if (config->recursion_depth > 1) - MSG_FATAL("\n"); - - while (fgets(line, MAX_LINE_LEN, fp)) { - if (errors >= 16) { - MSG_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; - MSG_ERR("too long option\n"); - errors++; - ret = -1; - goto nextline; - } - } - if (opt_pos == 0) { - PRINT_LINENUM; - MSG_ERR("parse error\n"); - ret = -1; - errors++; - continue; - } - opt[opt_pos] = '\0'; - -#ifdef MP_DEBUG - PRINT_LINENUM; - MSG_DBG2("option: %s\n", opt); -#endif - - /* skip whitespaces */ - while (isspace(line[line_pos])) - ++line_pos; - - /* check '=' */ - if (line[line_pos++] != '=') { - PRINT_LINENUM; - MSG_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; - MSG_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; - MSG_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; - MSG_ERR("option without parameter\n"); - ret = -1; - errors++; - continue; - } - -#ifdef MP_DEBUG - PRINT_LINENUM; - MSG_DBG2("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; - MSG_ERR("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_NO_SUBCONF: - case ERR_FUNC_ERR: - PRINT_LINENUM; - MSG_ERR("%s\n", opt); - ret = -1; - errors++; - continue; - /* break */ - } -nextline: - ; - } - - free(line); - fclose(fp); -out: - --config->recursion_depth; - return ret; -} - -extern void show_help(void); -extern void show_long_help(void); -int m_config_parse_command_line(m_config_t *config, int argc, char **argv, char **envp) -{ - 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(envp != 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]; - if(strcmp(opt,"--help")==0) { - show_help(); - exit(0); - } - if(strcmp(opt,"--long-help")==0) { - show_long_help(); - exit(0); - } - /* check for -- (no more options id.) except --help! */ - if ((*opt == '-') && (*(opt+1) == '-')) - { - no_more_opts = 1; - if (i+1 >= argc) - { - MSG_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) { - MSG_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 leading '-' */ - char *assign,*item,*parm; - opt++; - - MSG_DBG2( "this_option: %s\n", opt); - parm = argv[i+1]; - item=opt; - assign = strchr(opt,'='); - if(assign) { - item = malloc(assign-opt); - memcpy(item,opt,assign-opt); - item[assign-opt]='\0'; - parm = strdup(assign+1); - } - tmp = m_config_set_option(config, item, parm); - if(!tmp && assign) - MSG_ERR("Option '%s' doesn't require arguments\n",item); - if(assign) { - free(item); - free(parm); - } - if(!tmp && assign) goto err_out; - - switch (tmp) { - case ERR_NOT_AN_OPTION: - case ERR_MISSING_PARAM: - 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": - tmp==ERR_MISSING_PARAM?"missing-param": - tmp==ERR_OUT_OF_RANGE?"out-of-range": - tmp==ERR_NO_SUBCONF?"no-subconfig": - "func-error" - ,opt); - goto err_out; - default: - i += tmp; - if(assign) i--; - break; - } - } - else /* filename */ - { - play_tree_t* entry = play_tree_new(); - MSG_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) - MSG_ERR("Missing }- ?\n"); - UNSET_GLOBAL(config); - SET_RUNNING(config); - return 1; -#if 0 -err_out_mem: - MSG_ERR( "can't allocate memory for filenames (%s)\n", strerror(errno)); -#endif -err_out: - --config->recursion_depth; - MSG_ERR( "command line: %s\n", argv[i]); - return -1; -} - - - -int m_config_register_options(m_config_t *config,const config_t *args) { - int list_len = 0; - const 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) { - MSG_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; -} - -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]; - } - } - } - return NULL; -} - -config_t* m_config_get_option(m_config_t const*config,const char* arg) { - char *e; - const config_t **conf_list; - const 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; - return m_config_find_option(conf_list,arg); -} - -any_t* m_config_get_option_ptr(m_config_t const*config,const 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 const *config,const 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 const *config,const 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,const 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,const 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,const 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,const 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 const *config,const 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 const*config,const 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; -} - -static void __m_config_show_options(unsigned ntabs,const char *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; - unsigned pfxlen; - for(n=0;n<ntabs;n++) MSG_INFO(" "); - MSG_INFO("%s:\n",opts[i].help); - pfxlen=strlen(opts[i].name)+1; - if(pfx) pfxlen+=strlen(pfx); - newpfx=malloc(pfxlen+1); - if(pfx) strcpy(newpfx,pfx); - else newpfx[0]='\0'; - strcat(newpfx,opts[i].name); - strcat(newpfx,"."); - __m_config_show_options(ntabs+2,newpfx,(const config_t *)opts[i].p); - free(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); - if((opts[i].flags&CONF_NOCFG)==0) { - MSG_INFO(" {%s=", - 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":""); - 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"); - } - break; - case CONF_TYPE_STRING: { - const char **defv = (const char**)(opts[i].p); - if(defv) MSG_INFO("\"%s\"",*defv); - } - break; - case CONF_TYPE_INT: { - int defv = *((int*)(opts[i].p)); - MSG_INFO("%i",defv); - if((opts[i].flags&CONF_RANGE)==CONF_RANGE) { - MSG_INFO(" [%i...%i]",(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); - } - else - if((opts[i].flags&CONF_MAX)==CONF_MAX) { - MSG_INFO(" <max=%i>",(int)opts[i].max); - } - } - break; - case CONF_TYPE_FLOAT: { - float defv = *((float*)(opts[i].p)); - MSG_INFO("%f",defv); - if((opts[i].flags&CONF_RANGE)==CONF_RANGE) { - MSG_INFO(" [%f...%f]",(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); - } - else - if((opts[i].flags&CONF_MAX)==CONF_MAX) { - MSG_INFO(" <max=%f>",(float)opts[i].max); - } - } - break; - default: - break; - } - MSG_INFO("}"); - } - MSG_INFO("\n"); - } - i++; - }; -} - -void m_config_show_options(const m_config_t *args) { - unsigned j; - const config_t *opts; - j=0; - MSG_INFO("List of available command-line options:\n"); - while((opts=args->opt_list[j])!=NULL) { - __m_config_show_options(2,NULL,opts); - j++; - }; -} - -#undef AS_INT Deleted: mplayerxp/cfgparser.h =================================================================== --- mplayerxp/cfgparser.h 2012-10-25 06:52:41 UTC (rev 198) +++ mplayerxp/cfgparser.h 2012-10-25 07:50:09 UTC (rev 199) @@ -1,172 +0,0 @@ -/* - * command line and config file parser - */ - -#ifndef __CONFIG_H -#define __CONFIG_H - -/* config types */ -#define CONF_TYPE_FLAG 0 -#define CONF_TYPE_INT 1 -#define CONF_TYPE_FLOAT 2 -#define CONF_TYPE_STRING 3 -#define CONF_TYPE_PRINT 4 -#define CONF_TYPE_FUNC 5 -#define CONF_TYPE_FUNC_PARAM 6 -#define CONF_TYPE_FUNC_FULL 7 -#define CONF_TYPE_SUBCONFIG 8 - - -#define ERR_NOT_AN_OPTION -1 -#define ERR_MISSING_PARAM -2 -#define ERR_OUT_OF_RANGE -3 -#define ERR_FUNC_ERR -4 -#define ERR_NO_SUBCONF -5 - -/* config flags */ -#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) - -typedef struct config config_t; -typedef struct m_config m_config_t; -typedef struct config_save config_save_t; - -#include "libplaytree/playtree.h" - -typedef void (*cfg_default_func_t)(config_t *,const char*); - -struct config { - const char *name; - any_t* const p; - unsigned int type; - unsigned int flags; - float 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; - const char *help; -}; - -struct m_config { - const config_t** opt_list; - config_save_t** config_stack; - any_t**dynamics; - unsigned dynasize; - int cs_level; - int parser_mode; /* COMMAND_LINE or CONFIG_FILE */ - int flags; - const char* sub_conf; // When we save a subconfig - play_tree_t* pt; // play tree we use for playlist option, etc - play_tree_t* last_entry; // last added entry - play_tree_t* 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; - any_t* as_pointer; - } param; - char* opt_name; -}; - -extern m_config_t* mconfig; - -/* 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, char **envp); - -m_config_t* m_config_new(play_tree_t* 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,const config_t *args); - -void m_config_show_options(const m_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,const char *opt,const char *param); - -/** Get the config struct defining an option - * @return NULL on error -**/ -config_t* m_config_get_option(m_config_t const *config,const char* arg); - -/** Get the p field of the struct defining an option - * @return NULL on error -**/ -any_t* m_config_get_option_ptr(m_config_t const *config,const 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 const*config,const char* arg); - -/** Return 0 on error 1 on success -**/ -int m_config_switch_flag(m_config_t *config,const char* opt); - -/** Return 0 on error 1 on success -**/ -int m_config_set_flag(m_config_t *config,const 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 const *config,const 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,const char* 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 (m_config_t const *config,const 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,const char* 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 (m_config_t const *config,const char* arg,int* err_ret); - -#endif /* __CONFIG_H */ Deleted: mplayerxp/codec-cfg.c =================================================================== --- mplayerxp/codec-cfg.c 2012-10-25 06:52:41 UTC (rev 198) +++ mplayerxp/codec-cfg.c 2012-10-25 07:50:09 UTC (rev 199) @@ -1,968 +0,0 @@ -/* - * codec.conf parser - * by Szabolcs Berecz <sz...@in...> - * (C) 2001 - * - * to compile tester app: gcc -Iloader/ -DTESTING -o codec-cfg codec-cfg.c - * to compile CODECS2HTML: gcc -Iloader/ -DCODECS2HTML -o codecs2html codecs-cfg.c - * - * TODO: implement informat in CODECS2HTML too - */ - -#include <stdio.h> -#include <stdlib.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#include <ctype.h> -#include <assert.h> -#include <string.h> - -// for mmioFOURCC: -#include "loader/wine/avifmt.h" -#include "libvo/img_format.h" -#include "codec-cfg.h" -#define MSGT_CLASS MSGT_CODECCFG -#include "__mp_msg.h" - - -#define MAX_NR_TOKEN 16 - -#define MAX_LINE_LEN 1000 - -#define RET_EOF -1 -#define RET_EOL -2 - -#define TYPE_VIDEO 0 -#define TYPE_AUDIO 1 - -#define PRINT_LINENUM MSG_ERR(" at line %d\n", line_num) - -static int add_to_fourcc(const char *s, char *alias, unsigned int *fourcc, - unsigned int *map) -{ - int i, j, freeslots; - unsigned int tmp; - - /* find first unused slot */ - for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) - /* NOTHING */; - freeslots = CODECS_MAX_FOURCC - i; - if (!freeslots) - goto err_out_too_many; - - do { - tmp = mmioFOURCC(s[0], s[1], s[2], s[3]); - for (j = 0; j < i; j++) - if (tmp == fourcc[j]) - goto err_out_duplicated; - fourcc[i] = tmp; - map[i] = alias ? mmioFOURCC(alias[0], alias[1], alias[2], alias[3]) : tmp; - s += 4; - i++; - } while ((*(s++) == ',') && --freeslots); - - if (!freeslots) - goto err_out_too_many; - if (*(--s) != '\0') - goto err_out_parse_error; - return 1; -err_out_duplicated: - MSG_ERR("duplicated fourcc/format"); - return 0; -err_out_too_many: - MSG_ERR("too many fourcc/format..."); - return 0; -err_out_parse_error: - MSG_ERR("parse error"); - return 0; -} - -static int add_to_format(const char *s, unsigned int *fourcc, unsigned int *fourccmap) -{ - int i, j; - char *endptr; - - /* find first unused slot */ - for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) - /* NOTHING */; - if (i == CODECS_MAX_FOURCC) { - MSG_ERR("too many fourcc/format..."); - return 0; - } - - fourcc[i]=fourccmap[i]=strtoul(s,&endptr,0); - if (*endptr != '\0') { - MSG_ERR("parse error"); - return 0; - } - for (j = 0; j < i; j++) - if (fourcc[j] == fourcc[i]) { - MSG_ERR("duplicated fourcc/format"); - return 0; - } - - return 1; -} - -static const struct { - const char *name; - const uint32_t num; -} fmt_table[] = { - -{"Y800", IMGFMT_Y800}, - -{"YVU9", IMGFMT_YVU9}, -{"IF09", IMGFMT_IF09}, - -{"YV12", IMGFMT_YV12}, -{"I420", IMGFMT_I420}, -{"IYUV", IMGFMT_IYUV}, - -{"YUY2", IMGFMT_YUY2}, -{"UYVY", IMGFMT_UYVY}, -{"YVYU", IMGFMT_YVYU}, - -{"CLPL", IMGFMT_CLPL}, -{"CLJR", IMGFMT_CLJR}, -{"CYUV", IMGFMT_cyuv}, - -{"444P16BE", IMGFMT_444P16_BE}, -{"444P16LE", IMGFMT_444P16_LE}, -{"444P16", IMGFMT_444P16}, -{"422P16BE", IMGFMT_422P16_BE}, -{"422P16LE", IMGFMT_422P16_LE}, -{"422P16", IMGFMT_422P16}, -{"420P16BE", IMGFMT_420P16_BE}, -{"420P16LE", IMGFMT_420P16_LE}, -{"420P16", IMGFMT_420P16}, -{"444P", IMGFMT_444P}, -{"422P", IMGFMT_422P}, -{"411P", IMGFMT_411P}, -{"420A", IMGFMT_420A}, - -{"NV12", IMGFMT_NV12}, -{"NV21", IMGFMT_NV21}, -{"HM12", IMGFMT_HM12}, - -{"IY41", IMGFMT_IY41}, -{"IYU1", IMGFMT_IYU1}, -{"IYU2", IMGFMT_IYU2}, - -{"Y422", IMGFMT_Y422}, -{"Y211", IMGFMT_Y211}, -{"Y41P", IMGFMT_Y41P}, -{"Y41T", IMGFMT_Y41T}, -{"Y42T", IMGFMT_Y42T}, -{"YUNV", IMGFMT_YUNV}, -{"IYU2", IMGFMT_IYU2}, -{"V422", IMGFMT_V422}, -{"V655", IMGFMT_V655}, -{"YUVP", IMGFMT_YUVP}, -{"UYVP", IMGFMT_UYVP}, - -{"RGB48LE",IMGFMT_RGB48LE}, -{"RGB48BE",IMGFMT_RGB48BE}, -{"RGB48", IMGFMT_RGB48NE}, -{"RGB4", IMGFMT_RGB|4}, -{"RGB8", IMGFMT_RGB|8}, -{"RGB15", IMGFMT_RGB|15}, -{"RGB16", IMGFMT_RGB|16}, -{"RGB24", IMGFMT_RGB|24}, -{"RGB32", IMGFMT_RGB|32}, -{"RGBA", IMGFMT_RGBA}, -{"ARGB", IMGFMT_ARGB}, -{"RGB1", IMGFMT_RGB|1}, - -{"BGR48LE",IMGFMT_BGR48LE}, -{"BGR48BE",IMGFMT_BGR48BE}, -{"BGR48", IMGFMT_BGR48NE}, -{"BGR4", IMGFMT_BGR|4}, -{"BGR8", IMGFMT_BGR|8}, -{"BGR15", IMGFMT_BGR|15}, -{"BGR16", IMGFMT_BGR|16}, -{"BGR24", IMGFMT_BGR|24}, -{"BGR32", IMGFMT_BGR|32}, -{"BGRA", IMGFMT_BGRA}, -{"ABGR", IMGFMT_ABGR}, -{"BGR1", IMGFMT_BGR|1}, - -{"MPES", IMGFMT_MPEGPES}, -{"JPEGNI", IMGFMT_ZRMJPEGNI}, -{"JPEGIT", IMGFMT_ZRMJPEGIT}, -{"JPEGIB", IMGFMT_ZRMJPEGIB}, -{"MOCO_MPEG2", IMGFMT_XVMC_MOCO_MPEG2}, -{"IDCT_MPEG2", IMGFMT_XVMC_IDCT_MPEG2}, -{NULL, 0} -}; - - -static int add_to_inout(const char *sfmt,const char *sflags, unsigned int *outfmt, - unsigned char *outflags) -{ - - static const char *flagstr[] = { - "flip", - "noflip", - "yuvhack", - NULL - }; - - int i, j, freeslots; - unsigned char flags; - - for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++) - /* NOTHING */; - freeslots = CODECS_MAX_OUTFMT - i; - if (!freeslots) - goto err_out_too_many; - - flags = 0; - if(sflags) { - do { - for (j = 0; flagstr[j] != NULL; j++) - if (!strncmp(sflags, flagstr[j], - strlen(flagstr[j]))) - break; - if (flagstr[j] == NULL) - goto err_out_parse_error; - flags|=(1<<j); - sflags+=strlen(flagstr[j]); - } while (*(sflags++) == ','); - - if (*(--sflags) != '\0') { - MSG_ERR("\n{found unparsed flg tile: %s}\n",sflags); - goto err_out_parse_error; - } - } - - do { - for (j = 0; fmt_table[j].name != NULL; j++) - if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name))) - break; - if (fmt_table[j].name == NULL) { - MSG_ERR("\n{%s is not registered format}\n",sfmt); - goto err_out_parse_error; - } - outfmt[i] = fmt_table[j].num; - outflags[i] = flags; - ++i; - sfmt+=strlen(fmt_table[j].name); - } while ((*(sfmt++) == ',') && --freeslots); - - if (!freeslots) - goto err_out_too_many; - - if (*(--sfmt) != '\0') { - MSG_ERR("\n{found unparsed tile %s}\n",sfmt); - goto err_out_parse_error; - } - - return 1; -err_out_too_many: - MSG_ERR("too many out..."); - return 0; -err_out_parse_error: - MSG_ERR("parse error"); - return 0; -} - -static int validate_codec(codecs_t *c, int type) -{ - unsigned i; - char *tmp_name = strdup(c->codec_name); - - for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++) - /* NOTHING */; - - if (i < strlen(tmp_name)) { - MSG_ERR("\ncodec(%s) name is not valid!\n", c->codec_name); - free(tmp_name); - return 0; - } - - if (!c->s_info) - { - strncpy(c->s_info,c->codec_name,sizeof(c->s_info)); - c->s_info[sizeof(c->s_info)-1]=0; - } - free(tmp_name); - return 1; -} - -static short get_cpuflags(char *s) -{ - static const char *flagstr[] = { - "mmx", - "sse", - "3dnow", - NULL - }; - int i; - short flags = 0; - - do { - for (i = 0; flagstr[i]; i++) - if (!strncmp(s, flagstr[i], strlen(flagstr[i]))) - break; - if (!flagstr[i]) - goto err_out_parse_error; - flags |= 1<<i; - s += strlen(flagstr[i]); - } while (*(s++) == ','); - - if (*(--s) != '\0') - goto err_out_parse_error; - - return flags; -err_out_parse_error: - return 0; -} - -static FILE *fp; -static int line_num = 0; -static char *line; -static char *token[MAX_NR_TOKEN]; - -static int get_token(int min, int max) -{ - static int read_nextline = 1; - static int line_pos; - int i; - char c; - - if (max >= MAX_NR_TOKEN) { - MSG_ERR("get_token(): max >= MAX_NR_TOKEN!"); - goto out_eof; - } - - memset(token, 0x00, sizeof(*token) * max); - - if (read_nextline) { - if (!fgets(line, MAX_LINE_LEN, fp)) - goto out_eof; - line_pos = 0; - ++line_num; - read_nextline = 0; - } - for (i = 0; i < max; i++) { - while (isspace(line[line_pos])) - ++line_pos; - if (line[line_pos] == '\0' || line[line_pos] == '#' || - line[line_pos] == ';') { - read_nextline = 1; - if (i >= min) - goto out_ok; - goto out_eol; - } - token[i] = line + line_pos; - c = line[line_pos]; - if (c == '"' || c == '\'') { - token[i]++; - while (line[++line_pos] != c && line[line_pos]) - /* NOTHING */; - } else { - for (/* NOTHING */; !isspace(line[line_pos]) && - line[line_pos]; line_pos++) - /* NOTHING */; - } - if (!line[line_pos]) { - read_nextline = 1; - if (i >= min - 1) - goto out_ok; - goto out_eol; - } - line[line_pos] = '\0'; - line_pos++; - } -out_ok: - return i; -out_eof: - read_nextline = 1; - return RET_EOF; -out_eol: - return RET_EOL; -} - -static codecs_t *video_codecs=NULL; -static codecs_t *audio_codecs=NULL; -static int nr_vcodecs = 0; -static int nr_acodecs = 0; - -int parse_codec_cfg(const char *cfgfile) -{ - codecs_t *codec = NULL; // current codec - codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs - char *endptr; // strtoul()... - int *nr_codecsp; - const char *err_hint=NULL; - int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */ - int tmp, i; - - // in case we call it secont time - if(video_codecs!=NULL)free(video_codecs); - else video_codecs=NULL; - - if(audio_codecs!=NULL)free(audio_codecs); - else audio_codecs=NULL; - - nr_vcodecs = 0; - nr_acodecs = 0; - - if(cfgfile==NULL)return 0; - - if ((fp = fopen(cfgfile, "r")) == NULL) { - MSG_FATAL("can't open '%s': %s\n", cfgfile, strerror(errno)); - return 0; - } - - if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) { - MSG_FATAL("can't get memory for 'line': %s\n", strerror(errno)); - return 0; - } - - MSG_INFO("Reading %s: ", cfgfile); - /* - * check if the cfgfile starts with 'audiocodec' or - * with 'videocodec' - */ - while ((tmp = get_token(1, 1)) == RET_EOL) - /* NOTHING */; - if (tmp == RET_EOF) - goto out; - if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) - goto loop_enter; - err_hint=token[0]; - goto err_out_parse_error; - while ((tmp = get_token(1, 1)) != RET_EOF) { - if (tmp == RET_EOL) - continue; - if (!strcmp(token[0], "audiocodec") || - !strcmp(token[0], "videocodec")) { - if (!validate_codec(codec, codec_type)) - goto err_out_not_valid; - loop_enter: - if (*token[0] == 'v') { - codec_type = TYPE_VIDEO; - nr_codecsp = &nr_vcodecs; - codecsp = &video_codecs; - } else if (*token[0] == 'a') { - codec_type = TYPE_AUDIO; - nr_codecsp = &nr_acodecs; - codecsp = &audio_codecs; -#ifdef DEBUG - } else { - MSG_ERR("picsba\n"); - goto err_out; -#endif - } - if (!(*codecsp = (codecs_t *) realloc(*codecsp, - sizeof(codecs_t) * (*nr_codecsp + 2)))) { - MSG_FATAL(" can't realloc '*codecsp': %s\n", strerror(errno)); - goto err_out; - } - codec=*codecsp + *nr_codecsp; - ++*nr_codecsp; - memset(codec,0,sizeof(codecs_t)); - memset(codec->fourcc, 0xff, sizeof(codec->fourcc)); - memset(codec->outfmt, 0xff, sizeof(codec->outfmt)); - memset(codec->infmt, 0xff, sizeof(codec->infmt)); - - if (get_token(1, 1) < 0) - goto err_out_parse_error; - for (i = 0; i < *nr_codecsp - 1; i++) { - if(( (*codecsp)[i].codec_name!=NULL) && - (!strcmp(token[0], (*codecsp)[i].codec_name)) ) { - MSG_ERR(" codec name '%s' isn't unique", token[0]); - goto err_out_print_linenum; - } - } - strncpy(codec->codec_name,token[0],sizeof(codec->codec_name)); - codec->codec_name[sizeof(codec->codec_name)-1]=0; - } else if (!strcmp(token[0], "info")) { - err_hint="info"; - if (codec->s_info[0] || get_token(1, 1) < 0) { - goto err_out_parse_error; - } - strncpy(codec->s_info,token[0],sizeof(codec->s_info)); - codec->s_info[sizeof(codec->s_info)-1]=0; - } else if (!strcmp(token[0], "comment")) { - err_hint="comment"; - if (get_token(1, 1) < 0) { - goto err_out_parse_error; - } - strncat(codec->s_comment,token[0],sizeof(codec->s_comment)); - codec->s_comment[sizeof(codec->s_comment)-1]=0; - } else if (!strcmp(token[0], "fourcc")) { - err_hint="fourcc"; - if (get_token(1, 2) < 0) { - goto err_out_parse_error; - } - if (!add_to_fourcc(token[0], token[1], - codec->fourcc, - codec->fourccmap)) { - MSG_ERR(" can't add fourcc '%s'",token[0]); - goto err_out_print_linenum; - } - } else if (!strcmp(token[0], "format")) { - err_hint="format"; - if (get_token(1, 1) < 0) { - goto err_out_parse_error; - } - if (!add_to_format(token[0], codec->fourcc,codec->fourccmap)) { - MSG_ERR(" can't add format '%s'", token[0]); - goto err_out_print_linenum; - } - } else if (!strcmp(token[0], "driver")) { - err_hint="driver"; - if (get_token(1, 1) < 0) { - goto err_out_parse_error; - } - strncpy(codec->driver_name,token[0],sizeof(codec->driver_name)); - codec->driver_name[sizeof(codec->driver_name)-1]=0; - } else if (!strcmp(token[0], "dll")) { - err_hint="dll"; - if (get_token(1, 1) < 0) { - goto err_out_parse_error; - } - strncpy(codec->dll_name,token[0],sizeof(codec->dll_name)); - codec->dll_name[sizeof(codec->dll_name)-1]=0; - } else if (!strcmp(token[0], "guid")) { - err_hint="guid"; - if (get_token(11, 11) < 0) { - goto err_out_parse_error; - } - codec->guid.f1=strtoul(token[0],&endptr,0); - if ((*endptr != ',' || *(endptr + 1) != '\0') && - *endptr != '\0') - goto err_out_parse_error; - codec->guid.f2=strtoul(token[1],&endptr,0); - if ((*endptr != ',' || *(endptr + 1) != '\0') && - *endptr != '\0') - goto err_out_parse_error; - codec->guid.f3=strtoul(token[2],&endptr,0); - if ((*endptr != ',' || *(endptr + 1) != '\0') && - *endptr != '\0') - goto err_out_parse_error; - for (i = 0; i < 8; i++) { - codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0); - if ((*endptr != ',' || *(endptr + 1) != '\0') && - *endptr != '\0') - goto err_out_parse_error; - } - } else if (!strcmp(token[0], "out")) { - err_hint="out"; - if (get_token(1, 2) < 0) { - goto err_out_parse_error; - } - if (!add_to_inout(token[0], token[1], codec->outfmt, - codec->outflags)) { - MSG_ERR(" can't add outfmt '%s'", token[0]); - goto err_out_print_linenum; - } - } else if (!strcmp(token[0], "in")) { - err_hint="in"; - if (get_token(1, 2) < 0) { - goto err_out_parse_error; - } - if (!add_to_inout(token[0], toke... [truncated message content] |