9 int parse_args(int argc, char **argv)
14 for(i=1; i<argc; i++) {
15 if(argv[i][0] == '-') {
16 if(strcmp(argv[i], "-music") == 0) {
18 } else if(strcmp(argv[i], "-nomusic") == 0) {
20 } else if(strcmp(argv[i], "-scr") == 0 || strcmp(argv[i], "-screen") == 0) {
23 fprintf(stderr, "invalid option: %s\n", argv[i]);
28 fprintf(stderr, "unexpected option: %s\n", argv[i]);
35 opt.start_scr = scrname;
39 static char *strip_space(char *s)
44 while(*s && isspace(*s)) ++s;
47 if((end = strrchr(s, '#'))) {
54 while(end > s && isspace(*end)) *end-- = 0;
55 return end > s ? s : 0;
58 static int bool_value(char *s)
66 return strcmp(s, "true") == 0 || strcmp(s, "yes") == 0 || strcmp(s, "1") == 0;
69 int load_config(const char *fname)
75 if(!(fp = fopen(fname, "rb"))) {
76 return 0; /* just ignore missing config files */
79 while(fgets(buf, sizeof buf, fp)) {
80 char *line, *key, *value;
83 if(!(line = strip_space(buf))) {
87 if(!(value = strchr(line, '='))) {
88 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
93 if(!(key = strip_space(line)) || !(value = strip_space(value))) {
94 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
98 if(strcmp(line, "music") == 0) {
99 opt.music = bool_value(value);
100 } else if(strcmp(line, "screen") == 0) {
101 opt.start_scr = strdup(value);
103 fprintf(stderr, "%s:%d invalid option: %s\n", fname, nline, line);