diff options
author | szabii <szabii@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-03-19 01:49:44 +0000 |
---|---|---|
committer | szabii <szabii@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-03-19 01:49:44 +0000 |
commit | 05e521da6584589dfd6e6686108985abd928834a (patch) | |
tree | 727413d708eb12bb2545bc4b561d25f28ec6d79b | |
parent | 767917c5149349b42e3d7628b67fe1cb38721808 (diff) | |
download | mpv-05e521da6584589dfd6e6686108985abd928834a.tar.bz2 mpv-05e521da6584589dfd6e6686108985abd928834a.tar.xz |
cfgparse fixes
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@151 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | cfg-mplayer-func.c | 9 | ||||
-rw-r--r-- | cfg-mplayer-func.h | 1 | ||||
-rw-r--r-- | cfg-mplayer.h | 4 | ||||
-rw-r--r-- | cfgparser.c | 36 | ||||
-rw-r--r-- | cfgparser.h | 15 | ||||
-rw-r--r-- | mplayer.c | 1 |
7 files changed, 62 insertions, 10 deletions
@@ -17,8 +17,10 @@ PRG_TV = tvision prefix = /usr/local BINDIR = ${prefix}/bin # BINDIR = /usr/local/bin -SRCS = linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c -OBJS = linux/getch2.o linux/timer-lx.o linux/shmem.o xa/xa_gsm.o lirc_mp.o cfgparser.o +SRCS = linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c\ + cfg-mplayer-func.c +OBJS = linux/getch2.o linux/timer-lx.o linux/shmem.o xa/xa_gsm.o lirc_mp.o cfgparser.o\ + cfg-mplayer-func.o CFLAGS = $(OPTFLAGS) -Iloader -Ilibvo # -Wall A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3 VO_LIBS = -Llibvo -lvo $(X_LIBS) diff --git a/cfg-mplayer-func.c b/cfg-mplayer-func.c new file mode 100644 index 0000000000..60fc43d7f1 --- /dev/null +++ b/cfg-mplayer-func.c @@ -0,0 +1,9 @@ +#include "cfgparser.h" +#include "version.h" +#include "help_mp.h" + +int cfg_func_help(struct config *conf) +{ + printf("%s", help_text); + exit(0); +} diff --git a/cfg-mplayer-func.h b/cfg-mplayer-func.h new file mode 100644 index 0000000000..912d677370 --- /dev/null +++ b/cfg-mplayer-func.h @@ -0,0 +1 @@ +int cfg_func_help(struct config *conf); diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 10b367a59c..224a4cb5c4 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -2,6 +2,8 @@ * config for cfgparser */ +#include "cfg-mplayer-func.h" + struct config conf[]={ /* name, pointer, type, flags, min, max */ {"vo", &video_driver, CONF_TYPE_STRING, 0, 0, 0}, @@ -39,5 +41,7 @@ struct config conf[]={ {"idx", &no_index, CONF_TYPE_FLAG, 0, 1, 0}, {"noidx", &no_index, CONF_TYPE_FLAG, 0, 0, 1}, {"v", &verbose, CONF_TYPE_INT, 0, 0, 0}, + {"-help", &cfg_func_help, CONF_TYPE_FUNC, CONF_NOCFG, 0, 0}, + {"h", &cfg_func_help, CONF_TYPE_FUNC, CONF_NOCFG, 0, 0}, {NULL, NULL, 0, 0, 0, 0} }; 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) */ diff --git a/cfgparser.h b/cfgparser.h index ce6462eef6..9508085b46 100644 --- a/cfgparser.h +++ b/cfgparser.h @@ -9,18 +9,25 @@ #define CONF_TYPE_INT 1 #define CONF_TYPE_FLOAT 2 #define CONF_TYPE_STRING 3 +#define CONF_TYPE_FUNC 4 -#define CONF_CHK_MIN 1<<0 -#define CONF_CHK_MAX 1<<1 +#define CONF_CHK_MIN (1<<0) +#define CONF_CHK_MAX (1<<1) +#define CONF_FUNC_PARAM (1<<2) +#define CONF_NOCFG (1<<3) +#define CONF_NOCMD (1<<4) struct config { char *name; void *p; - unsigned int type :2; - unsigned int flags:2; + unsigned int type :3; + unsigned int flags:5; float min,max; }; +typedef int (*cfg_func_param_t)(struct config *, char *); +typedef int (*cfg_func_t)(struct config *); + /* parse_config_file returns: * -1 on error (can't malloc, invalid option...) * 0 if can't open configfile @@ -35,6 +35,7 @@ #include "config.h" #include "cfgparser.h" +#include "cfg-mplayer-func.h" #include "libvo/video_out.h" |