diff --git a/cfg-common.h b/cfg-common.h index 0d8439dd98..c0ef24b39f 100644 --- a/cfg-common.h +++ b/cfg-common.h @@ -54,7 +54,7 @@ {"frames", &play_n_frames_mf, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, // seek to byte/seconds position - {"sb", &seek_to_byte, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, + {"sb", &seek_to_byte, CONF_TYPE_POSITION, CONF_MIN, 0, 0, NULL}, {"ss", &seek_to_sec, CONF_TYPE_STRING, CONF_MIN, 0, 0, NULL}, // AVI specific: force non-interleaved mode diff --git a/cfgparser.c b/cfgparser.c index 0781126178..20430bf96a 100644 --- a/cfgparser.c +++ b/cfgparser.c @@ -112,6 +112,9 @@ m_config_save_option(m_config_t* config, config_t* conf,char* opt, char *param) case CONF_TYPE_STRING_LIST : save[sl].param.as_pointer = *((char***)conf->p); break; + case CONF_TYPE_POSITION : + save[sl].param.as_off_t = *((off_t*)conf->p); + break; default : mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Should never append in m_config_save_option : conf->type=%d\n",conf->type); } @@ -196,6 +199,9 @@ m_config_revert_option(m_config_t* config, config_save_t* save) { break; } break; + case CONF_TYPE_POSITION : + *((off_t*)save->opt->p) = save->param.as_off_t; + break; default : mp_msg(MSGT_CFGPARSER,MSGL_WARN,"Why do we reverse this : name=%s type=%d ?\n",save->opt->name,save->opt->type); } @@ -425,7 +431,9 @@ static int config_read_option(m_config_t *config,config_t** conf_list, char *opt { int i=0,nconf = 0; long tmp_int; + off_t tmp_off; double tmp_float; + int dummy; int ret = -1; char *endptr; config_t* conf=NULL; @@ -731,6 +739,42 @@ static int config_read_option(m_config_t *config,config_t** conf_list, char *opt case CONF_TYPE_PRINT: mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", (char *) conf[i].p); exit(1); + case CONF_TYPE_POSITION: + if (param == NULL) + goto err_missing_param; + + if (sscanf(param, sizeof(off_t) == sizeof(int) ? + "%d%c" : "%lld%c", &tmp_off, dummy) != 1) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parameter must be an integer: %s\n", param); + ret = ERR_OUT_OF_RANGE; + goto out; + } + + if (conf[i].flags & CONF_MIN) + if (tmp_off < conf[i].min) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + (sizeof(off_t) == sizeof(int) ? + "parameter must be >= %d: %s\n" : + "parameter must be >= %lld: %s\n"), + (off_t) conf[i].min, param); + ret = ERR_OUT_OF_RANGE; + goto out; + } + + if (conf[i].flags & CONF_MAX) + if (tmp_off > conf[i].max) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + (sizeof(off_t) == sizeof(int) ? + "parameter must be <= %d: %s\n" : + "parameter must be <= %lld: %s\n"), + (off_t) conf[i].max, param); + ret = ERR_OUT_OF_RANGE; + goto out; + } + + *((off_t *) conf[i].p) = tmp_off; + ret = 1; + break; default: mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknown config type specified in conf-mplayer.h!\n"); break; diff --git a/cfgparser.h b/cfgparser.h index 9f06eb798d..f4b52c2a01 100644 --- a/cfgparser.h +++ b/cfgparser.h @@ -15,6 +15,7 @@ #define CONF_TYPE_FUNC_FULL 7 #define CONF_TYPE_SUBCONFIG 8 #define CONF_TYPE_STRING_LIST 9 +#define CONF_TYPE_POSITION 10 #define ERR_NOT_AN_OPTION -1 @@ -73,6 +74,7 @@ struct config_save { int as_int; float as_float; void* as_pointer; + off_t* as_off_t; } param; char* opt_name; };