[Mplayer-cvslog] CVS: main cfgparser.c,1.6,1.7
Szabolcs Berecz
szabii at users.sourceforge.net
Mon Mar 19 15:35:40 CET 2001
Update of /cvsroot/mplayer/main
In directory usw-pr-cvs1:/tmp/cvs-serv24758
Modified Files:
cfgparser.c
Log Message:
cfgparse fix...
Index: cfgparser.c
===================================================================
RCS file: /cvsroot/mplayer/main/cfgparser.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** cfgparser.c 2001/03/19 13:12:48 1.6
--- cfgparser.c 2001/03/19 14:35:38 1.7
***************
*** 54,60 ****
{
int i;
- int need_param = -1;
int tmp_int;
float tmp_float;
for (i = 0; i < nr_options; i++) {
--- 54,60 ----
{
int i;
int tmp_int;
float tmp_float;
+ int ret = -1;
for (i = 0; i < nr_options; i++) {
***************
*** 62,72 ****
break;
}
! if (i == nr_options)
! return ERR_NOT_AN_OPTION;
!
! if (config[i].flags & CONF_NOCFG && parser_mode == CONFIG_FILE)
! return ERR_NOT_AN_OPTION;
! if (config[i].flags & CONF_NOCMD && parser_mode == COMMAND_LINE)
! return ERR_NOT_AN_OPTION;
switch (config[i].type) {
--- 62,80 ----
break;
}
! if (i == nr_options) {
! printf("invalid option:\n");
! ret = ERR_NOT_AN_OPTION;
! goto out;
! }
! if (config[i].flags & CONF_NOCFG && parser_mode == CONFIG_FILE) {
! printf("this option can only be used on command line:\n");
! ret = ERR_NOT_AN_OPTION;
! goto out;
! }
! if (config[i].flags & CONF_NOCMD && parser_mode == COMMAND_LINE) {
! printf("this option can only be used in config file:\n");
! ret = ERR_NOT_AN_OPTION;
! goto out;
! }
switch (config[i].type) {
***************
*** 88,163 ****
!strcmp(param, "0"))
*((int *) config[i].p) = config[i].min;
! else
! return ERR_OUT_OF_RANGE;
! need_param = 1;
} else { /* parser_mode == COMMAND_LINE */
*((int *) config[i].p) = config[i].max;
! need_param = 0;
}
break;
case CONF_TYPE_INT:
if (param == NULL)
! return ERR_MISSING_PARAM;
! if (!isdigit(*param))
! return ERR_MISSING_PARAM;
tmp_int = atoi(param);
if (config[i].flags & CONF_MIN)
! if (tmp_int < config[i].min)
! return ERR_OUT_OF_RANGE;
if (config[i].flags & CONF_MAX)
! if (tmp_int > config[i].max)
! return ERR_OUT_OF_RANGE;
*((int *) config[i].p) = tmp_int;
! need_param = 1;
break;
case CONF_TYPE_FLOAT:
if (param == NULL)
! return ERR_MISSING_PARAM;
! if (!isdigit(*param))
! return ERR_MISSING_PARAM;
tmp_float = atof(param);
if (config[i].flags & CONF_MIN)
! if (tmp_float < config[i].min)
! return ERR_OUT_OF_RANGE;
if (config[i].flags & CONF_MAX)
! if (tmp_float > config[i].max)
! return ERR_OUT_OF_RANGE;
*((float *) config[i].p) = tmp_float;
! need_param = 1;
break;
case CONF_TYPE_STRING:
if (param == NULL)
! return ERR_MISSING_PARAM;
if (config[i].flags & CONF_MIN)
! if (strlen(param) < config[i].min)
! return ERR_OUT_OF_RANGE;
if (config[i].flags & CONF_MAX)
! if (strlen(param) > config[i].max)
! return ERR_OUT_OF_RANGE;
*((char **) config[i].p) = strdup(param);
! need_param = 1;
break;
case CONF_TYPE_FUNC_PARAM:
if (param == NULL)
! return ERR_MISSING_PARAM;
! if ((((cfg_func_param_t) config[i].p)(config + i, param)) < 0)
! return ERR_FUNC_ERR;
! need_param = 1;
break;
case CONF_TYPE_FUNC:
! if ((((cfg_func_t) config[i].p)(config + i)) < 0)
! return ERR_FUNC_ERR;
! need_param = 0;
break;
case CONF_TYPE_PRINT:
--- 96,206 ----
!strcmp(param, "0"))
*((int *) config[i].p) = config[i].min;
! else {
! printf("invalid parameter for flag:\n");
! ret = ERR_OUT_OF_RANGE;
! goto out;
! }
! ret = 1;
} else { /* parser_mode == COMMAND_LINE */
*((int *) config[i].p) = config[i].max;
! ret = 0;
}
break;
case CONF_TYPE_INT:
if (param == NULL)
! goto err_missing_param;
! if (!isdigit(*param)) {
! 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);
! ret = ERR_OUT_OF_RANGE;
! goto out;
! }
if (config[i].flags & CONF_MAX)
! if (tmp_int > config[i].max) {
! printf("parameter must be <= %d:\n", (int) config[i].max);
! ret = ERR_OUT_OF_RANGE;
! goto out;
! }
*((int *) config[i].p) = tmp_int;
! ret = 1;
break;
case CONF_TYPE_FLOAT:
if (param == NULL)
! goto err_missing_param;
! if (!isdigit(*param)) {
! 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);
! ret = ERR_OUT_OF_RANGE;
! goto out;
! }
if (config[i].flags & CONF_MAX)
! if (tmp_float > config[i].max) {
! printf("parameter must be <= %f:\n", config[i].max);
! ret = ERR_OUT_OF_RANGE;
! goto out;
! }
*((float *) config[i].p) = tmp_float;
! ret = 1;
break;
case CONF_TYPE_STRING:
if (param == NULL)
! goto err_missing_param;
if (config[i].flags & CONF_MIN)
! if (strlen(param) < config[i].min) {
! printf("parameter must be >= %d chars:\n",
! (int) config[i].min);
! ret = ERR_OUT_OF_RANGE;
! goto out;
! }
if (config[i].flags & CONF_MAX)
! if (strlen(param) > config[i].max) {
! printf("parameter must be <= %d chars:\n",
! (int) config[i].max);
! ret = ERR_OUT_OF_RANGE;
! goto out;
! }
*((char **) config[i].p) = strdup(param);
! ret = 1;
break;
case CONF_TYPE_FUNC_PARAM:
if (param == NULL)
! goto err_missing_param;
! if ((((cfg_func_param_t) config[i].p)(config + i, param)) < 0) {
! printf("parser function returned error:\n");
! ret = ERR_FUNC_ERR;
! goto out;
! }
! ret = 1;
break;
case CONF_TYPE_FUNC:
! if ((((cfg_func_t) config[i].p)(config + i)) < 0) {
! printf("parser function returned error:\n");
! ret = ERR_FUNC_ERR;
! goto out;
! }
! ret = 0;
break;
case CONF_TYPE_PRINT:
***************
*** 168,172 ****
break;
}
! return need_param;
}
--- 211,220 ----
break;
}
! out:
! return ret;
! err_missing_param:
! printf("missing parameter:\n");
! ret = ERR_MISSING_PARAM;
! goto out;
}
***************
*** 258,263 ****
/* read the parameter */
! for (param_pos = 0; isprint(line[line_pos]) && !isspace(line[line_pos]);
! /* NOTHING */) {
param[param_pos++] = line[line_pos++];
if (param_pos >= MAX_PARAM_LEN) {
--- 306,311 ----
/* read the parameter */
! 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) {
***************
*** 296,319 ****
switch (tmp) {
case ERR_NOT_AN_OPTION:
- PRINT_LINENUM;
- printf("invalid option: %s\n", opt);
- ret = -1;
- continue;
- /* break; */
case ERR_MISSING_PARAM:
- PRINT_LINENUM;
- printf("missing parameter: %s\n", opt);
- ret = -1;
- continue;
- /* break; */
case ERR_OUT_OF_RANGE:
- PRINT_LINENUM;
- printf("parameter of %s out of range\n", opt);
- ret = -1;
- continue;
- /* break; */
case ERR_FUNC_ERR:
PRINT_LINENUM;
! printf("parser function returned error: %s\n", opt);
ret = -1;
continue;
--- 344,352 ----
switch (tmp) {
case ERR_NOT_AN_OPTION:
case ERR_MISSING_PARAM:
case ERR_OUT_OF_RANGE:
case ERR_FUNC_ERR:
PRINT_LINENUM;
! printf("%s\n", opt);
ret = -1;
continue;
***************
*** 350,364 ****
/* remove trailing '-' */
opt++;
- #if 0
- /* check for --help, -h, and --version */
- if (!strcasecmp(opt, "-help") || !strcasecmp(opt, "h")) {
- printf("%s%s", banner_text, help_text);
- continue;
- }
- if (!strcasecmp(opt, "-version")) {
- printf("%s", banner_text);
- continue;
- }
- #endif
tmp = read_option(opt, argv[i + 1]);
--- 383,386 ----
***************
*** 370,375 ****
if (found_filename) {
/* we already have a filename */
! printf("parse_command_line: invalid option: %s\n", argv[i]);
! return -1;
} else {
found_filename = 1;
--- 392,396 ----
if (found_filename) {
/* we already have a filename */
! goto err_out;
} else {
found_filename = 1;
***************
*** 380,398 ****
break;
case ERR_MISSING_PARAM:
- printf("parse_command_line: missing parameter: %s\n", argv[i]);
- return -1;
- /* break; */
case ERR_OUT_OF_RANGE:
- printf("parse_command_line: parameter of '%s' is out of range\n", argv[i]);
- return -1;
- /* break; */
case ERR_FUNC_ERR:
! printf("parse_command_line: parser function returned error: %s\n", argv[i]);
! return -1;
/* break; */
}
i += tmp; /* we already processed the params (if there was any) */
! }
return found_filename;
}
--- 401,415 ----
break;
case ERR_MISSING_PARAM:
case ERR_OUT_OF_RANGE:
case ERR_FUNC_ERR:
! goto err_out;
/* break; */
}
i += tmp; /* we already processed the params (if there was any) */
! }
return found_filename;
+ err_out:
+ printf("parse_command_line: %s\n", argv[i]);
+ return -1;
}
_______________________________________________
Mplayer-cvslog mailing list
Mplayer-cvslog at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-cvslog
More information about the MPlayer-cvslog
mailing list