Mercurial > mplayer.hg
diff cfgparser.c @ 150:2f3e01a1fd87
cfgparse fixes
author | szabii |
---|---|
date | Mon, 19 Mar 2001 01:49:44 +0000 |
parents | 0a0d7dd8fb51 |
children | 9708d4b2765b |
line wrap: on
line diff
--- a/cfgparser.c Mon Mar 19 01:04:03 2001 +0000 +++ b/cfgparser.c Mon Mar 19 01:49:44 2001 +0000 @@ -14,6 +14,7 @@ #define ERR_NOT_AN_OPTION -1 #define ERR_MISSING_PARAM -2 #define ERR_OUT_OF_RANGE -3 +#define ERR_FUNC_ERR -4 #define COMMAND_LINE 0 #define CONFIG_FILE 1 @@ -23,8 +24,6 @@ #endif #include "cfgparser.h" -#include "version.h" -#include "help_mp.h" static struct config *config; static int nr_options; /* number of options in 'conf' */ @@ -43,7 +42,7 @@ config = conf; #ifdef DEBUG if (mode != COMMAND_LINE && mode != CONFIG_FILE) { - printf("init_conf: wrong flag!\n"); + printf("init_conf: wrong mode!\n"); return -1; } #endif @@ -65,6 +64,11 @@ 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) { case CONF_TYPE_FLAG: /* flags need a parameter in config file */ @@ -142,6 +146,19 @@ *((char **) config[i].p) = strdup(param); need_param = 1; break; + case CONF_TYPE_FUNC: + if (config[i].flags & CONF_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; + } else { + if ((((cfg_func_t) config[i].p)(config + i)) < 0) + return ERR_FUNC_ERR; + need_param = 0; + } + break; default: printf("picsaba\n"); break; @@ -290,6 +307,12 @@ ret = -1; continue; /* break; */ + case ERR_FUNC_ERR: + PRINT_LINENUM; + printf("parser function returned error: %s\n", opt); + ret = -1; + continue; + /* break */ } } @@ -321,7 +344,7 @@ /* 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); @@ -331,6 +354,7 @@ printf("%s", banner_text); continue; } +#endif tmp = read_option(opt, argv[i + 1]); @@ -357,6 +381,10 @@ 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) */