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:
parent
05e521da65
commit
ce3e8346b6
4
cfg-mplayer-def.h
Normal file
4
cfg-mplayer-def.h
Normal file
@ -0,0 +1,4 @@
|
||||
static char* default_config=
|
||||
"nosound=nem"
|
||||
"\n";
|
||||
|
@ -5,5 +5,5 @@
|
||||
int cfg_func_help(struct config *conf)
|
||||
{
|
||||
printf("%s", help_text);
|
||||
exit(0);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -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}
|
||||
};
|
||||
|
25
cfgparser.c
25
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");
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
11
mplayer.c
11
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user