X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=blobdiff_plain;f=src%2Fopt.cc;h=6698f8c30f5a7a6396bd57d2ae334d4c490acdb6;hp=0b9914983c5de853b38120cc121ee6cc834a1abf;hb=f737a4688a44fa05c9a5ea7919819437fae85ae1;hpb=b7ea5b1ae3f0f0a5eba13b49e303b49876ee209e diff --git a/src/opt.cc b/src/opt.cc index 0b99149..6698f8c 100644 --- a/src/opt.cc +++ b/src/opt.cc @@ -7,6 +7,7 @@ Options opt; enum { + OPT_SIZE, OPT_VR, OPT_SRGB, OPT_FULLSCREEN, @@ -16,6 +17,7 @@ enum { static optcfg_option options[] = { // short, long, id, desc + {'s', "size", OPT_SIZE, "window size (WxH)"}, {0, "vr", OPT_VR, "enable VR mode"}, {0, "srgb", OPT_SRGB, "use linear color space"}, {'f', "fullscreen", OPT_FULLSCREEN, "run in fullscreen mode"}, @@ -25,19 +27,22 @@ 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; 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) { @@ -60,6 +65,16 @@ static bool is_enabled(optcfg *oc) static int opt_handler(optcfg *oc, int optid, void *cls) { switch(optid) { + case OPT_SIZE: + { + char *valstr = optcfg_next_value(oc); + if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) { + fprintf(stderr, "size must be in the form: WIDTHxHEIGHT\n"); + return -1; + } + } + break; + case OPT_VR: opt.vr = is_enabled(oc); break; @@ -81,5 +96,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; }