9 /* release default options */
10 #define DEFOPT_FULLSCR 1
11 #define DEFOPT_VSYNC 1
12 #define DEFOPT_MUSIC 1
14 /* debug default options */
15 #define DEFOPT_FULLSCR 0
16 #define DEFOPT_VSYNC 1
17 #define DEFOPT_MUSIC 1
20 struct options opt = {
27 static const char *usagefmt = "Usage: %s [options]\n"
29 " -music/-nomusic toggle music playback\n"
30 " -scr,-screen <name> ignore demoscript, run specific screen\n"
31 " -fs/-win run fullscreen/windowed\n"
32 " -vsync/-novsync toggle vsync\n"
33 " -h,-help print usage and exit\n";
35 int parse_args(int argc, char **argv)
40 for(i=1; i<argc; i++) {
41 if(argv[i][0] == '-') {
42 if(strcmp(argv[i], "-music") == 0) {
44 } else if(strcmp(argv[i], "-nomusic") == 0) {
46 } else if(strcmp(argv[i], "-scr") == 0 || strcmp(argv[i], "-screen") == 0) {
48 } else if(strcmp(argv[i], "-vsync") == 0) {
50 } else if(strcmp(argv[i], "-novsync") == 0) {
52 } else if(strcmp(argv[i], "-fs") == 0) {
54 } else if(strcmp(argv[i], "-win") == 0) {
56 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
57 printf(usagefmt, argv[0]);
60 fprintf(stderr, "invalid option: %s\n", argv[i]);
61 fprintf(stderr, usagefmt, argv[0]);
66 fprintf(stderr, "unexpected option: %s\n", argv[i]);
67 fprintf(stderr, usagefmt, argv[0]);
75 opt.scrname = scrname;
81 static char *strip_space(char *s)
86 while(*s && isspace(*s)) ++s;
89 if((end = strrchr(s, '#'))) {
96 while(end > s && isspace(*end)) *end-- = 0;
97 return end > s ? s : 0;
100 static int bool_value(char *s)
104 *ptr = tolower(*ptr);
108 return strcmp(s, "true") == 0 || strcmp(s, "yes") == 0 || strcmp(s, "1") == 0;
111 int load_config(const char *fname)
117 if(!(fp = ass_fopen(fname, "rb"))) {
118 return 0; /* just ignore missing config files */
121 while(ass_fgets(buf, sizeof buf, fp)) {
122 char *line, *key, *value;
125 if(!(line = strip_space(buf))) {
129 if(!(value = strchr(line, '='))) {
130 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
136 if(!(key = strip_space(line)) || !(value = strip_space(value))) {
137 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
142 if(strcmp(line, "music") == 0) {
143 opt.music = bool_value(value);
144 } else if(strcmp(line, "screen") == 0) {
145 opt.scrname = strdup(value);
146 } else if(strcmp(line, "vsync") == 0) {
147 opt.vsync = bool_value(value);
148 } else if(strcmp(line, "fullscreen") == 0) {
149 opt.fullscreen = bool_value(value);
151 fprintf(stderr, "%s:%d invalid option: %s\n", fname, nline, line);