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]);
36 opt.start_scr = scrname;
41 static char *strip_space(char *s)
46 while(*s && isspace(*s)) ++s;
49 if((end = strrchr(s, '#'))) {
56 while(end > s && isspace(*end)) *end-- = 0;
57 return end > s ? s : 0;
60 static int bool_value(char *s)
68 return strcmp(s, "true") == 0 || strcmp(s, "yes") == 0 || strcmp(s, "1") == 0;
71 int load_config(const char *fname)
77 if(!(fp = fopen(fname, "rb"))) {
78 return 0; /* just ignore missing config files */
81 while(fgets(buf, sizeof buf, fp)) {
82 char *line, *key, *value;
85 if(!(line = strip_space(buf))) {
89 if(!(value = strchr(line, '='))) {
90 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
95 if(!(key = strip_space(line)) || !(value = strip_space(value))) {
96 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
100 if(strcmp(line, "music") == 0) {
101 opt.music = bool_value(value);
102 } else if(strcmp(line, "screen") == 0) {
103 opt.start_scr = strdup(value);
105 fprintf(stderr, "%s:%d invalid option: %s\n", fname, nline, line);