changeset 150:2f3e01a1fd87

cfgparse fixes
author szabii
date Mon, 19 Mar 2001 01:49:44 +0000
parents 5762a1c7247b
children 9708d4b2765b
files Makefile cfg-mplayer-func.c cfg-mplayer-func.h cfg-mplayer.h cfgparser.c cfgparser.h mplayer.c
diffstat 7 files changed, 62 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Mar 19 01:04:03 2001 +0000
+++ b/Makefile	Mon Mar 19 01:49:44 2001 +0000
@@ -17,8 +17,10 @@
 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)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cfg-mplayer-func.c	Mon Mar 19 01:49:44 2001 +0000
@@ -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);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cfg-mplayer-func.h	Mon Mar 19 01:49:44 2001 +0000
@@ -0,0 +1,1 @@
+int cfg_func_help(struct config *conf);
--- a/cfg-mplayer.h	Mon Mar 19 01:04:03 2001 +0000
+++ b/cfg-mplayer.h	Mon Mar 19 01:49:44 2001 +0000
@@ -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 @@
 	{"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}
 };
--- 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) */
--- a/cfgparser.h	Mon Mar 19 01:04:03 2001 +0000
+++ b/cfgparser.h	Mon Mar 19 01:49:44 2001 +0000
@@ -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
--- a/mplayer.c	Mon Mar 19 01:04:03 2001 +0000
+++ b/mplayer.c	Mon Mar 19 01:49:44 2001 +0000
@@ -35,6 +35,7 @@
 #include "config.h"
 
 #include "cfgparser.h"
+#include "cfg-mplayer-func.h"
 
 #include "libvo/video_out.h"