changeset 151:9708d4b2765b

cfgparser fix
author szabii
date Mon, 19 Mar 2001 02:29:37 +0000
parents 2f3e01a1fd87
children 372a9a836e86
files cfg-mplayer-def.h cfg-mplayer-func.c cfg-mplayer.h cfgparser.c cfgparser.h mplayer.c
diffstat 6 files changed, 34 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cfg-mplayer-def.h	Mon Mar 19 02:29:37 2001 +0000
@@ -0,0 +1,4 @@
+static char* default_config=
+"nosound=nem"
+"\n";
+
--- a/cfg-mplayer-func.c	Mon Mar 19 01:49:44 2001 +0000
+++ b/cfg-mplayer-func.c	Mon Mar 19 02:29:37 2001 +0000
@@ -5,5 +5,5 @@
 int cfg_func_help(struct config *conf)
 {
 	printf("%s", help_text);
-	exit(0);
+	exit(1);
 }
--- a/cfg-mplayer.h	Mon Mar 19 01:49:44 2001 +0000
+++ b/cfg-mplayer.h	Mon Mar 19 02:29:37 2001 +0000
@@ -41,7 +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},
+	{"-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:49:44 2001 +0000
+++ b/cfgparser.c	Mon Mar 19 02:29:37 2001 +0000
@@ -80,13 +80,15 @@
 				    !strcasecmp(param, "i") ||
 				    !strcmp(param, "1"))
 					*((int *) config[i].p) = config[i].max;
-				if (!strcasecmp(param, "no") ||
+				else if (!strcasecmp(param, "no") ||
 				    !strcasecmp(param, "nein") ||
 				    !strcasecmp(param, "nicht") ||
 				    !strcasecmp(param, "nem") ||
 				    !strcasecmp(param, "n") ||
 				    !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;
@@ -146,18 +148,17 @@
 			*((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 (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;
-			}
+			if ((((cfg_func_t) config[i].p)(config + i)) < 0)
+				return ERR_FUNC_ERR;
+			need_param = 0;
 			break;
 		default:
 			printf("picsaba\n");
--- a/cfgparser.h	Mon Mar 19 01:49:44 2001 +0000
+++ b/cfgparser.h	Mon Mar 19 02:29:37 2001 +0000
@@ -10,18 +10,18 @@
 #define CONF_TYPE_FLOAT		2
 #define CONF_TYPE_STRING	3
 #define CONF_TYPE_FUNC		4
+#define CONF_TYPE_FUNC_PARAM	5
 
 #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)
+#define CONF_NOCFG		(1<<2)
+#define CONF_NOCMD		(1<<3)
 
 struct config {
 	char *name;
 	void *p;
 	unsigned int type :3;
-	unsigned int flags:5;
+	unsigned int flags:4;
 	float min,max;
 };
 
--- a/mplayer.c	Mon Mar 19 01:49:44 2001 +0000
+++ b/mplayer.c	Mon Mar 19 02:29:37 2001 +0000
@@ -36,6 +36,7 @@
 
 #include "cfgparser.h"
 #include "cfg-mplayer-func.h"
+#include "cfg-mplayer-def.h"
 
 #include "libvo/video_out.h"
 
@@ -374,6 +375,8 @@
 int force_ni=0;
 char *homedir;
 char conffile[100];
+char confdir[100];
+int conffile_fd;
 #include "cfg-mplayer.h"
 
   printf("%s",banner_text);
@@ -383,7 +386,13 @@
 if ((homedir = getenv("HOME")) == NULL) {
   printf("Can't find HOME dir\n");
 } else {
-  snprintf(conffile, 100, "%s/.mplayerrc", homedir);
+  snprintf(confdir, 100, "%s/.mplayer", homedir);
+  mkdir(confdir, 0777);
+  snprintf(conffile, 100, "%s/config", confdir);
+  if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0644)) != -1) {
+    write(conffile_fd, default_config, strlen(default_config));
+    close(conffile_fd);
+  }
   if (parse_config_file(conf, conffile) < 0)
     exit(1);
 }