From ea3e661db5ad8286f7fb8da7f585d94f6332090d Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 9 Feb 2016 13:02:22 +0100 Subject: [PATCH] Fixed: Compilation of bin2c (replaced _splitpath and _makepath by something more portable) --- code/tool/bin2c/bin2c.cpp | 48 +++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/code/tool/bin2c/bin2c.cpp b/code/tool/bin2c/bin2c.cpp index 7f8538d9b..9782af119 100644 --- a/code/tool/bin2c/bin2c.cpp +++ b/code/tool/bin2c/bin2c.cpp @@ -14,9 +14,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -// bin2c.cpp : Defines the entry point for the console application. -// - #include #include #include @@ -25,22 +22,55 @@ int main(int argc, char* argv[]) { if (argc<2) { - printf ("bin2c [filename.bin] [filename.c]\n"); + printf ("bin2c [filename.c]\n"); } else { - char sDir[256]; - char sPath[256]; + // path and filename but without extension + char sPathWithoutExtension[256]; + + // basename of file char sName[256]; - char sExt[256]; - _splitpath (argv[1], sDir, sPath, sName, sExt); + + // copy fullpath from command-line + strcpy(sPathWithoutExtension, argv[1]); + + char *tmpExt = strrchr(sPathWithoutExtension, '.'); + + // remove extension + if (tmpExt) *tmpExt = 0; + + // look for last directory separator + const char *tmpName1 = strrchr(sPathWithoutExtension, '/'); +#ifdef _WIN32 + const char *tmpName2 = strrchr(sPathWithoutExtension, '\\'); +#else + const char *tmpName2 = NULL; +#endif + + // take last separator + const char *tmpName = tmpName1 > tmpName2 ? tmpName1:tmpName2; + + // keep only path + if (tmpName) + { + // computes position in path + size_t pos = tmpName - sPathWithoutExtension; + + // copy basename + strcpy(sName, sPathWithoutExtension+pos+1); + } char sOutput[256]; + if (argc>2) + { strcpy (sOutput, argv[2]); + } else { - _makepath (sOutput, sDir, sPath, sName, ".cpp"); + strcpy(sOutput, sPathWithoutExtension); + strcat(sOutput, ".cpp"); } FILE *pIn=fopen( argv[1], "rb");