X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=blobdiff_plain;f=src%2Fopt.cc;h=6e22113dba1040f54f9ac4f352787b705676ea07;hp=b25edc5a17246f24a0b5889c7e4690ba8ca91e03;hb=20f18dc9afa4e7a9efb6253edce231f664d14215;hpb=818d6e49d86bc91748396a8c408cd84d17e10994 diff --git a/src/opt.cc b/src/opt.cc index b25edc5..6e22113 100644 --- a/src/opt.cc +++ b/src/opt.cc @@ -6,6 +6,14 @@ Options opt; +Options def_opt = { + 1280, 800, + false, // vr + true, // srgb + false, // fullscreen + 0 // path +}; + enum { OPT_SIZE, OPT_VR, @@ -27,21 +35,19 @@ static optcfg_option options[] = { }; static int opt_handler(optcfg *oc, int opt, void *cls); +static int arg_handler(optcfg *oc, const char *arg, void *cls); bool init_options(int argc, char **argv, const char *cfgfile) { // default options - memset(&opt, 0, sizeof opt); - opt.width = 1280; - opt.height = 800; - opt.srgb = true; + opt = def_opt; optcfg *oc = optcfg_init(options); optcfg_set_opt_callback(oc, opt_handler, 0); + optcfg_set_arg_callback(oc, arg_handler, 0); - if(cfgfile && optcfg_parse_config_file(oc, cfgfile) == -1) { - optcfg_destroy(oc); - return false; + if(cfgfile) { + optcfg_parse_config_file(oc, cfgfile); } if(argv && optcfg_parse_args(oc, argc, argv) == -1) { @@ -95,5 +101,15 @@ static int opt_handler(optcfg *oc, int optid, void *cls) optcfg_print_options(oc); exit(0); } - return true; + return 0; +} + +static int arg_handler(optcfg *oc, const char *arg, void *cls) +{ + if(opt.path) { + fprintf(stderr, "unexpected argument: %s\n", arg); + return -1; + } + opt.path = arg; + return 0; }