Mercurial > hg > openttd
changeset 4379:e96444d2a9fb draft
(svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
-Fix r6096: detect for PATHSEP on WIN32 or WIN64, not UNIX
(Windows compilers define either one, while other compilers don't define a thing)
author | truelight <truelight@openttd.org> |
---|---|
date | Fri, 25 Aug 2006 12:26:34 +0000 |
parents | 77ae86063736 |
children | dd585851c222 |
files | stdafx.h strgen/strgen.c |
diffstat | 2 files changed, 23 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/stdafx.h +++ b/stdafx.h @@ -173,12 +173,12 @@ # endif #endif /* WIN32 || __OS2__ || WIN64 */ -#if defined(UNIX) +#if defined(WIN32) || defined(WIN64) || defined(__OS2__) +# define PATHSEP "\\" +# define PATHSEPCHAR '\\' +#else # define PATHSEP "/" # define PATHSEPCHAR '/' -#else -# define PATHSEP "\\" -# define PATHSEPCHAR '\\' #endif typedef unsigned char byte;
--- a/strgen/strgen.c +++ b/strgen/strgen.c @@ -1,9 +1,5 @@ /* $Id$ */ -#if !(defined(WIN32) || defined(WIN64) || defined(__CYGWIN__)) -#define UNIX -#endif - #include "../stdafx.h" #include "../macros.h" #include "../string.h" @@ -1227,6 +1223,22 @@ return buf; } +#if defined(__MINGW32__) || defined(__CYGWIN__) +/** + * On MingW, it is common that both / as \ are accepted in the + * params. To go with those flow, we rewrite all incoming / + * simply to \, so internally we can safely assume \. + */ +static inline char *replace_pathsep(char *s) +{ + char *c; + + for (c = s; *c != '\0'; c++) if (*c == '/') *c = '\\'; + return s; +} +#else +static inline char *replace_pathsep(char *s) { return s; } +#endif int CDECL main(int argc, char* argv[]) { @@ -1272,12 +1284,12 @@ src_dir = dest_dir = "."; if (argc > 2 && (strcmp(argv[1], "-s") == 0 || strcmp(argv[1], "--source_dir") == 0)) { - src_dir = dest_dir = argv[2]; // if dest_dir is not specified, it equals src_dir + src_dir = dest_dir = replace_pathsep(argv[2]); // if dest_dir is not specified, it equals src_dir argc -= 2, argv += 2; } if (argc > 2 && (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "--dest_dir") == 0)) { - dest_dir = argv[2]; + dest_dir = replace_pathsep(argv[2]); argc -= 2, argv += 2; } @@ -1307,16 +1319,11 @@ _masterlang = false; ParseFile(pathbuf, true); MakeHashOfStrings(); - ParseFile(argv[1], false); // target file + ParseFile(replace_pathsep(argv[1]), false); // target file if (_errors) return 1; /* get the targetfile, strip any directories and append to destination path */ -#if defined(__MINGW32__) || defined (__CYGWIN__) - /* Under mingw32 and cygwin, we enter / via the Makefile, not the expected \ */ - r = strrchr(argv[1], '/'); -#else r = strrchr(argv[1], PATHSEPCHAR); -#endif mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : argv[1]); /* rename the .txt (input-extension) to .lng */