comparison config.c @ 866:69a6ec208111

Menu ROM now pulls real file names from the OS rather than using a fake list
author Michael Pavone <pavone@retrodev.com>
date Fri, 06 Nov 2015 12:19:39 -0800
parents 46bb673eed4e
children 54ffba3768d6
comparison
equal deleted inserted replaced
865:305c85c0b954 866:69a6ec208111
41 char *config_data, *curline; 41 char *config_data, *curline;
42 tern_node * head = NULL; 42 tern_node * head = NULL;
43 config_data = started ? NULL : *state; 43 config_data = started ? NULL : *state;
44 while ((curline = strtok_r(config_data, "\n", state))) 44 while ((curline = strtok_r(config_data, "\n", state)))
45 { 45 {
46 46
47 config_data = NULL; 47 config_data = NULL;
48 curline = strip_ws(curline); 48 curline = strip_ws(curline);
49 int len = strlen(curline); 49 int len = strlen(curline);
50 if (!len) { 50 if (!len) {
51 *line = *line + 1; 51 *line = *line + 1;
59 if (started) { 59 if (started) {
60 return head; 60 return head;
61 } 61 }
62 fatal_error("unexpected } on line %d\n", *line); 62 fatal_error("unexpected } on line %d\n", *line);
63 } 63 }
64 64
65 char * end = curline + len - 1; 65 char * end = curline + len - 1;
66 if (*end == '{') { 66 if (*end == '{') {
67 *end = 0; 67 *end = 0;
68 curline = strip_ws(curline); 68 curline = strip_ws(curline);
69 *line = *line + 1; 69 *line = *line + 1;
126 } 126 }
127 size_t config_size = rw->size(rw); 127 size_t config_size = rw->size(rw);
128 if (!config_size) { 128 if (!config_size) {
129 goto config_empty; 129 goto config_empty;
130 } 130 }
131 131
132 char * config_data = malloc(config_size+1); 132 char * config_data = malloc(config_size+1);
133 if (SDL_RWread(rw, config_data, 1, config_size) != config_size) { 133 if (SDL_RWread(rw, config_data, 1, config_size) != config_size) {
134 goto config_read_fail; 134 goto config_read_fail;
135 } 135 }
136 config_data[config_size] = '\0'; 136 config_data[config_size] = '\0';
150 tern_node * ret = parse_config_file(path); 150 tern_node * ret = parse_config_file(path);
151 free(path); 151 free(path);
152 if (ret) { 152 if (ret) {
153 return ret; 153 return ret;
154 } 154 }
155 155
156 ret = parse_config_file_assets("default.cfg"); 156 ret = parse_config_file_assets("default.cfg");
157 if (ret) { 157 if (ret) {
158 return ret; 158 return ret;
159 } 159 }
160 160
161 fatal_error("Failed to find a config file in internal storage or in the blastem APK\n"); 161 fatal_error("Failed to find a config file in internal storage or in the blastem APK\n");
162 //this will never get reached, but the compiler doesn't know that. Let's make it happy 162 //this will never get reached, but the compiler doesn't know that. Let's make it happy
163 return NULL; 163 return NULL;
164 } 164 }
165 165
167 167
168 tern_node * load_config() 168 tern_node * load_config()
169 { 169 {
170 char * exe_dir; 170 char * exe_dir;
171 char * home = get_home_dir(); 171 char * home = get_home_dir();
172 if (home) { 172 tern_node *ret;
173 if (home) {
173 char * path = alloc_concat(home, "/.config/blastem/blastem.cfg"); 174 char * path = alloc_concat(home, "/.config/blastem/blastem.cfg");
174 tern_node * ret = parse_config_file(path);
175 free(path);
176 if (ret) {
177 return ret;
178 }
179 }
180
181 exe_dir = get_exe_dir();
182 if (exe_dir) {
183 path = alloc_concat(exe_dir, "/default.cfg");
184 ret = parse_config_file(path); 175 ret = parse_config_file(path);
185 free(path); 176 free(path);
186 if (ret) { 177 if (ret) {
187 return ret; 178 return ret;
188 } 179 }
189 } 180 }
190 181
182 exe_dir = get_exe_dir();
183 if (exe_dir) {
184 char *path = alloc_concat(exe_dir, "/default.cfg");
185 ret = parse_config_file(path);
186 free(path);
187 if (ret) {
188 return ret;
189 }
190 }
191
191 fatal_error("Failed to find a config file in ~/.config/blastem/blastem.cfg or in the blastem executable directory\n"); 192 fatal_error("Failed to find a config file in ~/.config/blastem/blastem.cfg or in the blastem executable directory\n");
192 //this will never get reached, but the compiler doesn't know that. Let's make it happy 193 //this will never get reached, but the compiler doesn't know that. Let's make it happy
193 return NULL; 194 return NULL;
194 } 195 }
195 196