summaryrefslogtreecommitdiff
path: root/strgen
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-25 12:26:34 +0000
committertruelight <truelight@openttd.org>2006-08-25 12:26:34 +0000
commitbd80b4fd19532248f807eb6edcf991d4f024be48 (patch)
treeadf6d1b2b953c70b068bbaee2df79fe6a7ff548b /strgen
parente095b7441f96f9c17d77b7391ef8d2ce22d66a13 (diff)
downloadopenttd-bd80b4fd19532248f807eb6edcf991d4f024be48.tar.xz
(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)
Diffstat (limited to 'strgen')
-rw-r--r--strgen/strgen.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/strgen/strgen.c b/strgen/strgen.c
index 6a0dbf080..cb94a4463 100644
--- 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 @@ static inline char *mkpath(char *buf, size_t buflen, const char *path, const cha
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 @@ int CDECL main(int argc, char* argv[])
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 @@ int CDECL main(int argc, char* argv[])
_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 */