# # 2022 Tormod Volden # # 2. Base data directory on executable location # Index: cmoc-0.1.77-win/src/main.cpp =================================================================== --- cmoc-0.1.77-win.orig/src/main.cpp +++ cmoc-0.1.77-win/src/main.cpp @@ -1748,6 +1748,7 @@ interpretCommandLineOptions(int argc, ch return -1; } +extern char *_pgmptr; int main(int argc, char *argv[]) @@ -1755,13 +1756,25 @@ main(int argc, char *argv[]) /* Allow an environment variable to override the system #include directory. */ const char *e = getenv("PKGDATADIR"); - params.pkgdatadir = (e != NULL ? e : PKGDATADIR); + /* params.pkgdatadir = (e != NULL ? e : PKGDATADIR); */ + if (e == NULL) + { + char *lastslash; + e = strdup(_pgmptr); + lastslash = (char *) strrchr(e, '\\'); + if (lastslash) + *lastslash = '\0'; + } + params.pkgdatadir = e; int argi = 1; int code = interpretCommandLineOptions(argc, argv, argi); if (code != -1) return code == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + if (params.verbose) + cout << "Win32 build: Data directory is " << e << endl; + const char *targetPlatformName = NULL; // displayable name const char *targetPreprocId = NULL; // identifier used in IFDEF directives in stdlib/*.asm switch (params.targetPlatform)