26 static optcfg_option options[] = {
27 // short, long, id, desc
28 {'s', "size", OPT_SIZE, "window size (WxH)"},
29 {0, "vr", OPT_VR, "enable VR mode"},
30 {0, "srgb", OPT_SRGB, "use linear color space"},
31 {'f', "fullscreen", OPT_FULLSCREEN, "run in fullscreen mode"},
32 {'w', "windowed", OPT_WINDOWED, "run in windowed mode"},
33 {'h', "help", OPT_HELP, "print usage and exit"},
37 static int opt_handler(optcfg *oc, int opt, void *cls);
38 static int arg_handler(optcfg *oc, const char *arg, void *cls);
40 bool init_options(int argc, char **argv, const char *cfgfile)
45 optcfg *oc = optcfg_init(options);
46 optcfg_set_opt_callback(oc, opt_handler, 0);
47 optcfg_set_arg_callback(oc, arg_handler, 0);
50 optcfg_parse_config_file(oc, cfgfile);
53 if(argv && optcfg_parse_args(oc, argc, argv) == -1) {
54 fprintf(stderr, "invalid option\n");
63 static bool is_enabled(optcfg *oc)
66 optcfg_enabled_value(oc, &res);
70 static int opt_handler(optcfg *oc, int optid, void *cls)
75 char *valstr = optcfg_next_value(oc);
76 if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
77 fprintf(stderr, "size must be in the form: WIDTHxHEIGHT\n");
84 opt.vr = is_enabled(oc);
88 opt.srgb = is_enabled(oc);
92 opt.fullscreen = is_enabled(oc);
96 opt.fullscreen = !is_enabled(oc);
100 printf("Usage: vrfileman [options]\nOptions:\n");
101 optcfg_print_options(oc);
107 static int arg_handler(optcfg *oc, const char *arg, void *cls)
110 fprintf(stderr, "unexpected argument: %s\n", arg);