18 static optcfg_option options[] = {
19 // short, long, id, desc
20 {'s', "size", OPT_SIZE, "window size (WxH)"},
21 {0, "vr", OPT_VR, "enable VR mode"},
22 {0, "srgb", OPT_SRGB, "use linear color space"},
23 {'f', "fullscreen", OPT_FULLSCREEN, "run in fullscreen mode"},
24 {'w', "windowed", OPT_WINDOWED, "run in windowed mode"},
25 {'h', "help", OPT_HELP, "print usage and exit"},
29 static int opt_handler(optcfg *oc, int opt, void *cls);
30 static int arg_handler(optcfg *oc, const char *arg, void *cls);
32 bool init_options(int argc, char **argv, const char *cfgfile)
35 memset(&opt, 0, sizeof opt);
40 optcfg *oc = optcfg_init(options);
41 optcfg_set_opt_callback(oc, opt_handler, 0);
42 optcfg_set_arg_callback(oc, arg_handler, 0);
45 optcfg_parse_config_file(oc, cfgfile);
48 if(argv && optcfg_parse_args(oc, argc, argv) == -1) {
49 fprintf(stderr, "invalid option\n");
58 static bool is_enabled(optcfg *oc)
61 optcfg_enabled_value(oc, &res);
65 static int opt_handler(optcfg *oc, int optid, void *cls)
70 char *valstr = optcfg_next_value(oc);
71 if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
72 fprintf(stderr, "size must be in the form: WIDTHxHEIGHT\n");
79 opt.vr = is_enabled(oc);
83 opt.srgb = is_enabled(oc);
87 opt.fullscreen = is_enabled(oc);
91 opt.fullscreen = !is_enabled(oc);
95 printf("Usage: vrfileman [options]\nOptions:\n");
96 optcfg_print_options(oc);
102 static int arg_handler(optcfg *oc, const char *arg, void *cls)
105 fprintf(stderr, "unexpected argument: %s\n", arg);