From 51c46a106e551469c1ed3695f498f16ea7b1a949 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 23 Oct 2011 17:56:23 -0700 Subject: [PATCH] plPythonPack compiling and running on Linux. --- .../Plasma/Apps/plPythonPack/CMakeLists.txt | 2 +- Sources/Plasma/Apps/plPythonPack/main.cpp | 56 ++++++++++++++----- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/Sources/Plasma/Apps/plPythonPack/CMakeLists.txt b/Sources/Plasma/Apps/plPythonPack/CMakeLists.txt index 3fd9cf70..ddc18ed3 100644 --- a/Sources/Plasma/Apps/plPythonPack/CMakeLists.txt +++ b/Sources/Plasma/Apps/plPythonPack/CMakeLists.txt @@ -13,7 +13,7 @@ set(plPythonPack_HEADERS ) add_executable(plPythonPack ${plPythonPack_SOURCES} ${plPythonPack_HEADERS}) -target_link_libraries(plPythonPack CoreLib CoreLibExe plFile) +target_link_libraries(plPythonPack CoreLib CoreLibExe plFile plUnifiedTime) if(PYTHON_DEBUG_LIBRARY) target_link_libraries(plPythonPack debug ${PYTHON_DEBUG_LIBRARY}) diff --git a/Sources/Plasma/Apps/plPythonPack/main.cpp b/Sources/Plasma/Apps/plPythonPack/main.cpp index 82a25b1b..2fc5af5e 100644 --- a/Sources/Plasma/Apps/plPythonPack/main.cpp +++ b/Sources/Plasma/Apps/plPythonPack/main.cpp @@ -48,10 +48,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include -#include +#if HS_BUILD_FOR_WIN32 +# include + +# define getcwd _getcwd +# define chdir _chdir + +# ifndef MAXPATHLEN +# define MAXPATHLEN MAX_PATH +# endif +#elif HS_BUILD_FOR_UNIX +# include +# include +#endif static const char* kPackFileName = "python.pak"; -static const char* kGlueFile = ".\\plasma\\glue.py"; +#if HS_BUILD_FOR_WIN32 + static const char* kGlueFile = ".\\plasma\\glue.py"; +#else + static const char* kGlueFile = "./plasma/glue.py"; +#endif static char* glueFile = (char*)kGlueFile; void WritePythonFile(std::string fileName, std::string path, hsStream *s) @@ -267,16 +283,22 @@ void FindSubDirs(std::vector &dirnames, const char *path) // adds or removes the ending slash in a path as necessary std::string AdjustEndingSlash(std::string path, bool endingSlash = false) { +#if HS_BUILD_FOR_WIN32 + char slash = '\\'; +#else + char slash = '/'; +#endif + std::string retVal = path; bool endSlashExists = false; char temp = path[path.length()-1]; - if (temp == '\\') + if (temp == slash) endSlashExists = true; if (endingSlash) { if (!endSlashExists) - retVal += "\\"; + retVal += slash; } else { @@ -294,17 +316,23 @@ std::string AdjustEndingSlash(std::string path, bool endingSlash = false) // appends partialPath onto the end of fullPath, inserting or removing slashes as necesssary std::string ConcatDirs(std::string fullPath, std::string partialPath) { +#if HS_BUILD_FOR_WIN32 + char slash = '\\'; +#else + char slash = '/'; +#endif + bool fullSlash = false, partialSlash = false; char temp = fullPath[fullPath.length()-1]; - if (temp == '\\') + if (temp == slash) fullSlash = true; temp = partialPath[0]; - if (temp == '\\') + if (temp == slash) partialSlash = true; std::string retVal = ""; if (!fullSlash) - retVal = fullPath + "\\"; + retVal = fullPath + slash; if (partialSlash) { std::string temp = ""; @@ -346,7 +374,7 @@ void PackDirectory(std::string dir, std::string rootPath, std::string pakName, s printf("\nCreating %s using the contents of %s\n",pakName.c_str(),dir.c_str()); printf("Changing working directory to %s\n",rootPath.c_str()); - if (_chdir(rootPath.c_str())) + if (chdir(rootPath.c_str())) { printf("ERROR: Directory change to %s failed for some reason\n",rootPath.c_str()); printf("Unable to continue with the packing of this directory, aborting...\n"); @@ -428,12 +456,12 @@ void PrintUsage() printf(" must be a relative path to the current working directory\n"); } -void main(int argc, char *argv[]) +int main(int argc, char *argv[]) { printf("The Python Pack Utility\n"); - char buffer[_MAX_PATH]; - _getcwd(buffer,_MAX_PATH); + char buffer[MAXPATHLEN]; + getcwd(buffer, MAXPATHLEN); std::string baseWorkingDir = buffer; // are they asking for usage? @@ -445,14 +473,14 @@ void main(int argc, char *argv[]) || (temp == "-h") || (temp == "/h")) { PrintUsage(); - return; + return -1; } } // wrong number of args, print usage if (argc > 2) { PrintUsage(); - return; + return -1; } std::vector dirNames; @@ -476,4 +504,6 @@ void main(int argc, char *argv[]) { PackDirectory(dirNames[i],rootPath,rootPath+dirNames[i]+".pak",dirNames); } + + return 0; }