summaryrefslogtreecommitdiffstats
path: root/cfgparser.c
diff options
context:
space:
mode:
authorszabii <szabii@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-03-19 01:49:44 +0000
committerszabii <szabii@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-03-19 01:49:44 +0000
commit05e521da6584589dfd6e6686108985abd928834a (patch)
tree727413d708eb12bb2545bc4b561d25f28ec6d79b /cfgparser.c
parent767917c5149349b42e3d7628b67fe1cb38721808 (diff)
downloadmpv-05e521da6584589dfd6e6686108985abd928834a.tar.bz2
mpv-05e521da6584589dfd6e6686108985abd928834a.tar.xz
cfgparse fixes
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@151 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'cfgparser.c')
-rw-r--r--cfgparser.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/cfgparser.c b/cfgparser.c
index 0577322304..5ef32241af 100644
--- a/cfgparser.c
+++ b/cfgparser.c
@@ -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 @@ static int init_conf(struct config *conf, int mode)
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 @@ static int read_option(char *opt, char *param)
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 @@ static int read_option(char *opt, char *param)
*((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 @@ int parse_config_file(struct config *conf, char *conffile)
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 @@ int parse_command_line(struct config *conf, int argc, char **argv, char **envp,
/* 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 @@ int parse_command_line(struct config *conf, int argc, char **argv, char **envp,
printf("%s", banner_text);
continue;
}
+#endif
tmp = read_option(opt, argv[i + 1]);
@@ -357,6 +381,10 @@ not_an_option:
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) */