14 int parse_args(int argc, char **argv)
19 for(i=1; i<argc; i++) {
20 if(argv[i][0] == '-') {
21 if(strcmp(argv[i], "-music") == 0) {
23 } else if(strcmp(argv[i], "-nomusic") == 0) {
25 } else if(strcmp(argv[i], "-scr") == 0 || strcmp(argv[i], "-screen") == 0) {
27 } else if(strcmp(argv[i], "-sball") == 0) {
28 opt.sball = !opt.sball;
29 } else if(strcmp(argv[i], "-vsync") == 0) {
31 } else if(strcmp(argv[i], "-novsync") == 0) {
34 fprintf(stderr, "invalid option: %s\n", argv[i]);
39 fprintf(stderr, "unexpected option: %s\n", argv[i]);
47 opt.start_scr = scrname;
52 static char *strip_space(char *s)
57 while(*s && isspace(*s)) ++s;
60 if((end = strrchr(s, '#'))) {
67 while(end > s && isspace(*end)) *end-- = 0;
68 return end > s ? s : 0;
71 static int bool_value(char *s)
79 return strcmp(s, "true") == 0 || strcmp(s, "yes") == 0 || strcmp(s, "1") == 0;
82 int load_config(const char *fname)
88 if(!(fp = fopen(fname, "rb"))) {
89 return 0; /* just ignore missing config files */
92 while(fgets(buf, sizeof buf, fp)) {
93 char *line, *key, *value;
96 if(!(line = strip_space(buf))) {
100 if(!(value = strchr(line, '='))) {
101 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
106 if(!(key = strip_space(line)) || !(value = strip_space(value))) {
107 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
111 if(strcmp(line, "music") == 0) {
112 opt.music = bool_value(value);
113 } else if(strcmp(line, "screen") == 0) {
114 opt.start_scr = strdup(value);
115 } else if(strcmp(line, "sball") == 0) {
116 opt.sball = bool_value(value);
117 } else if(strcmp(line, "vsync") == 0) {
118 opt.vsync = bool_value(value);
120 fprintf(stderr, "%s:%d invalid option: %s\n", fname, nline, line);