diff --git a/cfg-mplayer-def.h b/cfg-mplayer-def.h new file mode 100644 index 0000000000..f75cb44a98 --- /dev/null +++ b/cfg-mplayer-def.h @@ -0,0 +1,4 @@ +static char* default_config= +"nosound=nem" +"\n"; + diff --git a/cfg-mplayer-func.c b/cfg-mplayer-func.c index 60fc43d7f1..06d1a9c9c8 100644 --- a/cfg-mplayer-func.c +++ b/cfg-mplayer-func.c @@ -5,5 +5,5 @@ int cfg_func_help(struct config *conf) { printf("%s", help_text); - exit(0); + exit(1); } diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 224a4cb5c4..f0be7d0787 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -41,7 +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}, + {"-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 5ef32241af..f405bf7095 100644 --- a/cfgparser.c +++ b/cfgparser.c @@ -80,13 +80,15 @@ static int read_option(char *opt, char *param) !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 @@ static int read_option(char *opt, char *param) *((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"); diff --git a/cfgparser.h b/cfgparser.h index 9508085b46..3e384f6076 100644 --- a/cfgparser.h +++ b/cfgparser.h @@ -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; }; diff --git a/mplayer.c b/mplayer.c index 3be64c8d3c..3a0f062a68 100644 --- a/mplayer.c +++ b/mplayer.c @@ -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 @@ char *dsp="/dev/dsp"; 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 (parse_config_file(conf, "/etc/mplayer.conf") < 0) 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); }