8 struct options def_opt = { 1024, 768, 0, "game" };
19 static struct optcfg_option options[] = {
20 // short, long, id, desc
21 {'s', "size", OPTCFG_SIZE, "window size (WxH)"},
22 {0, "vr", OPTCFG_VR, "enable VR mode"},
23 {'f', "fullscreen", OPTCFG_FULLSCREEN, "run in fullscreen mode"},
24 {'w', "windowed", OPTCFG_WINDOWED, "run in windowed mode"},
25 {0, "screen", OPTCFG_SCREEN, "select starting screen"},
26 {'h', "help", OPTCFG_HELP, "print usage and exit"},
30 static int opt_handler(struct optcfg *oc, int opt, void *cls);
31 static int arg_handler(struct optcfg *oc, const char *arg, void *cls);
35 int init_options(int argc, char **argv, const char *cfgfile)
44 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 int is_enabled(struct optcfg *oc)
65 optcfg_enabled_value(oc, &res);
69 static int opt_handler(struct optcfg *oc, int optid, void *cls)
75 valstr = optcfg_next_value(oc);
76 if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
77 fprintf(stderr, "size must be of the form: WIDTHxHEIGHT\n");
90 case OPTCFG_FULLSCREEN:
92 opt.flags |= OPT_FULLSCREEN;
94 opt.flags &= ~OPT_FULLSCREEN;
100 opt.flags &= ~OPT_FULLSCREEN;
102 opt.flags |= OPT_FULLSCREEN;
107 if(!(valstr = optcfg_next_value(oc))) {
108 fprintf(stderr, "screen name missing\n");
112 if(!(opt.start_scr = malloc(strlen(valstr) + 1))) {
113 perror("failed to allocate memory");
116 strcpy(opt.start_scr, valstr);
120 printf("Usage: %s [options]\nOptions:\n", argv0);
121 optcfg_print_options(oc);
127 static int arg_handler(struct optcfg *oc, const char *arg, void *cls)
129 fprintf(stderr, "unexpected argument: %s\n", arg);