fixed incorrect checking of the existence of GLX_EXT_swap_control and friends
[demo_prior] / src / opt.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "opt.h"
5 #include "treestore.h"
6
7 static void print_usage(const char *argv0);
8
9 struct options opt = {
10         1280, 800,
11         1,                      /* fullscreen */
12         1,                      /* music */
13         1,                      /* sRGB */
14         1,                      /* anti-aliasing */
15         1                       /* vsync */
16 };
17
18 int parse_args(int argc, char **argv)
19 {
20         int i;
21
22         for(i=1; i<argc; i++) {
23                 if(strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "-size") == 0) {
24                         if(sscanf(argv[++i], "%dx%d", &opt.width, &opt.height) != 2) {
25                                 fprintf(stderr, "%s must be followed by <width>x<height>\n", argv[-1]);
26                                 return -1;
27                         }
28                 } else if(strcmp(argv[i], "-fs") == 0) {
29                         opt.fullscr = 1;
30                 } else if(strcmp(argv[i], "-win") == 0) {
31                         opt.fullscr = 0;
32                 } else if(strcmp(argv[i], "-srgb") == 0) {
33                         opt.srgb = 1;
34                 } else if(strcmp(argv[i], "-nosrgb") == 0) {
35                         opt.srgb = 0;
36                 } else if(strcmp(argv[i], "-aa") == 0) {
37                         opt.msaa = 1;
38                 } else if(strcmp(argv[i], "-noaa") == 0) {
39                         opt.msaa = 0;
40                 } else if(strcmp(argv[i], "-music") == 0) {
41                         opt.music = 1;
42                 } else if(strcmp(argv[i], "-nomusic") == 0) {
43                         opt.music = 0;
44                 } else if(strcmp(argv[i], "-vsync") == 0) {
45                         opt.vsync = 1;
46                 } else if(strcmp(argv[i], "-novsync") == 0) {
47                         opt.vsync = 0;
48                 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
49                         print_usage(argv[0]);
50                         exit(0);
51                 } else {
52                         fprintf(stderr, "invalid argument: %s\n", argv[i]);
53                         print_usage(argv[0]);
54                         return -1;
55                 }
56         }
57         return 0;
58 }
59
60 static void print_usage(const char *argv0)
61 {
62         printf("Usage: %s [options]\n", argv0);
63         printf("  -fs: fullscr\n");
64         printf("  -win: windowed\n");
65         printf("  -s,-size <WxH>: windowed resolution\n");
66         printf("  -srgb/-nosrgb: enable/disable sRGB framebuffer\n");
67         printf("  -aa/-noaa: enable/disable multisample anti-aliasing\n");
68         printf("  -music/-nomusic: enable/disable music playback\n");
69         printf("  -vsync/-novsync: enable/disable vertical sync\n");
70         printf("  -h,-help: print usage and exit\n");
71 }
72
73 int read_cfg(const char *fname)
74 {
75         struct ts_node *ts;
76
77         if(!(ts = ts_load(fname))) {
78                 return -1;
79         }
80         opt.width = ts_lookup_int(ts, "demo.width", opt.width);
81         opt.height = ts_lookup_int(ts, "demo.height", opt.height);
82         opt.fullscr = ts_lookup_int(ts, "demo.fullscreen", opt.fullscr);
83         opt.music = ts_lookup_int(ts, "demo.music", opt.music);
84         opt.srgb = ts_lookup_int(ts, "demo.srgb", opt.srgb);
85         opt.msaa = ts_lookup_int(ts, "demo.aa", opt.msaa);
86         opt.vsync = ts_lookup_int(ts, "demo.vsync", opt.vsync);
87
88         ts_free_tree(ts);
89         return 0;
90 }