8 struct options def_opt = { 1024, 768, 0 };
18 static struct optcfg_option options[] = {
19 // short, long, id, desc
20 {'s', "size", OPTCFG_SIZE, "window size (WxH)"},
21 {0, "vr", OPTCFG_VR, "enable VR mode"},
22 {'f', "fullscreen", OPTCFG_FULLSCREEN, "run in fullscreen mode"},
23 {'w', "windowed", OPTCFG_WINDOWED, "run in windowed mode"},
24 {'h', "help", OPTCFG_HELP, "print usage and exit"},
28 static int opt_handler(struct optcfg *oc, int opt, void *cls);
29 static int arg_handler(struct optcfg *oc, const char *arg, void *cls);
33 int init_options(int argc, char **argv, const char *cfgfile)
42 oc = optcfg_init(options);
43 optcfg_set_opt_callback(oc, opt_handler, 0);
44 optcfg_set_arg_callback(oc, arg_handler, 0);
47 optcfg_parse_config_file(oc, cfgfile);
50 if(argv && optcfg_parse_args(oc, argc, argv) == -1) {
51 fprintf(stderr, "invalid option\n");
60 static int is_enabled(struct optcfg *oc)
63 optcfg_enabled_value(oc, &res);
67 static int opt_handler(struct optcfg *oc, int optid, void *cls)
72 char *valstr = optcfg_next_value(oc);
73 if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
74 fprintf(stderr, "size must be in the form: WIDTHxHEIGHT\n");
88 case OPTCFG_FULLSCREEN:
90 opt.flags |= OPT_FULLSCREEN;
92 opt.flags &= ~OPT_FULLSCREEN;
98 opt.flags &= ~OPT_FULLSCREEN;
100 opt.flags |= OPT_FULLSCREEN;
105 printf("Usage: %s [options]\nOptions:\n", argv0);
106 optcfg_print_options(oc);
112 static int arg_handler(struct optcfg *oc, const char *arg, void *cls)
114 fprintf(stderr, "unexpected argument: %s\n", arg);