about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-03-26 19:13:17 -0400
committerJune McEnroe <june@causal.agency>2019-03-26 19:13:17 -0400
commitb55b4eca7235b85b9cec188f4a9218eabfd812b8 (patch)
treeafc844b07bc7e020d87238a49b70d2b33e86825f
parentMake Stack capacity configurable (diff)
downloadcards-b55b4eca7235b85b9cec188f4a9218eabfd812b8.tar.gz
cards-b55b4eca7235b85b9cec188f4a9218eabfd812b8.zip
Search for lowercase cards.dll and fall back to current directory
Diffstat (limited to '')
-rw-r--r--sol.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/sol.c b/sol.c
index 4da4933..16a688f 100644
--- a/sol.c
+++ b/sol.c
@@ -24,6 +24,8 @@
 #include "cards.h"
 #include "stack.h"
 
+#define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0]))
+
 typedef unsigned uint;
 
 enum {
@@ -403,24 +405,24 @@ int main(void) {
 	char *basePath = SDL_GetBasePath();
 	if (!basePath) err("SDL_GetBasePath");
 
-	char paths[4][1024];
-	snprintf(paths[0], sizeof(paths[0]), "%sCARDS.DLL", prefPath);
-	snprintf(paths[1], sizeof(paths[1]), "%sSOL.EXE", prefPath);
-	snprintf(paths[2], sizeof(paths[2]), "%sCARDS.DLL", basePath);
-	snprintf(paths[3], sizeof(paths[3]), "%sSOL.EXE", basePath);
+	const char *paths[] = { prefPath, basePath, "" };
+	const char *names[] = { "CARDS.DLL", "SOL.EXE", "cards.dll" };
 
-	SDL_RWops *rw;
-	for (uint i = 0; i < 4; ++i) {
-		rw = SDL_RWFromFile(paths[i], "rb");
-		if (rw) break;
+	SDL_RWops *rw = NULL;
+	for (uint i = 0; !rw && i < ARRAY_LEN(paths); ++i) {
+		for (uint j = 0; !rw && j < ARRAY_LEN(names); ++j) {
+			char path[1024];
+			snprintf(path, sizeof(path), "%s%s", paths[i], names[j]);
+			rw = SDL_RWFromFile(path, "rb");
+		}
 	}
 	if (!rw) {
-		char buf[4096];
+		char msg[4096];
 		snprintf(
-			buf, sizeof(buf), "CARDS.DLL not found in:\n%s\n%s",
+			msg, sizeof(msg), "CARDS.DLL or SOL.EXE not found in:\n%s\n%s",
 			prefPath, basePath
 		);
-		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Cards", buf, NULL);
+		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Cards", msg, NULL);
 		return EXIT_FAILURE;
 	}
 
l from hi if input is binaryJune McEnroe 2019-12-16Post "cgit setup"June McEnroe