Use subopt helper to parse arguments

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@14287 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2004-12-31 14:58:49 +00:00
parent 1f74d67f87
commit efa1ae2274
1 changed files with 19 additions and 50 deletions

View File

@ -6,6 +6,7 @@
#include "mp_msg.h"
#include "config.h"
#include "subopt-helper.h"
#include "video_out.h"
#include "video_out_internal.h"
#include "font_load.h"
@ -470,63 +471,31 @@ uninit(void)
vo_x11_uninit();
}
static int int_non_neg(int *sh)
{
if ( *sh < 0 )
return 0;
return 1;
}
static opt_t subopts[] = {
{"manyfmts", OPT_ARG_BOOL, &many_fmts, NULL},
{"osd", OPT_ARG_BOOL, &use_osd, NULL},
{"scaled-osd", OPT_ARG_BOOL, &scaled_osd, NULL},
{"aspect", OPT_ARG_BOOL, &use_aspect, NULL},
{"slice-height", OPT_ARG_INT, &slice_height, (opt_test_f)int_non_neg},
{NULL}
};
static uint32_t preinit(const char *arg)
{
int parse_err = 0;
unsigned int parse_pos = 0;
// set defaults
many_fmts = 0;
use_osd = 1;
scaled_osd = 0;
use_aspect = 1;
slice_height = 4;
if(arg)
{
while (arg[parse_pos] && !parse_err) {
if (strncmp (&arg[parse_pos], "manyfmts", 8) == 0) {
parse_pos += 8;
many_fmts = 1;
} else if (strncmp (&arg[parse_pos], "nomanyfmts", 10) == 0) {
parse_pos += 10;
many_fmts = 0;
} else if (strncmp (&arg[parse_pos], "osd", 3) == 0) {
parse_pos += 3;
use_osd = 1;
} else if (strncmp (&arg[parse_pos], "noosd", 5) == 0) {
parse_pos += 5;
use_osd = 0;
} else if (strncmp (&arg[parse_pos], "scaled-osd", 10) == 0) {
parse_pos += 10;
scaled_osd = 1;
} else if (strncmp (&arg[parse_pos], "noscaled-osd", 12) == 0) {
parse_pos += 12;
scaled_osd = 0;
} else if (strncmp (&arg[parse_pos], "aspect", 6) == 0) {
parse_pos += 6;
use_aspect = 1;
} else if (strncmp (&arg[parse_pos], "noaspect", 8) == 0) {
parse_pos += 8;
use_aspect = 0;
} else if (strncmp (&arg[parse_pos], "slice-height=", 13) == 0) {
int val;
char *end;
parse_pos += 13;
val = strtol(&arg[parse_pos], &end, 0);
if (val < 0) parse_err = 1;
else {
slice_height = val;
parse_pos = end - arg;
}
}
if (arg[parse_pos] == ':') parse_pos++;
else if (arg[parse_pos]) parse_err = 1;
}
}
if (parse_err) {
unsigned int i;
mp_msg(MSGT_VO, MSGL_FATAL, "Could not parse arguments:\n%s\n", arg);
for (i = 0; i < parse_pos; i++)
mp_msg(MSGT_VO, MSGL_FATAL, " ");
mp_msg(MSGT_VO, MSGL_FATAL, "^\n");
if (subopt_parse(arg, subopts) != 0) {
mp_msg(MSGT_VO, MSGL_FATAL,
"\n-vo gl command line help:\n"
"Example: mplayer -vo gl:slice-height=4\n"