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) {
22 } else if(strcmp(argv[i], "-sball") == 0) {
23 opt.sball = !opt.sball;
25 fprintf(stderr, "invalid option: %s\n", argv[i]);
30 fprintf(stderr, "unexpected option: %s\n", argv[i]);
38 opt.start_scr = scrname;
43 static char *strip_space(char *s)
48 while(*s && isspace(*s)) ++s;
51 if((end = strrchr(s, '#'))) {
58 while(end > s && isspace(*end)) *end-- = 0;
59 return end > s ? s : 0;
62 static int bool_value(char *s)
70 return strcmp(s, "true") == 0 || strcmp(s, "yes") == 0 || strcmp(s, "1") == 0;
73 int load_config(const char *fname)
79 if(!(fp = fopen(fname, "rb"))) {
80 return 0; /* just ignore missing config files */
83 while(fgets(buf, sizeof buf, fp)) {
84 char *line, *key, *value;
87 if(!(line = strip_space(buf))) {
91 if(!(value = strchr(line, '='))) {
92 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
97 if(!(key = strip_space(line)) || !(value = strip_space(value))) {
98 fprintf(stderr, "%s:%d invalid key/value pair\n", fname, nline);
102 if(strcmp(line, "music") == 0) {
103 opt.music = bool_value(value);
104 } else if(strcmp(line, "screen") == 0) {
105 opt.start_scr = strdup(value);
106 } else if(strcmp(line, "sball") == 0) {
107 opt.sball = bool_value(value);
109 fprintf(stderr, "%s:%d invalid option: %s\n", fname, nline, line);