25 static optcfg_option options[] = {
26 // short, long, id, desc
27 {'s', "size", OPT_SIZE, "window size (WxH)"},
28 {0, "vr", OPT_VR, "enable VR mode"},
29 {'f', "fullscreen", OPT_FULLSCREEN, "run in fullscreen mode"},
30 {'w', "windowed", OPT_WINDOWED, "run in windowed mode"},
31 {0, "scene", OPT_SCENEFILE, "scene file to open"},
32 {'h', "help", OPT_HELP, "print usage and exit"},
36 static int opt_handler(optcfg *oc, int opt, void *cls);
37 static int arg_handler(optcfg *oc, const char *arg, void *cls);
39 bool init_options(int argc, char **argv, const char *cfgfile)
44 optcfg *oc = optcfg_init(options);
45 optcfg_set_opt_callback(oc, opt_handler, 0);
46 optcfg_set_arg_callback(oc, arg_handler, 0);
49 optcfg_parse_config_file(oc, cfgfile);
52 if(argv && optcfg_parse_args(oc, argc, argv) == -1) {
53 fprintf(stderr, "invalid option\n");
62 static bool is_enabled(optcfg *oc)
65 optcfg_enabled_value(oc, &res);
69 static int opt_handler(optcfg *oc, int optid, void *cls)
74 char *valstr = optcfg_next_value(oc);
75 if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
76 fprintf(stderr, "size must be in the form: WIDTHxHEIGHT\n");
83 opt.vr = is_enabled(oc);
87 opt.fullscreen = is_enabled(oc);
91 opt.fullscreen = !is_enabled(oc);
95 opt.scenefile = strdup(optcfg_next_value(oc));
99 printf("Usage: vrfileman [options]\nOptions:\n");
100 optcfg_print_options(oc);
106 static int arg_handler(optcfg *oc, const char *arg, void *cls)
109 fprintf(stderr, "unexpected argument: %s\n", arg);