8 /* release default options */
9 #define DEFOPT_FULLSCR 1
10 #define DEFOPT_VSYNC 1
11 #define DEFOPT_MUSIC 1
13 /* debug default options */
14 #define DEFOPT_FULLSCR 0
15 #define DEFOPT_VSYNC 1
16 #define DEFOPT_MUSIC 0
19 struct options opt = {
26 static const char *usagefmt = "Usage: %s [options]\n"
28 " -music/-nomusic toggle music playback\n"
29 " -scr,-screen <name> ignore demoscript, run specific screen\n"
30 " -fs/-win run fullscreen/windowed\n"
31 " -vsync/-novsync toggle vsync\n"
32 " -h,-help print usage and exit\n";
34 int parse_args(int argc, char **argv)
39 for(i=1; i<argc; i++) {
40 if(argv[i][0] == '-') {
41 if(strcmp(argv[i], "-music") == 0) {
43 } else if(strcmp(argv[i], "-nomusic") == 0) {
45 } else if(strcmp(argv[i], "-scr") == 0 || strcmp(argv[i], "-screen") == 0) {
47 } else if(strcmp(argv[i], "-vsync") == 0) {
49 } else if(strcmp(argv[i], "-novsync") == 0) {
51 } else if(strcmp(argv[i], "-fs") == 0) {
53 } else if(strcmp(argv[i], "-win") == 0) {
55 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
56 printf(usagefmt, argv[0]);
59 fprintf(stderr, "invalid option: %s\n", argv[i]);
60 fprintf(stderr, usagefmt, argv[0]);
65 fprintf(stderr, "unexpected option: %s\n", argv[i]);
66 fprintf(stderr, usagefmt, argv[0]);
74 opt.scrname = scrname;
80 static char *strip_space(char *s)
85 while(*s && isspace(*s)) ++s;
88 if((end = strrchr(s, '#'))) {
95 while(end > s && isspace(*end)) *end-- = 0;
96 return end > s ? s : 0;
99 static int bool_value(char *s)
103 *ptr = tolower(*ptr);
107 return strcmp(s, "true") == 0 || strcmp(s, "yes") == 0 || strcmp(s, "1") == 0;
110 int load_config(const char *fname)
116 if(!(fp = fopen(fname, "rb"))) {
117 return 0; /* just ignore missing config files */
120 while(fgets(buf, sizeof buf, fp)) {
121 char *line, *key, *value;
124 if(!(line = strip_space(buf))) {
128 if(!(value = strchr(line, '='))) {
129 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
134 if(!(key = strip_space(line)) || !(value = strip_space(value))) {
135 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
139 if(strcmp(line, "music") == 0) {
140 opt.music = bool_value(value);
141 } else if(strcmp(line, "screen") == 0) {
142 opt.scrname = strdup(value);
143 } else if(strcmp(line, "vsync") == 0) {
144 opt.vsync = bool_value(value);
145 } else if(strcmp(line, "fullscreen") == 0) {
146 opt.fullscreen = bool_value(value);
148 fprintf(stderr, "%s:%d invalid option: %s\n", fname, nline, line);