# # 2020 Tormod Volden # # 1. Use double quotes in command invokations # 2. Base data directory on executable location # --- ../cmoc-0.1.65/src/main.cpp 2020-04-04 19:14:41.000000000 +0200 +++ src/main.cpp 2020-05-02 17:10:20.568713699 +0200 @@ -413,9 +413,9 @@ invokeAssembler(const string &inputFilen string lwasmCmdLine = params.lwasmPath + " -fobj --pragma=forwardrefmax" + " -D" + targetPreprocId - + " --output='" + objectFilename + "'" - + (params.intermediateFilesKept ? " --list='" + lstFilename + "'" : "") - + " '" + inputFilename + "'"; + + " --output=\"" + objectFilename + "\"" + + (params.intermediateFilesKept ? " --list=\"" + lstFilename + "\"" : "") + + " \"" + inputFilename + "\""; if (verbose) cout << "Assembler command: " << lwasmCmdLine << endl; @@ -716,11 +716,11 @@ invokeLinker(const vector &objec string lwlinkCmdLine = params.lwlinkPath + " --format=" + lwlinkFormat - + " --output='" + outputFilename - + "' --script='" + linkScriptFilename - + "' --map='" + mapFilename + "'"; + + " --output=\"" + outputFilename + + "\" --script=\"" + linkScriptFilename + + "\" --map=\"" + mapFilename + "\""; for (vector::const_iterator it = libDirs.begin(); it != libDirs.end(); ++it) - lwlinkCmdLine += " -L'" + *it + "'"; + lwlinkCmdLine += " -L\"" + *it + "\""; lwlinkCmdLine += " -L" + params.pkgdatadir + "/lib"; lwlinkCmdLine += " -lcmoc-crt-" + string(targetKW); @@ -733,11 +733,11 @@ invokeLinker(const vector &objec for (vector::const_iterator it = objectFilenames.begin(); it != objectFilenames.end(); ++it) - lwlinkCmdLine += " '" + useIntDir(*it) + ".o'"; + lwlinkCmdLine += " \"" + useIntDir(*it) + ".o\""; for (vector::const_iterator it = libraryFilenames.begin(); it != libraryFilenames.end(); ++it) - lwlinkCmdLine += " '" + *it + "'"; + lwlinkCmdLine += " \"" + *it + "\""; if (verbose) cout << "Linker command: " << lwlinkCmdLine << endl; @@ -1041,7 +1041,7 @@ Parameters::compileCFile(const string &i stringstream cppCommand; cppCommand << "cpp -xc++ -U__cplusplus"; // -xc++ makes sure cpp accepts C++-style comments for (list::const_iterator it = includeDirList.begin(); it != includeDirList.end(); ++it) - cppCommand << " -I'" << *it << "'"; + cppCommand << " -I\"" << *it << "\""; cppCommand << " -D_CMOC_VERSION_=" << getVersionInteger(); cppCommand << " -D" << targetPreprocId << "=1"; if (monolithMode) @@ -1049,7 +1049,7 @@ Parameters::compileCFile(const string &i cppCommand << " -U__GNUC__ -nostdinc -undef"; for (list::const_iterator it = defines.begin(); it != defines.end(); ++it) - cppCommand << " -D'" << *it << "'"; + cppCommand << " -D\"" << *it << "\""; cppCommand << " " << inputFilename; // must be last argument, for portability @@ -1735,7 +1735,7 @@ assembleInMonolithMode(const char *targe stringstream ss; ss << params.getAssemblerFilename(); for (list::const_iterator it = params.includeDirList.begin(); it != params.includeDirList.end(); ++it) - ss << " --includedir='" << *it << "'"; + ss << " --includedir=\"" << *it << "\""; if (params.targetPlatform != OS9) ss << " --entry=" << hex << params.codeAddress << dec; if (params.assumeTrack34) @@ -1756,7 +1756,7 @@ assembleInMonolithMode(const char *targe if (params.verbose) ss << " --verbose"; if (!params.outputFilename.empty()) - ss << " --output='" << params.outputFilename << "'"; + ss << " --output=\"" << params.outputFilename << "\""; ss << " " << asmFilename; string asmCommand = ss.str(); @@ -1823,13 +1823,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 = 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; const char *targetPreprocId = NULL; switch (params.targetPlatform)