15 #define DEF_INVMOUSEY 0
16 #define DEF_MOUSE_SPEED 50
19 struct options opt = {
23 DEF_VOL, DEF_VOL, DEF_VOL,
29 int parse_options(int argc, char **argv)
32 static const char *usage_fmt = "Usage: %s [options]\n"
34 " -screen <name>: select starting screen\n"
35 " -h,-help: print usage information and exit\n\n";
37 for(i=1; i<argc; i++) {
38 if(argv[i][0] == '-') {
39 if(strcmp(argv[i], "-scr") == 0 || strcmp(argv[i], "-screen") == 0) {
41 fprintf(stderr, "%s must be followed by a screen name\n", argv[i - 1]);
44 start_scr_name = argv[i];
46 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
47 printf(usage_fmt, argv[0]);
50 fprintf(stderr, "invalid option: %s\n", argv[i]);
54 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
62 int load_options(const char *fname)
66 if(!(cfg = ts_load(fname))) {
69 printf("loaded config: %s\n", fname);
71 opt.xres = ts_lookup_int(cfg, "options.video.xres", DEF_XRES);
72 opt.yres = ts_lookup_int(cfg, "options.video.yres", DEF_YRES);
73 opt.vsync = ts_lookup_int(cfg, "options.video.vsync", DEF_VSYNC);
74 opt.fullscreen = ts_lookup_int(cfg, "options.video.fullscreen", DEF_FULLSCR);
76 opt.vol_master = ts_lookup_int(cfg, "options.audio.volmaster", DEF_VOL);
77 opt.vol_mus = ts_lookup_int(cfg, "options.audio.volmusic", DEF_VOL);
78 opt.vol_sfx = ts_lookup_int(cfg, "options.audio.volsfx", DEF_VOL);
79 opt.music = ts_lookup_int(cfg, "options.audio.music", DEF_MUS);
81 opt.inv_mouse_y = ts_lookup_int(cfg, "options.controls.invmousey", DEF_INVMOUSEY);
82 opt.mouse_speed = ts_lookup_int(cfg, "options.controls.mousespeed", DEF_MOUSE_SPEED);
88 #define WROPT(lvl, fmt, val, defval) \
91 for(i=0; i<lvl; i++) fputc('\t', fp); \
92 if((val) == (defval)) { \
93 fprintf(fp, fmt "\t# default\n", val); \
95 fprintf(fp, fmt "\n", val); \
99 int save_options(const char *fname)
103 printf("writing config: %s\n", fname);
105 if(!(fp = fopen(fname, "wb"))) {
106 fprintf(stderr, "failed to save options (%s): %s\n", fname, strerror(errno));
108 fprintf(fp, "options {\n");
109 fprintf(fp, "\tvideo {\n");
110 WROPT(2, "xres = %d", opt.xres, DEF_XRES);
111 WROPT(2, "yres = %d", opt.yres, DEF_YRES);
112 WROPT(2, "vsync = %d", opt.vsync, DEF_VSYNC);
113 WROPT(2, "fullscreen = %d", opt.fullscreen, DEF_FULLSCR);
114 fprintf(fp, "\t}\n");
116 fprintf(fp, "\taudio {\n");
117 WROPT(2, "volmaster = %d", opt.vol_master, DEF_VOL);
118 WROPT(2, "volmusic = %d", opt.vol_mus, DEF_VOL);
119 WROPT(2, "volsfx = %d", opt.vol_sfx, DEF_VOL);
120 WROPT(2, "music = %d", opt.music ? 1 : 0, DEF_MUS);
121 fprintf(fp, "\t}\n");
123 fprintf(fp, "\tcontrols {\n");
124 WROPT(2, "invmousey = %d", opt.inv_mouse_y, DEF_INVMOUSEY);
125 WROPT(2, "mousespeed = %d", opt.mouse_speed, DEF_MOUSE_SPEED);
126 fprintf(fp, "\t}\n");
129 fprintf(fp, "# v" "i:ts=4 sts=4 sw=4 noexpandtab:\n");