strto* int/float reader

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@196 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
szabii 2001-03-22 18:52:45 +00:00
parent 43db163b04
commit 83a5430364
1 changed files with 9 additions and 8 deletions

View File

@ -56,9 +56,10 @@ static int init_conf(struct config *conf, int mode)
static int read_option(char *opt, char *param)
{
int i;
int tmp_int;
float tmp_float;
long tmp_int;
double tmp_float;
int ret = -1;
char *endptr;
for (i = 0; i < nr_options; i++) {
if (!strcasecmp(opt, config[i].name))
@ -113,14 +114,14 @@ static int read_option(char *opt, char *param)
case CONF_TYPE_INT:
if (param == NULL)
goto err_missing_param;
if (!isdigit(*param)) {
tmp_int = strtol(param, &endptr, 0);
if (*endptr) {
printf("parameter must be an integer:\n");
ret = ERR_OUT_OF_RANGE;
goto out;
}
tmp_int = atoi(param);
if (config[i].flags & CONF_MIN)
if (tmp_int < config[i].min) {
printf("parameter must be >= %d:\n", (int) config[i].min);
@ -141,14 +142,14 @@ static int read_option(char *opt, char *param)
case CONF_TYPE_FLOAT:
if (param == NULL)
goto err_missing_param;
if (!isdigit(*param) && *param != '-' && *param != '.') {
tmp_float = strtod(param, &endptr);
if (*endptr) {
printf("parameter must be a floating point number:\n");
ret = ERR_MISSING_PARAM;
goto out;
}
tmp_float = atof(param);
if (config[i].flags & CONF_MIN)
if (tmp_float < config[i].min) {
printf("parameter must be >= %f:\n", config[i].min);