annotate config.c @ 859:46bb673eed4e

Load config file and rom.db from appropriate locations on Android
author Michael Pavone <pavone@retrodev.com>
date Wed, 04 Nov 2015 22:48:27 -0800
parents 7ed55a361e79
children 69a6ec208111
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1 /*
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
2 Copyright 2013 Michael Pavone
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
3 This file is part of BlastEm.
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
5 */
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "tern.h"
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
7 #include "util.h"
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include <stdio.h>
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 #include <stdlib.h>
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 #include <string.h>
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11
795
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
12 #ifdef __MINGW64_VERSION_MAJOR
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
13 #define MINGW_W64_VERSION (__MINGW64_VERSION_MAJOR * 1000 + __MINGW64_VERSION_MINOR)
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
14 #else
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
15 #define MINGW_W64_VERSION 0
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
16 #endif
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
17
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
18 #if defined(_WIN32) && (MINGW_W64_VERSION < 3003)
741
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
19 char * strtok_r(char * input, char * sep, char ** state)
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
20 {
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
21 if (input) {
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
22 *state = input;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
23 }
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
24 char * ret = *state;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
25 while (**state && **state != *sep)
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
26 {
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
27 ++*state;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
28 }
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
29 if (**state)
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
30 {
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
31 **state = 0;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
32 ++*state;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
33 return ret;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
34 }
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
35 return NULL;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
36 }
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
37 #endif
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
38
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
39 tern_node * parse_config_int(char **state, int started, int *line)
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
41 char *config_data, *curline;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
42 tern_node * head = NULL;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
43 config_data = started ? NULL : *state;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
44 while ((curline = strtok_r(config_data, "\n", state)))
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45 {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
46
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 config_data = NULL;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 curline = strip_ws(curline);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 int len = strlen(curline);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 if (!len) {
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 795
diff changeset
51 *line = *line + 1;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 continue;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
54 if (curline[0] == '#') {
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 795
diff changeset
55 *line = *line + 1;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56 continue;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 if (curline[0] == '}') {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
59 if (started) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
60 return head;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61 }
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
62 fatal_error("unexpected } on line %d\n", *line);
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 }
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
64
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 char * end = curline + len - 1;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 if (*end == '{') {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 *end = 0;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 curline = strip_ws(curline);
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 795
diff changeset
69 *line = *line + 1;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
70 head = tern_insert_node(head, curline, parse_config_int(state, 1, line));
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 } else {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 char * val = strip_ws(split_keyval(curline));
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 char * key = curline;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
74 if (*val) {
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
75 head = tern_insert_ptr(head, key, strdup(val));
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
76 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
77 fprintf(stderr, "Key %s is missing a value on line %d\n", key, *line);
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
78 }
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 795
diff changeset
79 *line = *line + 1;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
80 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
81 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
82 return head;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
83 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
84
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
85 tern_node * parse_config(char * config_data)
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
86 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
87 int line = 1;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
88 return parse_config_int(&config_data, 0, &line);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
89 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
90
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
91 tern_node * parse_config_file(char * config_path)
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
92 {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
93 tern_node * ret = NULL;
816
7ed55a361e79 Use binary mode for reading shaders and config files so we actually get the number of bytes we expect
Michael Pavone <pavone@retrodev.com>
parents: 799
diff changeset
94 FILE * config_file = fopen(config_path, "rb");
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95 if (!config_file) {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
96 goto open_fail;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
97 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
98 long config_size = file_size(config_file);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
99 if (!config_size) {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 goto config_empty;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 }
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 795
diff changeset
102 char * config_data = malloc(config_size+1);
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
103 if (fread(config_data, 1, config_size, config_file) != config_size) {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
104 goto config_read_fail;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105 }
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 795
diff changeset
106 config_data[config_size] = '\0';
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 795
diff changeset
107
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108 ret = parse_config(config_data);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 config_read_fail:
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
110 free(config_data);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
111 config_empty:
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
112 fclose(config_file);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
113 open_fail:
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114 return ret;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
115 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
116
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
117 #ifdef __ANDROID__
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
118 #include <SDL.h>
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
119
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
120 tern_node * parse_config_file_assets(char *config_path)
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
121 {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
122 tern_node * ret = NULL;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
123 SDL_RWops *rw = SDL_RWFromFile(config_path, "rb");
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
124 if (!rw) {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
125 goto open_fail;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
126 }
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
127 size_t config_size = rw->size(rw);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
128 if (!config_size) {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
129 goto config_empty;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
130 }
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
131
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
132 char * config_data = malloc(config_size+1);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
133 if (SDL_RWread(rw, config_data, 1, config_size) != config_size) {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
134 goto config_read_fail;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
135 }
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
136 config_data[config_size] = '\0';
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
137
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
138 ret = parse_config(config_data);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
139 config_read_fail:
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
140 free(config_data);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
141 config_empty:
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
142 SDL_RWclose(rw);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
143 open_fail:
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
144 return ret;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
145 }
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
146
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
147 tern_node * load_config()
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
148 {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
149 char *path = alloc_concat(SDL_AndroidGetInternalStoragePath(), "/blastem.cfg");
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
150 tern_node * ret = parse_config_file(path);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
151 free(path);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
152 if (ret) {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
153 return ret;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
154 }
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
155
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
156 ret = parse_config_file_assets("default.cfg");
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
157 if (ret) {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
158 return ret;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
159 }
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
160
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
161 fatal_error("Failed to find a config file in internal storage or in the blastem APK\n");
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
162 //this will never get reached, but the compiler doesn't know that. Let's make it happy
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
163 return NULL;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
164 }
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
165
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
166 #else
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
167
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
168 tern_node * load_config()
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
169 {
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
170 char * exe_dir;
742
2e1b3b258523 Make Windows port a little less half-assed
Michael Pavone <pavone@retrodev.com>
parents: 741
diff changeset
171 char * home = get_home_dir();
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
172 if (home) {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
173 char * path = alloc_concat(home, "/.config/blastem/blastem.cfg");
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
174 tern_node * ret = parse_config_file(path);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
175 free(path);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
176 if (ret) {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
177 return ret;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
178 }
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
179 }
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
180
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
181 exe_dir = get_exe_dir();
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
182 if (exe_dir) {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
183 path = alloc_concat(exe_dir, "/default.cfg");
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
184 ret = parse_config_file(path);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
185 free(path);
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
186 if (ret) {
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
187 return ret;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
188 }
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 }
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
190
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
191 fatal_error("Failed to find a config file in ~/.config/blastem/blastem.cfg or in the blastem executable directory\n");
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
192 //this will never get reached, but the compiler doesn't know that. Let's make it happy
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
193 return NULL;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
194 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
195
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
196 #endif
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
197