$OpenBSD$

Teach simutrans to find itself in PATH, so simmain.cc may find data
files relative to the executable.

Index: simsys.cc
--- simsys.cc.orig
+++ simsys.cc
@@ -1026,6 +1026,28 @@ int sysmain(int const argc, char** const argv)
 	if (length != -1) {
 		buffer[length] = '\0'; /* readlink() does not NUL-terminate */
 		argv[0] = buffer;
+	} else if (strchr(argv[0], '/') == NULL) {
+		// no /proc, no '/' in argv[0] => search PATH
+		const char* path = getenv("PATH");
+		if (path != NULL) {
+			size_t flen = strlen(argv[0]);
+			for (;;) { /* for each directory in PATH */
+				size_t dlen = strcspn(path, ":");
+				if (dlen > 0 && dlen + flen + 2 < lengthof(buffer)) {
+					// buffer = dir '/' argv[0] '\0'
+					memcpy(buffer, path, dlen);
+					buffer[dlen] = '/';
+					memcpy(buffer + dlen + 1, argv[0], flen + 1);
+					if (access(buffer, X_OK) == 0) {
+						argv[0] = buffer;
+						break; /* found it! */
+					}
+				}
+				if (path[dlen] == '\0')
+					break;
+				path += dlen + 1; /* skip ':' */
+			}
+		}
 	}
 #	endif
 	// no process file system => need to parse argv[0]
