1
mirror of https://github.com/mpv-player/mpv synced 2024-12-24 07:33:46 +01:00

cfgparser fix

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@152 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
szabii 2001-03-19 02:29:37 +00:00
parent 05e521da65
commit ce3e8346b6
6 changed files with 34 additions and 20 deletions

4
cfg-mplayer-def.h Normal file
View File

@ -0,0 +1,4 @@
static char* default_config=
"nosound=nem"
"\n";

View File

@ -5,5 +5,5 @@
int cfg_func_help(struct config *conf) int cfg_func_help(struct config *conf)
{ {
printf("%s", help_text); printf("%s", help_text);
exit(0); exit(1);
} }

View File

@ -41,7 +41,7 @@ struct config conf[]={
{"idx", &no_index, CONF_TYPE_FLAG, 0, 1, 0}, {"idx", &no_index, CONF_TYPE_FLAG, 0, 1, 0},
{"noidx", &no_index, CONF_TYPE_FLAG, 0, 0, 1}, {"noidx", &no_index, CONF_TYPE_FLAG, 0, 0, 1},
{"v", &verbose, CONF_TYPE_INT, 0, 0, 0}, {"v", &verbose, CONF_TYPE_INT, 0, 0, 0},
{"-help", &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}, {"h", cfg_func_help, CONF_TYPE_FUNC, CONF_NOCFG, 0, 0},
{NULL, NULL, 0, 0, 0, 0} {NULL, NULL, 0, 0, 0, 0}
}; };

View File

@ -80,13 +80,15 @@ static int read_option(char *opt, char *param)
!strcasecmp(param, "i") || !strcasecmp(param, "i") ||
!strcmp(param, "1")) !strcmp(param, "1"))
*((int *) config[i].p) = config[i].max; *((int *) config[i].p) = config[i].max;
if (!strcasecmp(param, "no") || else if (!strcasecmp(param, "no") ||
!strcasecmp(param, "nein") || !strcasecmp(param, "nein") ||
!strcasecmp(param, "nicht") || !strcasecmp(param, "nicht") ||
!strcasecmp(param, "nem") || !strcasecmp(param, "nem") ||
!strcasecmp(param, "n") || !strcasecmp(param, "n") ||
!strcmp(param, "0")) !strcmp(param, "0"))
*((int *) config[i].p) = config[i].min; *((int *) config[i].p) = config[i].min;
else
return ERR_OUT_OF_RANGE;
need_param = 1; need_param = 1;
} else { /* parser_mode == COMMAND_LINE */ } else { /* parser_mode == COMMAND_LINE */
*((int *) config[i].p) = config[i].max; *((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); *((char **) config[i].p) = strdup(param);
need_param = 1; need_param = 1;
break; 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: case CONF_TYPE_FUNC:
if (config[i].flags & CONF_FUNC_PARAM) { if ((((cfg_func_t) config[i].p)(config + i)) < 0)
if (param == NULL) return ERR_FUNC_ERR;
return ERR_MISSING_PARAM; need_param = 0;
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; break;
default: default:
printf("picsaba\n"); printf("picsaba\n");

View File

@ -10,18 +10,18 @@
#define CONF_TYPE_FLOAT 2 #define CONF_TYPE_FLOAT 2
#define CONF_TYPE_STRING 3 #define CONF_TYPE_STRING 3
#define CONF_TYPE_FUNC 4 #define CONF_TYPE_FUNC 4
#define CONF_TYPE_FUNC_PARAM 5
#define CONF_CHK_MIN (1<<0) #define CONF_CHK_MIN (1<<0)
#define CONF_CHK_MAX (1<<1) #define CONF_CHK_MAX (1<<1)
#define CONF_FUNC_PARAM (1<<2) #define CONF_NOCFG (1<<2)
#define CONF_NOCFG (1<<3) #define CONF_NOCMD (1<<3)
#define CONF_NOCMD (1<<4)
struct config { struct config {
char *name; char *name;
void *p; void *p;
unsigned int type :3; unsigned int type :3;
unsigned int flags:5; unsigned int flags:4;
float min,max; float min,max;
}; };

View File

@ -36,6 +36,7 @@
#include "cfgparser.h" #include "cfgparser.h"
#include "cfg-mplayer-func.h" #include "cfg-mplayer-func.h"
#include "cfg-mplayer-def.h"
#include "libvo/video_out.h" #include "libvo/video_out.h"
@ -374,6 +375,8 @@ char *dsp="/dev/dsp";
int force_ni=0; int force_ni=0;
char *homedir; char *homedir;
char conffile[100]; char conffile[100];
char confdir[100];
int conffile_fd;
#include "cfg-mplayer.h" #include "cfg-mplayer.h"
printf("%s",banner_text); printf("%s",banner_text);
@ -383,7 +386,13 @@ if (parse_config_file(conf, "/etc/mplayer.conf") < 0)
if ((homedir = getenv("HOME")) == NULL) { if ((homedir = getenv("HOME")) == NULL) {
printf("Can't find HOME dir\n"); printf("Can't find HOME dir\n");
} else { } 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) if (parse_config_file(conf, conffile) < 0)
exit(1); exit(1);
} }